Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Variables 有条件地附加到Makefile目标内的变量_Variables_Makefile_Gnu Make - Fatal编程技术网

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

Variables 有条件地附加到Makefile目标内的变量,variables,makefile,gnu-make,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 我的想法是,我要么运行mak

我有一个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”


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

一点解释:这称为目标特定变量。它的工作方式是现在实际上有两个
列表
变量:一个用于targetA,另一个用于targetB<代码>目标:变量=值语法是指定目标特定变量的方式。两个
列表
变量中的哪一个展开取决于您所处的目标的命令脚本。注意,正因为如此,特定于目标的变量只能从命令脚本内部引用(甚至不能在prerequesites行中引用)。太好了,这似乎就是我想要的!谢谢,丹,我应该加上一些解释。:-)
LIST = item1

.PHONY: targetMain targetA targetB

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

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

targetA targetB: targetMain