Adding directory to PATH through Makefile

makefile set environment variable from file
makefile relative path
makefile current directory
set path in makefile windows
makefile directory
makefile export
how to set java_home in makefile
makefile set variable from command

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.

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)

How I could add dir to $PATH in Makefile?, Did you try export directive of Make itself (assuming that you use GNU Make)? export PATH := bin:$(PATH) test all: x. Also, there is a bug in you  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:

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.

linux - How I could add dir to $PATH in Makefile?, If it prints the expected value then, I guess, you've set PATH variable somewhere earlier in your Makefile, or in a shell that invoked Make. To add a new path, simply click on New and it’ll add a new line to the bottom of the list. If you know the path, simply type it in or copy and paste it. If you prefer, you can also click Browse and then navigate to the desired path. To edit any path, simply select it and then click on the Edit button.

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"

Adding directory to PATH through Makefile - unix - csharp, 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  I'm trying to learn how to use makefiles, and this is my attempt at making a makefile that compiles source files in a source directory (src/) into object files that are created in a bin directory.

Setting environment variables in Makefile, How do I set an environment variable in a Makefile? JAVA_HOME=/usr/jdk/​jdk1.5.0_06 export ANT_HOME JAVA_HOME PATH echo $$ANT_HOME echo  The $(OUT)/.f rule uses the GNU Make function $(dir FILE) to extract the directory portion of the target (which is the path to the .f file) and passes that directory to mkdir. The only disadvantage here is that it\'s necessary to specify the .f files for every rule that builds a target in a directory that might need creating.

How to get a Makefile directory path « timmurphy.org, Sometimes in a Makefile you need to reference something from the directory where the Makefile lives. $(PWD) won't work in this instance, since  Append dir to the prefix specified previously with -iprefix, and add the resulting directory to the include search path. -iwithprefixbefore puts it in the same place -I would; -iwithprefix puts it where -idirafter would.

Makefile Basics (GNU Coding Standards), So it is a good idea to set the suffix list explicitly using only the suffixes you need in the particular Don't assume that . is in the path for command execution.

Comments
  • might have better luck asking at unix.stackexchange.com
  • Thanks for the tip, gonna try that @Crayon Violent
  • @Crayon: Build systems are explicitly a programming topic, and make questions---while probably acceptable on unix.SE are better on Stack Overflow.
  • He doesn't want to export it to subprocesses, but to the 'superprocess' instead.
  • While you're right that a make process can't change the environment of its parent process (as far as I know), the export PATH statement here is part of a recipe, and thus not treated as make syntax, but executed in a subshell as shell syntax.