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?
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.
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.
The variable $@ represents the name of the target and $< represents the first prerequisite required to create the output file.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With