bugmake - Bugs: bug #47715, Implicit rule defined for multiple...

 
 

bug #47715: Implicit rule defined for multiple targets at once only runs one time

Submitted by:  Tristan Wibberley <codeshot>
Submitted on:  Sat 16 Apr 2016 01:12:44 PM UTC  
 
Severity: 3 - NormalItem Group: Bug
Status: Not A BugPrivacy: Public
Assigned to: NoneOpen/Closed: Closed
Component Version: 4.0Operating System: POSIX-Based
Fixed Release: NoneTriage Status: None

Add a New Comment(Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

(Jump to the original submission Jump to the original submission)

Sun 17 Apr 2016 07:57:38 AM UTC, comment #6:

Please find here detailed thoughts on the documentation to cover this situation.

I will add to https://savannah.gnu.org/bugs/?42125 with a suggested mechanism to choose the behaviour of multiple targets that I think is probably straightforward to implement and generally useful. I will be heppy to try to implement it myself given a little pointer to the right places to change.

I definitely saw these nodes to find an explanation after encountering the issue:

- https://www.gnu.org/software/make/manual/html_node/Multiple-Targets.html#Multiple-Targets
- https://www.gnu.org/software/make/manual/html_node/Static-versus-Implicit.html#Static-versus-Implicit
- various content lists in a few nodes.

I would have seen this node previously when learning how to use make in detail but that was a long time ago, but I was searching contents lists for "multiple" because I thought there would be a detailed section as for general rules and static pattern rules.

- https://www.gnu.org/software/make/manual/html_node/Pattern-Intro.html#Pattern-Intro

I didn't see the relevant information in the pattern rules node, I think a few reasons combined to make me disregard it - this is even despite me thinking in the back of my mind that there was something about multiple targets in implicit rules:

- I'd learned the term "Implicit Rule" and searched through the contents for that term to find more information

- The relevant paragraph in the Pattern Rules section is dense and doesn't have an example of this behaviour in a form like the other examples in the documentation which I've become accustomed to.

- The section that compares static pattern rules to implicit rules didn't mention this as a difference yet it is a big and confusing difference and the behaviour of static rules is demonstrated with clear examples.

- I felt like I have been learning a lot of make and pushing the limit of what is normal and my experience with software is that there are odd behaviours in such an endeavour that would normally be bugs.

Suggested changes to documentation:

- Add a section, if not already present, named "Multiple Targets in a Rule" to each rule type that supports them with a worked example for each.
I think "each" means "general", "static pattern", "implicit pattern" but not "suffix".

- Add an overall section on Multiple Targets in a Rule, if not already present. Make it briefly compare, in text only, the behaviour of each type of rule and link to the multiple rules section of each type.

- Add a table-structured comparison of features against rule types as a brief mnemonic.

- If the behaviour of multiple rules for one target has similar differences then maybe do the same for that so the same confusion doesn't happen in the future there either since this would be the cheap moment to make such a change.

Tristan Wibberley <codeshot>
Sun 17 Apr 2016 04:59:26 AM UTC, comment #5:

Well, you'll have to provide some details on where you looked and what kinds of things would have helped you understand the situation. This is a disadvantage of authorship: we already know the subject well so it seems clear to us.

As shown in my comment below, the behavior is documented in the "Introduction to Pattern Rules" section of the manual, in the sentence right after the concept of multiple targets in pattern rules is introduced.

Paul D. Smith <psmith>
Project Administrator
Sat 16 Apr 2016 11:43:26 PM UTC, comment #4:

Can you consider this a bug against the documentation? I looked through to find explanation of this issue with some care.

Tristan Wibberley <codeshot>
Sat 16 Apr 2016 11:10:58 PM UTC, comment #3:

Sure, because when make tries to build "a/foo.o" it finds the pattern rule and it assumes when the recipe is run it has produced the output files "a/foo.o", "b/foo.o", and "c/foo.o" (because that's what your rule says it does, and make believes you).

If it then is asked to build "b/foo.o", make says "hey, I already built that as a result of running this recipe so I don't need to run it again".

But if you ask to build "b/bar.o", then make doesn't believe that this file is already built so it matches the recipe again, this time with a stem of "bar", and believes that the recipe builds the files "a/bar.o", "b/bar.o", and "c/bar.o".

Probably it's better to email -unavailable- to get instruction and help on these issues, rather than doing it through the bug tracking system.

Paul D. Smith <psmith>
Project Administrator
Sat 16 Apr 2016 05:03:01 PM UTC, comment #2:

Note that when running `make a/foo.o b/bar.o` the recipe is run twice instead of only once.

Is this expected to differ from the behaviour of `make a/foo.o b/foo.o` ? If so then what's the key factor? whether the value of $* differs between the two times the rule is considered?

Tristan Wibberley <codeshot>
Sat 16 Apr 2016 01:50:07 PM UTC, comment #1:

This is the expected behavior. See http://www.gnu.org/software/make/manual/html_node/Pattern-Intro.html:

Pattern rules may have more than one target. Unlike normal rules, this does not act as many different rules with the same prerequisites and recipe. If a pattern rule has multiple targets, make knows that the rule’s recipe is responsible for making all of the targets. The recipe is executed only once to make all the targets.

If you want to run the recipe once for each target, you have to declare one pattern rule per target. You can put the recipe into a variable if you want to reduce duplication.

Paul D. Smith <psmith>
Project Administrator
Sat 16 Apr 2016 01:12:44 PM UTC, original submission:

An implicit rule defined for several targets at once only runs once during any single make invocation.

This can be seen with the attached Makefile by running `make a/foo.o b/foo.o`

Output:
true
make: Nothing to be done for 'b/foo.o'.

Expected Output:
true
true

Interestingly, `make a/foo.o b/bar.o` produces the expected output.

A critical side effect of this is also that a rule that relies on an implicit rule can be remade "successfully" even though its prerequisites have not been updated - which can be confirmed with a more complex makefile.

Tristan Wibberley <codeshot>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach File(s):
   
   
Comment:
   

Attached Files
file #36950:  Makefile added by codeshot (26B - application/octet-stream)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by psmith (Posted a comment)
  • -unavailable- added by codeshot (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 3 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Sat 16 Apr 2016 01:50:07 PM UTCpsmithStatusNone=>Not A Bug
      Open/ClosedOpen=>Closed
    Sat 16 Apr 2016 01:12:44 PM UTCcodeshotAttached File-=>Added Makefile, #36950

    Back to the top


    Powered by Savane 3.1-cleanup1