2011-10-17 28 views
2

我需要將a user-defined GNU make function(即a recursively expanded makefile variable)導出到子製作。然而,make似乎將所有這些變量擴展爲簡單的擴展變量,這使得它們無用。將遞歸製作文件變量導出到子製作

下面是一個例子:

「parent.make」 的內容:

export myfunc = my arg is $1 
$(info parent testing myfunc: $(call myfunc,parent)) 
all: ; $(MAKE) -f child.make 

「child.make」 的內容:

$(info child testing myfunc: $(call myfunc,child)) 
nullrule: ; @true 

暗戰「讓-f父。使「產生以下輸出:

parent testing myfunc: my arg is parent 
make -f child.make 
child testing myfunc: my arg is 

Parent將myfunc導出爲包含「my arg is」的簡單擴展變量,並將其作爲函數使用。

回答

0

我不知道這是否會滿足您的要求,但在這裏有雲:

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.makegrandchild.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規定的其他事情。看看這是否適合你的情況;有可能是另一種方式......

+0

這是一個巧妙的方法。然而,它並沒有真正解決我當前的問題,因爲我既需要父母和孩子做才能夠指使用同一名稱的功能。 (這是一個預先存在的,絕對的,龐大而複雜的make設置)。我的後備選項是在一個單獨的文件中只定義這些功能和針對每submake實例文件,但也不太理想。 – mtoossi

+0

關於你的編輯,這是不是真的實用。有許多功能,每個添加2個額外的行太冗長。此外,有幾個級別的運行子製造使這進一步複雜化。無論如何,我會接受你的答案,因爲它似乎是唯一可用的選擇! – mtoossi

3

是否有共同的原因變量和函數不能被放入由父母和孩子的makefile都包含一個單獨的makefile理由嗎?