You need to remember that the "makefile" part of make, is separate from the "shell" part.
Once you're inside the recipe for the makefile it's all shell commands. That means you can't set a makefile variable from within it.
There are ways to get around this however, using the $(shell) and $(eval) makefile commands.
https://www.gnu.org/software/make/manual/html_node/Shell-Function.html
https://www.gnu.org/software/make/manual/html_node/Eval-Function.html
In your case something like this could work. The eval
command evaluates the remaining text AS makefile (even when inside a recipe), so we set the Makefile variable profile
to the result of a shell
command. In there, you can make your bash assertions and echo out whatever you want the variable to be.
Only then will your change to the makefile variable actually occur.
set_vars:
$(eval profile := $(shell [ "${profile}" = "" ] && echo 'test' || echo 'Profile Exists')
echo $(profile);
On the other hand, you could instead, convert your Makefile variable to a bash variable and manipulate it that way:
set_vars:
PROFILE=${profile}
if [ $PROFILE = "" ]; then \
PROFILE="test"; \
else \
echo "Profile exists";\
fi
echo $PROFILE;
Hope this helps!