Instantly share code, notes, and snippets.

Embed
What would you like to do?
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