2015-02-09 32 views
-1

我嘗試使用下面展示的foreach功能reault在生成文件:的foreach功能的Makefile

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 

如果我刪除前兩個參數迪爾斯。然後它沒有錯誤。或者,如果我只向一個目錄添加參數(../),那麼也沒有錯誤。但是對於兩個目錄(../../)它會引發錯誤。 有人可以幫我解決。謝謝。

回答

2

錯誤來自(殼運行)echo,而不是從make。與往常一樣,您需要引用包含括號等特殊字符的字符串(通常爲pretty much everything)。