Skip to content

Instantly share code, notes, and snippets.

@stek29
Created November 29, 2018 04:59
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 stek29/80a40c4abd7792bc3a71e486fe1862e3 to your computer and use it in GitHub Desktop.
Save stek29/80a40c4abd7792bc3a71e486fe1862e3 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -euo pipefail
getlibs() {
otool -l "$1" |\
(grep -A2 LC_LOAD_DYLIB || true) |\
(grep name || true) |\
awk '{ print $2 }' |\
(grep '/usr/local' || true)
}
patchdeps() {
getlibs "$1" | while read lib; do
BASELIB="$(basename "$lib")"
if [ ! -e "$BASELIB" ]; then
cp "$lib" "$BASELIB"
chmod +w "$BASELIB"
install_name_tool -id "@executable_path/$BASELIB" "$BASELIB"
patchdeps "$BASELIB"
fi
install_name_tool -change "$lib" "@executable_path/$BASELIB" "$1"
done
}
chmod +w "$1"
patchdeps "$1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment