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).
- when multiple pattern rules match a target
- Makefile implicit rule matching - prefix length not affecting match
> 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.
4.2.1- MilesF