Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I affect PATH in a makefile variable? Why is my example not working?

Tags:

At the beginning of a makefile I have this line :

PATH := $(PATH):/other/dir 

and this gives this error: Recursive variable 'PATH' references itself. What do I have to do so it works?

like image 932
Geo Avatar asked Oct 22 '09 07:10

Geo


People also ask

How do I set an environment variable in makefile?

Re: Setting Environment variable in MakefileTo get the shell to see one "$", you must use "$$" in the Makefile. 2.) Environment variables can only be inherited from parent to child processes, not vice versa. In this case, the parent process is the 'make' that is processing the Makefile.

What is VAR in makefile?

A variable is a name defined in a makefile to represent a string of text, called the variable's value. These values are substituted by explicit request into targets, prerequisites, commands, and other parts of the makefile.


2 Answers

GNU make (and many others) has two main ways of assigning values to variables. They differ according to the operator which you use. According to the documentation, a single equals sign (=) will cause a recursive expansion of the value, whereas a colon-equals (:=) will cause a simple expansion.

Your quoted code uses a := and so should cause a simple expansion. What you are seeing is an error message associated with a recursive expansion. I would expect that sort of error if you had something like this:

PATH = $(PATH):/other/dir 

Could the error be being caused by a different line in your makefile which you haven't quoted? If you're sure that your cut-and-pasting is correct, and that it is this line which is causing the problem, it would be helpful if we could see the whole, unedited makefile.

like image 85
Tim Avatar answered Sep 18 '22 16:09

Tim


Another possibility is to use the shell function:

PATH = $(shell printenv PATH):/other/dir

like image 36
J. A. Faucett Avatar answered Sep 21 '22 16:09

J. A. Faucett