bug-make
[Top][All Lists]
Advanced

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

Re: make -jN runs some rules more than once


From: Paul Smith
Subject: Re: make -jN runs some rules more than once
Date: Fri, 11 Sep 2015 08:35:30 -0400

On Thu, 2015-09-10 at 15:17 -0700, Brian Malehorn wrote:
> Consider the following Makefile:
> 
> all: a.gz b.gz
> 
> a.gz b.gz:
>         touch a
>         gzip a
>         touch b
>         gzip b
> 
> If you run it with 'make -j1', it runs fine.
> 
> But if you run it with 'make -j2',
>   - target "a.gz" must be built, spawning job 1 to build "a.gz b.gz"
>   - target "b.gz" must be built, spawning job 2 to build "a.gz b.gz"
>   - they trip over each other and the build crashes
> 
> There are plenty of workarounds, but this strikes me as a bizarre
> default behavior. Shouldn't the rule "a.gz b.gz" should only be run
> once, regardless of -jN?

No.  Make's behavior is correct.

The thing you have to understand is that this construct in your
makefile:

    a b:
            <somerule>

is identical to, and interpreted by make as:

    a:
            <somerule>
    b:
            <somerule>

E.g., multiple explicit targets are just a shorthand way of writing
multiple rules, so make still expects to run one instance of the recipe
for each target.  It is NOT a statement to make that one invocation of
the recipe will build all the targets.

This interpretation has been true of every make ever created since the
first one in the 1970's and is mandated by the POSIX standard (not to
mention hundreds of thousands of makefiles already in existence).

For GNU make, admittedly confusingly, _pattern rules_ with multiple
targets specify that make should run the pattern one time to build all
the targets.  This behavior is unique to GNU make of course but it's
codified in thousands of makefiles as well and cannot be changed.




reply via email to

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