2013-10-06 61 views
0

我有一個包含另一個makefile的Makefile,比如CommonMakefile。有一個變量,我想用一個值作爲前綴(參見附加使用+=)保持值的其餘值不變。如何爲gmake變量加上前綴

V = value1 # set in CommonMakefile that is included 

V = value0 $(V) # I want to prefix value0 to V 

# rule defined in CommonMakefile that is included 
whatsV: 
    echo $V # first char is a <TAB> here 

我該怎麼做?

期待:

$ gmake whatsV 
value0 value1 

實際:

$ gmake whatsV 
Makefile:3: *** Recursive variable `V' references itself (eventually). Stop. 

PS:我而不是/拒收要換CommonMakefile。

回答

0

這是行不通的:

V = value0 $(V) 

因爲這裏Vrecursively expanded variable,它不能在其本身來定義。但是,將其更改爲簡單擴展型變量

V := value0 $(V) # <-- Note the colon 

,並如預期它會奏效。

+0

感謝@Beta的答案和鏈接。另外,從鏈接中,[Reading Makefiles](http://www.gnu.org/software/make/manual/make.html#Reading-Makefiles)部分有一個註釋:對於附加運算符'+ = ',如果變量先前被設置爲簡單變量(':='),則右側被視爲立即數,否則爲延遲。 – vapace