当前位置:网站首页>12.书写规则-静态模式
12.书写规则-静态模式
2022-07-29 02:18:00 【其木王·王子】
书写规则-静态模式
静态模式可以更加容易地定义多目标的规则,可以让我们的规则变得更加的有弹性和灵活。
我们还是先来看一下语法:
<targets ...>: <target-pattern>: <prereq-patterns ...>
<commands>
....
targets 定义了一系列的目标文件,可以有通配符。是目标的一个集合;
target-parrtern 是指明了 targets 的模式,也就是的目标集模式;
prereq-parrterns 是目标的依赖模式,它对 target-parrtern 形成的模式再进行一次依赖目标的定义。
举个例子来说明一下吧。
如果我们的<target-parrtern>定义成“%.o”,意思是我们的<target>集合中都是以“.o”结尾的,
而如果我们的<prereq-parrterns>定义成“%.c”,意思是对<target-parrtern>所形成的目标集进行二次定义,
其计算方法是:
取<target-parrtern>模式中的“%”(也就是去掉了[.o]这个结尾),并为其加上[.c]这个结尾,形成的新集合。
所以,我们的“目标模式”或是“依赖模式”中都应该有“%”这个字符,如果你的文件名中有“%”那么你可以使用反斜杠“\”进行转义,来标明真实的“%”字符。
看一个例子:
objects = foo.o bar.o
all: $(objects)
$(objects): %.o: %.c
$(CC) -c $(CFLAGS) $< -o [email protected]
指明了我们的目标从$object 中获取,“%.o”表明要所有以“.o”结尾的目标,也就是“foo.o bar.o”,
也就是变量$object 集合的模式;
而依赖模式“%.c”则取模式“%.o”的“%”,也就是“foo bar”,并为其加下“.c”的后缀,
于是,我们的依赖目标就是“foo.c bar.c”。
而命令中的“$<”和“[email protected]”则是自动化变量,
“$<”表示所有的依赖目标集(也就是“foo.c bar.c”),
“[email protected]”表示目标集(也就是“foo.o bar.o”)。
于是,上面的规则展开后等价于下面的规则:
foo.o : foo.c
$(CC) -c $(CFLAGS) foo.c -o foo.o
bar.o : bar.c
$(CC) -c $(CFLAGS) bar.c -o bar.o
试想,如果我们的“%.o”有几百个,那种我们只要用这种很简单的“静态模式规则”就可以写完一堆规则,实在是太有效率了。“静态模式规则”的用法很灵活,如果用得好,那会一个很强大的功能。
边栏推荐
- XSS range (II) xss.haozi
- Wechat applet - Advanced chapter Lin UI component library source code analysis button component (II)
- Memories of many years ago
- UE4.25 Slate源码解读
- Understanding service governance in distributed development
- C language to achieve the three chess game
- MySQL和Redis的双写一致性
- 0728~面试题梳理
- 架构师进阶,微服务设计与治理的 16 条常用原则
- idea替换所有文件中的内容
猜你喜欢

Family relationship calculator wechat applet source code

第八天笔记

Polygon point test

Exploration and practice of network security vulnerability management

第五天实验

Ten methods to prevent blackmail software from attacking data

云开发口袋工具箱微信小程序源码

HTTP缓存

Library management system

Deliver temperature with science and technology, vivo appears at the digital China Construction Summit
随机推荐
ES6 detailed quick start!
Shell script quick start-01
ASEMI整流桥S25VB100,S25VB100参数,S25VB100应用
Rust list (VEC) replication
idea替换所有文件中的内容
Understand the evolution of redis architecture in one article
Some records during the development of ros2/ros1
ROS2/ROS1开发过程中的一些记录
工程经济学简答题
Polygon zkEVM——Hermez 2.0简介
C language to achieve the three chess game
【无标题】
九宫格心形拼图小程序源码/带流量主微信小程序源码
MySQL和Redis的双写一致性
Which is a good automatic account distribution system?
Really time NTP service startup command
童年的快乐时光
Flink生产环境经典问题汇总
Cloud development pocket toolbox wechat applet source code
多重继承与派生类成员标识