Natim Natim - 1 year ago 80
Bash Question

Define a Makefile variable using a ENV variable or a default value

I am trying to do a simple thing:

TMPDIR ?= /tmp

@echo $(TMPDIR)

This works if I run:

$ make test

It also works if I run:

$ make test -e TMPDIR=~/tmp

What can I do to also have it works for:

$ TMPDIR=~/tmp make test

Answer Source

To follow up on my comments above, here's an example:

T ?= foo
all:;: '$(T)'

Now if I run the various options it behaves as expected (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'
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download