【发布时间】:2017-04-19 13:14:13
【问题描述】:
我有一个如下的生成文件:
.PHONY: all
all: foo_1.txt foo_2.txt foo_xxx.txt
.PHONY: clean
clean:
rm -f foo_* bar_*
foo_%.txt: bar_%.txt
cp $< $@
#.PRECIOUS: bar_%.txt
bar_%.txt:
touch $@
bar_2.txt:
touch $@
“make all”的输出如下
touch bar_1.txt
cp bar_1.txt foo_1.txt
touch bar_2.txt
cp bar_2.txt foo_2.txt
touch bar_xxx.txt
cp bar_xxx.txt foo_xxx.txt
rm bar_xxx.txt bar_1.txt
使用模式(bar_xxx.txt,bar_1.txt)的规则创建的中间文件最后被删除。我发现 .PRECIOUS 可以抑制这种行为(在代码中是有意注释掉的行)。
为什么默认去掉pattern的rule创建的中间文件,没有pattern的rule创建的文件?
【问题讨论】: