bug-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: prerequisites alter choice of pattern match rules?


From: Philip Guenther
Subject: Re: prerequisites alter choice of pattern match rules?
Date: Mon, 25 Feb 2013 16:41:31 -0800

On Mon, Feb 25, 2013 at 5:57 AM, Brian J. Murrell <address@hidden> wrote:
> 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 $@
>
> Trying to create a target of /tmp/a.foo and /tmp/a.bar should result in
> the same rules being run but they don't:
...
> 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.
>
> So the question is, why does a prerequisite change the behavior of
> pattern match rules?  I would think the selection of a pattern match
> rule would be independent of prerequisites but of course once the
> pattern match rule was chosen, the rule for the prerequisite would also
> need to be called to ensure it's freshness.
>
> Thoughts?

When there's no explicit rule for a target (i.e., a rule where the
exact target name is listed), the algorithm for chosing the implicit
rule to apply first checks for rule(s) for which all the prerequisites
either already exist or are explicitly listed as targets themselves,
or have no prerequisites**.  Only if all the pattern rules have at
least one non-existent prerequisite that isn't explicitly listed
elsewhere does make then recursively try chaining to other rules for
each of the (missing) prerequisites.  Yes, this behavior is documented
in the info pages in more than sufficient detail to be sure that it
was clearly intended.

You ask why that's done.  To really answer that question I think you
would have to find and review the discussions among the developers
when it was actually added to GNU make, presumably back when Roland
was the maintainer.  The answer might be "because that's how Stu
Feldman's version of make did it".  Or maybe "it was too slow if we
tried all the possible chains, and we also wanted some way other than
order-in-the-makefile to prefer a rule".  Or "if there's a direct way
to build something, it must obviously be the right choice over
something which requires an intermediate file; if you don't want that,
then you should craft your patterns and filename choices so that you
don't get overlapping patterns!"

...but I wasn't there and those are just guesses.


Philip Guenther


** if there are no prerequisites, then all of the prereqs are present;
the list of missing prereqs is empty.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]