Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the name of the makefile from the makefile

Tags:

makefile

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 
like image 721
hcs42 Avatar asked Sep 09 '09 14:09

hcs42


People also ask

What is makefile name?

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'.

Which is the correct way of passing the makefile with the name MyMake MK to the make command?

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.

What is $@ in makefile?

$@ 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.

What is Makefile_list?

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.


1 Answers

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.

like image 135
Michael Foukarakis Avatar answered Oct 18 '22 00:10

Michael Foukarakis