help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Is a pattern rule implicitly double-colon?


From: Paul Smith
Subject: Re: Is a pattern rule implicitly double-colon?
Date: Mon, 18 Jan 2021 09:43:23 -0500
User-agent: Evolution 3.36.4-0ubuntu1

On Sun, 2021-01-17 at 17:43 -0800, Fangrui Song wrote:
> % cat Makefile
> .SUFFIXES:
> %.o: %.c
>          touch $@
> %.o: %.d
>          touch $@

It might be more clear what was happening if you made the recipes for
these two rules different in some way:

  %.o : %.c ; echo from .c > $@
  %.o : %.d ; echo from .d > $@

> % rm -f a.o b.o; touch a.c b.d; make a.o b.o
> removed 'a.o'
> removed 'b.o'
> touch a.o
> touch b.o
> 
> The behavior is similar to double-colon rules.

No, not really; as Nick explains if it were similar to double-colon
rules BOTH rules would be run for BOTH targets.

>  It can not be explained by
> 
> > If more than one rule gives a recipe for the same file, make uses
> > the ast one given and prints an error message.
> 
> in 
> https://www.gnu.org/software/make/manual/html_node/Multiple-Rules.html

That section deals only with _explicit_ rules.  You are working with
implicit (pattern) rules, which follow a completely different algorithm
for matching; see here:

https://www.gnu.org/software/make/manual/html_node/Pattern-Match.html

If it helps you can think of explicit rules like classes in C++: there
can be only one with that name.  Pattern rules are like templates in
C++: each template must be different (can't have exactly the same set
of target and prerequisite patterns) but they can apply to a large
number of different targets.  The section above shows how make chooses
which implicit rule (template) to apply in a given situation.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]