我不知道這是否會滿足您的要求,但在這裏有雲:
parent.make:
export myfunc1 = my arg is $1
export myfunc2 = $(value myfunc1)
$(info parent testing myfunc1: $(call myfunc1,parent))
all: ; $(MAKE) -f child.make
child.make:
$(info child testing myfunc2: $(call myfunc2,child))
nullrule: ; @true
編輯:
好的,這個怎麼樣:
child.make:
myfunc1=$(myfunc2)
$(info child testing myfunc1: $(call myfunc1,child))
nullrule: ; @true
編輯:
沒有這麼快。看看這個:
parent.make:
myfunc_base = my arg is $1
export myfunc = $(value myfunc_base)
$(info parent testing myfunc: $(call myfunc_base,parent))
all: ; @$(MAKE) -f child.make
child.make:
$(info child testing myfunc: $(call myfunc,child))
nullrule: ; @$(MAKE) -f grandchild.make
grandchild.make:
$(info grandchild testing myfunc: $(call myfunc,grandchild))
nullrule: ; @true
這適用於任何修改都到child.make
或grandchild.make
。它確實需要parent.make
呼叫myfunc_base
而不是myfunc
;如果這是一個問題,那麼有一種解決辦法,可能不止一個。
一種可能性,我們把定義成什麼叫parent
,它實際上不會在所有被稱爲:
grandparent.make:
myfunc_base = my arg is $1
export myfunc = $(value myfunc_base)
all: ; @$(MAKE) -f child.make
父。令:
$(info parent testing myfunc: $(call myfunc,parent))
all: ; @$(MAKE) -f child.make
我知道這可能不是可行的,因爲myfunc
的定義可能需要parent.make
規定的其他事情。看看這是否適合你的情況;有可能是另一種方式......
這是一個巧妙的方法。然而,它並沒有真正解決我當前的問題,因爲我既需要父母和孩子做才能夠指使用同一名稱的功能。 (這是一個預先存在的,絕對的,龐大而複雜的make設置)。我的後備選項是在一個單獨的文件中只定義這些功能和針對每submake實例文件,但也不太理想。 – mtoossi
關於你的編輯,這是不是真的實用。有許多功能,每個添加2個額外的行太冗長。此外,有幾個級別的運行子製造使這進一步複雜化。無論如何,我會接受你的答案,因爲它似乎是唯一可用的選擇! – mtoossi