Double colon rule

Source: Internet
Author: User

 Double colon rule

The double colon rule is the rule obtained by replacing the ":" of the common rule. When the same file is the target of multiple rules, the processing process of the double colon rule is completely different from that of the general rule (the double colon rule allows multiple rules to specify different reconstruction target commands for the same target ).

The first thing to note is:In makefile, a target can appear in multiple rules. However, these rules must be of the same type, either common or double colon. A target cannot appear in two different types of rules at the same time.. The difference between the processing of double-colon rules and common rules is as follows:

1. In the dual-colon rule, when the dependent files are updated than the target files. The rule will be executed. For a dual-colon rule with no dependency but command lines, when this target is referenced, the command of the rule will be executed unconditionally. In general rules, when the target file of the rule exists, the command of the rule will never be executed (the target file will always be the latest ).

2. When the same file is used as the target of multiple double-colon rules. These different rules will be processed independently, rather than merging all dependencies into a target file as common rules do. This means that the processing of these rules is the same as that of multiple common rules. That is to say, after each dependency file in multiple double-colon rules is changed, make only executes the commands defined by this rule, other double-colon rules that use this file as the target will not be executed.

Let's look at an example. Our makefile contains the following two rules:


Newprog: Foo. c

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

Newprog: bar. c

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


If the "foo. c" file is modified, after you execute make, the target "newprog" will be rebuilt based on the "foo. c" file ". If bar. C is modified, newprog is rebuilt based on bar. C. Let's recall what happens when the above two rules are common rules? (Make will have an error and prompt the error message)

When a single target appears in multiple double-colon rules, the execution sequence of the rules is the same as that of common rules, and is executed in the writing sequence of makefile.

The double colon rule of GNU make provides a mechanism for us to execute different commands Based on dependency updates to recreate the same target. Generally, this is rarely required, so the use of double colon rules is rare. Generally, commands need to be defined for double-colon rules. If a double-colon rule does not have a defined command, the implicit rules will be automatically searched for the target when the rule is executed.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.