How to get the name of the makefile in the makefile?
Thanks.
Note:
I would need that because I would like my makefile to call itself, but the makefile is not called Makefile, so I'd like to write something like this:
target: ($MAKE) -f ($MAKEFILENAME) other_target
By default, when make looks for the makefile, it tries the following names, in order: `GNUmakefile', `makefile' and `Makefile'. Normally you should call your makefile either `makefile' or `Makefile'.
However, if you pass in a makefile to make via make all --print-data-base MAKEFILES=MyMake.mk , then the first entry will be MyMake.mk . Therefore, the rule appears to be: look at the variable -*-command-variables-*- and determine if a makefile has been passed in.
$@ is the name of the target being generated, and $< the first prerequisite (usually a source file). You can find a list of all these special variables in the GNU Make manual.
MAKEFILE_LIST. Contains the name of each makefile that is parsed by make , in the order in which it was parsed. The name is appended just before make begins to parse the makefile. Thus, if the first thing a makefile does is examine the last word in this variable, it will be the name of the current makefile.
location = $(CURDIR)/$(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST)) WHERE_ART_THOU := $(location) $(warning $(WHERE_ART_THOU))
I also believe this is GNU make-specific, but I'm not too sure.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With