我正在尝试将变量解释为for循环中的另一个变量,我无法弄清楚应该如何完成。我的测试是:
TEST= one two three
one := one1
two := two2
three := three3
all:
@echo $(TEST)
@for NUM in $(TEST) ; do \
echo $($$NUM) ; \
done ; exit 0
foo:
echo
最终结果:我有一些Makefile,其中包含一个指向一个中央makefile的include。我希望这些单独的makefile包含文件的变量以便连接在一起 - 但是不同的目录具有不同的文件。所以,。/ /中的makefile可能是: one:=“file0 file1 file2” 二:=“other0 other1 other2” 三:=“boo.txt blah.txt” 包括../main.mk
和./2/可能是 one:=“file0 file5 file6” 二:=“foo bar baz” 三:=“blah.txt” 包括../main.mk
答案 0 :(得分:1)
这不能像你写的那样工作。你正越过界限。
当你的shell循环运行时,make变量已经被扩展,所以你的循环体最终包含的是'echo;'。
如果你想获得预期的输出,你需要在制作级别进行循环。
类似的东西:
TEST= one two three
one := one1
two := two2
three := three3
define loop
$(foreach n,$(TEST),@echo $($n)
)
endef
all:
@echo $(TEST)
$(loop)
虽然我觉得应该有一种稍微简单的方法,但我现在还没有看到它。