bugmake - Bugs: bug #42125, Explicit rules do not support...


bug #42125: Explicit rules do not support multiple targets

Submitted by:  None
Submitted on:  Tue Apr 15 16:02:29 2014  
Severity: 3 - NormalItem Group: Enhancement
Status: NonePrivacy: Public
Assigned to: NoneOpen/Closed: Open
Component Version: 4.0Operating System: POSIX-Based
Fixed Release: NoneTriage Status: Medium Effort

Add a New Comment (Rich MarkupRich Markup):

You are not logged in

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


Sun Apr 17 18:21:27 2016, comment #3:

Hi Tristan. Please move this proposal to the -unavailable- mailing list. I don't want to have a design discussion in the bug tracker. Thanks.

Paul D. Smith <psmith>
Project Administrator
Sun Apr 17 15:33:24 2016, comment #2:

There is a space of inputs that is currently disallowed that could support both multiple rule types:
1. a single target for each of multiple rules, and
2. a single rule having multiple targets
for both implicit and explicit rules.

The static pattern syntax could be extended to support implicit pattern rules, changing
targets …: target-pattern: prereq-patterns … ; recipe
factors …: factors-pattern[=substitutions …]: prereq-patterns … ; recipe

This would default to the current behaviour when [=substitutions]: is missing
Also, add support for %% at any place which would form implicit rules from several factors in the same way that static pattern rules do

The meaning of rules of this form would be as follows

For each factor, one rule will be generated, that rule may have multiple targets and multiple prerequisites as well as order-only prerequisites. Double-percent '%%' will appear in the resulting per-factor rule as a single percent '%' and thus the resulting per-factor rule will be an implicit rules

For each per-factor rule, its factor is matched against factors-pattern as normal but the factors-pattern is substituted by the right-hand side of the '=' sign as in patsubst in order to define one or more targets of that per-factor rule.

If an equal sign '=' is not given then the behaviour is as if the equal sign is given and the substitution is the factors-pattern is repeated to provide a one-to-one mapping by default (eg "%.o" behaves as "%.o=%.o"). Thus the default behaviour is the same as for the existing static pattern syntax

If an explicit rule is generated with multiple targets then the make database lists each target separately in addition to its rule with a note that it is a sibling of a multiple target rule in order to facilitate commandline tab completion. The multiple target rule itself is listed as '# Not a target' and '# Multiple targets' so that existing commandline tab completion is not broken. Examples of commandline tab completion includes bash-completion.

build/x86-64/main.o build/x86/main.o build/armel/main.o: %.o=%.o: %.c ; true
# same as build/x86-64/main.o build/x86/main.o build/armel/main.o: %.o: %.c ; true
# same as
# build/x86-64/main.o: build/x86-64/main.c ; true
# build/x86/main.o: build/x86/main.c ; true
# build/armel/main.o: build/armel/main.c ; true

x86-64 x86 armel: %=build/%/main.o: main.c ; true
# same as
# build/x86-64/main.o: main.c ; true
# build/x86/main.o: main.c ; true
# build/armel/main.o: main.c ; true

%%.o: %.o=%.o %.log .%.deps %.symbols: %.c ; true
# same as
# %.o %.log .%.deps %.symbols: %.c ; true

x86-64 x86 armel: %=build/%/%%.o log/%/%%.log .deps/%/%%.d symbols/%/%%.symbols: %%.c ; true
# same as
# build/x86-64/%.o log/x86-64/%.log .deps/x86-64/%.d symbols/x86-64/%.symbols: %.c ; true
# build/x86/%.o log/x86/%.log .deps/x86/%.d symbols/x86-64/%.symbols: %.c ; true
# build/armel/%.o log/armel/%.log .deps/armel/%.d symbols/x86-64/%.symbols: %.c ; true

main.o err.o: %.o=%.o %.log .%.deps %.symbols: %.c ; true
# same as this where all targets of one rulesare generated in a single step (as if there is a
# % sign in there but $* must be the empty string)
# main.o main.log .main.deps main.symbols: main.c ; # err.o err.log .err.deps err.symbols: err.c ; true

Please consider making each rule defined like this fail if any of the targets for one factor is not updated unless it is a prerequisite of .PHONY to avoid incorrect builds due to mistakes. ie, all non-phony targets must be updated by its rule. I can imagine mistakes in the recipes for multiple simulataneous outputs causing bad incrmental builds.

I will be happy to do the bulk of the work to implement this, if some guidance can be provided and help with the hard bits.

Tristan Wibberley <codeshot>
Tue Apr 15 16:21:58 2014, comment #1:

This is not technically a bug. A static pattern rule is a form of explicit rule, not an implicit rule such as pattern rule. Explicit rules do not support multiple targets being created from a single invocation of the recipe, although this is a long-requested enhancement. Looking through the bug tracker I couldn't find an enhancement for it, though, so I'm leaving this one here as that request.

Paul D. Smith <psmith>
Project Administrator
Tue Apr 15 16:02:29 2014, original submission:

Makefile allows to create pattern rule with multiple targets, like below. This is very handy for rules which generates multiple files at once.

%.h %.c : %.idl
touch $(<:%.idl=%.c) $(<:%.idl=%.h)

I tried to build static pattern rule in similar way, but it do not work - make reports error "multiple target patterns":

$(IDLS:%.idl=%.c) $(IDLS:%.idl=%.h) : %.h %.c : %.idl
touch $(<:%.idl=%.c) $(<:%.idl=%.h)

I tested this using make 4.0 on Linux. Please fix this.



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

Attach File(s):

No files currently attached


Depends on the following items: None found

Items that depend on this one: None found


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

    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
    Tue Apr 15 16:21:58 2014psmithItem GroupBug=>Enhancement
      Triage StatusNone=>Medium Effort
      SummaryStatic pattern rules do not support multiple targets=>Explicit rules do not support multiple targets

    Back to the top

    Powered by Savane 3.1-cleanup1