IPhone-command line compilation-make and makefile (2)

Source: Internet
Author: User

<) Variables in makefile

SimilarC LanguageThe statement is as follows:

 
Objects = test1.o test2.o test3.0 test4.o

Then you can use $ (objects) to reference this variable.

<) Pseudo-target file

 
. Phony: clean
Chean:
Rm Test

The. Phony label indicates that clean is a pseudo-target and must be displayed and specified in the command before it can be executed. For example, run: Make chean

 

<) Makefile contains five items: Display rules, concealed rules, variable definitions, file instructions, and annotations.

1. Display rules: displays the files to be generated, file dependencies, and command generation.

2. Concealed rules: Automatic Derivation

2. variable definition: When makefile is executed, the variables in the makefile will be extended to specific objects.

4. File indication: One makefile introduces another makefile, such as the C language include; judge the valid part according to the condition, such as if, then, else; define multi-line command package

5. Comment: Use # To comment a line

 

<) Explicitly specify the name of the MAKEFILE file

-F parameter, for example:

 
Make-FMakefiletest

 

<) Include other makefiles

Include test. mk

In the above example, put the content in the test. mk file to the location where the above language is located.

 

<) Specify the file directory

 
Make-I/usr/local/bin

-I parameter. When the make command is executed, find the file in the specified directory.

 

<) Make:

1. Read all makefiles

2. Read Other makefiles to be included

3. initialize the variable

4. deduce and analyze concealed rules

5. Establish dependency links for all files

6. Determine which targets need to be regenerated Based on the dependency.

7. Execute the command generation

1-5 is the first stage and 6-7 is the second stage.

In the first stage, if the defined variable is used, make will expand it to the position in use.

But it is extended. If the variable appears in the dependency, it is expanded only when the dependency is used.

 

<) Wildcard *

"*. O" indicates all. O files.

 
Clean:
Rm-F*. O

Delete all. O files

However, * When a wildcard is used in a variable, it can represent "*. O" itself and will not be expanded, as shown below:

Objects = *. o

To expand * in a variable that is equal to the set of all. O files, you must use the keyword wildcard:

 
Objects: = $ (wildcard *. O)

<) File search keywords:Vpath

 
File Path in vpath matching mode

For example, all. M files in the/usr/test directory:

 
Vpath %. M/usr/test

% Matches zero or several characters

Search multiple paths, separated ":"

 

<) Multiple executable files are generated at a time.

You can use pseudo-targets to achieve this.

When the pseudo object is the ultimate goal, put it in a single place and specify the dependent files for it, these dependent files will generate executable files

 
ALL: test1 Test2 tes3
. Phony: All
Tes1: test1.o
CC-O test1 test1.o
Tes2: test2.o
CC-O Test2 test2.o
Test3: test3.o
CC-O test3 test3.o

Generate three executable files test1, Test2, and test3 at a time

 

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.