The difference between make file =,:=,?=,+=

Source: Internet
Author: User


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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.