当前位置:网站首页>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 .
边栏推荐
- Vs code plug-in korofileheader
- When absolutely positioned, the element is horizontally and vertically centered
- Rsync远程同步
- QT adjust win screen brightness and sound size
- [combinatorics] recursive equation (example of solving recursive equation without multiple roots | complete process of solving recursive equation without multiple roots)
- University of Electronic Science and technology, accounting computerization, spring 20 final exam [standard answer]
- New library online | cnopendata complete data of Chinese insurance institution outlets
- PHP online confusion encryption tutorial sharing + basically no solution
- TensorBoard快速入门(Pytorch使用TensorBoard)
- 2021 ICPC regional competition (Shanghai) g.edge groups (tree DP)
猜你喜欢

Golang单元测试、Mock测试以及基准测试

Thread pool: the most common and error prone component of business code

Wechat applet for the first time

IntelliJ 2021.3 short command line when running applications

QT adjust win screen brightness and sound size

ANOVA example
![How to read the source code [debug and observe the source code]](/img/40/a2fca67bcde3c468a739c6990325f4.jpg)
How to read the source code [debug and observe the source code]

2021 ICPC regional competition (Shanghai) g.edge groups (tree DP)
![[error reporting] omp: error 15: initializing libiomp5md dll, but found libiomp5md. dll already initialized.](/img/a0/4fc0e0741aad2885873e60f2af3387.jpg)
[error reporting] omp: error 15: initializing libiomp5md dll, but found libiomp5md. dll already initialized.

1164 Good in C
随机推荐
Collection of the most beautiful graduation photos in the graduation season, collection of excellent graduation photos
C language string inversion
How SVN views modified file records
HP 阵列卡排障一例
Rsync远程同步
One brush 147-force deduction hot question-4 find the median of two positive arrays (H)
RedHat 6.2 配置 Zabbix
Where is the database account used when running SQL tasks in data warehouse tasks configured
Unity notes unityxr simple to use
Solution to long waiting time of SSH connection to remote host
Simple configuration of postfix server
Vs code plug-in korofileheader
Where is the monitoring page of RDS database?
UE4 official charging resources, with a total price of several thousand
Examination questions for the assignment of selected readings of British and American Literature in the course examination of Fujian Normal University in February 2022
新库上线 | CnOpenData中国观鸟记录数据
TensorBoard快速入门(Pytorch使用TensorBoard)
Simple use of unity pen XR grab
Qt调节Win屏幕亮度和声音大小
Dagong 21 autumn "power plant electrical part" online operation 1 [standard answer] power plant electrical part