-
Notifications
You must be signed in to change notification settings - Fork 12
/
fix-dylib.sh
executable file
·152 lines (128 loc) · 4.82 KB
/
fix-dylib.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#! /bin/bash
PLUGIN="$1"
BUNDLE="$2"
#curl -L https://download.gimp.org/mirror/pub/gimp/v2.10/osx/gimp-2.10.6-x86_64.dmg -O || exit 1
#hdiutil attach gimp-2.10.6-x86_64.dmg >& attach.log || exit 1
#hdiutil attach ~/Downloads/gimp-2.10.6-x86_64.dmg >& attach.log
#MOUNT_POINT=$(cat attach.log | tr "\t" "\n" | tail -n 1)
#echo "MOUNT_POINT: $MOUNT_POINT"
#TARGET="/Applications/GIMP-2.10.app"
#TARGET="/Applications/McGimp-2.10.6.app"
#TARGET="$(find "$MOUNT_POINT" -depth 1 -name "*.app" | tail -n 1)"
TARGET="/tmp/gimp.app"
echo "TARGET: $TARGET"
#exit
rm -rf plugins-fixed
mkdir -p plugins-fixed
cd plugins
echo "Contents of plugins folder:"
ls -l
for F in ./??*; do
DYLIST=$(otool -L "$F")
NDY=$(echo "$DYLIST" | wc -l)
echo "NDY: $NDY"
#F2="$HOME/Library/Application Support/GIMP/2.10/plug-ins/$f"
#F2="$TARGET/Contents/Resources/lib/gimp/2.0/plug-ins/$f"
F2="../plugins-fixed/$F"
cp -a "$F" "$F2"
../build/macdylibbundler/dylibbundler -b -x "$F2" -d "../plugins-fixed/$PLUGIN/lib" --create-dir -p "@rpath" > /dev/null
for DYLIB in "../plugins-fixed/$PLUGIN/lib/"*.dylib; do
PREFIX=$(basename "$DYLIB" | cut -d'.' -f 1)
echo "PREFIX: $PREFIX"
DYLIB2=$(find "$TARGET/Contents" -name "$PREFIX"*)
if [ -n "$DYLIB2" ]; then
echo "rm -f \"$DYLIB\""
rm -f "$DYLIB"
fi
done
#continue
cp -a "$F" "$F2"
cp -a "$F" "${F2}-orig"
# remove all the version information for non-system libraries
I=2
while [ $I -le $NDY ]; do
LINE=$(echo "$DYLIST" | sed -n ${I}p)
DYLIB=$(echo $LINE | sed -e 's/^[ \t]*//' | tr -s ' ' | tr ' ' '\n' | head -n 1)
TEST=$(echo "$DYLIB" | grep '^/usr/local/')
if [ -z "$TEST" ]; then
TEST=$(echo "$DYLIB" | grep 'gimp-plugins-collection/inst/')
fi
if [ -n "$TEST" ]; then
echo "../build/optool/build/Release/optool vreset -p \"$DYLIB\" -t \"$F2\""
../build/optool/build/Release/optool vreset -p "$DYLIB" -t "$F2"
fi
I=$((I+1))
done
# patch absolute paths
I=2
while [ $I -le $NDY ]; do
LINE=$(echo "$DYLIST" | sed -n ${I}p)
DYLIB=$(echo $LINE | sed -e 's/^[ \t]*//' | tr -s ' ' | tr ' ' '\n' | head -n 1)
PREFIX=$(basename "$DYLIB" | cut -d'.' -f 1)
echo "PREFIX: $PREFIX"
DYLIB2=$(find "$TARGET/Contents" -name "$PREFIX"*)
echo "DYLIB2: $DYLIB2"
#check if this is a system library, using an ad-hoc euristic
TEST=$(echo "$DYLIB" | grep '\.framework')
if [ -n "$TEST" ]; then
# this looks like a framework, no ned to patch the absolute path
I=$((I+1)); continue;
fi
TEST=$(echo "$DYLIB" | grep '/usr/lib/')
if [ -n "$TEST" ]; then
# this looks like a system library, no ned to patch the absolute path
I=$((I+1)); continue;
fi
# replace absolute paths for non-system libraries and frameworks
# at runtime the libraries will be searched through the @rpath list
# if the library is provided by the application bundle, we eventually replace
# the original file name with the one in the bundle
if [ -n "$DYLIB2" ]; then
DYLIB2NAME=$(basename "$DYLIB2")
echo "install_name_tool -change \"$DYLIB\" \"@rpath/$DYLIB2NAME\" \"$F2\""
install_name_tool -change "$DYLIB" "@rpath/$DYLIB2NAME" "$F2"
else
DYLIBNAME=$(basename "$DYLIB")
echo "install_name_tool -change \"$DYLIB\" \"@rpath/$DYLIBNAME\" \"$F2\""
install_name_tool -change "$DYLIB" "@rpath/$DYLIBNAME" "$F2"
fi
I=$((I+1))
done
otool -L "$F2"
# fill the directory list in @rpath
install_name_tool -add_rpath "@loader_path/../../.." "$F2"
install_name_tool -add_rpath "@loader_path/../../../../../Frameworks" "$F2"
install_name_tool -add_rpath "@loader_path/$PLUGIN/lib" "$F2"
install_name_tool -add_rpath "/Applications/$BUNDLE/Contents/Resources/lib" "$F2"
install_name_tool -add_rpath "/Applications/$BUNDLE/Contents/Frameworks" "$F2"
#install_name_tool -add_rpath "/tmp/McGimp-2.10.6/Contents/Resources/lib" "../../PhFGimp/build/$f"
#install_name_tool -add_rpath "/tmp/lib-std" "../../PhFGimp/build/$f"
done
# remove version information for dependencies of plugin libraries
for F in "../plugins-fixed/$PLUGIN/lib"/*.dylib; do
echo "Fixing paths and library versions in \"$F\""
DYLIST=$(otool -L "$F")
NDY=$(echo "$DYLIST" | wc -l)
echo "NDY: $NDY"
# remove all the version information for non-system libraries
I=2
while [ $I -le $NDY ]; do
LINE=$(echo "$DYLIST" | sed -n ${I}p)
DYLIB=$(echo $LINE | sed -e 's/^[ \t]*//' | tr -s ' ' | tr ' ' '\n' | head -n 1)
PREFIX=$(basename "$DYLIB" | cut -d'.' -f 1)
echo "PREFIX: $PREFIX"
DYLIB2=$(find "$TARGET/Contents" -name "$PREFIX"*)
echo "DYLIB2: $DYLIB2"
TEST=$(echo "$DYLIB" | grep '^@rpath/')
if [ -n "$TEST" ]; then
echo "../build/optool/build/Release/optool vreset -p \"$DYLIB\" -t \"$F\""
../build/optool/build/Release/optool vreset -p "$DYLIB" -t "$F"
if [ -n "$DYLIB2" ]; then
DYLIB2NAME=$(basename "$DYLIB2")
echo "install_name_tool -change \"$DYLIB\" \"@rpath/$DYLIB2NAME\" \"$F\""
install_name_tool -change "$DYLIB" "@rpath/$DYLIB2NAME" "$F"
fi
fi
I=$((I+1))
done
done