【问题标题】:Why GNU make removes intermediate targets when using pattern rules?为什么 GNU make 在使用模式规则时会删除中间目标?
【发布时间】: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创建的文件?

【问题讨论】:

    标签: makefile gnu-make


    【解决方案1】:

    根据“中间文件”的定义,您不能拥有由显式规则(“没有模式”的规则)创建的中间文件。

    请参阅Chains of Implicit Rules 部分以了解此功能。如果您有具体问题,请更新您的问题。

    【讨论】:

      猜你喜欢
      • 2013-06-13
      • 1970-01-01
      • 1970-01-01
      • 2022-12-02
      • 1970-01-01
      • 1970-01-01
      • 2012-02-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多