Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Makefile rule "foo : bar : baz"

What does it mean to have a rule specified as follows?

foo: bar : baz

I understand that foo is a target, bar and baz are prerequisites but why there is another colon between bar and baz - what's the meaning of that colon?

like image 635
name Avatar asked Feb 19 '26 07:02

name


2 Answers

The feature you are thinking of is a static pattern rule, and the syntax you give: foo : bar : baz is illegal; the bar part must be a pattern (that is, it must contain a % character).

Tripleee gives a reasonable explanation, except the statement when we build foo, bar depends on baz is somewhat confusing. What a static pattern rule means is that for each word in targets, create a new explicit rule where the target is the result of applying the pattern pattern to that word with the prerequisites prerequisites.

like image 71
MadScientist Avatar answered Feb 21 '26 22:02

MadScientist


The general syntax is

targets: pattern: prerequisites

So this -- grossly oversimplified -- example of yours says, basically, when we build foo, bar depends on baz. However, the second argument needs to be a pattern rule, so your example is in fact a syntax error.

A more useful and correct example would be along the lines of

$(OBJS): %.o: ick.h

which says that if you are building one of OBJS, their .o file depends on ick.h.

like image 34
tripleee Avatar answered Feb 21 '26 22:02

tripleee