I have a makefile
that I want to run against both linux (debian/Ubuntu) and Windows/Cygwin.
I need to do something slightly different according to the running environment and I came out with the following piece of code which is supposed to store in the variable a string which is foo
if the OS is linux, otherwise foo.exe
:
EXECUTABLE_FILENAME=bash -c 'os_type=`uname`; if [ $os_type == "Linux" ]; then echo "foo"; else echo "foo.exe"; fi'
then I would like to use that variable in another one, something like:
GODEPBUILD=$(godep go build -o $(EXECUTABLE_FILENAME))
the previous one with/without the evaluation via $(...some stuff...)
(see below for all the tests I made to make this work)
finally I would like to "run" that command somewhere else in a task within the makefile
, something like:
build-all:
@echo -e "build my project"
$(GODEPBUILD)
I have tried many different combinations
- with/without
$(some stuff here)
, - with/without single quotes
'
, - with/without the bash "`"
- with/without the wrap
bash -c '...some commands here...'
but I get all sorts of bash errors e.g.:
invalid option -- 'c'
- the
go
compiler complainingEXECUTABLE_FILENAME
is empty with this message:flag needs an argument: -o
- silent ignore of the
$(GODEPBUILD)
(I believe because somehow it evaluates to an empty command)
I am doing this chain of steps because I need to wrap many commands of the go
toolchain into another tool called godep
, also I need to combine this with some specific features of the Operating System (e.g. the filename thing I am stuck with). I have defined many different "commands" of the go
toolchain at the beginning of the makefile
e.g.:
GODEP_VERSION=godep version
GODEPRESTORE=godep restore
GODEPTEST=godep go test -v
GOCLEAN=go clean
I call these "commands" inside the makefile
tasks like $(GODEP_VERSION)
(or -$(GODEP_VERSION)
if I need to ignore the stderr
) and for me it was nice to add the "build command" in a similar fashion.
The make
version is:
- 4.1 on Ubuntu
- 4.2.1 on Cygwin
Is this thing possible at all?
How could I achieve this combination of different "small scripts" to build the final command that make
should run inside a task?