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.