Makefile中的Foreach函数

时间:2015-02-09 04:04:59

标签: linux makefile

我试图使用以下内容在makefile中演示foreach函数的reault:

dirs := ../../Downloads ../../Documents ../special-var ../subdir-test

files := $(foreach dir,$(dirs),$(wildcard $(dir)/*))

all : ; @echo all-files: $(files)

执行时我遇到以下错误:

/bin/sh: -c: line 0: syntax error near unexpected token `('
/bin/sh: -c: line 0: `echo all-files:
../../Downloads/install svnentos6.mp4 
../../Downloads/Abacus-Fees.xls 
../../Downloads/DiskOnRAM 
../../Downloads/Device Driver(FPGA) 
../../Downloads/GNU make and Makefiles.mp4 
../../Downloads/openwrt 
../../Downloads/Study Materials 
../../Downloads/Images 
../../Downloads/spread-src-4.4.0.tar.gz 

Makefile-foreach-func:7: recipe for target 'all' failed
make: *** [all] Error 1

如果我从dirs中删除前两个参数。然后它没有错误。或者如果我只将参数添加到一个目录(.../),那么也没有错误。但是对于两个目录up(../../)它会抛出错误。 有人可以帮我解决。感谢。

1 个答案:

答案 0 :(得分:2)

错误来自(shell运行)echo,而不是来自make。与以往一样,您需要引用包含括号等特殊字符的字符串(通常为pretty much everything)。