I'm trying to write a makefile to produce several output files for each of several sources, using pattern rules.
I have the following Makefile
(GNU Make 3.8.1):
all : foo.all bar.all
%.all : %.pdf %.svg
@echo Made $*
%.pdf :
touch $@
%.svg :
touch $@
.PHONY: foo.all bar.all
Since *.all
do not represent real output files, I tried marking them as .PHONY
. However, running make
then doesn't work:
$ ls
Makefile
$ make
make: Nothing to be done for `all'.
According to make -d
:
No implicit rule found for `all'.
Considering target file `foo.all'.
File `foo.all' does not exist.
Finished prerequisites of target file `foo.all'.
Must remake target `foo.all'.
Successfully remade target file `foo.all'.
Considering target file `bar.all'.
File `bar.all' does not exist.
Finished prerequisites of target file `bar.all'.
Must remake target `bar.all'.
Successfully remade target file `bar.all'.
Finished prerequisites of target file `all'.
Must remake target `all'.
Successfully remade target file `all'.
make: Nothing to be done for `all'.
which seems to be pretending to run the %.all
rules, but skipping the bodies.
But with the .PHONY
line commented out, Make runs the targets, but then spontaneously decides to delete the output files:
$ make
touch foo.pdf
touch foo.svg
Made foo
touch bar.pdf
touch bar.svg
Made bar
rm foo.pdf foo.svg bar.pdf bar.svg
According to make -d
, it says:
Removing intermediate files...
Minimal example
A minimal example giving anomalous behavior:
%.all: %.out
@echo Made $*
%.out:
touch $@
I expect running make somefile.all
to cause it to create the file somefile.out
, but it gets deleted:
$ make somefile.all
touch somefile.out
Made somefile
rm somefile.out