Reputation: 17450
While testing the parallelization possibilities in case of recursive make
, I have stumbled on a weird behavior with the pattern rules.
The Makefile
:
## prepare the dir structure
# mkdir -p bs{1,2,3}
# for i in 1 2 3; do ln -s ../Makefile bs$i ; done
aaa:
@echo $(CURDIR)
sleep 1
s: bs1 bs2 bs3
true
## alt1
bs1 bs2 bs3: ; +make -C $@ aaa
## alt2
#bs%: ; +make -C $@ aaa
.PHONY: s bs1 bs2 bs3
There are two alternatives how to specify the targets: either literally list all the targets in the recipe, alt1 - bs1 bs2 bs3
- or use the %
pattern, alt2 - bs%
.
When I run make -j s
with the alt1, it works as expected.
But if I switch to alt2 (comment out alt1 rule, comment in alt2 rule), the make -j s
runs only the true
, and silently ignores the prerequisite bs1
, bs2
and bs3
targets.
Likewise, with alt1, make bs1
calls the sub-make, while with alt2, make bs1
says that Nothing to be done for 'bs1'.
The trick with the .force
dummy target didn't change the behavior.
Why?
Upvotes: 1
Views: 605
Reputation: 21040
From the manual
The implicit rule search (see Implicit Rules) is skipped for
.PHONY
targets.
bs%:
is an implicit rule, so it is ignored.
Upvotes: 1