Shamoon
Shamoon

Reputation: 43531

What does ?= do in a Makefile?

Looking through my Makefile, I see SOMEVAR?=somestuff and I'm not sure what that means.

Any help would be appreciated.

Thanks!

Upvotes: 3

Views: 5940

Answers (3)

Matten
Matten

Reputation: 17631

See the MAN-pages of make:

VARIABLE ASSIGNMENTS Variables in make are much like variables in the shell, and, by tradi- tion, consist of all upper-case letters.

Variable assignment modifiers The five operators that can be used to assign values to variables are as follows:

 =       Assign the value to the variable.  Any previous value is overrid-
         den.

 +=      Append the value to the current value of the variable.

 ?=      Assign the value to the variable if it is not already defined.

 :=      Assign with expansion, i.e. expand the value before assigning it
         to the variable.  Normally, expansion is not done until the vari-
         able is referenced.  NOTE: References to undefined variables are
         not expanded.  This can cause problems when variable modifiers
         are used.

 !=      Expand the value and pass it to the shell for execution and
         assign the result to the variable.  Any newlines in the result
         are replaced with spaces.

Upvotes: 6

NaCl
NaCl

Reputation: 2723

It assigns the value to SOMEVAR if it is not already defined.

Upvotes: 3

Phil Miller
Phil Miller

Reputation: 38118

Per the GNU Make Manual, it sets SOMEVAR only if it is not currently defined with some other value.

Upvotes: 8

Related Questions