当前位置:网站首页>Introduction to gun make (1)
Introduction to gun make (1)
2022-06-26 01:55:00 【Chen_ Hulk】
1. GNU make Introduce
make By comparing the last modification time of the corresponding file , To determine which files need to be updated , Which files do not need to be updated .
When using make When the tool is compiled , The following documents are being executed in the project make Will be compiled when :
- All source files have not been compiled , For each C Source files to compile Links , Generate executable files .
- Each one was executed last time make Later modified C The source file is executed this time make Will be recompiled .
- The header file was last executed make Later modified , All that contain this header file C The source file is executed this time make Will be recompiled .
2. makefile Introduction to the rules
TARGET...:PREREQUISITES
COMMAND
....
perhaps
TARGET...:PREREQUISITES;COMMAND
COMMAND
....
The goal is : rely on
[tab] command TARGET: The goal of the rules , Is the last file name to be generated or the intermediate process file name for this purpose .
It can also be a make The name of the action performed , Like the goal clean.
PREREQUISITES: Rule dependency , Generate a list of file names required for rule targets .( Dependence is not necessary , such as clean)
COMMAND:
- When a rule's command line appears alone , Each command line must be [tab] Character start .
- When a command and a target dependency appear in the same row , Need to use “;” Separate .
3. make If work
By default ,make Execution is makefile The first rule in , The first goal of this rule is The ultimate goal / The ultimate goal .
If makefile The first rule of has multiple targets , Then the default ultimate goal is the first of multiple goals .
give an example :
edit:main.o kbd.o
cc -o edit main.o kdb.o
main.o:main.c defs.h
cc -c main.c
kdb.o:kdb.c command.h
cc -c kdb.c
- make First, analyze the rules of the ultimate goal , According to its dependent files , Look for the rules that create these dependent files from left to right .
- After rebuilding all dependent files , The last step is to rebuild the goal of this rule .
- If an error occurs in any rule execution , be make Immediately report an error and exit .(make It doesn't matter whether the dependency on the rule is correct , Whether the command line of the rule describing the reconstruction target does error checking correctly .)
All the dependent files of the ultimate goal main.o kbd.o update rule :
- The goal is .o file does not exist , Create it using its description rules .
- The goal is .o File exists , The goal is .o File depends on .c Source file , .h Any one of the files is larger than the target file .o to update , Regenerate it more regularly .
- The goal is .o File exists , The goal is .o The file is newer than any of its dependent files (.c / .h), And do nothing .
- defs.h Appear in dependencies , But it doesn't appear in the command , Because of the assumption main.c Already in the include 了 defs.h file .
The ultimate goal edit update rule :
- The ultimate goal file does not exist , Then execute the rule to create the target .
- The ultimate goal file exists , One or more of its dependent files are newer than it , Then re link to generate the ultimate goal according to the rules .
- The ultimate goal file exists , It is more up-to-date than any of its dependent files , And do nothing .
4. Specify variables
edit:main.o kbd.o
cc -o edit main.o kdb.oIn the above rules ,main.o kbd.o There are two occurrences in dependency and rule respectively , When you need to add or delete , You need to add... In two places , Later maintenance remains unchanged .
To avoid this problem , Use a variable objects/OBJECTS/objs/OBJS/obj/OBJ For all .o File list : objects = main.o kbd.o
objects = main.o kbd.o
edit:$(objects)
cc -o edit:$(objects)
5. Automatically deduce rules
In the use of make compile .c Source file , compile .c The command of the source file rule may not be explicitly given , because make There is a default rule in itself , Can automatically complete the process of .c Compile the file and generate the corresponding .o file , Carry out orders “cc -c” To compile the .c Source file .
stay makefile In, we only need to give the name of the target file to be rebuilt (.o file ),make Automatically for this .o File search for appropriate dependent files ( The suffix is .c, Files with the same file name .)
such , We can omit the description .c Document and .o Rules for dependencies .
give an example :
main.o : main.c defs.h
cc -c main.c
make Automatically for main.o File addressing appropriate dependent files main.c, And use , The default rules cc -c main.c -o main.o
The above can be simplified to :
main.o:defs.h
边栏推荐
- Eight principles of element positioning
- 阳光男孩陈颢天 受邀担任第六季完美童模全球总决赛代言人
- Playful girl wangyixuan was invited to serve as the Promotion Ambassador for the global finals of the sixth season perfect children's model
- LeetCode 31 ~ 40
- CYCA少儿形体礼仪 乐清市培训成果考核圆满落幕
- 秀场精灵陈梓桐 受邀担任第六季完美童模全球总决赛首席体验官
- PTA class a simulated fifth bomb: 1148-1151
- 胶原蛋白酶丨Worthington中英文说明书
- regular expression
- Postman接口测试之断言
猜你喜欢

28. contour discovery

Basic concepts of machine learning

阳光男孩陈颢天 受邀担任第六季完美童模全球总决赛代言人

Log4j2 vulnerability

Easy to understand C language keyword static

Redis7.0的安装步骤

清甜女孩李斯霞 受邀担任第六季完美童模全球总决赛小主持人

GNN (graph neural network) introduction vernacular

Pixel6 unlock bootloader

biggan:large scale gan training for high fidelity natural image synthesis
随机推荐
GUN make (3) Makefile的规则
Interpretation of script corresponding to postman assertion
Input 3 integers and output them from large to small
xargs 的作用详解
Energetic girl wangyujie was invited to be the spokesperson for the global finals of the sixth season perfect children's model
Exploring temporary information for dynamic network embedding
关于strlen与sizeof的区别
秀场精灵陈梓桐 受邀担任第六季完美童模全球总决赛首席体验官
recvmsg & sendmsg
GUN make (1) 简介
What happens from entering a web address in the browser's input box to seeing the contents of the web page?
Forgotten Jieba participle
反向输出一个整数
俏皮少女王艺璇 受邀担任第六季完美童模全球总决赛推广大使
蒟蒻初学单片机的一丢丢笔记
Difference between app test and web test
Assertion of postman interface test
27. template match
PTA class a simulation bomb 10: 1119-1123
tos cos dscp 区别和作用