Makefile中的双冒号规则

make的手册


https://www.gnu.org/software/make/manual/make.html#Double_002dColon


4.13 Double-Colon Rules

Double-colon rules are explicit rules written with ‘::’instead of ‘:’ after the target names. They are handleddifferently from ordinary rules when the same target appears in morethan one rule. Pattern rules with double-colons have an entirelydifferent meaning (see Match-Anything Rules).

When a target appears in multiple rules, all the rules must be the sametype: all ordinary, or all double-colon. If they are double-colon, eachof them is independent of the others. Each double-colon rule's recipeis executed if the target is older than any prerequisites of that rule. If there are no prerequisites for that rule, its recipe is alwaysexecuted (even if the target already exists). This can result inexecuting none, any, or all of the double-colon rules.

Double-colon rules with the same target are in fact completely separatefrom one another. Each double-colon rule is processed individually, justas rules with different targets are processed.

The double-colon rules for a target are executed in the order they appearin the makefile. However, the cases where double-colon rules really makesense are those where the order of executing the recipes would not matter.

Double-colon rules are somewhat obscure and not often very useful; theyprovide a mechanism for cases in which the method used to update a targetdiffers depending on which prerequisite files caused the update, and suchcases are rare.

Each double-colon rule should specify a recipe; if it does not, animplicit rule will be used if one applies. SeeUsing Implicit Rules.


Makefile示例1:


all:
        @echo aaaa

all:
        @echo bbbb


执行make报警告

Makefile:7: warning: overriding commands for target `all'
Makefile:4: warning: ignoring old commands for target `all'
bbbb

只有第2个规则的命令会被执行


Makefile示例2,在1上将单冒号改为双冒号:


all::
        @echo aaaa

all::
        @echo bbbb


执行make

aaaa
bbbb

2个规则的命令都会正确执行



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值