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.
Double dollar sign If you want a string to have a dollar sign, you can use $$ . This is how to use a shell variable in bash or sh . Note the differences between Makefile variables and Shell variables in this next example.
Bash brace expansion is used to generate stings at the command line or in a shell script. The syntax for brace expansion consists of either a sequence specification or a comma separated list of items inside curly braces "{}". A sequence consists of a starting and ending item separated by two periods "..".
In programming, curly braces (the { and } characters) are used in a variety of ways. In C/C++, they are used to signify the start and end of a series of statements. In the following expression, everything between the { and } are executed if the variable mouseDOWNinText is true.
The end of the variable name is usually signified by a space or newline. But what if we don't want a space or newline after printing the variable value? The curly braces tell the shell interpreter where the end of the variable name is.
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).
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With