Chinaunix首页 | 论坛 | 博客
  • 博客访问: 488229
  • 博文数量: 104
  • 博客积分: 3045
  • 博客等级: 少校
  • 技术积分: 1230
  • 用 户 组: 普通用户
  • 注册时间: 2008-02-29 10:18
文章分类

全部博文(104)

文章存档

2011年(72)

2010年(1)

2009年(1)

2008年(30)

分类: 项目管理

2011-04-24 18:15:39

Makefile的双冒号规则,英文解释如下:
Double-colon rules are an obscure feature that allows the same target to be updated
with different commands depending on which set of prerequisites are newer than the
target.       Normally, when a target appears more than once all the prerequisites are
appended in a long list with only one command script to perform the update.                                                              With double-colon rules, however, each occurrence of the target is considered a com-
pletely separate entity and is handled individually. This means that for a particular
target, all the rules must be of the same type, either they are all double-colon rules or
all single-colon rules.
文中的意思也就是如下:
1.        双冒号规则中,当依赖文件比目标更新时。规则将会被执行。对于一个没有依赖而只有命令行的双冒号规则,当引用此目标时,规则的命令将会被无条件执行。而普通规则,当规则的目标文件存在时,此规则的命令永远不会被执行(目标文件永远是最新的)
2.        当同一个文件作为多个双冒号规则的目标时。这些不同的规则会被独立的处理,而不是像普通规则那样合并所有的依赖到一个目标文件。这就意味着对这些规则的处理就像多个不同的普通规则一样。就是说多个双冒号规则中的每一个的依赖文件被改变之后,make只执行此规则定义的命令,而其它的以这个文件作为目标的双冒号规则将不会被执行。
GNU make的双冒号规则给我们提供一种根据依赖的更新情况而执行不同的命令来重建同一目标的机制。一般这种需要的情况很少,所以双冒号规则的使用比较罕见。
一般双冒号规则都需要定义命令,如果一个双冒号规则没有定义命令,在执行规则时将为其目标自动查找隐含规则。
看下例:
all::
%::
         $(MAKE) -C lib $@




阅读(2122) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~