当前位置:网站首页>Makefile application
Makefile application
2022-07-05 07:54:00 【Soy sauce;】
1.Makefile The concept of
Use keil, mdk, avr When the tool develops the program, you can compile it with a little mouse
What is its internal mechanism ? How it organizes the management process ? How to decide which file to compile ?
gcc -o test a.c b.c
// Simple ,
// But all the files will be processed once ,
// When there are many files, if only one of them is modified, it will lead to low efficiency
stay linux In the system make Is a very important compilation command , Whether it's project development or application software installation , We all use it a lot make or makeinstall. utilize make Tools , We can decompose large-scale development projects into more manageable modules , The source files in a project are not counted , By type 、 function 、 Modules are placed in several directories ,makefile A series of rules are defined to specify , Which files need to be compiled first , Which files need to be post compiled , Which files need to be recompiled , Even more complex functional operations , because makefile Like a Shell The script is the same , It can also execute operating system commands .makefile The benefit is “ Automated compilation ”, Once it's written , Just one make command , The whole project compiles completely automatically , Greatly improve the efficiency of software development .
2.Makefile Rules and usage
Conditions
When " Target file " non-existent ,
or
A dependent file is larger than the target file " new ",
be : perform " command "
The rules
One rule :
The goal is : rely on 1 rely on 2 …
[TAB] command
From top to bottom , Break down the task
perform :make
Two rules :
The pseudo target does not judge whether the target file exists or has been updated
Unconditionally execute the command
Fake target
.PHONY:
clean:( no need tab)
rm -rf $(OBJS) $(TARGET)
perform :make clean
Makefile Three elements of the basic rule :
The goal is : rely on 1 rely on 2 …
[TAB] command
notes : Take the names of these two documents casually , The purpose is to link
1) Target file :
Usually the name of the file to be generated , The target can be an executable or something else obj file , It can also be the name of an action ( There has to be )
Only one
2) Dependency file :
The file used to input and generate the target
A target usually has several dependent files ( There can be no )
One or more
3) command :
make The action performed , A rule can contain several commands ( There can be no )
When there are multiple commands , Every command takes a line
grammar :
make [ Fake target ]
If there is no false target , Default to the first target
Use
Execute... In the current directory make command , I'll find it myself Makefile And execute
explain : When it is detected that no dependency needs to be updated, the following error will be reported
3.Makefile Advanced Grammar
a. wildcard : %.o
[email protected] It means a goal
$< It means the first one 1 A dependency file
$^ Represents all dependent files
4.Makefile Variables in use
similar C Macro definition in language
stay Makefile It is a little similar to the variable in use C Macro definition in language , Using this variable is equivalent to replacing , Using variables can make Makefile Easy to maintain , The modification content becomes simple, variable definition and use .
7.1 Custom variable
1) Define variable methods :
Variable name = A variable's value
2) How to reference variables :
( change The amount name ) or ( Variable name ) or ( Variable name ) or { Variable name }
3)makefile Variable name :
makefile Variable names can start with numbers
Variables are case sensitive
Variables are generally in makefile The head definition of
Variables can be found almost in makefile Anywhere
4) Variable type
Real time variables 、 Delay variable , export
Simple variable ( Real time variables ) :
A := xxx # A The value of is determined immediately , It is determined at the time of definition
B = xxx # B The value of is determined only when it is used
:= # Real time variables
= # Delay variable
?= # Delay variable , If it's No 1 The second definition works , If the variable has been defined before, ignore this sentence
+= # additional , Whether it's a real-time variable or a delay variable depends on the previous definition
5.Makefile function
a. $(foreach var,list,text)
b. $(filter pattern…,text) # stay text In accordance with patten Value of format
$(filter-out pattern…,text) # stay text It doesn't conform to patten Value of format
c. $(wildcard pattern) # pattern Defines the format of the file name ,
# wildcard Take out the existing files
d. ( p a t s u b s t p a t t e r n , r e p l a c e m e n t , (patsubst pattern,replacement, (patsubstpattern,replacement,(var)) # Take each value from the list
# If meet pattern
边栏推荐
- How to define guid in AMI code
- Threads and processes
- Global and Chinese market of rammers 2022-2028: Research Report on technology, participants, trends, market size and share
- Package ‘*****‘ has no installation candidate
- How to migrate the device data accessed by the RTSP of the easycvr platform to easynvr?
- Use of orbbec Astra depth camera of OBI Zhongguang in ROS melody
- Opendrive ramp
- Baiwen 7-day smart home learning experience of Internet of things
- 软件设计师:03-数据库系统
- STM32 knowledge points
猜你喜欢
Could NOT find XXX (missing: XXX_LIBRARY XXX_DIR)
Programming knowledge -- assembly knowledge
Opendrive ramp
Altium designer learning (I)
Altium designer 19.1.18 - hide the fly line of a network
Screen record of the opening ceremony of the Beijing winter olympics 2
The research found that the cross-border e-commerce customer service system has these five functions!
Cadence simulation encountered "input.scs": can not open input file change path problem
Create inf module in AMI code
Shell脚本基本语法
随机推荐
Define in and define out
msys2
万字详解八大排序 必读(代码+动图演示)
MySQL - storage engine
Improve lighting C program
How to excavate and research ideas from the paper
Opendrive record
Shell脚本基本语法
Cygwin installation
Acwing - the collection of pet elves - (multidimensional 01 Backpack + positive and reverse order + two forms of DP for the answer)
Extended application of single chip microcomputer-06 independent key
Markdown tips
Logistic regression: the most basic neural network
Screen record of the opening ceremony of the Beijing winter olympics 2
生产中影响滑环质量的因素
Openxlsx field reading problem
STM32 knowledge points
SQL JOINS
C#,数值计算(Numerical Recipes in C#),线性代数方程的求解,LU分解(LU Decomposition)源程序
Distinction between heap and stack