What is the difference between the GNU Makefile variable assignments =, ?=, := and +=?

mmoris

Can anybody give a clear explanation of how variable assignment really works in Makefiles.

What is the difference between :

 VARIABLE = value
 VARIABLE ?= value
 VARIABLE := value
 VARIABLE += value

I have read the section in GNU Make's manual, but it still doesn't make sense to me.

Alnitak

Lazy Set

VARIABLE = value

Normal setting of a variable, but any other variables mentioned with the value field are recursively expanded with their value at the point at which the variable is used, not the one it had when it was declared

Immediate Set

VARIABLE := value

Setting of a variable with simple expansion of the values inside - values within it are expanded at declaration time.

Lazy Set If Absent

VARIABLE ?= value

Setting of a variable only if it doesn't have a value. value is always evaluated when VARIABLE is accessed. It is equivalent to

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

See the documentation for more details.

Append

VARIABLE += value

Appending the supplied value to the existing value (or setting to that value if the variable didn't exist)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

What is the difference between discard and not assigning a variable?

From Java

What's the difference between parenthesis $() and curly bracket ${} syntax in Makefile?

From Dev

What is the difference between makefile and sh file

From Dev

What is the difference between a static const and constexpr variable?

From Dev

Function and difference between $() and ${} in Makefile

From Dev

Difference between Dynamic and Static type assignments in Java

From Dev

What is the difference between a variable and a reference in C++?

From Dev

Lua: What is the difference in these variable assignments?

From Dev

What is the difference between a symbol and a variable in Ruby?

From Dev

What is the difference between javascript property and javascript variable?

From Dev

What's the difference between "$(variable)" and "$(VARIABLE)"

From Dev

What is difference between initialized variable and a literal in java?

From Dev

What is the difference between GNU bison and yacc?

From Dev

What is the difference between a property and a variable in Swift?

From Dev

What is the difference between % and * in a makefile

From Dev

Difference between 2 event handlers assignments

From Dev

What is the difference between = and => for a variable?

From Dev

In Tensorflow, what is the difference between a Variable and a Tensor?

From Dev

what is difference between environment variable types

From Dev

What's the difference between versions of GNU Make in Cygwin setup

From Dev

What's the difference between "$(variable)" and "$(VARIABLE)"

From Dev

What is the difference between += and = when changing the value of a variable?

From Dev

What is difference between initialized variable and a literal in java?

From Dev

What is the difference between GNU bison and yacc?

From Dev

Difference between 2 event handlers assignments

From Dev

What is the difference between the assignments to pointers in C?

From Dev

What is the difference between these two assignments?

From Dev

What is the difference between variable === constant & constant === variable

From Dev

What is the difference between a variable and a mixin in sass?

Related Related

  1. 1

    What is the difference between discard and not assigning a variable?

  2. 2

    What's the difference between parenthesis $() and curly bracket ${} syntax in Makefile?

  3. 3

    What is the difference between makefile and sh file

  4. 4

    What is the difference between a static const and constexpr variable?

  5. 5

    Function and difference between $() and ${} in Makefile

  6. 6

    Difference between Dynamic and Static type assignments in Java

  7. 7

    What is the difference between a variable and a reference in C++?

  8. 8

    Lua: What is the difference in these variable assignments?

  9. 9

    What is the difference between a symbol and a variable in Ruby?

  10. 10

    What is the difference between javascript property and javascript variable?

  11. 11

    What's the difference between "$(variable)" and "$(VARIABLE)"

  12. 12

    What is difference between initialized variable and a literal in java?

  13. 13

    What is the difference between GNU bison and yacc?

  14. 14

    What is the difference between a property and a variable in Swift?

  15. 15

    What is the difference between % and * in a makefile

  16. 16

    Difference between 2 event handlers assignments

  17. 17

    What is the difference between = and => for a variable?

  18. 18

    In Tensorflow, what is the difference between a Variable and a Tensor?

  19. 19

    what is difference between environment variable types

  20. 20

    What's the difference between versions of GNU Make in Cygwin setup

  21. 21

    What's the difference between "$(variable)" and "$(VARIABLE)"

  22. 22

    What is the difference between += and = when changing the value of a variable?

  23. 23

    What is difference between initialized variable and a literal in java?

  24. 24

    What is the difference between GNU bison and yacc?

  25. 25

    Difference between 2 event handlers assignments

  26. 26

    What is the difference between the assignments to pointers in C?

  27. 27

    What is the difference between these two assignments?

  28. 28

    What is the difference between variable === constant & constant === variable

  29. 29

    What is the difference between a variable and a mixin in sass?

HotTag

Archive