What is in all in a Makefile?

  • Thread starter Thread starter Eus
  • Start date Start date
Click For Summary

Discussion Overview

The discussion centers on the use of the "::" syntax in Makefiles, specifically regarding the "all::" target. Participants explore the implications of using single-colon versus double-colon rules in GNU Make, including their execution behavior and documentation references.

Discussion Character

  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant describes the behavior of "all:" and "all::", noting that both produce the same output, while "all:::" results in an error.
  • Another participant suggests that "all::" may be interpreted as "all:" followed by an empty target.
  • A different participant explains that "all:" is a single-colon rule, while "all::" is a double-colon rule, which allows multiple definitions without mixing rule types.
  • This participant further elaborates on the behavior of double-colon rules, stating that they are independent and can execute commands based on the age of the target relative to its prerequisites.
  • One participant mentions that double-colon rules are not commonly used and are somewhat obscure, but they can be useful in specific scenarios.
  • Another participant acknowledges the clarification about double-colon rules and expresses gratitude for the information regarding its documentation.

Areas of Agreement / Disagreement

Participants express varying interpretations of the "::" syntax, with some agreeing on the definitions and behaviors of single and double-colon rules, while others raise questions about their practical applications and documentation clarity. The discussion remains unresolved regarding the specific utility of "all::".

Contextual Notes

Some participants note that the documentation in 'man make' is limited, suggesting that 'info make' provides more detailed information on double-colon rules. There is also mention of the potential for confusion regarding the execution order and independence of double-colon rules.

Eus
Messages
93
Reaction score
0
What is "::" in "all::" in a Makefile?

Hi Ho!

Executing GNU Make:

If Makefile only contains the following lines,

Code:
all:
	echo $@

it will produce

Code:
echo all
all

If Makefile only contains the following lines,

Code:
all::
	echo $@

it will still produce

Code:
echo all
all

But, if Makefile only contains the following lines,

Code:
all:::
	echo $@

it will produce

Code:
Makefile:1: *** missing target pattern.  Stop.

all: is just the usual way. all::: is an error.
all:: is the mystery that I don't know.

I know, all:| exists for order-only execution.
But, all:: is not documented in GNU Make texinfo.

Does any of you know what the use of all:: is?

Thank you.


Eus
 
Technology news on Phys.org
I think it is being intepreted as "all:" followed by an empty target "blank:"
but "all:::" would have 2 targets "blank:" targets the same.
 
all: is an ordinary (i.e., single-colon) rule. You can have only one 'all:' rule in a makefile (exception: you can have multiple dependency-only rules for the same target). all:: is a double-colon rule. You can have as many of these as you want in a makefile, but you cannot mix ordinary and double-colon rules.

'man make' doesn't say much. Use 'info make' instead. This is the make.info section on double-colon rules (type 'info make double-colon' on the UNIX command line):
info make double-colon said:
Double-Colon Rules

"Double-colon" rules are rules written with `::' instead of `:'
after the target names. They are handled differently from ordinary
rules when the same target appears in more than one rule.

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

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

The double-colon rules for a target are executed in the order they
appear in the makefile. However, the cases where double-colon rules
really make sense are those where the order of executing the commands
would not matter.

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

Each double-colon rule should specify commands; if it does not, an
implicit rule will be used if one applies. *Note Using Implicit Rules:
Implicit Rules.
 
Last edited:
D H said:
'man make' doesn't say much. Use 'info make' instead. This is the make.info section on double-colon rules (type 'info make double-colon' on the UNIX command line):

Yes, you are right! Thank you very much for telling me that it is called double-colon rule and it is documented in the texinfo file.


Eus
 

Similar threads

  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 34 ·
2
Replies
34
Views
5K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 12 ·
Replies
12
Views
4K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 3 ·
Replies
3
Views
7K
Replies
6
Views
3K
  • · Replies 9 ·
Replies
9
Views
9K