bugmake - Bugs: bug #8297, Allow multiple targets to be built...

 
 

bug #8297: Allow multiple targets to be built from a single explicit rule recipe invocation

Submitter:  Fred Bleuzet <fbleuzet4>
Submitted:  Thu 25 Mar 2004 04:05:39 PM UTC
Votes: 100
 
Severity:  3 - Normal Item Group:  Enhancement
Status:  Fixed Privacy:  Public
Assigned to:  psmith Open/Closed:  Closed
Component Version:  None Operating System:  Any
Fixed Release:  4.3 Triage Status:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Mon 20 Jan 2020 12:08:48 PM UTC, comment #11: 

comment #10:

How do you think about to insert a specification like “@cindex &:” in the file “make.texi”?

Markus Elfring <elfring>
Sun 12 May 2019 08:36:08 PM UTC, comment #10: 

I made some changes to the patch and pushed it to Git master.

Paul D. Smith <psmith>
Group administrator
Thu 14 Mar 2019 06:21:45 PM UTC, comment #9: 

Regarding the past discussion, this comment by Henning Makholm:

https://lists.gnu.org/archive/html/make-alpha/2002-12/msg00007.html

provides an accurate synopsis of what I have also done.

From the GNU Make manual, I realized that the semantics is already present in pattern rules. Then in the code I found the also_make member of struct file and so it went.

Kaz Kylheku <kkylheku>
Wed 13 Mar 2019 08:00:18 PM UTC, comment #8: 

The patch I uploaded just now is almost the same as what I posted to the mailing list, modulo fixing a memory leak (not freeing the also_make dep list built up in the register_files function).

Paul Smith pointed to this bug and suggested the &: syntax instead; I will be reworking the change to use that syntax.

Kaz Kylheku <kkylheku>
Wed 13 Mar 2019 12:15:42 PM UTC, comment #7: 

FYI some discussion of this feature can be found here:

https://lists.gnu.org/archive/html/make-alpha/2002-12/msg00000.html

Paul D. Smith <psmith>
Group administrator
Wed 05 Nov 2008 02:05:48 AM UTC, comment #6: 

How about adding a new special target such as '.MULTIPLE_OUTPUTS'?  Usage would be something like:

.MULTIPLE_OUTPUTS cmdparser.cpp cmdparser.h: cmdparser.y
    bison -d -o cmdparser.cpp cmdparser.y

Tom Honermann <tahonermann>
Mon 03 Nov 2008 08:25:24 PM UTC, comment #5: 

At the very least, the documentation needs to be revised to discuss the situation of multiple targets being produced by a rule action and to offer the pattern workaround.

Dave Yost <yost>
Sun 02 Apr 2006 05:10:29 AM UTC, comment #4: 

I can answer this question wrt Solaris make and Sun Studio dmake.

foo + bar baz boz + biz:

What does this mean?

It means there are 2 groups:
1. foo + bar
2. boz + biz

Here is an example.
-------------------
volga2% cat Makefile
T = foo bar baz boz biz
all: ${T}
# Two groups
foo + bar baz boz + biz:
        @echo $@
        touch ${T}

If I run GNU make, it treats "+" as a target,
and repeats the same command 5 times:
-------------------------------------
volga2% rm -f foo bar baz boz biz
volga2% gmake -j 8
Makefile:7: target `+' given more than once in the same rule.
foo
touch foo bar baz boz biz
bar
baz
boz
biz
touch foo bar baz boz biz
touch foo bar baz boz biz
touch foo bar baz boz biz
touch foo bar baz boz biz

If I run Sun Studio dmake, it treats "+" as a group sign,
and repeats the same command 3 times:
-------------------------------------
volga2% rm -f foo bar baz boz biz
volga2% dmake -j 8
echo baz
baz
touch foo bar baz boz biz
echo boz
boz
touch foo bar baz boz biz
echo foo
foo
touch foo bar baz boz biz


Nikolay Molchanov <nikm>
Sun 02 Apr 2006 03:04:55 AM UTC, comment #3: 

Yes, but I don't like that syntax because it seems to allow both kinds of "rules" to be defined at the same time; consider:

  foo + bar baz boz + biz:

What does this mean?  In discussions on the GNU make developers' list we discussed a syntax like this:

    foo bar |: biz baz
    %.y %.z |: %.a

and:

    foo bar &: biz baz
    %.y %.z &: %.a

The "&:" separator means that all targets are built with one invocation (default today for pattern rules) and the "|:" separator means each target is built with a separate invocation (default today for explicit rules).  The unadorned ":" would keep its current behavior (different depending on whether you use pattern or explicit rules).

Paul D. Smith <psmith>
Group administrator
Sun 02 Apr 2006 12:38:48 AM UTC, comment #2: 

Solaris "make" utility provides the following solution: if the
targets are connected (separated) with a "+" sign, they are
combined in a target group.

  target [+ target...] :  Target group. The rule in the target
                          entry  builds all the indicated tar-
                          gets as a group. It is normally per-
                          formed  only  once per make run, but
                          is checked for command  dependencies
                          every  time a target in the group is
                          encountered in the dependency scan.

Here is an example:

# Dependencies
cmdparser.hpp: cmdparser.cpp
cmdparser.cpp: cmdparser.y

# Common Rule
cmdparser.hpp + cmdparser.cpp:
        bison -d -o cmdparser.cpp cmdparser.y

I can be wrong, but I think POSIX standard allows this syntax.

Nikolay Molchanov <nikm>
Sat 27 Mar 2004 04:17:48 AM UTC, comment #1: 

We're not going to change the syntax of multiple-target explicit rules, even with a special flag.

If you need to define explicit rules with multiple outputs today you have two choices: if the rule can be expressed as a pattern then define it with multiple patterns in the target area: this DOES mean that all those targets are created with one invocation of the command script.  Your example could be written as:

    %.cpp %.h : %.y
            bison -d -o cmdparser.cpp cmdparser.y

and it will work as you expect.  The other option, if you can't express it with implicit rules, is to use a sentinel like this:

    foo.cpp bar.xyz: .sentinel
    .sentinel: ; command-to-gernerate-output; touch $@

There have been patches proposed that add a new rule syntax to allow explicit rules to behave as you like and one of those may be adopted, but it will be a new and unique syntax, it won't be an option to redefine an existing, well-understood syntax.

Paul D. Smith <psmith>
Group administrator
Thu 25 Mar 2004 04:05:39 PM UTC, original submission:  

I need an additional mode where make runs under the assumption that each multiple-target rule needs to execute the rule action only once to generate all the targets.

This is to avoid file locking and build failure in parallel make for such rules:

cmdparser.cpp cmdparser.hpp: cmdparser.y
bison -d -o cmdparser.cpp cmdparser.y

If 2 other rules need the 2 targets at the same time, currently the bison comand runs twice in parallel. At best the 2 bison processes have write access to the output files, produce corrupted output files and the build doesn't fail. At worst one bison process locks the output files, the second bison process errors out because it cannot get write access to the files, and the build fails.

A possible work around is this:

cmdparser.hpp: cmdparser.cpp
cmdparser.cpp: cmdparser.y
bison -d -o cmdparser.cpp cmdparser.y

But this syntax is not as clean and less intuitive.

Thank you,
Fred

Fred Bleuzet <fbleuzet4>

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #46542:  0001-Implement-grouped-targets-in-ordinary-rules.patch added by kkylheku (23KiB - text/x-patch - New patch against git head (parent: 214865ed5c66d8e363b16ea74509f23d93456707 2018-09-16).)
file #46537:  0001-Implement-grouped-targets-in-ordinary-rules.patch added by kkylheku (21KiB - text/x-patch - New patch: just more test cases relative to previous patch; all else identical.)
file #46536:  0001-Implement-grouped-targets-in-ordinary-rules.patch added by kkylheku (20KiB - text/x-patch - New patch: implements &: and &:: syntax; test cases; improved doc.)
file #46529:  0001-Implement-grouped-targets-in-ordinary-rules.patch added by kkylheku (10KiB - text/x-patch - Here is an initial patch against 4.2.1 to implement the feature )

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by elfring (Posted a comment)
  • -email is unavailable- added by kkylheku (Updated the item)
  • -email is unavailable- added by psmith (Posted a comment)
  • -email is unavailable- added by ccb23 (Voted in favor of this item)
  • -email is unavailable- added by tahonermann (Posted a comment)
  • -email is unavailable- added by yost (Posted a comment)
  •  

    There are 100 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follow 11 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2019-05-12 psmith Assigned toNone psmith
        Open/ClosedOpen Closed
        Fixed ReleaseNone 4.3
    2019-05-12 psmith StatusNone Fixed
    2019-03-15 kkylheku Attached File- Added 0001-Implement-grouped-targets-in-ordinary-rules.patch, #46542
    2019-03-14 kkylheku Attached File- Added 0001-Implement-grouped-targets-in-ordinary-rules.patch, #46537
    2019-03-14 kkylheku Attached File- Added 0001-Implement-grouped-targets-in-ordinary-rules.patch, #46536
    2019-03-13 kkylheku Attached File- Added 0001-Implement-grouped-targets-in-ordinary-rules.patch, #46529
    2019-03-13 psmith SummaryAdd a non-posix feature for parallel mode. Allow multiple targets to be built from a single explicit rule recipe invocation
    2010-02-16 ccb23 Carbon-Copy- Added ccb23
    2006-04-02 nikm Carbon-Copy- Added -email is unavailable-

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code