当前位置:网站首页>1147_ Makefile learning_ Target files and dependent files in makefile
1147_ Makefile learning_ Target files and dependent files in makefile
2022-07-03 17:23:00 【grey_ csdn】
All learning summary : https://github.com/GreyZhang/g_makefile
Let's start with a simple example :
hello:
echo "hello world"
If you create a file named Makefile The file of , Enter the above content to save . after , Start the command line and enter the directory where the file is located make( perhaps gmake etc. ) The following effect appears :

It can be seen that the original command statement is printed on the interactive interface , At the same time, the result of statement execution is printed . I understand this somewhat , It should be possible to add a @ Symbol to deal with the echo of the command itself .

This is a makefile Part of the basic grammar of . According to the explanation here , The target file can be multiple . Between target files , Use spaces to distinguish . such , In fact, there is a problem worth confirming : If the name of the file itself has spaces , What should be done here ? Again , Similar problems also exist in dependent files . Next , Another thing to note is that the command starts from TAB The beginning, not the space .
Let's take another example :

Result of operation :

This example has a note when running , That is in Windows You need to use a bash Simulation environment of . because Windows There is also a command system in echo, But with the bash Medium echo Their behavior is different . If you don't pay attention to this , The above example cannot be executed successfully .
Here is an interesting mode of thinking , That is, the execution sequence written in the comment . In this way ,Makefile The execution and derivation process of is a little recursive in programming .

Here are two other examples , Easier to understand . First every time make Will execute the output , Because the target file never exists . The second one will print for the first time because the target file does not exist , create a file . From the second execution , It will not output but prompt that the file has been updated .
Considering dependence and time relationship , The above implementation process is very understandable . But here we can also see another problem :Makefile The implementation of does not mean that the target file will be updated to the latest .
some_file: other_file
echo "This will run second, because it depends on other_file"
touch some_file
other_file:
echo "This will run first"
touch other_file
The example above , It involves the dependence on other files . The effect of operation :

This example can actually show the relationship between File Dependencies , If the file is not ready , So update . If the file is ready , Then don't update . If the timestamp of the dependent file changes , The target file will also be updated .

A better test method described above is like this , Directly by formulating target To generate other_file, After performing gmake Handle default target, That's the first one target. such , Not only can we see makefile For the management concept of file timestamp , At the same time, you can also see the specified target Processing function .

such , Another concept about object file is introduced .make clean Is a common operation , In fact, it is only used to deal with the specified target nothing more .clean Not at all makefile A keyword or reserved word in .
边栏推荐
- Free data | new library online | cnopendata complete data of China's insurance intermediary outlets
- [combinatorics] recursive equation (the relationship theorem between the solution of the recursive equation and the characteristic root | the linear property theorem of the solution of the recursive e
- Where is the database account used when running SQL tasks in data warehouse tasks configured
- Answer to the homework assessment of advanced English reading (II) of the course examination of Fuzhou Normal University in February 2022
- University of Electronic Science and technology, accounting computerization, spring 20 final exam [standard answer]
- AcWing 4489. Longest subsequence
- What is your income level in the country?
- C language modifies files by line
- PHP online confusion encryption tutorial sharing + basically no solution
- Luogu: p1155 [noip2008 improvement group] double stack sorting (bipartite graph, simulation)
猜你喜欢

Swm32 series Tutorial 4 port mapping and serial port application

【RT-Thread】nxp rt10xx 设备驱动框架之--hwtimer搭建和使用

Free data | new library online | cnopendata complete data of China's insurance intermediary outlets

kubernetes资源对象介绍及常用命令(四)

国内如何购买Google Colab会员

聊聊接口优化的几个方法

PS screen printing brush 131, many illustrators have followed suit

29:第三章:开发通行证服务:12:开发【获得用户账户信息,接口】;(使用VO类包装查到的数据,以符合接口对返回数据的要求)(在多处都会用到的逻辑,在Controller中可以把其抽成一个共用方法)

SWM32系列教程4-端口映射及串口应用

新库上线 | CnOpenData中国保险机构网点全集数据
随机推荐
[try to hack] active detection and concealment technology
【RT-Thread】nxp rt10xx 设备驱动框架之--Pin搭建和使用
Leetcode13. Roman numeral to integer (three solutions)
[RT thread] construction and use of --hwtimer of NXP rt10xx device driver framework
Simple use of unity pen XR grab
[RT thread] NXP rt10xx device driver framework -- Audio construction and use
Type conversion, variable
Squid service startup script
Svn full backup svnadmin hotcopy
Define a structure fraction to represent a fraction, which is used to represent fractions such as 2/3 and 5/6
線程池:業務代碼最常用也最容易犯錯的組件
visual studio “通常每个套接字地址(协议/网络地址/端口)只允许使用一次“
大消费企业怎样做数字化转型?
Select 3 fcpx plug-ins. Come and see if you like them
ANOVA example
互联网医院HIS管理平台源码,在线问诊,预约挂号 智慧医院小程序源码
[UE4] brush Arctic pack high quality Arctic terrain pack
QT学习日记9——对话框
Talk about several methods of interface optimization
One brush 142 monotone stack next larger element II (m)