18

When I run below command on shell, it works properly. but if I write it in a Makefile and call it with "make" command it doesn't work.

cp wpa_{cli,supplicant,passphrase,event} /usr/local/bin/

error after "make" command:

cp: cannot stat `wpa_{cli,supplicant,passphrase,event}': No such file or directory

What can i do to make it work with Makefile? I use Ubuntu 12.04. Same Makefile works on other linux distributions.

Necip Onur Uzun
  • 1,115
  • 3
  • 13
  • 16

3 Answers3

30

Make uses old-school Bourne shell (/bin/sh) by default which does not support brace expansion. Set the SHELL variable in your makefile to /bin/bash if it's not already set.

Just add a line in the top of your makefile with:

SHELL=/usr/bin/bash

(please confirm your bash path).

Alberto
  • 499
  • 4
  • 23
Steve K
  • 2,124
  • 16
  • 19
1

As Steve K explains, it's a bashism. If you want to stick more closely to the standard, you can use a for loop without too much trouble.

for x in cli supplicant passphrase event; do cp -v wpa_$$x /usr/local/bin/; done

As usual for makefiles, put it all on one line or use backslashes to break it into a few lines. The double dollar sign indicates that make needs to pass the $ to the shell.

bk.
  • 6,068
  • 2
  • 24
  • 28
0

i like @bk 's answer since it stays within the conventions of the tool, but for reference, you could also directly call the bash shell for just one command to do the brace expansion:

wpa_files := $(shell /bin/bash -c 'echo wpa_{cli,supplicant,passphrase,event}')

target:
    cp $(wpa_files) /usr/local/bin/
ellemenno
  • 712
  • 5
  • 11