[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: how to reference the directory where current Makefile resides ?
From: |
John Graham-Cumming |
Subject: |
Re: how to reference the directory where current Makefile resides ? |
Date: |
Mon, 21 May 2007 09:56:44 +0200 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040208 Thunderbird/0.5 Mnenhy/0.6.0.104 |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Pax Unix wrote:
> It sounds like you could use MAKEFILE_LIST inside Makefile:
>
> makefileDir := $(dir $(firstword $(MAKEFILE_LIST)))
>
> MAKEFILE_LIST contains the paths of all makefiles read (in order) during
> make's invocation. The above won't quite work, though, if someone
> causes a different file to be included before the Makefile you specified:
>
> make -f otherdir/preMakefile -f Makefile
>
> In this case, the above would echo 'otherdir/', not './' like I expect
> you want.
As you point out that isn't reliable because of the fact that
MAKEFILE_LIST gets appended any time a Makefile is loaded (e.g. -f or
include). If you want to work with MAKEFILE_LIST it must be done right
at the start of the Makefile you are in. My recommendation is that the
first line of the Makefile be:
CURRENT_MAKEFILE_LIST := $(MAKEFILE_LIST)
and then work with CURRENT_MAKEFILE_LIST.
If you do that the your makefileDir becomes:
makefileDir := $(dir $(firstword $(CURRENT_MAKEFILE_LIST)))
and is reliable.
John.
- --
John Graham-Cumming
address@hidden
Home: http://www.jgc.org/
Blog: http://www.jgc.org/blog/
New! UseTheSource: http://usethesource.com/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFGUVC8Lphrp73n/hARAuGgAJ9mjzcHXzFfSbkjNt4dEL+/4t7RCwCdHRXM
VnDjR+SvukWfz7/NyjebUDo=
=YqET
-----END PGP SIGNATURE-----