3
votes

Considering this excerpt from the GNU make manual for PHONY targets:

Once this is done, make clean' will run the commands regardless of whether there is a file namedclean'.

Why am I not seeing my recipes executed, event though in the debug output make says it must remake those targets? Here is an example makefile to demonstrate the issue:

all:
    @echo Rule to build 'all'

.PHONY: clean a.clean b.clean
clean: a.clean b.clean
    @echo Cleaning toplevel

%.clean:
    @echo Cleaning $*

Here is the output - note there is no mention of Cleaning $*

make: Entering directory `/tmp'
Cleaning toplevel
make: Leaving directory `/tmp'

Here is the output from -d:

Considering target file `clean'.
 File `clean' does not exist.
  Considering target file `a.clean'.
   File `a.clean' does not exist.
   Finished prerequisites of target file `a.clean'.
  Must remake target `a.clean'.
 Successfully remade target file `a.clean'.
  Considering target file `b.clean'.
   File `b.clean' does not exist.
   Finished prerequisites of target file `b.clean'.
  Must remake target `b.clean'.
  Successfully remade target file `b.clean'.
 Finished prerequisites of target file `clean'.
Must remake target `clean'.
1

1 Answers

6
votes

From the same section of the manual:

Since it knows that phony targets do not name actual files that could be remade from other files, make skips the implicit rule search for phony targets (see Implicit Rules).

So yes, Make knows that it must "remake" a.clean and b.clean, but when looking for rules to do so, it does not consider your pattern rule. It finds no recipes for these targets, so it shrugs, considers the job done and moves on.

You can get around this by making the pattern rule a static pattern rule:

a.clean b.clean : %.clean :
    @echo Cleaning $*