0
votes

Why is the shortest stem not being matched in this makefile?

foo/%/baz:
    @echo "Prereq - stem $*"

foo/%/baz/thing.txt: foo/%/baz
    @echo "Good match - stem $*"

foo/%:
    @echo "Bad match - stem $*"

Here's the output:

> make foo/bar/baz/thing.txt
Bad match - stem bar/baz/thing.txt

I'd expect make to match the more specific (shorter stem) foo/%/baz/thing.txt instead of foo/%.

This is not a version 3.81 issue, (as was the case in these other two similar SO questions).

> make --version            
GNU Make 4.2.1

I can achieve expected behavior by either:

Removing the more general rule

foo/%/baz:
    @echo "Prereq - stem $*"

foo/%/baz/thing.txt: foo/%/baz
    @echo "Good match - stem $*"
> make foo/bar/baz/thing.txt
Prereq - stem bar
Good match - stem bar

Removing the prerequesite from the more specific rule

foo/%/baz:
    @echo "Prereq - stem $*"

foo/%/baz/thing.txt:
    @echo "Good match - stem $*"

foo/%:
    @echo "Bad match - stem $*"
> make foo/bar/baz/thing.txt
Good match - stem bar

I'm confused why the prerequesite added to the specific rule causes the general rule to be matched instead.

1
Can you gnu make version you use - it will make it easier to troubleshoot - dash-o
There's a code snippet in my post showing version 4.2.1 - MilesF
This looks like a bug to me. You should think about reporting it via [email protected] or else on Savannah savannah.gnu.org/bugs/?func=additem&group=make - MadScientist
Thanks. Just wanted to confirm this wasn't user error on my end before making the bug report. Here it is: savannah.gnu.org/bugs/index.php?58639 - MilesF

1 Answers

0
votes

Sorry, when I suggested you file a bug I didn't read your question carefully enough and was confused that it was the prerequisite that should have been matched, but you were wondering why the initial rule wasn't matched.

That is not a bug: it is due to this statement in the documentation:

Note however, that a rule whose prerequisites actually exist or are mentioned always takes priority over a rule with prerequisites that must be made by chaining other implicit rules.

I really apologize, that was totally my bad for not reading carefully :(.