1 foreach
# Makefile
all:
names = a b c d
files := $(foreach n,$(names),$(n).o)
demo:
通过foreach遍历names,每个值存到n中,并通过表达式$(n).o输出,多个值则以空格隔开
2 for
# Makefile
all:
names = a b c d
files := $(foreach n,$(names),$(n).o)
demo:
cd subdir && \
for x in $(files); do \
echo $$a; \
done
先进入subdir目录,然后遍历files中的每个值,输出【注意】要加空格\,这样会视为一条命令