[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: prerequisites alter choice of pattern match rules?
From: |
Sebastian Pipping |
Subject: |
Re: prerequisites alter choice of pattern match rules? |
Date: |
Mon, 25 Feb 2013 23:30:25 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130113 Thunderbird/17.0.2 |
On 25.02.2013 14:57, Brian J. Murrell wrote:
> Hi,
>
> I have run into something I find strange with GNU Make 3.81 (yes, I know
> 3.82 is latest but since it's not in EL6, my target platform, I cannot
> depend on it's features).
>
> I would think that given the following set of rules:
>
> /tmp/%.foo: %.foo
> echo "foo rule 1"
> touch $@
>
> %.foo:
> echo "foo rule 2"
> touch $@
>
> /tmp/%.bar:
> make $*.bar
> echo "bar rule 1"
> touch $@
>
> %.bar:
> echo "bar rule 2"
> touch $@
>
> [..]
>
> $ make /tmp/a.foo
> echo "foo rule 2"
> foo rule 2
> touch /tmp/a.foo
> $ make /tmp/a.bar
> make a.bar
> make[1]: Entering directory `/home/brian/chroma/deps/lustre/test'
> echo "bar rule 2"
> bar rule 2
> touch a.bar
> make[1]: Leaving directory `/home/brian/chroma/deps/lustre/test'
> echo "bar rule 1"
> bar rule 1
> touch /tmp/a.bar
>
> It would seem that for the /tmp/a.foo, the "/tmp/%.foo" pattern rule is
> not being chosen but for /tmp/a.bar" the "/tmp/%.bar" pattern rule is
> being chosen. The only difference in those choices I can see is that
> the "/tmp/%.foo" pattern rule has a prerequisite and the "/tmp/%.bar"
> one doesn't.
Confirming the same behavior for make 3.82.
It seems like normally GNU make walks the path of the most specific
match in case of ambiguities. I wonder if that's specified/documented
anywhere. For this Makefile
xxx%:
@echo '$@ --> xxx%'
x%:
@echo '$@ --> x%'
xx%:
@echo '$@ --> xx%'
the most specific rule is chosen one might expect:
# make x1 xx2 xxx3 xxxx4
x1 --> x%
xx2 --> xx%
xxx3 --> xxx%
xxxx4 --> xxx%
Side notes on the above Makefile:
- "make $*.bar" in there does not seem to be relevant.
After removing that line, the file still reproduces your case.
- "make $*.bar" should be "$(MAKE) $*.bar", use $(MAKE)
to invoke make to not run into parallel build issues
- To reduce output noise, you can use lines like
@echo "foo rule 1"
^
instead of
echo "foo rule 1"
> So the question is, why does a prerequisite change the behavior of
> pattern match rules?
Good question.
Best,
Sebastian