Last active
August 8, 2018 02:10
-
-
Save Lupino/87bf8deccb4926e6a2a7399901a58a9c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#/usr/bin/env bash | |
LIB_PATH=../lib | |
test -d $LIB_PATH || mkdir -p $LIB_PATH | |
copy() { | |
F=$1 | |
LN=`readlink $F || echo ""` | |
if [ "$LN" != "" ]; then | |
LF=`dirname $L`/$LN | |
test -f $LIB_PATH/$LN || cp -av $LF $LIB_PATH | |
fi | |
N=`basename $F` | |
test -f $LIB_PATH/$N || cp -av $L $LIB_PATH | |
} | |
patch_mach() { | |
EXE=$1 | |
chmod +w $EXE | |
EXECNAME=`basename $EXE` | |
if [ "${EXECNAME##*.}" == "dylib" ]; then | |
install_name_tool -id @rpath/$EXECNAME $EXE | |
otool -l $EXE | grep @loader_path > /dev/null || install_name_tool -add_rpath @loader_path $EXE | |
else | |
otool -l $EXE | grep @executable_path/$LIB_PATH > /dev/null ||install_name_tool -add_rpath @executable_path/$LIB_PATH $EXE | |
fi | |
otool -L $EXE | grep nix | awk '{print $1}' | while read L;do | |
copy $L | |
install_name_tool -change $L @rpath/$N $EXE | |
done | |
otool -l $EXE | grep nix | awk '{print $2}' | while read P;do | |
install_name_tool -delete_rpath $P $EXE | |
done | |
chmod -w $EXE | |
} | |
echo "Patch all executable" | |
OUT=`find -type f | while read F; do patch_mach $F; done` | |
echo "Patch all executable done" | |
echo "Patch library" | |
while [ "$OUT" != "" ]; do | |
OUT=`find $LIB_PATH -type f | while read F; do patch_mach $F; done` | |
done | |
echo "Patch library done" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment