Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding directory to PATH through Makefile

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.

like image 430
Bruno Avatar asked Apr 17 '11 20:04

Bruno


2 Answers

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)
like image 196
Eric Melski Avatar answered Sep 21 '22 23:09

Eric Melski


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.

like image 28
Lesmana Avatar answered Sep 19 '22 23:09

Lesmana