[Top][All Lists]

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

Re: Improvement on parallel make

From: Paul Smith
Subject: Re: Improvement on parallel make
Date: Tue, 12 Dec 2006 09:58:48 -0500

On Tue, 2006-12-12 at 01:15 -0700, Philip Guenther wrote:

> The desire in that example is to just write _this_ makefile:
>    local_objects = a.o b.o c.o d.o
>    all: all-recursive .WAIT all-local
>    all-recursive:
>         $(MAKE) -C subdir all
>    all-local: $(local_objects)

> So, one or more of the local objects is dependent on all-recursive
> being built first.  But all-recursive is a phony, so they must
> _really_ be dependent on something that all-recursive builds.  Rather
> than actually state the real dependencies (a.o needs subdir/built.h
> and c.o needs subdir2/another-built.h), that makefile tries to say
> "all dependencies of all-local are order-only dependent on
> all-recursive".

Right, exactly.  However, this is a very common requirement in recursive
builds; we can't get away from it.  Suppose we were to declare the REAL
prerequisites in the top-level makefile; a.o depends on foo.h (which
will be generated from one of the subdirectory builds):

  a.o: foo.h

Now, we need a rule for building foo.h in the top-level makefile... and
how do we write that?  Well, the command to be run is obviously a
recursive invocation of make, but you either need to import all of
foo.h's prerequisites into the top-level makefile so make can determine
when it needs to run that recursive make (in which case you've
duplicated a lot of rules... in fact if you take this to its logical
conclusion you end up with inclusive make and no recursion at all!!) or
you have to declare foo.h to be phony so that the recursive make always
runs, to determine whether the file needs to be updated.  But of course
you can't use .PHONY or else a.o will always be rebuilt.  So you need to
use a FORCE rule, I guess.  I'm not sure that would work well.

> But it doesn't really do that!  The .WAIT connection only applies when
> both all-local and all-recursive are being built.  If you simply say
> "make a.o" the .WAIT will have no effect and it will build a.o without
> first trying running all-recursive.

But in a recursive environment this is often what you want.  You leave
it up to the user to understand that if they run "make a.o" it will
build just a.o, without recursing and updating everything else.
Although this is not "safe", it's often a necessary sacrifice for
performance, and the risk is after all not that high if you internalize
a few defensive practices.

 Paul D. Smith <address@hidden>          Find some GNU make tips at:            
 "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]