双冒号规则就是使用“::”代替普通规则的“:”得到的规则。当同一个文件作为多个规则的目标时,双冒号规则的处理和普通规则的处理过程完全不同(双冒号规则允许在多个规则中为同一个目标指定不同的重建目标的命令)。

首先需要明确的是:Makefile中,一个目标可以出现在多个规则中。但是这些规则必须是同一类型的规则,要么都是普通规则,要么都是双冒号规则。而不允许一个目标同时出现在两种不同类型的规则中。双冒号规则和普通规则的处理的不同点表现在以下几个方面:

1.        双冒号规则中,当依赖文件比目标更新时。规则将会被执行。对于一个没有依赖而只有命令行的双冒号规则,当引用此目标时,规则的命令将会被无条件执行。而普通规则,当规则的目标文件存在时,此规则的命令永远不会被执行(目标文件永远是最新的)。

2.        当同一个文件作为多个双冒号规则的目标时。这些不同的规则会被独立的处理,而不是像普通规则那样合并所有的依赖到一个目标文件。这就意味着对这些规则的处理就像多个不同的普通规则一样。就是说多个双冒号规则中的每一个的依赖文件被改变之后,make只执行此规则定义的命令,而其它的以这个文件作为目标的双冒号规则将不会被执行。

我们来看一个例子,在我们的Makefile中包含以下两个规则:

Newprog :: foo.c

$(CC) $(CFLAGS) $< -o $@

Newprog :: bar.c

$(CC) $(CFLAGS) $< -o $@

如果“foo.c”文件被修改,执行make以后将根据“foo.c”文件重建目标“Newprog”。而如果“bar.c”被修改那么“Newprog”将根据“bar.c”被重建。回想一下,如果以上两个规则为普通规时出现的情况是什么?(make将会出错并提示错误信息)

当同一个目标出现在多个双冒号规则中时,规则的执行顺序和普通规则的执行顺序一样,按照其在Makefile中的书写顺序执行。

GNU make的双冒号规则给我们提供一种根据依赖的更新情况而执行不同的命令来重建同一目标的机制。一般这种需要的情况很少,所以双冒号规则的使用比较罕见。一般双冒号规则都需要定义命令,如果一个双冒号规则没有定义命令,在执行规则时将为其目标自动查找隐含规则。
---------------------
作者:旭子
来源:CSDN
原文:https://blog.csdn.net/dengxu11/article/details/6932523
版权声明:本文为博主原创文章,转载请附上博文链接!

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
completely 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.
Realistic, useful examples of this feature are difficult to come by (which is why it is an obscure feature), but
here is an artificial example:

file-list:: generate-list-script
chmod +x $<
generate-list-script $(files) > file-list
file-list:: $(files)
generate-list-script $(files) > file-list

We can regenerate the file-list target two ways. If the generating script has been updated, we make the script
executable, then run it. If the source files have changed, we simply run the script. Although a bit far-fetched,
this gives you a feel for how the feature might be used.
We've covered most of the features of make rules and, along with variables and commands, this is the
essence of make. We've focused largely on the specific syntax and behavior of the features without going
much into how to apply them in more complex situations. That is the subject of later chapters. For now, we
will continue our discussion with variables and then commands.

makefile 双冒号规则的更多相关文章

  1. php中"::"双冒号有什么作用

    PHP代码 lazycms::$sysname 第一次见到这种表现方式,请问是双冒号什么意思 答:直接属类的方法或属性.也就是static 静态方法或属性的使用.域运算符,一般用于在B类对象中使用A类 ...

  2. Java开发笔记(六十三)双冒号标记的方法引用

    前面介绍了如何自己定义函数式接口,本文接续函数式接口的实现原理,阐述它在数组处理中的实际应用.数组工具Arrays提供了sort方法用于数组元素排序,可是并未提供更丰富的数组加工操作,比如从某个字符串 ...

  3. php中双冒号::的用法

    注:本篇博客系转载,出处不可考(至少对我来说不可考...) 双冒号操作符即作用域限定操作符Scope Resolution Operator可以访问静态.const和类中重写的属性与方法. 在类定义外 ...

  4. wind的R接口、况客RSDK学习,双冒号以及quantmod主题

    本文主要参考:来自segmentfault上的FinanceR的专栏 https://segmentfault.com/a/1190000004580610 并自己对生疏不解之处做了补充和注释. 当然 ...

  5. C#中双问号、双冒号等几个特殊关键字

    1.@ 这个东东看似和邮件有关啊,但是在C#的世界里,可跟邮件没有一毛钱关系,它是string的女朋友(当然了string有N多女友),二者结合就可以发挥作用了.你可以给它起个名字,叫做“逐字字符串” ...

  6. C++ 箭头-> 双冒号:: 点号.操作符区别

    点 (.) 如果变量是一个对象或者对象引用,则用它来访问对象成员. 箭头( ->) 如果变量是一个对象指针,则用它来访问对象成员. 双冒号 (::) 如果操作目标是一个具有名空间的标识符,则用它 ...

  7. C++@冒号(:)和双冒号(::)的用法

    转自:http://blog.csdn.net/zimingjushi/article/details/6549390 1.冒号(:)用法 (1)表示机构内位域的定义(即该变量占几个bit空间) ty ...

  8. 关于css3中before与after用单冒号还是双冒号的疑虑

    在 CSS3 中为了区别伪元素和伪类为伪元素使用了双冒号,因此如果使用了 display 或者 width 等属性时使得显示脱离了原本元素后,建议按照标准双写.

  9. c++中冒号(:)和双冒号(::)的用法

    1.冒号(:)用法 (1)表示机构内位域的定义(即该变量占几个bit空间) typedef struct _XXX{ unsigned ; unsigned char c; } ; XXX (2)构造 ...

随机推荐

  1. vue 点击当前的标签,获取当前标签的value值

    点击当前的标签,获取当前标签的value值 html <p class="title" v-for="(item, i) in items" :key=& ...

  2. abap函数返回结构体类型

    1: 定义一个结构体 T-CODE   se11 2: 选择 structure 3:输入相应的字段 4:激活 5:创建一个function module zfm_return_table,返回类型为 ...

  3. Spark代码中设置appName在client模式和cluster模式中不一样问题

    问题 Spark应用名在使用yarn-cluster模式提交时不生效,在使用yarn-client模式提交时生效,如图1所示,第一个应用是使用yarn-client模式提交的,正确显示我们代码里设置的 ...

  4. Linux下fork机制详解(以PHP为例)

    考:https://blog.csdn.net/jason314/article/details/5640969 1.fork简介 一个进程,包括代码.数据和分配给进程的资源.fork()函数通过系统 ...

  5. SQL简单操作

    删除表数据,保留表结构: delete from employee 将删除所有的记录 delete from employee where lastname = 'May' 这条语句是从emplyee ...

  6. [Java in NetBeans] Lesson 02. Variables, Data Types and Assignment.

    这个课程的参考视频在youtube. 主要学到的知识点有: Data Type: int, char, String, double, boolean. When into printf, int ( ...

  7. python while for else

    python的循环挺有意思 while和for体中可以带上else项 while中的else表示循环条件不成立时,去执行一次,也就是退出循环前去做一次 for中的else表示固定循环正常完成后,去执行 ...

  8. andorid CmakeLists

    # cmake要求低版本 cmake_minimum_required(VERSION 3.4.1) # Creates and names a library, sets it as either ...

  9. python list成员函数extend与append的区别

    extend 原文解释,是以list中元素形式加入到列表中 extend list by appending elements from the iterable append(obj) 是将整个ob ...

  10. eclipse显示xml提示

    当网速比较慢时,可以添加本地的dtd. window下的preferces,输入xml,找到xml catalog 接着