Reputation: 61
I'm having some trouble in exporting the PATH I've modified inside the Makefile into the current Terminal. I'm trying to add to the PATH, the bin folder inside wherever the Makefile directory is.
Here's the relevant strip of the makefile:
PATH := $(shell pwd)/bin:$(PATH)
install:
mkdir -p ./bin
export PATH
echo $(PATH)
The echo prints it correctly but if I redo the echo in the terminal, the PATH remains the same.
Thanks in advance for the help.
Upvotes: 6
Views: 11612
Reputation: 1704
Perhaps you can rely on the user to do it for you. Note the quoting
install_hint:
@echo "Execute this command at your shell prompt:"
@echo "export PATH=$(shell pwd)/bin:\$$PATH"
Upvotes: 0
Reputation: 27053
What you are trying to do is not possible. Make is running in another process than the shell in your terminal. Changes to the environment in the make process does not transfer to the shell.
Perhaps you are confusing the effect of the export
statement. export
does not export the values of the variables from the make process to the shell. Instead, export
marks variables so they will be transfered any child processes of make. As far as I know there is no way to change the environment of the parent process (the shell where you started make is the parent process of the make process).
Perhaps this answers will make the concept of exporting variables to child processes a bit clearer.
Upvotes: 1
Reputation: 16790
If you're using GNU make, you need to explicitly export
the PATH variable to the environment for subprocesses:
export PATH := $(shell pwd)/bin:$(PATH)
install:
mkdir -p ./bin
export PATH
echo $(PATH)
Upvotes: 6