当前位置:网站首页>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 .
边栏推荐
- vs2013已阻止安装程序,需安装IE10
- [combinatorics] recursive equation (characteristic equation and characteristic root | example of characteristic equation | root formula of monadic quadratic equation)
- Take you to API development by hand
- When absolutely positioned, the element is horizontally and vertically centered
- C language string practice
- Great changes! National housing prices fell below the 10000 yuan mark
- 29:第三章:开发通行证服务:12:开发【获得用户账户信息,接口】;(使用VO类包装查到的数据,以符合接口对返回数据的要求)(在多处都会用到的逻辑,在Controller中可以把其抽成一个共用方法)
- One brush 144 force deduction hot question-1 sum of two numbers (E)
- STM32H7 HAL库SPI DMA发送一直处于busy的解决办法
- kubernetes资源对象介绍及常用命令(四)
猜你喜欢
跨境电商:外贸企业做海外社媒营销的优势
Kotlin learning quick start (7) -- wonderful use of expansion
大变局!全国房价,跌破万元大关
kubernetes资源对象介绍及常用命令(五)-(NFS&PV&PVC)
Wechat applet for the first time
Qt调节Win屏幕亮度和声音大小
鸿蒙第三次培训
Great changes! National housing prices fell below the 10000 yuan mark
Depth first search of graph
Internet Hospital his Management Platform source, online Inquiry, appointment Registration Smart Hospital Small program source
随机推荐
Qt调节Win屏幕亮度和声音大小
SVN完全备份svnadmin hotcopy
PR second time
Simple configuration of postfix server
大消费企业怎样做数字化转型?
Dagong 21 autumn "power plant electrical part" online operation 1 [standard answer] power plant electrical part
How do large consumer enterprises make digital transformation?
[UE4] brush Arctic pack high quality Arctic terrain pack
Stm32h7 Hal library SPI DMA transmission has been in busy solution
Where is the database account used when running SQL tasks in data warehouse tasks configured
One brush 149 force deduction hot question-10 regular expression matching (H)
Kotlin learning quick start (7) -- wonderful use of expansion
Depth first search of graph
AcWing 3438. 数制转换
基于主机的入侵系统IDS
Svn full backup svnadmin hotcopy
One brush 146 force buckle hot question-3 longest substring without repeated characters (m)
鸿蒙第三次培训
鸿蒙第四次培训
[RT thread] NXP rt10xx device driver framework -- Audio construction and use