In makefile we often see =: = = = = These assignment operators, then what is the difference between them? Let's do a simple experiment.
Create a new makefile with the content:
Ifdef Define_vre
VRE = "Hello world!"
Else
endif
Ifeq ($ (OPT), define)
VRE? = "Hello world! First! "
endif
Ifeq ($ (OPT), add)
VRE + = "kelly!"
endif
Ifeq ($ (OPT), recover)
VRE: = "Hello world! again! "
endif
All
@echo $ (VRE)
Typing the following make command:
Make define_vre=true opt=define output: Hello world!
Make define_vre=true opt=add output: Hello world! kelly!
Make define_vre=true opt=recover output: Hello world! again!
Make define_vre= opt=define output: Hello world! first!
Make define_vre= opt=add output: kelly!
Make define_vre= opt=recover output: Hello world! again!
From the results above, we can clearly see the difference between them.
= is the most basic assignment
: = is the value before overwriting
= Yes if you have not been assigned, give the value after the equal sign
+ = is the value after adding an equal sign
The difference between "=" and ": =" in Makefile has been tangled up before, because when assigning a value to a variable, two symbols are used. Online search, someone gave the answer, but I dull, do not understand what meaning. A few seek without fruit, also put down. Read a blog today, inadvertently found that the author of the problem has been a good answer. To solve the problem can not help but sigh, sometimes give an example is not clear. Why do you have to speak so academically? ^_^
1, "="
Make will expand the entire makefile and then determine the value of the variable. In other words, the value of the variable will be the last value specified in the entire makefile. See Example:
x = foo
y = $ (x) bar
x = xyz
In the example above, the value of Y will be XYZ bar, not foo bar.
2, ": ="
": =" means that the value of the variable is determined by its position in makefile, not the final value of the entire makefile expansion.
x: = foo
Y: = $ (x) bar
x: = xyz
In the example above, the value of y will be foo bar instead of XYZ bar.