help-make
[Top][All Lists]
Advanced

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

Re: Pattern rule executed multiple times with multiple jobs


From: Philip Guenther
Subject: Re: Pattern rule executed multiple times with multiple jobs
Date: Sat, 9 Aug 2014 15:15:10 -0700

On Sat, Aug 9, 2014 at 2:24 PM, Kevin Locke <address@hidden> wrote:
>
> I'm trying to write a rule which generates multiple files from a
> single command invocation.  I'm a bit of a make newbie, so my
> understanding is likely flawed and I'd appreciate your help.
>
> The Introduction to Pattern Rules section of the Manual[1] states "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."  However, this does not appear to
> be the case when running make with multiple jobs.
>
> For example, consider the following Makefile:
>
> all: foo1 foo2
>
> foo%:
>         sleep 2
>         touch foo1 foo2

...

> Demonstrating that the recipe is executed twice, once for each target.
> Is this the expected behavior?  Am I misinterpreting the sentence from
> the manual?


Yep.  That pattern rule only has a single target "foo%", not multiple
targets.  An example of the latter can be found a little further down in
the manual:

----
This pattern rule has two targets:

     %.tab.c %.tab.h: %.y
             bison -d $<

This tells make that the recipe ‘bison -d x.y’ will make both x.tab.c and x
.tab.h. If the file foo depends on the files parse.tab.o and scan.o and the
file scan.odepends on the file parse.tab.h, when parse.y is changed, the
recipe ‘bison -d parse.y’ will be executed only once, and the prerequisites
of both parse.tab.o andscan.o will be satisfied. (Presumably the file
parse.tab.o will be recompiled from parse.tab.c and the file scan.o from
scan.c, while foo is linked from parse.tab.o,scan.o, and its other
prerequisites, and it will execute happily ever after.)

----

 Is there any way to specify that the rule should be run
> once to make both files, even when running with multiple jobs, without
> resorting to one of the hacks in the oft-cited CMCrossroads article on
> Rules with Multiple Outputs in GNU Make[2]?
>

An example closer to yours would be

%1 %2:
        sleep 2
        touch $*1 $*2

$ make -j3 foo1 foo2
sleep 1
touch foo1 foo2
make: Nothing to be done for 'foo2'.
$


Philip Guenther


reply via email to

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