2013-10-29 48 views
3

考慮從GNU的摘錄進行手動對僞目標:請不執行食譜爲僞目標

一旦做到這一點,make clean' will run the commands regardless of whether there is a file named乾淨」。

爲什麼我看不到我的食譜執行,事件雖然在調試輸出使說它必須重拍這些目標?下面是一個例子生成文件來證明這個問題:

all: 
    @echo Rule to build 'all' 

.PHONY: clean a.clean b.clean 
clean: a.clean b.clean 
    @echo Cleaning toplevel 

%.clean: 
    @echo Cleaning $* 

這裏是輸出 - 注意,是沒有Cleaning $*

make: Entering directory `/tmp' 
Cleaning toplevel 
make: Leaving directory `/tmp' 

這裏提到的是從-d輸出:

Considering target file `clean'. 
File `clean' does not exist. 
    Considering target file `a.clean'. 
    File `a.clean' does not exist. 
    Finished prerequisites of target file `a.clean'. 
    Must remake target `a.clean'. 
Successfully remade target file `a.clean'. 
    Considering target file `b.clean'. 
    File `b.clean' does not exist. 
    Finished prerequisites of target file `b.clean'. 
    Must remake target `b.clean'. 
    Successfully remade target file `b.clean'. 
Finished prerequisites of target file `clean'. 
Must remake target `clean'. 

回答

6

From the same section of the manual

由於它知道虛假目標不會命名可能從其他文件重新創建的實際文件,因此可跳過隱式規則搜索虛假目標(請參閱隱式規則)。

所以是的,Make知道它必須「重拍」a.cleanb.clean,但是在尋找規則時,它不會考慮您的模式規則。它沒有發現這些目標的食譜,所以它聳聳肩,認爲工作已經完成並繼續前進。

您可以通過該模式繞過這個規則一靜態模式規則:

a.clean b.clean : %.clean : 
    @echo Cleaning $*