bug-make
[Top][All Lists]
Advanced

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

Re: make -j2 does the same thing twice


From: Paul D. Smith
Subject: Re: make -j2 does the same thing twice
Date: Thu, 11 Apr 2002 09:16:10 -0400

%% Peter Kutschera <address@hidden> writes:

  pk> The problem is if there exists rules generating some "object"-files from 
  pk> one "source"-file with rules like:

  pk> my_clnt.c my_xdr.c my.h my_svc.c : my.x
  pk>     rpcgen my.x

  pk> When using make -j rpcgen is executed IM PARALELL several times.

Yes.  The rule above doesn't say "run this once to build all these
targets".  It says "each of these targets can be built using this same
rule".  So, that's what make does.  The rule above is simply syntactic
sugar for writing this:

  my_clnt.c: my.x
        rpcgen my.x
  my_xdr.c: my.x
        rpcgen my.x
  my_svc.c: my.x
        rpcgen my.x

See the manual.

The only _good_ way to write a rule that generates multiple targets is
with patterns.  Unlike normal targets, a rule with multiple pattern
targets is interpreted such that all targets are created with one
invocation of the rule, like this:

  %_clnt.c %_xdr.c %_svc.c: %.x
        rpcgen $<

  all: my_clnt.c my_xdr.c my.h my_svc.c

will only run the rule once and understand that all the targets are
created with one invocation.

If you can't write your rules as patterns (there's no common stem) then
you have much bigger problems.

This is in the GNU make manual as well (see the section on pattern
rules).  Note this is a GNU make extension and is not portable to other
versions of make.

-- 
-------------------------------------------------------------------------------
 Paul D. Smith <address@hidden>          Find some GNU make tips at:
 http://www.gnu.org                      http://www.paulandlesley.org/gmake/
 "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]