Ordering dependencies

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Ordering dependencies

Hitesh Kulkarni
Hi

We have an intricate system of Makefiles that build our software. The
software is divided into modules which form a DAG which is fed to GNU make.
Through some analysis we have identified modules that take a long time to
build and want to get them going before anything else can start. We tried
introducing a rule to similar to


some_target : module1 module2 module3

module3: module1


$ gmake some_target -j


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.

So in the above case with j value higher than 1 we observed that module1 is
built before module3 cause of the dependency, but module2 which is not
dependent on module1 or module3 isn’t always built before module3.

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

Thank you.
Hitesh.
_______________________________________________
Help-make mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-make
Reply | Threaded
Open this post in threaded view
|

Re: Ordering dependencies

Paul Smith-20
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

_______________________________________________
Help-make mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-make