当前位置:网站首页>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
边栏推荐
- datetime与logging模块
- Oracle 日期格式化异常:无效数字
- Katalon当中的使用循环for、while和if...else、break、continue
- Décompression par compression
- 一套十万级TPS的IM综合消息系统的架构实践与思考
- 树莓派无需显示屏的VNC Viewer方式的远程连接
- Katalon framework tests a web page operation example code
- How to use output in katalon
- Basic 02: variable, remember the mobile number of the object
- 【功能建议】多个工作空间启动时选择某个空间
猜你喜欢

Realization of a springboard machine

Metersphere实现UI自动化元素不可点击(部分遮挡)

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

动态库(共享库)的制作和使用

Katalon全局变量在TestObject引用

Set up your own website (11)

Yann LeCun新论文:构建自动智能体之路

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

Spatial-Temporal时间序列预测建模方法汇总

Fastposter v2.8.4 release e-commerce poster generator
随机推荐
Wealth management for programmers
Ruoyi integrated building block report (NICE)
Redis数据库
Katalon global variable is referenced in testobject
动态库(共享库)的制作和使用
[practice] appium settings app is not running after 5000ms
Does flink1.15 support MySQL views? I configured the view name at the table name to save, but the table could not be found. Think
时间戳和date转换「建议收藏」
[cloud resident co creation] detailed introduction to DWS alarm service DMS and cluster connection mode
JS基础3
Create ECS using API shortcut
Makefile简介
Summary of characteristics of five wireless transmission protocols of Internet of things
Installing MySQL database (CentOS) in Linux source code
DlhSoft Kanban Library for WPF
Bytecode proof in appliedzkp zkevm (9)
JSON module, hashlib, Base64
[Li Kou - dynamic planning] sort out topic 1: basic topics: 509, 70, 746, 62, 63, 343, 96 (with links, topic descriptions, problem solving methods and codes)
Set up your own website (11)
MarkDown——基本使用语法