I want to set a variable if it is empty. I tried in this way:
....
TEST := $(something)
...
TEST ?= $(something else)
The first $(somethi
Just in case anyone stumbled upon putting the condition in the rule itself. below how I did it, thought it might help others.
In Makefile
, suppose we have the following rule with check
target and we need to check whether var was passed.
check:
@[ "${var}" ] && echo "all good" || ( echo "var is not set"; exit 1 )
To test this out, run the following commands
$ make check
var is not set
make: *** [check] Error 1
$ make check var=test
all good
So, Now we can pass the variable value or a default value in case it was not passed to a bash script that will be responsible to do the logic. something like the following:
@[ "${var}" ] && ./b.sh ${var} || ./b.sh 'ss'
Here's below what b.sh
might look like, though you can add more logic to it.
#!/bin/sh
echo $1