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