Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the invoking target of makefile?

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?

like image 974
Justin Avatar asked Jul 08 '10 09:07

Justin


People also ask

What is the target in a makefile?

A simple makefile consists of "rules" with the following shape: target ... : dependencies ... command ... ... A target is usually the name of a file that is generated by a program; examples of targets are executable or object files.

What is makefile default target?

By default, the goal is the first target in the makefile (not counting targets that start with a period). Therefore, makefiles are usually written so that the first target is for compiling the entire program or programs they describe.

What is $@ in makefile?

The variable $@ represents the name of the target and $< represents the first prerequisite required to create the output file.


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

like image 144
Beta Avatar answered Sep 30 '22 19:09

Beta