我有一个看起来有点像这样的GNU Makefile: LIST = item1.PHONY: targetMain targetA targetB preA preBtargetMain:# DO all the work in here echo $(LIST)targetA: preA targetMaintargetB: preB targetMainpreA:LIST += itemApreB:LIST += i
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”.
我如何有条件地附加到变量?
LIST = item1
.PHONY: targetMain targetA targetB
targetMain:
# DO all the work in here
echo $(LIST)
targetA: LIST+=itemA
targetB: LIST+=itemB
targetA targetB: targetMain
