-1

I was trying to demonstrate reault of foreach function in makefile using the following:

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

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

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

while execution I have following error:

/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

If I remove first two arguments from dirs. Then it has no errors. Or if I am adding the argument to only one directory up (../) then also there is no error. But for two directory up (../../) it throws error. Can somebody help me to resolve. Thanks.

Abhijatya Singh
  • 642
  • 6
  • 23

1 Answers1

2

The error is from (the shell running) echo, not from make. As ever, you need to quote strings which contain special characters like parentheses (and generally pretty much everything).

Community
  • 1
  • 1
tripleee
  • 175,061
  • 34
  • 275
  • 318