2015-06-20 28 views
0

Makefile的模板是如下有Makefile中很難理解$$$$(DIR $$$$ @):使用eval

# cc compile template, generate rule for dep, obj: (file, cc[, flags, dir]) 
define cc_template 

$$(call todep,$(1),$(4)): $(1) | $$$$(dir [email protected]) 

    @$(2) -I$$(dir $(1)) $(3) -MM $$< -MT "$$(patsubst %.d,%.o,[email protected]) [email protected]"> [email protected] 

$$(call toobj,$(1),$(4)): $(1) | $$$$(dir [email protected]) 

    @echo + cc $$< 

    $(V)$(2) -I$$(dir $(1)) $(3) -c $$< -o [email protected] 

ALLOBJS += $$(call toobj,$(1),$(4)) 

endef 

# compile file: (#files, cc[, flags, dir]) 
define do_cc_compile 

$$(foreach f,$(1),$$(eval $$(call cc_template,$$(f),$(2),$(3),$(4)))) 

endef 

我知道的eval將擴大兩倍,所以我們應該用另一種$。但是我們爲什麼要在這裏使用$$$$(dir [email protected])?我試圖理解這一點,但我失敗了。

回答

0

當解析文件時,它展開。如果它看到$$它將它擴展到$。因此$$$$將擴大到$$(兩美元)。 eval一旦申請,將要再次擴展到$。因此你需要4美元(注意$$$將擴展到$,接下來是$(的擴展,或者下一個字符碰巧是什麼,這可能會導致錯誤)