[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Multi-stem pattern rule
From: |
Masahiro Yamada |
Subject: |
Re: Multi-stem pattern rule |
Date: |
Fri, 28 Jun 2024 17:53:16 +0900 |
On Mon, Jun 3, 2024 at 3:14 AM Dmitry Goncharov <dgoncharov@users.sf.net> wrote:
>
> On Sat, Jun 1, 2024 at 3:22 PM Masahiro Yamada <masahiroy@kernel.org> wrote:
>
> > So, % matches a part of the file name, excluding the
> > directory path, correct?
>
> The behavior is trickier than that.
>
>
> When the target pattern carries no slash.
>
> $ ls
> a makefile p
> $ cat makefile
> all: a/.b.timestamp
> .%.timestamp: %.x; $(info building $@ from $<)
> $ make -rR --debug=i |tail +14 |head -4
> Looking for an implicit rule for 'a/.b.timestamp'.
> Trying pattern rule '.%.timestamp: %.x' with stem 'b'.
> Trying implicit prerequisite 'a/b.x'.
> Found 'a/b.x'.
>
>
>
> 1. make compares the target ('a/.b.timestamp') against the target pattern
> ('.%.timestamp') of a potential rule.
> 2. make calculates the stem. In the case of target 'a/.b.timestamp' and target
> pattern '.%.timestamp' the stem is 'a/b'.
> 3. make splits the stem to dirname 'a/' and basename 'b'.
> 4. make replaces '%' in the prerequisite pattern '%.x' with the
> basename part of the
> stem ('b'). Make prepends the dirname part of the stem ('a/') to the
> prerequisite and ends up with prerequisite 'a/b.x'.
> 5. make checks if file 'a/b.x' exists or can be made.
> In our case 'a/b.x' exists and therefore the rule matches.
>
> When the target pattern carries a slash, e.g. if the pattern was
> 'a/.%.timestamp', then
>
> $ ls
> a makefile p
> $ cat makefile
> all: a/.b.timestamp
> a/.%.timestamp: %.x; $(info building $@ from $<)
> $
> $
> $ make -rR --debug=i |tail +14 |head -4
> make: *** No rule to make target 'a/.b.timestamp', needed by 'all'. Stop.
> Looking for an implicit rule for 'a/.b.timestamp'.
> Trying pattern rule 'a/.%.timestamp: %.x' with stem 'b'.
> Trying implicit prerequisite 'b.x'.
> Not found 'b.x'.
>
>
> 1. make compares the target ('a/.b.timestamp') against the target pattern
> ('a/.%.timestamp') of a potential rule.
> 2. make calculates the stem. In the case of target 'a/.b.timestamp' and target
> pattern 'a/.%.timestamp' the stem is 'b'.
> 3. make replaces '%' in the prerequisite pattern '%.x' with the
> stem ('b') and ends up with prerequisite 'b.x'.
> 4. make checks if file 'b.x' exists or can be made.
> In our case there is no 'b.x' and it cannot be made and therefore the rule
> does
> not match.
>
>
> regards, Dmitry
But, it does not work with the static pattern rule.
[pattern rule]
all: a/b.o p/q/r.o
%.o : .%.mod
[ do something ]
==> look for prerequisites:
a/.b.mod
p/q/.r.mod
[static pattern rule]
all: a/b.o p/q/r.o
a/b.o p/q/r.o : %.o : .%.mod
[ do something ]
==> look for prerequisites
.a/b.mod
.p/q/r.mod
So, I started to think that
this is not so useful because I do not see consistency
between "pattern rules" and "static pattern rule".
So, still I'd like to see a solution that
works consistently.
--
Best Regards
Masahiro Yamada