[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: bug with order-only prerequisites & implicit rules implementation ?
From: |
Philip Guenther |
Subject: |
Re: bug with order-only prerequisites & implicit rules implementation ? |
Date: |
Sat, 10 Jan 2015 19:32:31 -0800 |
On Sat, Jan 10, 2015 at 7:06 PM, Jason Vas Dias
<address@hidden> wrote:
> Please could anyone explain the behaviour of this test makefile (attached) :
>
> <quote><code>
> TMP:=/tmp
>
> %.ext:
> touch $@
>
> .PHONY: *.oop
> %.oop:
> @echo 'A phony order-only prequisite of /tmp/a.t';
>
> #$(TMP)/%.t: | %.oop
>
> $(TMP)/%.t:$(TMP)/%.ext | %.oop
> @echo Specific Rule
>
> %.t:%.ext
> @echo General rule
>
> </code></quote>
>
> when invoked with :
>
> $ make -f ${the_makefile} /tmp/a.t
>
> I would expect that the most specific matching first rule
> would be invoked always, with its extra order-only
> pre-requisite recipe always being invoked, but actually
> this occurs only if /tmp/a.ext does not already exist -
> I tested latest make-4.1, and make-3.82, on a RHEL6 linux
> platform, and both show the same behaviour:
>
> $ make -f ${the_makefile} /tmp/a.t
> touch /tmp/a.ext
> A phony order-only prequisite of /tmp/a.t
> Specific Rule
> rm /tmp/a.ext
>
> but if I :
> $ touch /tmp/a.ext
> and then :
> $ make -f ${the_makefile} /tmp/a.t
> Gemeral Rule
This behavior is documented. To quote from the info pages, section
10.5.4 How Patterns Match:
----
A pattern rule can be used to build a given file only if there is a
target pattern that matches the file name, _and_ all prerequisites in
that rule either exist or can be built. The rules you write take
precedence over those that are built in. 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.
----
When /tmp/a.ext exists but a.oop doesn't, then the 'general' rule has
precedence because all the prerequisites exist, while the 'specific'
rule has a non-existent prerequisite (a.oop).
> If I remove the phony order only dependency. so that the /tmp/%.t rule reads:
> <quote><code>
> $(TMP)/%.t:$(TMP)/%.ext
> </code></quote>
> then the makefile always runs the first recipe, regardless of the existence
> of /tmp/a.ext :
Given the explanation above, that should make sense.
> Also, a second problem is that order-only dependencies are not
> recognized when specified by multiple rules without recipes are
> specified for same target , ie:
> <quote><code>
> $(TMP)/%.t: | %.oop
> $(TMP)/%.t:$(TMP)/%.ext
> </quote></code>
> has the same effect (recipe for implicit order-only pre-requisite never runs)
> as no order-only dependency being specified at all. I thought the
> dependencies should be merged and the %.oop recipe should be run in
> this case, especially as I've told make that all *.oop targets are
> phony.
Pattern rules, unlike normal rules, are never merged. Each one stands
alone and either completely overrides a previous pattern rule with the
exact same target and prerequisites (but possibly different commands,
or *no* commands, which cancels the previous pattern rule), or adds a
new pattern for the target with different prerequisites.
Philip Guenther