I would like to customize the shell for a Makefile, but I am running into trouble. Here is a MWE. I have a Makefile,
all: abc def
rm -f abc def
chmod +x my_shell.sh
make: Entering directory `<CONFIDENTIAL>'
./my_shell.sh: line 2: eval: -c: invalid option
eval: usage: eval [arg ...]
make: *** [abc] Error 2
make: Leaving directory `<CONFIDENTIAL>`
First, if you want to set a make variable to empty use
By adding the quotes you've actually set the variable to the literal string
'' (make is not the shell and does not do shell quote stripping).
.SHELLFLAGS variable was added in GNU make 3.82 so if your version is older than that, it won't work. If you have 3.82 or newer then it does work (I just tried it).
Lastly, as Jean-François points out you will problems if your command has escaped spaces. However, his solution of using
"$@" cannot work as-is, because then the entire command is seen as a single string.
A more reliable implementation of the script would be:
#!/bin/bash exec /bin/bash "$@"
And then do not modify
.SHELLFLAGS. Or else, do set
.SHELLFLAGS to empty and make your script:
#!/bin/bash exec /bin/bash -c "$@"