bug-make
[Top][All Lists]
Advanced

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

Pattern matching for static pattern rules


From: Alex Dehnert
Subject: Pattern matching for static pattern rules
Date: Mon, 21 May 2018 18:03:47 -0400 (EDT)
User-agent: Alpine 2.20 (DEB 67 2015-01-07)

I was running into some behavior that surprised me when using static pattern rules with files in a subdirectory.

A fairly minimal case:
$ mkdir foo && echo foo/bar > foo/text.bar

$ cat Makefile
all : foo/text.bar.sha1 foo/text.bar.md5

text.%.sha1 : text.%
        sha1sum "$<" > "$@"

foo/text.bar.md5 : text.%.md5 : text.%
        md5sum "$<" /dev/null > "$@"

$ make
Makefile:7: target `foo/text.bar.md5' doesn't match the target pattern
sha1sum "foo/text.bar" > "foo/text.bar.sha1"
md5sum "" /dev/null > "foo/text.bar.md5"
md5sum: : No such file or directory
make: *** [foo/text.bar.md5] Error 1

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. 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]

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.

(I'd imagine this may not have been noticed because in the (common?) case that the pattern is "%something", it doesn't mattern whether the directory is removed first, then the pattern is matched, and finally the directory re-added; or the match is done against the full path. Unfortunately, for my actual case, filenames have a common prefix, not a common suffix.)

Thanks,
Alex

[1] 
https://www.gnu.org/software/make/manual/html_node/Pattern-Match.html#Pattern-Match
[2] 
https://www.gnu.org/software/make/manual/html_node/Static-versus-Implicit.html#Static-versus-Implicit



reply via email to

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