I'm trying out GNU Make grouped targets and seem to misunderstand something, because the targets are not grouped as I'd expect. Here is my makefile:
all: foo bar
.PHONY: foo bar
foo bar &:
@echo grouped target run for \"target\" $@
And output:
$ make
grouped target run for "target" foo
grouped target run for "target" bar
The recipe is run for each target, hence not grouped. What am I missing here?
GNU Make version 4.2.1.
$@ is the name of the target being generated, and $< the first prerequisite (usually a source file). You can find a list of all these special variables in the GNU Make manual.
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.
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.
When you type make or make [target] , the Make will look through your current directory for a Makefile. This file must be called makefile or Makefile . Make will then look for the corresponding target in the makefile. If you don't provide a target, Make will just run the first target it finds.
Never mind, turns out grouped target is a 4.3 feature.
Source (not official release notes): https://linuxreviews.org/GNU_make_4.3_Is_Released
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