I am trying to do a simple thing:
TMPDIR ?= /tmp test: @echo $(TMPDIR)
This works if I run:
$ make test /tmp
It also works if I run:
$ make test -e TMPDIR=~/tmp /home/user/tmp
What can I do to also have it works for:
$ TMPDIR=~/tmp make test /home/user/tmp
Re: Setting Environment variable in Makefile the "$" character is special to make. To 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.
Expanded assignment = defines a recursively-expanded variable. := defines a simply-expanded variable.
There is one way that the makefile can change a variable that you have overridden. This is to use the override directive, which is a line that looks like this: ' override variable = value ' (see The override Directive).
env file. A fourth file that the operating system uses at login time is the .env file, if your .profile contains the following line: export ENV=$HOME/.env. The . env file lets you customize your individual working environment variables.
To follow up on my comments above, here's an example:
T ?= foo all: : '$(T)'
Now if I run the Makefile in various ways, it behaves as we expect (I get foo
only if I don't set T
either on the command line or environment):
$ make : 'foo' $ make T=bar : 'bar' $ T=bar make : 'bar'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With