Reputation: 63259
I am running make
on macOS
and it is not pleased with any local variables . Take this snippet intended to get the full path to the directory of the Makefile script
setup_for_run:
mkfile_path=$(abspath $(lastword $(MAKEFILE_LIST)))
mkfile_dir=$(dir $(mkfile_path))
echo "scriptdir=$(SCRIPT_DIR)"
export PATH=$($(SCRIPT_DIR)/.venv/bin:$(PATH))
The result of make setup_for_run
is:
$make setup_for_run
mkfile_path=/Users/steve/git/hercl/Makefile
mkfile_dir=
echo "scriptdir="
scriptdir=
export PATH=
So we see that none of the local variables are operational. What is the way to get them activated in the gnu make
installed by default on macOS
?
Upvotes: 0
Views: 414
Reputation: 5301
Make runs each command in a recipe in its own shell (unless declaring .ONESHELL
). Any modified state such as variables is cleared for each command. And, any variables set are never communicated outside make. For this purpose you're more likely to want to source
a bash script.
Make are for making files from other files.
There are several alternatives to set the variables:
# Global scope
VARIABLE := myglobal
# Target specific
mytarget: VARIABLE := targetspecific
# Prefix the command
myprefix:
VARIABLE=prefix env
Upvotes: 1