在目标内部设置 make 变量
鉴于 GNU Make 3.81。
下面的 makefile
all:
echo before
TEST=1
echo after
产生“命令在第一个目标之前开始。停止”。在“TEST=1”行。
从另一侧向 TEST 添加“覆盖”,如下所示:
all:
echo before
override TEST=1
echo after
运行良好(之前和“之后”均“打印”)。
问题:
为什么“TEST=1”不行,而“override TEST=1”可以?
为什么目标命令中的“override TEST=1”没问题? Proba
Given GNU Make 3.81.
The below makefile
all:
echo before
TEST=1
echo after
yields "commands commence before first target. Stop." on "TEST=1" line.
From other side adding "override" to TEST as following:
all:
echo before
override TEST=1
echo after
runs fine (both before and "after" are "printed").
Questions:
Why "TEST=1" is not ok, while "override TEST=1" is ok?
Why "override TEST=1" inside target's command is fine? Proba
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的猜测是,它
会被解释为:
...这在 GNU make 中是完全有效的。
您可以简单地通过命名目标来修改每个目标的变量,然后像在 make 文件的全局部分中一样设置变量,如下所示:
这样,向 CFLAGS 添加某些内容或修改 CFLAGS 是很常见的 仅适用于单个目标文件...
注意: 但是,在目标的命令块中进行变量赋值是错误的语法正在尝试。
My guess would be that
gets interpreted as:
... which is perfectly valid in GNU make.
You can modify variables per-target simply by naming the target and then setting the variable as you would in the global section of the make file, such as this:
This way it is common-place to append something to or modify
CFLAGS
for just a single object file ...NOTE: However, it is wrong syntax to make a variable assignment within the command-block of a target as you were trying.