当前位置:网站首页>11. Writing rules - pseudo target
11. Writing rules - pseudo target
2022-07-29 02:47:00 【Qimu king · Prince】
Writing rules - Fake target
1. PHONY
perform :
make [ The goal is ]
If there is no target , Default to the first target .
.PHONY : clean
clean:
rm *.o temp
Like in our previous example “clean” equally , That's to say, we generate a lot of compiled files , We should also provide a way to clear them “ The goal is ” For complete recompilation . ( With “make clean” To use the target )
because , We don't generate “clean” This file .“ Fake target ” It's not a document , It's just a label , because “ Fake target ” It's not a document , therefore make Unable to generate its dependencies and determine whether it will execute . We can only indicate this by showing “ The goal is ” To make it work . however ,“ Fake target ” The name of cannot be the same as the file name , Otherwise, it will lose “ Fake target ” That's the meaning of .
Of course , In order to avoid the situation of duplicate name with file , We can use a special tag “.PHONY” To show that a goal is “ Fake target ”, towards make explain , Whether or not there's this file , The goal is “ Fake target ”.
.PHONY : clean
As long as there's this statement , Whether or not there is “clean” file , To run “clean” This goal , Only “makeclean” such . So the whole process can be written like this :
.PHONY: clean
clean:
rm *.o temp
2. Specify the dependent file for the pseudo target
Pseudo targets generally have no dependent files . however , We can also specify the file that the pseudo target depends on . Pseudo targets can also be used as “ The default target ”, Just put it first . An example is , If your Makefile You need to generate several executables at one time , But you just want to simply tap one make Finished , also , All the target files are written in a Makefile in , Then you can use “ Fake target ” This feature :
.PHONY : all
all : prog1 prog2 prog3
prog1 : prog1.o utils.o
cc -o prog1 prog1.o utils.o
prog2 : prog2.o
cc -o prog2 prog2.o
prog3 : prog3.o sort.o utils.o
cc -o prog3 prog3.o sort.o utils.o
We know ,Makefile The first target in will be taken as its default target . We declared a “all” False target , It depends on three other goals . Because the characteristic of false target is , Always executed , Therefore, the three goals it depends on are always inferior to “all” This goal is new . therefore , The rules of the other three goals are always decided . This will achieve our goal of generating multiple goals in one breath .“.PHONY : all” The statement “all” This goal is “ Fake target ”.
3. Make pseudo targets dependent
As can be seen from the above example , Goals can also become dependencies . therefore , Pseudo targets can also become dependencies . See the following example :
.PHONY: cleanall cleanobj cleandiff
cleanall : cleanobj cleandiff
rm program
cleanobj :
rm *.o
cleandiff :
rm *.diff
“make clean” All files to be cleared will be cleared .“cleanobj” and “cleandiff” These two pseudo targets are a bit like “ Subroutines ” It means . We can type in “make cleanall” and “make cleanobj” and “make cleandiff” Command to clear different kinds of files .
边栏推荐
- 6-21漏洞利用-mysql弱口令破解
- CatchAdmin实战教程(四)Table组件相关功能实现
- C language to achieve the three chess game
- 6 years of testing experience, teaching you how to test ~ how to control the project
- What are the TCP retransmission mechanisms?
- Deliver temperature with science and technology, vivo appears at the digital China Construction Summit
- Intel's IPP Library (Integrated Performance Primitives)
- Driverless obstacle avoidance technology
- MySQL和Redis的双写一致性
- Cloud development pocket toolbox wechat applet source code
猜你喜欢

Asemi rectifier bridge s25vb100, s25vb100 parameters, s25vb100 application

【报错】node:internal/modules/cjs/loader:936 【解决方法】

Understanding service governance in distributed development

php 进程通信系列 (一) 命名管道

Rocbos open source micro community light forum source code

JMeter's BeanShell generates MD5 encrypted data and writes it to the database

h. 264 code stream explanation

Source code of Jiugongge heart puzzle Applet / source code of main wechat applet with traffic

FTP协议详解

Shell 脚本 快速入门 -01
随机推荐
K210 - sound source location and sound recognition
Multiple inheritance and derived class member identification
并发模式之异步回调Future模式
idea配置web容器与war打包
CatchAdmin实战教程(四)Table组件相关功能实现
以科技传递温度,vivo亮相数字中国建设峰会
第八天笔记
Cuda-npp image and video processing
多年前的回忆
Multimodal unsupervised image to image translation
Intel's IPP Library (Integrated Performance Primitives)
VR safety training of mine mining virtual reality improves employees' vigilance and protection awareness
全新UI四方聚合支付系统源码/新增USDT提现/最新更新安全升级修复XSS漏洞补单漏洞
Stm32f103xx firmware function library-1
XSS靶场(二)xss.haozi
nacos名字的由来
云开发打工人必备上班摸鱼划水微信小程序源码
第九天笔记
C语言实现三子棋游戏
Catchadmin practical tutorial (IV) implementation of relevant functions of table components