Makefile topic: Automatic Generation of dependency (I), makefile topic

Source: Internet
Author: User

Makefile topic: Automatic Generation of dependency (I), makefile topic
1. Problem Introduction

1) Does the target file (. o) only depend on the source file (. c )?
2) How does the compiler compile source files and header files?

2. defects caused by compilation behaviors Preprocessor transfers the code in the header file Insert directlyTo the source file compiler, you can only use The source file after preprocessing generates the target fileTherefore, The rule depends on the source file, and the command may not be executed.3. The problem header file of the solution in the experiment serves DependencyAppears in the corresponding Rule in progressWhen the header file is changed, Any source files are recompiled (inefficient compilation)When the number of header files in a project is large, Makefile will be difficult to maintain4. Crazy ideas through commands Automatic GenerationThe dependency of the object to be generated Auto includeAfter changing the header file in makefile, Automatic confirmationFiles to be re-compiled 5. Preparations (raw materials) Linux commands Sed compiler dependency generation Optiongcc -MM (gcc -M) 6. Linux commandssed Sed isStream EditorUsed to modify the stream text (add, delete, query, and modify)Sed can be usedStream text string replacement Sed string replacement method:sed 's:src:des:g'
echo "test=>abc+abc=abc" | sed 's:abc:xyz:g'test=>xyz+xyz=xyz
InSed can be usedRegular ExpressionMatch and replace the target, and you can useMatching target generation and replacement results
7. gcc key compilation options-generate dependency Obtain the targetComplete dependency Gcc-M test. c gets the targetPartial dependency gcc -MM test.c 8. Split the dependency of the target Split the full dependency of the target into multiple partial dependencies.

Related Article

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.