Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GNU Make grouped targets are not grouped

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.

like image 581
Andreas Avatar asked Apr 21 '20 14:04

Andreas


People also ask

What is $@ in makefile?

$@ 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.

What is the default target in a makefile?

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 are targets in 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.

How do I call a target in makefile?

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.


1 Answers

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

like image 69
Andreas Avatar answered Oct 12 '22 12:10

Andreas