bug-make
[Top][All Lists]
Advanced

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

[bug #48643] Irrelevant targets can confuse make on which pattern rule t


From: Paul D. Smith
Subject: [bug #48643] Irrelevant targets can confuse make on which pattern rule to select.
Date: Mon, 18 Oct 2021 01:24:15 -0400 (EDT)
User-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.81 Safari/537.36

Update of bug #48643 (project make):

                  Status:                   Fixed => None                   
             Open/Closed:                  Closed => Open                   

    _______________________________________________________

Follow-up Comment #6:

I'm seeing some failures after applying this patch.

I think that the behavior of the makefile provided is actually correct in 4.x
(that is, the error is correct and this attempt to change it is not right).

I know it seems counter-intuitive.  However, the manual says that first, make
will try to build all targets using a simple implicit rule (that is, it tries
all pattern rules that match the target) and only if that doesn't work, will
it "try harder".  That is, pattern rule trees are searched "width first", not
"depth first".

Refer to
https://www.gnu.org/software/make/manual/html_node/Implicit-Rule-Search.html

Note that in step #2 we construct a list of pattern rules that match the
target, then in step #5 we walk all those patterns.  Then only if no rule
matches in step #5 do we proceed to step #6, and try to build non-existent
prerequisites of pattern rules found in step #2.

In the example we have:


default: a.foo
%.foo: %.correct ; @echo $@ from $<
%.foo: %.mislead ; @echo $@ from $<


so we have two patterns that match "a.foo".  We will try BOTH of these, using
step #5 in the above page, before we try to recurse and look for ways to
create prerequisites of these patterns (step #6).

We first look at '%.foo : %.correct' but there is no file 'foo.correct'
existing, and there's no mention of it in the makefile anywhere, so this rule
doesn't match and we keep going.

We then look at '%.foo : %.mislead'.  There is no file 'foo.mislead',
*however* the file 'foo.mislead' is mentioned in the makefile, here:


misleading_target: a.mislead


It's true that it's a prerequisite of some completely different target, and
we're not even trying to build that target, but that doesn't matter.  The rule
5.3 in the above page says that it matches if all the prerequisites "exists or
*ought to exist*".  As can be seen in the rule statement, the definition of
"ought to exist" is simply, "is mentioned in the makefile as a target or as an
explicit prerquisite".  The file "a.mislead" definitely meets that criteria,
thus this rule matches... and leads to an error.

After the extra debugging output added as part of bug #61042 the process
becomes easier to understand:

  Considering target file 'a.foo'.
   File 'a.foo' does not exist.
   Looking for an implicit rule for 'a.foo'.
   Trying pattern rule '%.foo: %.correct' with stem 'a'.
   Trying implicit prerequisite 'a.correct'.
   Not found 'a.correct'.
   Trying pattern rule '%.foo: %.mislead' with stem 'a'.
   Trying implicit prerequisite 'a.mislead'.
   'a.mislead' ought to exist.
   Found implicit rule '%.foo: %.mislead' for 'a.foo'.


    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?48643>

_______________________________________________
  Message sent via Savannah
  https://savannah.gnu.org/




reply via email to

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