Skip to content

Instantly share code, notes, and snippets.

@stek29 stek29/distbrew.sh
Created Nov 29, 2018

Embed
What would you like to do?
#!/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
You can’t perform that action at this time.