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 使用include指令和target特定变量生成文件变量_Variables_Makefile_Include_Target - Fatal编程技术网

Variables 使用include指令和target特定变量生成文件变量

Variables 使用include指令和target特定变量生成文件变量,variables,makefile,include,target,Variables,Makefile,Include,Target,这是一个非常简单的测试,我无法理解我错在哪里: 文件制作公司 MSG = I am myprog: USE_FOO = 1 ifeq ($(USE_FOO), 1) MSG += using foo else MSG += not using foo endif 文件生成文件 include Makefile.inc all: myprog myprog: @echo "USE_FOO = $(USE_FOO)" @echo $(MSG) 我得到: $>

这是一个非常简单的测试,我无法理解我错在哪里:

文件制作公司

MSG = I am

myprog: USE_FOO = 1

ifeq ($(USE_FOO), 1)
  MSG += using foo
else
  MSG += not using foo
endif
文件生成文件

include Makefile.inc

all: myprog

myprog:
    @echo "USE_FOO = $(USE_FOO)"
    @echo $(MSG)
我得到:

$> make
USE_FOO = 1
I am not using foo

请告诉我,为什么我的消息不是“我正在使用foo”

在目标
myprog
的上下文中,没有对
ifeq
进行评估,因此评估结果为false,消息设置为“我没有使用foo”

您可以改为使用
文件Makefile.inc

MSG = I am not using foo

myprog: USE_FOO = 1
myprog: MSG=I am using foo

为什么在include Makefile中指定了目标名称?因为我只想对该目标使用foo。在我的实际程序中,我有几个目标,其中只有两个需要使用foo。我只想将变量USE\u FOO设置为1,以简化我的makefile。根据下面的答案,似乎拥有一些特定于目标的变量的唯一方法是使用以下语法:target:assignment谢谢你的回答。使用_FOO变量将变得无用。我将使用语法:target:assignment分配所有特定于目标的变量