Adding directory to PATH through Makefile

Bruno picture Bruno · Apr 17, 2011 · Viewed 10.8k times · Source

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.

Answer

Eric Melski picture Eric Melski · Apr 17, 2011

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)