我如何为gmake变量添加前缀

时间:2013-10-06 03:58:19

标签: makefile gnu-make

我有一个包含另一个makefile的Makefile,比如CommonMakefile。有一个变量我希望用一个值作为前缀( cf。使用+=追加)保持其余的值不变。

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。

1 个答案:

答案 0 :(得分:0)

这不起作用:

V = value0 $(V)

因为此处Vrecursively expanded variable,并且无法根据自身进行定义。但是将其更改为简单扩展变量

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

它将按预期工作。