我有一个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”。
我如何有条件地追加到一个变量中?
target: VARIABLE = value
语法是分配目标特定变量的方式。哪个LIST
变量扩展取决于您所在的目标命令脚本。请注意,由于此原因,只能从命令脚本内部引用目标特定变量(甚至不能在先决条件行中引用它们)。 - Dan Moulding