user13693155
user13693155

Reputation:

make variable ?= is really intended for immediate

How do we assign using ?= but it's really intended for immediate,
as the 'make' reference manual say that its RHS must be meant to be deferred?

Upvotes: 0

Views: 69

Answers (2)

HardcoreHenry
HardcoreHenry

Reputation: 6387

Either of the following should work:

VAR := $(or $(VAR),newval)

or

VAR?=val
VAR:=$(VAR)

Both have repetition of the variable name, which can't be avoided.

One small difference with the first one -- If $(VAR) is set, but set to blank, then the first option will override it to newval, but the ?= operator will leave it as blank.

As a side note, I'm a bit surprised make hasn't introduced an ?:= operator yet...

Upvotes: 1

MadScientist
MadScientist

Reputation: 100856

You can use this:

ifeq ($(origin FOO), undefined)
  FOO := bar
endif

However, this means that the variable will be simple if it's set here, and will be whatever type it was before if it was already set.

Or you can use this which has slightly different behavior:

FOO ?= bar
FOO := $(FOO)

Here FOO will always be simple, but it will also expand the value of FOO if it was set before, which you may not want.

These are your only options.

Upvotes: 1

Related Questions