2

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?

Daniel H
  • 25
  • 3
  • `GNU make` follows all dependencies strictly. It will not build something if all its dependencies are not up to date. – igagis Jul 25 '17 at 16:13
  • The only way is to do it yourself in your makefile. Make has no ability to do this. – MadScientist Jul 25 '17 at 18:24
  • 1
    You could redefine `CC`, `CXX`, etc with something like: `CC:=sleep $(bc -l <<< "scale=4 ; ${RANDOM}/3276") && gcc`, which will randomize build order a bit – blackghost Jul 25 '17 at 20:24
  • @igagis I am talking more about the things that dont depend on each other. For example if you have rules A-F and only B depends on C then there could be issues when it runs A C D E F B vs running F A E D C B but when it runs ether way it follows the dependence rules. – Daniel H Jul 26 '17 at 17:38
  • @DanielH If there are issues if those are run in wrong order, then you have to specify dependencies so that those are run in correct order. It's a matter of writing your `makefile` properly. – igagis Jul 26 '17 at 19:50
  • @igagis I agree! I am trying to find if there are any dependencies that I am missing. It is working now but there are 60ish things being built and I am not the original archetecht. I am just changing over to use make and want to make sure I am not missing anything. – Daniel H Jul 26 '17 at 20:20
  • Looks like an XY-problem. To find out if all targets are built properly, run a clean build. For the dependencies, IIRC, gmake has an option to dump the dependency tree. But as I use a more modern tool (SCons) which is also more reliable on rebuilds, I can be wrong, though. – too honest for this site Sep 07 '17 at 17:08

2 Answers2

1

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.

Alexey Semenyuk
  • 674
  • 4
  • 9
0

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.