有条件地附加到Makefile目标内的变量

时间:2010-01-27 17:16:43

标签: variables makefile gnu-make

我有一个看起来有点像这样的GNU Makefile:

LIST = item1

.PHONY: targetMain targetA targetB preA preB

targetMain:
# DO all the work in here
    echo $(LIST)

targetA: preA targetMain
targetB: preB targetMain

preA:
LIST += itemA

preB:
LIST += itemB

我的想法是运行make targetA或make targetB。他们两个都做了非常类似的事情,但有一个不同的项目列表。问题是变量没有有条件地附加到,它总是附加到,这意味着我的输出始终是“item1 itemA itemB”。

如何有条件地附加到变量?

1 个答案:

答案 0 :(得分:7)

LIST = item1

.PHONY: targetMain targetA targetB

targetMain:
# DO all the work in here
    echo $(LIST)

targetA: LIST+=itemA
targetB: LIST+=itemB

targetA targetB: targetMain
相关问题