当前位置:网站首页>Makefile introduction
Makefile introduction
2022-06-28 11:01:00 【MoyangCitta】
Makefile It is mainly used to manage projects and realize automatic compilation
Makefile The rules
1. File naming
makefile or Makefile
2. Format
(1) One Makefile There can be one or more rules in the file
The goal is : rely on
command (Shell command )- The goal is : The final file to be generated ( Except pseudo targets )
- rely on : The file or target needed to generate the target
- command : Operate on dependencies and generate targets by executing commands ( The command must be preceded by Tab Indent )
(2)Makefile The other rules in are generally for the first rule
working principle
main:sub.c add.c main.c
gcc sub.c add.c main.c -o app1. Before the command is executed , You need to check whether the dependency in the rule exists
- If there is , Carry out orders
- If it doesn't exist , Check other rules down , If there are relevant rules, execute
2. Detect updates , When executing a command in a rule , Will compare the time of target and dependent files
- If the dependent time is later than the target time , Regenerate target
main:sub.o add.o main.o
gcc sub.o add.o main.c -o app
sub.o:sub.c
gcc -c sub.c -o sub.o
add.o:add.c
gcc -c add.c -o add.o
main.o:main.c
gcc -c main.c -o main.oAlthough the above formula is more complicated than before , But if sub.c To change, you only need to execute the first rule and compile sub.o The rules of , The previous procedure needs to be re executed , Consume more system resources .
Variable
1. Custom variable
Variable name = A variable's value (var=a.c b.c)
2. Predefined variables
AR: The name of the archive maintenance program , The default value is ar
CC:C The name of the compiler , The default value is cc
CXX:C++ The name of the compiler , The default value is g++
[email protected]: The full name of the target
$<: The name of the first dependency file
$^: All dependent files
3. Get the value of the variable
$( Variable name ) ($var)
main:main.c a.c b.c
gcc -c main.c a.c b.cmain:main.c a.c b.c
$(CC) -c $^ -o [email protected]Pattern matching
%.o:%.c%: wildcard , Match a string
Two % The match is the same string
%.o:%.c
gcc -c $< -o [email protected]function
$(wildcard PATTERN...)- function : Gets the list of files of the specified type in the specified directory
- Parameters :PATTERN It refers to the corresponding type of files in one or more directories , If there are multiple directories , Spaces are generally used
- return : File list of several files obtained , Use spaces between file names
Example :
$(wildcard *.c ./sub/*.c)Return value format :a.c b.c
$(patsubst <pattern>,<replacement>,<text>)- function : lookup <text> The words in ( Words with “ Space ”、“Tab” or “ enter ”“ Line break ” Separate ) Whether it conforms to the pattern <pattern>, If it matches , with <replacement> Replace .
- <pattern> You can include wildcards “%”, A string of any length . If <replacement>
Also contains “%”, that , <replacement> In this “%” It will be <pattern> In the %
The string represented by . ( It can be used “\” To escape , With “\%” To express the true meaning of “%” character ) - return : The () function returns the replaced string
Example : take .c convert to .o
$(patsubst %.c, %.o, x.c bar.c)Return value format :x.o bar.o
.PHONYFake target : Do not compare with external files , Can effectively execute objectives
Example :
.PHONY:clean
clean:
rm $(objs) -fIf there is a file with the same name as the target in the current folder , Because the target does not contain dependencies , So the target cannot detect updates , Unable to execute clean operation , False targets can prevent such phenomena
边栏推荐
- 字符串 & 堆 & 方法区
- ProCAST有限元铸造工艺模拟软件
- Gee: mcd64a1 based globfire daily fire data set
- [QT] connect syntax reference implementation
- AQS understanding
- JSON模块、hashlib、base64
- Move command
- Information hidden in the trend chart of Hong Kong London gold market
- Katalon global variable is referenced in testobject
- Secretary of the Ukrainian national security and National Defense Commission: will carry out precision strikes against targets in Russia
猜你喜欢

Metersphere implements UI automation elements that are not clickable (partially occluded)

Ble Bluetooth module nrf518/nrf281/nrf528/nrf284 chip scheme comparison

阿里三面:LEFT JOIN关联表中用ON还是WHERE跟条件有什么区别

Word、PDF、TXT文件实现全文内容检索需要用什么方法?

Katalon全局变量在TestObject引用
![[monkey] Introduction to monkey test](/img/70/5a7152d0b6b77df7f9d6ad0e09e000.png)
[monkey] Introduction to monkey test

【实战】1364- 实现一个完美的移动端瀑布流组件(附源码)

Metersphere实现UI自动化元素不可点击(部分遮挡)
![[practice] 1364- implement a perfect waterfall flow component on the mobile terminal (with source code)](/img/e8/21d8d81a3d7b544687d6adc06ad4b1.png)
[practice] 1364- implement a perfect waterfall flow component on the mobile terminal (with source code)

Katalon框架测试web(二十)自定义关键字以及上传弹窗操作
随机推荐
Installing MySQL database (CentOS) in Linux source code
ProCAST有限元铸造工艺模拟软件
Wireshark数据抓包分析之FTP协议
Six fusion positioning technologies in wireless communication application of Internet of things
选择哪种编程语言,会吸引优秀的人才?
Compression and decompression
科研丨Web of Science检索技巧
Graduation season, some suggestions for you who are new to the society
Internet of things application case of wireless module transparent transmission technology
爱可可AI前沿推介(6.28)
一种跳板机的实现思路
Create ECS using API shortcut
什么是主链系统?
关于Pytorch中双向LSTM的输出表示问题
Summary of characteristics of five wireless transmission protocols of Internet of things
【实操】Appium Settings app is not running after 5000ms
第2章 还记得点、线、面吗(二)
Convert the file URL in the browser to a file stream
【实战】1364- 实现一个完美的移动端瀑布流组件(附源码)
Debug debugging in katalon