forked from ayyi/samplecat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
buildmac.sh
executable file
·332 lines (281 loc) · 9.82 KB
/
buildmac.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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
#!/bin/bash
PRODUCT_NAME="Samplecat"
VERSION=`grep AC_INIT configure.ac | sed 's/^.*\[\([0-9.]*\)\].*$/\1/g'`
echo "version: $VERSION"
GTKDIR=${GTKDIR:-"$HOME/gtk/inst"}
GTKLOADER=gtk-2.0/2.10.0/loaders
PANGOPATH=pango/1.6.0/modules
DMGFILE=/tmp/${PRODUCT_NAME}_v$VERSION.dmg
echo "building: $DMGFILE"
if [ -e $DMGFILE ]; then
echo "DMG file exists:"
ls -dl $DMGFILE
exit;
fi
/bin/echo -n " go?[Enter|CTRL-C]"
read
#NOREBUILD=1
#NOCLEAN=1
##############################################################################
if test -d $GTKDIR; then
export PKG_CONFIG_PATH=$GTKDIR/lib/pkgconfig/:$PKG_CONFIG_PATH
else
echo "no GTK installation-prefix was specified."
exit;
fi
if test -z "$NOREBUILD"; then
automake --gnu --add-missing -Wall
libtoolize --automake || glibtoolize
autoreconf
automake --gnu --add-missing -Wall
autoconf
CFLAGS="-arch i386 -arch x86_64 -arch ppc" \
CXXFLAGS="-arch i386 -arch x86_64 -arch ppc" \
LDFLAGS="-headerpad_max_install_names" \
./configure --disable-dependency-tracking
make clean
make || exit
fi
file src/samplecat
test -f src/samplecat || exit
##############################################################################
follow_dependencies () {
libname=$1
cd "${TARGET_BUILD_DIR}/${PRODUCT_NAME}.app/Contents/Frameworks"
dependencies=`otool -arch all -L "$libname" | egrep '\/((opt|usr)\/local\/lib|gtk\/inst\/lib)' | awk '{print $1}'`
for l in $dependencies; do
depname=`basename $l`
deppath=`dirname $l`
if [ ! -f "${TARGET_BUILD_DIR}/${PRODUCT_NAME}.app/Contents/Frameworks/$depname" ]; then
deploy_lib $depname "$deppath"
fi
done
}
update_links () {
libname=$1
libpath=$2
for n in `ls ${LIBS_PATH}/*`; do
install_name_tool \
-change "$libpath/$libname" \
@executable_path/../Frameworks/$libname \
"$n"
done
}
deploy_lib () {
libname=$1
libpath=$2
check=`echo $INSTALLED | grep $libname`
if [ "X$check" = "X" ]; then
if [ ! -f "${TARGET_BUILD_DIR}/${PRODUCT_NAME}.app/Contents/Frameworks/$libname" ]; then
cp -f "$libpath/$libname" "${TARGET_BUILD_DIR}/${PRODUCT_NAME}.app/Contents/Frameworks/$libname"
install_name_tool \
-id @executable_path/../Frameworks/$libname \
"${TARGET_BUILD_DIR}/${PRODUCT_NAME}.app/Contents/Frameworks/$libname"
follow_dependencies $libname
fi
export INSTALLED="$INSTALLED $libname"
fi
update_links $libname $libpath
}
update_executable() {
echo "updating executable ${TARGET}"
LIBS=`otool -arch all -L "$TARGET" | egrep '\/((opt|usr)\/local\/lib|gtk\/inst\/lib)' | awk '{print $1}'`
for l in $LIBS; do
libname=`basename $l`
libpath=`dirname $l`
deploy_lib $libname $libpath
install_name_tool \
-change $libpath/$libname \
@executable_path/../Frameworks/$libname \
"$TARGET"
done
}
##############################################################################
echo "------------------------------------"
export TARGET_BUILD_DIR="$(pwd)/build"
export PRODUCT_NAME
export INSTALLED=""
export CONTENTS_PATH="$TARGET_BUILD_DIR/${PRODUCT_NAME}.app/Contents"
export LIBS_PATH="${CONTENTS_PATH}/Frameworks"
export TARGET_PATH="${CONTENTS_PATH}/MacOS"
export TARGET="${TARGET_PATH}/${PRODUCT_NAME}"
BGPIC=$(pwd)/icons/dmgbg.png
TOPDIR=$(pwd)
SRCDIR=${TOPDIR}/src
echo "BASEDIR: ${TARGET_BUILD_DIR}"
echo "TARGET : ${TARGET}"
echo "LIBDIR : ${LIBS_PATH}"
rm -rf "$TARGET_BUILD_DIR"
mkdir -p "${CONTENTS_PATH}/Resources/share/"
mkdir -p "$LIBS_PATH"
mkdir -p "$TARGET_PATH"
echo "------------------------------------"
echo "installing files"
cp -v ${TOPDIR}/icons/${PRODUCT_NAME}.icns ${CONTENTS_PATH}/Resources
cat > "${TARGET_BUILD_DIR}/${PRODUCT_NAME}.app/Contents/Info.plist" << EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleExecutable</key>
<string>$PRODUCT_NAME</string>
<key>CFBundleName</key>
<string>$PRODUCT_NAME</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleSignature</key>
<string>RG42</string>
<key>CFBundleIdentifier</key>
<string>org.gareus.samplecat</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>CFBundleIconFile</key>
<string>$PRODUCT_NAME</string>
<key>CSResourcesFileMapped</key>
<true/>
</dict>
</plist>
EOF
# install binaries
install -m 755 ${SRCDIR}/${PRODUCT_NAME} ${TARGET}
update_executable
#file "$TARGET"
cp -v /Library/Audio/Plug-Ins/LADSPA/ladspa-rubberband.so $LIBS_PATH/
echo "------------------------------------"
echo "installing dependent libs..."
cd $LIBS_PATH && MORELIBS=`otool -arch all -L * | egrep '\/((opt|usr)\/local\/lib|gtk\/inst\/lib)' | awk '{print $1}'` && cd - > /dev/null
test -n "${MORELIBS}" && MORELIBS="$MORELIBS "
while [ "X$MORELIBS" != "X" ]; do
for l in $MORELIBS; do
libname=`basename $l`
libpath=`dirname $l`
deploy_lib "$libname" "$libpath"
done
cd $LIBS_PATH && MORELIBS=`otool -arch all -L * | egrep '\/((opt|usr)\/local\/lib|gtk\/inst\/lib)' | awk '{print $1}'` && cd - > /dev/null
test -n "${MORELIBS}" && MORELIBS="$MORELIBS "
done
echo "------------------------------------"
echo "updating references in executable"
update_executable
echo "------------------------------------"
otool -arch all -L "$TARGET"
echo "------------------------------------"
echo "installing GTK/Pango modules"
mkdir -p "${CONTENTS_PATH}/Resources/etc/pango"
mkdir -p ${LIBS_PATH}/${PANGOPATH}
mkdir -p ${CONTENTS_PATH}/Resources/etc/gtk-2.0/
mkdir -p ${LIBS_PATH}/${GTKLOADER}
cp -R ${GTKDIR}/lib/${PANGOPATH}/*.so ${LIBS_PATH}/${PANGOPATH}/
cp -R ${GTKDIR}/lib/${GTKLOADER}/*.so ${LIBS_PATH}/${GTKLOADER}/
if test -d "$HOME/data/gtk-shared/"; then
cp -R $HOME/data/gtk-shared/mime "${CONTENTS_PATH}/Resources/share/"
cp -R $HOME/data/gtk-shared/samplecat-icons ${CONTENTS_PATH}/Resources/share/icons
else
cp -R $GTKDIR/share/mime "${CONTENTS_PATH}/Resources/share/"
cp -R $GTKDIR/share/icons "${CONTENTS_PATH}/Resources/share/"
fi
# generate resource config files
cat > "${CONTENTS_PATH}/Resources/etc/pango/pango.rc" << EOF
[Pango]
ModuleFiles=../Resources/etc/pango/pango.modules
EOF
ESCAPEDGTKDIR="`echo \"$GTKDIR\" | sed 's/\\//\\\\\//g'`"
sed 's/'"$ESCAPEDGTKDIR"'\/lib/..\/Frameworks/g' \
${GTKDIR}/etc/pango/pango.modules > ${CONTENTS_PATH}/Resources/etc/pango/pango.modules
sed 's/'"$ESCAPEDGTKDIR"'\/lib/..\/Frameworks/g' \
${GTKDIR}/etc/gtk-2.0/gdk-pixbuf.loaders > ${CONTENTS_PATH}/Resources/etc/gtk-2.0/gdk-pixbuf.loaders
# change symbols links of plugins
for n in ${LIBS_PATH}/${PANGOPATH}/*.so; do
for m in `otool -L $n | grep "gtk/inst" | awk '{print $1}'`; do
BN=`basename $m`;
install_name_tool -change "$m" "@executable_path/../Frameworks/$BN" "$n";
done
done
for n in ${LIBS_PATH}/${GTKLOADER}/*.so; do
for m in `otool -L $n | grep "gtk/inst" | awk '{print $1}'`; do
BN=`basename $m`;
install_name_tool -change "$m" "@executable_path/../Frameworks/$BN" "$n";
done
done
echo "------------------------------------"
echo "generate startup-script"
mv -vf ${TARGET} ${TARGET}-bin
cat > "${TARGET}" << EOF
#!/bin/bash
CWD="\`/usr/bin/dirname \"\$0\"\`"
export XDG_DATA_HOME="\$CWD/../Resources/share/"
export PANGO_RC_FILE="\$CWD/../Resources/etc/pango/pango.rc"
export GDK_PIXBUF_MODULE_FILE="\$CWD/../Resources/etc/gtk-2.0/gdk-pixbuf.loaders"
cd "\$CWD"
exec "\$CWD/${PRODUCT_NAME}-bin"
EOF
chmod +x "${TARGET}"
##############################################################################
#roll a DMG
echo "------------------------------------"
echo "generating DMG.."
TMPFILE=/tmp/sctmp.dmg
MNTPATH=/tmp/mnt/
VOLNAME=Samplecat
APPNAME="${PRODUCT_NAME}.app"
mkdir -p $MNTPATH
if [ -e $TMPFILE -o -e $DMGFILE -o ! -d $MNTPATH ]; then
echo
echo "could not create DMG. tmp-file or destination file exists."
echo "please clean up previous builds:"
ls -dl $TMPFILE $DMGFILE $MNTPATH
exit;
fi
hdiutil create -megabytes 200 $TMPFILE
DiskDevice=$(hdid -nomount "${TMPFILE}" | grep Apple_HFS | cut -f 1 -d ' ')
newfs_hfs -v "${VOLNAME}" "${DiskDevice}"
mount -t hfs "${DiskDevice}" "${MNTPATH}"
cp -R ${TARGET_BUILD_DIR}/${PRODUCT_NAME}.app ${MNTPATH}/
mkdir ${MNTPATH}/.background
BGFILE=$(basename $BGPIC)
cp -vi ${BGPIC} ${MNTPATH}/.background/${BGFILE}
echo '
tell application "Finder"
tell disk "'${VOLNAME}'"
open
set current view of container window to icon view
set toolbar visible of container window to false
set statusbar visible of container window to false
set the bounds of container window to {400, 200, 800, 440}
set theViewOptions to the icon view options of container window
set arrangement of theViewOptions to not arranged
set icon size of theViewOptions to 64
set background picture of theViewOptions to file ".background:'${BGFILE}'"
make new alias file at container window to POSIX file "/Applications" with properties {name:"Applications"}
set position of item "'${APPNAME}'" of container window to {100, 100}
set position of item "Applications" of container window to {310, 100}
close
open
update without registering applications
delay 5
eject
end tell
end tell
' | osascript
sync
# Umount the image
umount "${DiskDevice}"
hdiutil eject "${DiskDevice}"
# Create a read-only version, use zlib compression
hdiutil convert -format UDZO "${TMPFILE}" -imagekey zlib-level=9 -o "${DMGFILE}"
# Delete the temporary files
if [ -z "$KEEPTMP" ]; then
rm $TMPFILE
fi
rmdir $MNTPATH
echo
echo "packaging suceeded."
if [ -n "$KEEPTMP" ]; then
ls -l $TMPFILE
fi
ls -l $DMGFILE
ls -lh $DMGFILE
/bin/echo -n " upload?[Enter|CTRL-C]"
read
echo "rsync -Pc $DMGFILE rg42.org:/home/data/download/"
rsync -Pc $DMGFILE rg42.org:/home/data/download/