help-make
[Top][All Lists]
Advanced

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

Re: Ordering dependencies


From: Paul Smith
Subject: Re: Ordering dependencies
Date: Thu, 07 Jul 2016 12:08:24 -0400

On Thu, 2016-07-07 at 10:27 -0400, Hitesh Kulkarni wrote:
> some_target : module1 module2 module3
> 
> module3: module1
> 
> 
> GNU make honors the order of modules when we use -j1 but as soon as
> we increase the value for j, the ordering of modules doesn’t seem to
> work.

Make will use the same algorithm for both serial and parallel builds,
except that in parallel builds make won't wait for the current job to
finish before trying to start a new one.  The order make uses is always
the same: for a given target, try to build its prerequisites in the
order they were defined (prerequisites listed in rules with recipes
always come first, before any other prerequisites; beyond that they are
built in the order they appeared).

In your example above make starts to build module1 then because of -j
it doesn't wait.  It then starts to build module2 and because of -j it
doesn't wait.  It then wants to start module3 but sees that it depends
on module1 which is still building, so it won't start module3 yet.

That's all it can build so now it waits for something to finish.  When
module1 is finished, it will start module3.

> Is there any way we can explicitly provide hints to gmake to build in
> the order that we provide?

GNU make always STARTS jobs "in the order you provide", but obviously
if you ask it to build in parallel then some jobs will be built at the
same time and depending on when previous jobs finish, the order in
which things are built can vary.

The only way to prevent that is to declare dependencies between
targets.  So if you don't want module2 to start to build until module1
is complete, then you should tell make about it:

  module2: module1



reply via email to

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