Randomize Parallel Recipe Execution Order In Makefile

393 Views Asked by At

I have a makefile that has a ton of subsystem and am able to build it with the -j flag so that it goes much faster and builds the different recipes in parallel.

This seems to be working fine for now but am not sure if I am missing some needed dependencies and am just "getting lucky" with the order that these are being built.

Is there a way where I can randomize the order recipes are run while still following all the dependencies that I have defined?

2

There are 2 best solutions below

0
On

You can control number of jobs Make is allowed to run asynchronously with -j command line option. This way you can "randomize" recipes being executed simultaneously and catch some issues in your makefiles.

0
On

I'll duplicate the answer from https://stackoverflow.com/a/72722756/5610270 here:

Next release of GNU make will have --shuffle mode. It will allow you to execute prerequisites in random order to shake out missing dependencies by running $ make --shuffle.

The feature was recently added in https://savannah.gnu.org/bugs/index.php?62100 and so far is available only in GNU make's git tree.