我正在尝试使用模式规则编写一个生成文件来为多个源中的每一个生成多个输出文件。
我有以下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
由于*.all
不代表真实的输出文件,我尝试将它们标记为.PHONY
. 但是,运行make
then 不起作用:
$ ls
Makefile
$ make
make: Nothing to be done for `all'.
根据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'.
这似乎是在假装%.all
遵守规则,但跳过了尸体。
但是随着.PHONY
注释掉的行,Make 运行目标,但随后自发地决定删除输出文件:
$ 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
据make -d
,它说:
Removing intermediate files...
最小的例子
给出异常行为的最小示例:
%.all: %.out
@echo Made $*
%.out:
touch $@
我希望运行make somefile.all
会导致它创建文件somefile.out
,但它会被删除:
$ make somefile.all
touch somefile.out
Made somefile
rm somefile.out