2017-04-19 52 views
0

我有如下所示生成文件:爲什麼在使用模式規則時,GNU make會刪除中間目標?

.PHONY: all 
all: foo_1.txt foo_2.txt foo_xxx.txt 

.PHONY: clean 
clean: 
     rm -f foo_* bar_* 

foo_%.txt: bar_%.txt 
     cp $< [email protected] 

#.PRECIOUS: bar_%.txt 
bar_%.txt: 
     touch [email protected] 

bar_2.txt: 
     touch [email protected] 

的「使所有」的輸出如下因素使用圖案由規則創建

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(在代碼中是故意註釋掉的行)來抑制。

爲什麼默認情況下已刪除模式的規則創建的中間文件以及無模式規則創建的文件不是?

回答

1

通過「中間文件」的定義,不能有由顯式規則(規則「沒有模式」)創建的中間文件。

要了解此功能,請參閱關於Chains of Implicit Rules的部分。如果您有具體問題,請更新您的問題。

相關問題