Skip to content

Instantly share code, notes, and snippets.

@msullivan
Created February 25, 2015 19:15
Show Gist options
  • Save msullivan/d33029fcda6889b7d097 to your computer and use it in GitHub Desktop.
Save msullivan/d33029fcda6889b7d097 to your computer and use it in GitHub Desktop.
Wrapper script to make commands that look like linking run in serial
#!/bin/sh
# Run a command with a lock if it looks like it is a linker command: that is,
# if none of its arguments are -c.
# Then you can do a build where compilation is parallel but linking is serial
# by doing something like (for llvm/clang):
# make -j4 'CXX=lock-linking /tmp/llvm-build-lock clang++'
LOCKFILE="$1"
shift
for I in "$@"; do
if [ $I = "-c" ]; then
# Not a linker command, just run it
exec "$@"
fi
done
# Run the linker command under the lock
flock "$LOCKFILE" "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment