I am working on a Makefile
that gets executed in a Linux environment and Windows environment (through MINGW64). The script has a variable which is pointing to the shell command which should be used:
SHELL:=/usr/bin/env bash
Later on, that variable is being used to run a shell script:
${SHELL} ./utils/tests.sh
On Linux that works just fine but on Windows with MINGW64 (Git Bash) it fails because /usr/bin/env
is being replaced with C:/Program Files/Git/usr/local
and there is a space character in "Program Files" which breaks the path in the Makefile.
To solve the issue on Windows, I can put ${SHELL}
in quotes to make sure that the space character is kept:
"${SHELL}" ./utils/tests.sh
However, this is breaking on Linux environments because it becomes a string now and "/usr/bin/env bash"
is not executable.
So I came up with this solution:
ifeq ($(OS),Windows_NT)
"${SHELL}" ./utils/tests.sh
else
${SHELL} ./utils/tests.sh
endif
That's now working in both environments (Linux & MINGW64) but it comes with the downside of having 5 lines of code everywhere where I want to run a script. Ideally, I would like to assign the variable just once. I tried this but it doesn't work either:
ifeq ($(OS),Windows_NT)
SHELL:="/usr/bin/env" bash
else
SHELL:=/usr/bin/env bash
endif
test: clean build
${SHELL} ./utils/tests.sh
Does anyone have a clever solution to my problem?
CodePudding user response:
You could replace:
SHELL:=/usr/bin/env bash
with one of these (or with whatever path leads to Bash's executable):
SHELL:=/bin/bash
SHELL:=/usr/bin/bash
SHELL:=bash
which would eliminate the space from the equation.
That being said, you should also be able to run the commands directly, i.e.:
./utils/tests.sh
instead of:
${SHELL} ./utils/tests.sh
which would eliminate the need to set and use variable SHELL
altogether.