help-make
[Top][All Lists]
Advanced

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

Pattern rule executed multiple times with multiple jobs


From: Kevin Locke
Subject: Pattern rule executed multiple times with multiple jobs
Date: Sat, 9 Aug 2014 15:24:45 -0600
User-agent: Mutt/1.5.23 (2014-03-12)

Hello All,

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

If I invoke `make -j2` it prints:

sleep 2
sleep 2
touch foo1 foo2
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?  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]?

Any help would be greatly appreciated.

Thanks,
Kevin

P.S.  I am currently using the Debian package of GNU Make 4.0.

1.  https://www.gnu.org/software/make/manual/make.html#Pattern-Intro
2.  http://www.cmcrossroads.com/article/rules-multiple-outputs-gnu-make



reply via email to

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