Skip to content

Instantly share code, notes, and snippets.

@msullivan
Created February 25, 2015 18:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save msullivan/3290e688670c54f8d1a2 to your computer and use it in GitHub Desktop.
Save msullivan/3290e688670c54f8d1a2 to your computer and use it in GitHub Desktop.
Hacky wrapper to run make in parallel until linking starts
#!/bin/bash
# Terrible hack to run a build in parallel until it starts linking
# things and then switch to running it in serial to cut down on memory usage.
# This could be better and more robust in a *lot* of ways.
# I use this for building llvm/clang.
# The first argument gets passed to the initial make that runs until
# linking starts and should be -j4 or whatever. The rest of the
# arguments get passed to both makes.
PARALLEL="$1"
shift
(while ! pgrep -u `whoami` ld.bfd.real; do sleep 1; done;
killall make ld.bfd.real) &
trap 'kill %1' INT QUIT TERM EXIT
make "$PARALLEL" "$@"
# Sleep to give the kill a chance to finish so the new make doesn't
# get killed. Evade, don't solve, concurrency problems.
sleep 2
make "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment