title: How to detect which the first Makefile in a include chain?
body: <p>Let's say I have a directory <code>~/dir1/dir2/dir3/</code> and a file <code>Makefile</code> in that directory with the contents</p>
  <pre class="lang-make prettyprint-override"><code>include ../Makefile
  </code></pre>
  <p><code>~/dir1/dir2/Makefile</code> has the same contents as <code>~/dir1/dir2/dir3/Makefile</code></p>
  <p>If I am allowed to control the contents of <code>~/dir1/Makefile</code>, and <code>make</code> was invoked in <code>~/dir1/dir2/dir3/</code>, How do I get the string <code>~/dir1/dir2/dir3/Makefile</code>(The first include file) for use as a variable in <code>~/dir1/Makefile</code>?</p>
  <p>Reproducible Example (as requested by MadScientist) :</p>
  <ol>
  <li>Any unix system</li>
  <li><code>mkdir -p ~/dir1/dir2/dir3</code></li>
  <li><code>cd ~/dir1/dir2/dir3</code></li>
  <li><code>echo 'include ../Makefile' &gt; Makefile</code></li>
  <li><code>cp ./Makefile ../Makefile</code></li>
  </ol>
  <p>Now we have a Makefile in <code>~/dir1/dir2/dir3/</code> and <code>~/dir1/dir2/</code> with the same declaration, i.e. an include declaration that includes the Makefile in the parent directory.</p>
  <p>If <code>make</code> is invoked in <code>~/dir1/dir2/dir3</code>, then the include chains finally stop at <code>~/dir1/Makefile</code></p>
  <p>How do I find the path of the first file in this chain of includes, i.e. <code>~/dir1/dir2/dir3/Makefile</code> for use as a variable in <code>~/dir1/Makefile</code>?</p>