当前位置:网站首页>Command of gun make (4) rule
Command of gun make (4) rule
2022-06-26 01:55:00 【Chen_ Hulk】
The order of the rule is made up of shell The command line consists of , Be executed one by one .
Usually there are different in the system shell, But in make Handle Makefile In the process , If not specified , Then for command line parsing in all rules, use “/bin/sh” complete .
1. Command echo
Echo refers to outputting the command to be executed to the standard output device before executing the command .
@ Parameters :
If the command line starts with @ Start , be make The command to be executed will not be echoed when the command is executed .
such as :
@echo Start compilation
Output is : Start compilation
echo Start compilation
Output is :echo Start compilation
-n or --just-print Parameters :
make Only the command to be executed is displayed during execution , But I will not really execute these commands .
-s or --slient Parameters :
Disable the explicit... Of the command to be executed , It's like all the commands you want use @ At first .
2. Execution of command
2.1 Independent execution
When a multiline command , Each line of command will be in a separate sub - shell In process execution , Execution is independent of each other .
Multiple commands on the same line belong to a complete shell Command line .
2.2 Concurrent execution
Use -j perhaps --job bring make Multiple commands can be executed at the same time .
The problem of concurrent execution :
- The output information of multiple simultaneously executed commands will be output to the terminal at the same time .
- Only one of the multiple processes executing commands at the same time can obtain standard input , Other processes that need to read the standard input stream cause errors because the input stream is invalid .
3. Command execution error
If a command in a rule goes wrong ,make The execution of subsequent commands of the current rule will be abandoned , It is also possible to terminate the execution of all rules .
In order to ignore some unrelated command execution failure :
- Add... Before the command “-” Indicates that the execution of this command is ignored .
- Use -i perhaps --ignore-errors, bring make Ignore command execution errors in all rules .
- Use -k perhaps --keep-going, Make it impossible to exit immediately when an error occurs , Instead, continue the execution of subsequent commands , There is no abnormal exit until the last link is executed .
4. interrupt make Implementation
make If you receive a fatal signal when executing a command , that make The target files of the rules that have been rebuilt in this process will be deleted .
reason :
If the interrupt signal shuts down the compiler , Then it generates foo.o It could be incomplete , At that time, this was not completed foo.o The time stamp of the file is larger than that of the source program foo.c Timestamp NEW , If you don't delete foo.o, Then execute next time make This file is considered to be up-to-date and will not be rebuilt .
5. make Recursive execution of
make Recursive execution means to execute in makefile Use in make As a command to execute itself or other makefile Documentation process .
stay make When called recursively , Variables should be used in the command line of the rule MAKE Instead of make. The advantage is when we use a different version of make The program , It can guarantee the use of the top layer make Program and its subdirectories make The program remains .
subsystem:
cd subdir && $(MAKE)
Equivalent to entering subdirectory for execution :
subsystem:
$(MAKE) -C subdir
6. Variables and recursion
stay make In the process of execution , When using environment variables to pass variables defined by the upper layer , Will not cover the child make in Makefile Variable definition with the same name in the file .
If there is a repetition , Then take the son Makefile Whichever comes first , Unless used -e Options .
If you need to pass a variable to a child make, need export Make a designation .
export VAR
- If not used export Make a designation , The upper make Only the environment variables that have been initialized and Use the variables specified on the command line (make CFLAGS += -g) Pass to child make Program .
- There are special variables SHELL and MAKEFLAGS , These two variables unless you use unexport Make a statement , They are in the whole make It is always automatically passed to the child during execution make.
- When you don't want to pass MAKEFLAGS, You need to call the sub make Empty the variable here :
sub:
cd subdir && $(MAKE) MAKEFLAGS=
- One without parameters export The indicator indicates that Makefile All variables defined in are passed to the child make. If you don't need one of them , Use unexport Specified separately , But without parameters unexport It makes no sense .
export
7. -w Options
In multilevel make During recursive call , Use -w perhaps --print-directory Give Way make Give corresponding prompt information before starting to compile a directory and after completing directory compilation , Easy to track .
Usually -w Will be opened by default . have access to -s Disable this option .
such as , In the catalog /u/gun/make Execute under directory make -w:
See... Before execution starts :
make:Entering directory '/u/gun/make'
After the execution is completed, you see :
make:Leaving directory '/u/gun/make'
8. Define command packages
Use define Define a set of commands as command packages , Implement functions similar to functions .
In the command package , References to variables and functions in the command body are not expanded , When rules are used, they are fully expanded .
such as :
define run-yacc
yacc $(firstword $^)
mv y.tab.c [email protected]
endef
Use :
foo.c:foo.y
$(run-yacc)
Replacement process :
Command package $^ Will be foo.y Replace
[email protected] Will be foo.c Replace
边栏推荐
- 二造实务案例答题技巧和举例汇总,满满都是精髓
- Can bus transceiver principle
- NLP enhanced technology
- What happens from entering a web address in the browser's input box to seeing the contents of the web page?
- Redis的使用
- GUN make (1) 简介
- JQ获取对象的几种方式
- Redis7.0的安装步骤
- PTA class a simulated ninth bullet: 1114-1117
- PTA class a simulated fifth bomb: 1148-1151
猜你喜欢
One stop solution EMQ for hundreds of millions of communication of Internet of things
Differences and functions of TOS cos DSCP
二造实务案例答题技巧和举例汇总,满满都是精髓
Make a row of the dataframe a column name
tos cos dscp 区别和作用
Easy to understand C language keyword static
甜酷少女金书伊 受邀担任第六季完美童模全球总决赛代言人
Sweet cool girl jinshuyi was invited to be the spokesperson for the global finals of the sixth season perfect children's model
recv & send
Pixel6 unlock bootloader
随机推荐
关于VS scanf出现‘scanf‘: This function or variable may be unsafe. Consider usi问题的解决方法
NLP enhanced technology
App test (I)
APP测试(一)
Byte order problem
Tengwenze, a hot-blooded boy, was invited to serve as the image ambassador of the global finals of the sixth season perfect children's model
Distributed systems (II) understanding of distributed transactions
Brief introduction to the usage of iloc in dataframe
Postman斷言對應脚本的解釋
Worthington胶原蛋白酶的多类型研究
PTA class a simulated 11th bomb: 1124-1131
wifi 相关知识详解
弹性蛋白酶的用途和化学性质
Talking about interface test (2)
反向输出一个整数
PTA class a simulation bomb 10: 1119-1123
GUN make (2) 总述
秀场精灵陈梓桐 受邀担任第六季完美童模全球总决赛首席体验官
元素定位的八大法则
recvmsg & sendmsg