58

How to get the invoking target of the GNU make Makefile?

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

make a-target 

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

Further more, if more than one target is specified on the command line:

make target1 target2 ... 

How do I get all of them?

2 Answers 2

94

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

Sign up to request clarification or add additional context in comments.

Comments

21

Maybe you need $@?

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

1 Comment

$@ is the current target, not the target that was specified on the command line as in the original question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.