2015-08-22 43 views
0

一個Makefile是:

all : foo ; 


# A 'DEFAULT' special-target, providing a recipe to execute for target 'foo'. 
.DEFAULT : 
    @echo '[email protected] is: "[email protected]"' 
    @echo '$$< is: "$<"' 



執行,我得到:

[email protected] is: "foo" 
$< is: "foo" 


爲什麼$<[email protected]擴展到相同的目標?

請記住,我們在這裏度過了:

  1. 的文件foo,使正在執行的配方。 (因此,[email protected]的擴展是OK)
  2. 目標foo根本沒有先決條件。 (因此,$<應擴展爲空的字符串)。



爲了使它更荒謬的,讓我們嘗試下面的Makefile:

.DEFAULT : 
    @echo '$$< is "$<"' 
    @echo '[email protected] is "[email protected]"' 


運行,我們得到:

$ make .DEFAULT 
$< is ".DEFAULT" 
[email protected] is ".DEFAULT" 


真的,我們可以證明這$<[email protected]擴大到相同的字符串(.DEFAULT),當目標也沒有給任何先決條件,開始用?

回答

1

因爲foo是暗含的前提條件.DEFAULT$< will include implicit prerequisites

第一個先決條件的名稱。如果目標從隱式規則中獲得配方,這將是隱式規則添加的第一個先決條件(請參閱隱式規則)。