Take the 2-minute tour ×

How to get the invoking target of the gnu makefile?

for example, I invoke the makefile with the following command line:

make a-target

How can I get the invoking target "a-target" in the makefile to assign it to a variable?

further more, if more than one target is specified in cmd line:

make target1 target2 ...

How to get all of them?

share|improve this question
add comment

2 Answers

The variable MAKECMDGOALS contains the list of targets that were specified on the command line, no matter how many (it's empty if there were none).

share|improve this answer
add comment

Maybe you need $@?

See http://www.gnu.org/software/make/manual/make.html#Automatic-Variables for more details.

share|improve this answer
add comment

Your Answer


