bug-make
[Top][All Lists]
Advanced

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

Re: Inconsistent behaviour when building in parallel


From: Paul Smith
Subject: Re: Inconsistent behaviour when building in parallel
Date: Sat, 20 Jan 2007 10:12:34 -0500

On Fri, 2007-01-19 at 20:01 +0100, Dirk Heinrichs wrote:

> I'm using GNU make 3.81 (on Linux, if this is important) and see strange 
> behaviour in parallel builds with the following Makefile:
> 
> file1.txt file2.txt: file.in
>       cat $< >file1.txt|tee file2.txt
> 
> test: file1.txt file2.txt
>       cat $^ >$@
> 
> In a normal build, make does the right thing:
> 
> % make test
> cat file.in >file1.txt|tee file2.txt
> cat file1.txt file2.txt >test
> 
> In case of a parallel build, the "cat ... | tee ..." command for file[12].txt 
> is executed twice, which should not happen:
> 
> % make -j 2 test
> cat file.in >file1.txt|tee file2.txt
> cat file.in >file1.txt|tee file2.txt
> cat file1.txt file2.txt >test

Make is behaving correctly here.  Multiple targets in a single rule does
not mean "all these targets are built from one invocation of the rule".
It means that each of these targets has the same prerequisites and rule,
and will be built one at a time by running the rule.  IOW, this:

    a b c : d e f ; command

is identical to writing this:

    a : d e f ; command
    b : d e f ; command
    c : d e f ; command

See the GNU make manual for details.

You can use pattern rules:

        %1.txt %2.txt : %.in
                ...

which do work as you expect.  Or you have to use a sentinel file.

-- 
-------------------------------------------------------------------------------
 Paul D. Smith <address@hidden>          Find some GNU make tips at:
 http://www.gnu.org                      http://make.paulandlesley.org
 "Please remain calm...I may be mad, but I am a professional." --Mad Scientist




reply via email to

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