bra*_*amp 3 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
Run Code Online (Sandbox Code Playgroud)
我的想法是运行make targetA或make targetB.他们两个都做了非常类似的事情,但有一个不同的项目列表.问题是变量没有有条件地附加到,它总是附加到,这意味着我的输出始终是"item1 itemA itemB".
我如何有条件地附加到变量?
小智 8
LIST = item1
.PHONY: targetMain targetA targetB
targetMain:
# DO all the work in here
echo $(LIST)
targetA: LIST+=itemA
targetB: LIST+=itemB
targetA targetB: targetMain
Run Code Online (Sandbox Code Playgroud)