gpt4 book ai didi

makefile - 如何在 Makefile 配方中连接变量

转载 作者:行者123 更新时间:2023-12-05 03:23:57 24 4
gpt4 key购买 nike

我得到这个 Makefile:

LIST = foo bar                                                                  

$(LIST):
echo $@

当我运行 make targets 时,输出按预期工作:

$ make foo
echo foo
foo

$ make bar
echo bar
bar

但是如果我连接一个字符串 another-,只有 another-foo 有效:

LIST = foo bar

another-$(LIST):
echo $@
$ make another-foo 
echo another-foo
another-foo

$ make another-bar
make: *** No rule to make target 'another-bar'. Stop.

如何连接目标以扩展到变量中的所有值?

最佳答案

您观察到的行为是标准的:写作时

另一个-$(LIST)

make 只是将 $(LIST) 替换为其内容,生成 another-foo bar

也就是说,这与诸如 another-{foo,bar} 之类的 bash 大括号表达式无关。

然而,您可以通过执行以下操作来实现您想要的:

LIST = foo bar

$(addprefix another-,$(LIST)):
echo "$@"

关于makefile - 如何在 Makefile 配方中连接变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72410632/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com