3
votes

An excerpt of my Makefile is as follows:

.PHONY: product1 product2 product3
product1 product2 product3:
    $(MAKE) $(MAKEPRGFLAGS) -C $(LIBS_ROOT)/$@
    cp -r `ls -A | grep ".*\.a$"` $(PROJECT_PATH)/lib/ $(PRODUCT_PATH)/

After the compilation is done, when it tries to copy the .a files, it gives me this error:

/bin/sh: command substitution: line 0: unexpected EOF while looking for matching `"'

/bin/sh: command substitution: line 1: syntax error: unexpected end of file

I have taken care to provide the matching braces. What is wrong in my Makefile declaration?

I am running on cygwin in Windows. Editing Makefiles from Notepad++ with EOL conversion as windows format.

1

1 Answers

6
votes

$ has special meaning in makefiles. If you want to use it in a shell command, you have to double it.

product1 product2 product3:
    $(MAKE) $(MAKEPRGFLAGS) -C $(LIBS_ROOT)/$@
    cp -r `ls -A | grep ".*\.a$$"` $(PROJECT_PATH)/lib/ $(PRODUCT_PATH)/

But instead of using ls and grep, you could just give wildcards to ls:

    cp -r *.a .*.a $(PROJECT_PATH)/lib/ $(PRODUCT_PATH)/