Assign values to variables in Makefile and assign values to makefile

Source: Internet
Author: User

Assign values to variables in Makefile and assign values to makefile

Variable assignment in Makefile

BEIJING-Haidian District

First, the Makefile syntax is as follows:

Targets: prerequisites

Command

.........

Or:

Targets: prerequisites; command

Command

.........

Targets is a file name separated by spaces. Wildcards can be used. In general, our goal is basically one file, but it may also be multiple files.

Command is a command line. If it is not in a line with "targetrerequisites", it must start with the [Tab key]. If it is in a line with prerequisites, you can use a semicolon to separate it.

Prerequisites is the object (or dependency target) on which the target depends ). If a file is newer than the target file, the target is regarded as "outdated" and is considered to need to be re-compiled.

 

Because makefile is related to the compilation rules of the entire project. There are many source files in a project. They are stored in several directories by type, function, and module. When we modify, add, or delete some source files, we need to modify the corresponding Makefile, if the source file is used in multiple places in Makefile, we need to modify multiple places in Makefile, which will cause a lot of inconvenience. In order to make makefile easier to maintain, variables can be used in makefile. The makefile variable is a string, which may be better understood as a macro in C language.

There are several ways to assign values to variables. The difference between "=" and ": =" is somewhat confusing ~

 

= Is a recursive expansion variable

Value1 = 1

Value2 = $ (value1)

Value1 = 2

In the end, $ (value2) becomes 2.

: = Is a directly expanded variable

Value1: = 1

Value2: = $ (value1)

Value1: = 2

Eventually $ (value2) is 1

? = Condition assignment

Value? = Abc indicates that if the value is not used before, the value is assigned abc. If the value is used before, the value is not assigned.

+ = Append Value

Value = filename1.o filename2.o

Value + = filename3.o

Then $ (value) is filename1.o filename2.o filename3.o

When assigning values to variables, if they cannot be placed in a row, they can be connected with the \ symbol.

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.