55

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?

user1129682
  • 989
  • 8
  • 27
Justin
  • 693
  • 1
  • 5
  • 7

2 Answers2

88

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

Petr
  • 62,528
  • 13
  • 153
  • 317
Beta
  • 96,650
  • 16
  • 149
  • 150
20

Maybe you need $@?

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

Vlad
  • 35,022
  • 6
  • 77
  • 199