[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Pattern matching for static pattern rules
From: |
Edward Welbourne |
Subject: |
Re: Pattern matching for static pattern rules |
Date: |
Tue, 22 May 2018 13:00:17 +0000 |
Alex Dehnert (22 May 2018 00:03)
> I was running into some behavior that surprised me when using static
> pattern rules with files in a subdirectory.
[snip]
> With (implicit) pattern rules, "When the target pattern does not contain a
> slash (and it usually does not), directory names in the file names are
> removed from the file name before it is compared with the target prefix
> and suffix."[1] With static pattern rules, this doesn't seem to be the
> case. I'm not sure whether this is intentional or not.
> [1]
> https://www.gnu.org/software/make/manual/html_node/Pattern-Match.html#Pattern-Match
I'm reasonably confident it's intentional.
> The documentation seems to suggest that static pattern rules and
> implicit pattern rules should behave basically equivalently (with
> respect to pattern-matching file names, at least), claiming that "A
> static pattern rule has much in common with an implicit rule defined
> as a pattern rule (see Defining and Redefining Pattern Rules). Both
> have a pattern for the target and patterns for constructing the names
> of prerequisites. The difference is in how make decides when the rule
> applies."[2]
> [2]
> https://www.gnu.org/software/make/manual/html_node/Static-versus-Implicit.html#Static-versus-Implicit
Well, how matching is done is indeed part of how the rule applies.
I agree this could be highlighted, though.
> It seems like either this is a bug in the code, or something that should
> be clarified in the documentation as a difference between the two rule
> types.
The relevant part is in "Syntax of Static Pattern Rules" [3]
[3] https://www.gnu.org/software/make/manual/html_node/Static-Usage.html
Each pattern normally contains the character '%' just once. When the
TARGET-PATTERN matches a target, the '%' can match any part of the
target name; this part is called the "stem". The rest of the pattern
must match exactly. For example, the target 'foo.o' matches the pattern
'%.o', with 'foo' as the stem. The targets 'foo.c' and 'foo.out' do not
match that pattern.
Notice "The rest of the pattern must match exactly." You would need to
add to the examples, to bring out the lack of the special handling of
directories, that applies only to traditional pattern rules.
Eddy.