views:

38

answers:

2

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?

A: 

Maybe you need $@?

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

Vlad
+1  A: 

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

Beta