/
build-example.sh
executable file
·264 lines (226 loc) · 7.57 KB
/
build-example.sh
OlderNewer
1
2
#!/bin/bash
3
4
5
6
7
8
# This script is now used for most of the examples, since this was meant to
# be a simple script, but grew to be fairly complicated, and mostly identical
# between each project. So you have to have a bunch of arguments to this
# script, which are set by the "details.txt" in a given example's
# subdirectory. Run this like: "./build-example.sh braid" or whatever.
9
10
11
12
# This script is not robust for all platforms or situations. Use as a rough
# example, but invest effort in what it's trying to do, and what it produces.
# (make sure you don't build in features you don't need, etc).
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
if [ -z "$1" ]; then
echo "USAGE: $0 <appid> [--debug]" 1>&2
exit 1
fi
APPID="$1"
cd `dirname "$0"`
BASEDIR=`pwd`/"$APPID"
source "$BASEDIR/details.txt"
MISSING_ARG=0
if [ -z "$MINIMAL" ]; then MINIMAL=0 ; fi
if [ -z "$NEEDHTTP" ]; then NEEDHTTP=0 ; fi
if [ -z "$DATAFILE" ]; then MISSING_ARG=1 ; fi
if [ -z "$APPTITLE" ]; then MISSING_ARG=1 ; fi
if [ "$MISSING_ARG" == "1" ]; then
echo "Missing required arguments." 1>&2
echo "Please make sure $BASEDIR/details.txt is complete." 1>&2
exit 1
fi
# The real work happens below here.
37
38
39
40
# Stop if anything produces an error.
set -e
DEBUG=0
41
if [ "$2" = "--debug" ]; then
42
43
44
45
echo "debug build!"
DEBUG=1
fi
46
47
48
49
50
if [ ! -f "$BASEDIR/$DATAFILE" ]; then
echo "We don't see '$BASEDIR/$DATAFILE' ..." 1>&2
echo " Either you're in the wrong directory, or you didn't copy the" 1>&2
echo " install data into here (it's unreasonably big to store it in" 1>&2
echo " revision control for no good reason)." 1>&2
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
exit 1
fi
# I use a "cross compiler" to build binaries that are isolated from the
# particulars of my Linux workstation's current distribution. This both
# keeps me at a consistent ABI for generated binaries and prevent subtle
# dependencies from leaking in.
# You may not care about this at all. In which case, just use the
# CC=gcc and CXX=g++ lines instead.
CC=/usr/bin/gcc
CXX=/usr/bin/g++
#CC=/opt/crosstool/gcc-3.3.6-glibc-2.3.5/i686-unknown-linux-gnu/i686-unknown-linux-gnu/bin/gcc
#CXX=/opt/crosstool/gcc-3.3.6-glibc-2.3.5/i686-unknown-linux-gnu/i686-unknown-linux-gnu/bin/g++
OSTYPE=`uname -s`
if [ "$OSTYPE" = "Linux" ]; then
NCPU=`cat /proc/cpuinfo |grep vendor_id |wc -l`
let NCPU=$NCPU+1
elif [ "$OSTYPE" = "Darwin" ]; then
NCPU=`sysctl -n hw.ncpu`
elif [ "$OSTYPE" = "SunOS" ]; then
NCPU=`/usr/sbin/psrinfo |wc -l |sed -e 's/^ *//g;s/ *$//g'`
else
NCPU=1
fi
77
if [ -z "$NCPU" ]; then
78
NCPU=1
79
elif [ "$NCPU" = "0" ]; then
80
81
82
83
84
85
86
87
NCPU=1
fi
echo "Will use make -j$NCPU. If this is wrong, check NCPU at top of script."
# Show everything that we do here on stdout.
set -x
88
89
90
91
92
93
94
95
96
97
98
99
100
if [ "$MINIMAL" = "1" ]; then
FALSEIFMINIMAL="FALSE"
else
FALSEIFMINIMAL="TRUE"
fi
if [ "$NEEDHTTP" = "1" ]; then
TRUEIFNEEDHTTP="TRUE"
else
TRUEIFNEEDHTTP="FALSE"
fi
101
if [ "$DEBUG" = "1" ]; then
102
103
104
105
LUASTRIPOPT=""
BUILDTYPE="Debug"
TRUEIFDEBUG="TRUE"
FALSEIFDEBUG="FALSE"
106
else
107
108
109
110
LUASTRIPOPT="-s"
BUILDTYPE="MinSizeRel"
TRUEIFDEBUG="FALSE"
FALSEIFDEBUG="TRUE"
111
112
fi
113
114
cd "$BASEDIR"
115
# this is a little nasty, but it works!
116
TOTALINSTALL=`du -sb data |perl -w -p -e 's/\A(\d+)\s+data\Z/$1/;'`
117
118
119
perl -w -pi -e "s/\A\s*(local TOTAL_INSTALL_SIZE)\s*\=\s*\d+\s*;\s*\Z/\$1 = $TOTALINSTALL;\n/;" scripts/config.lua
# Clean up previous run, build fresh dirs for Base Archive.
120
rm -rf image "$APPID-installer" pdata.zip
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
mkdir image
mkdir image/guis
mkdir image/scripts
mkdir image/data
mkdir image/meta
# Build MojoSetup binaries from scratch.
# YOU ALWAYS NEED THE LUA PARSER IF YOU WANT UNINSTALL SUPPORT!
cd ../..
rm -rf cmake-build
mkdir cmake-build
cd cmake-build
cmake \
-DCMAKE_BUILD_TYPE=$BUILDTYPE \
-DCMAKE_C_COMPILER=$CC \
-DCMAKE_CXX_COMPILER=$CXX \
-DMOJOSETUP_MULTIARCH=FALSE \
-DMOJOSETUP_ARCHIVE_ZIP=TRUE \
-DMOJOSETUP_ARCHIVE_TAR=FALSE \
-DMOJOSETUP_ARCHIVE_TAR_BZ2=FALSE \
-DMOJOSETUP_ARCHIVE_TAR_GZ=FALSE \
142
-DMOJOSETUP_GUI_GTKPLUS2=$FALSEIFMINIMAL \
143
-DMOJOSETUP_GUI_GTKPLUS2_STATIC=FALSE \
144
145
-DMOJOSETUP_GUI_GTKPLUS3=$FALSEIFMINIMAL \
-DMOJOSETUP_GUI_GTKPLUS3_STATIC=FALSE \
146
-DMOJOSETUP_GUI_NCURSES=$FALSEIFMINIMAL \
147
148
149
150
151
152
153
154
155
156
-DMOJOSETUP_GUI_NCURSES_STATIC=FALSE \
-DMOJOSETUP_GUI_STDIO=TRUE \
-DMOJOSETUP_GUI_STDIO_STATIC=TRUE \
-DMOJOSETUP_GUI_WWW=FALSE \
-DMOJOSETUP_GUI_WWW_STATIC=FALSE \
-DMOJOSETUP_LUALIB_DB=FALSE \
-DMOJOSETUP_LUALIB_IO=FALSE \
-DMOJOSETUP_LUALIB_MATH=FALSE \
-DMOJOSETUP_LUALIB_OS=FALSE \
-DMOJOSETUP_LUALIB_PACKAGE=FALSE \
157
158
-DMOJOSETUP_LUA_PARSER=$FALSEIFMINIMAL \
-DMOJOSETUP_IMAGE_BMP=$FALSEIFMINIMAL \
159
160
161
162
-DMOJOSETUP_IMAGE_JPG=FALSE \
-DMOJOSETUP_IMAGE_PNG=FALSE \
-DMOJOSETUP_INTERNAL_BZLIB=FALSE \
-DMOJOSETUP_INTERNAL_ZLIB=TRUE \
163
-DMOJOSETUP_URL_HTTP=$TRUEIFNEEDHTTP \
164
165
-DMOJOSETUP_URL_FTP=FALSE \
..
166
167
168
169
170
171
172
173
make -j$NCPU
# Strip the binaries and GUI plugins, put them somewhere useful.
if [ "$DEBUG" != "1" ]; then
strip ./mojosetup
fi
174
mv ./mojosetup "$BASEDIR/$APPID-installer"
175
176
177
178
179
for feh in *.so *.dll *.dylib ; do
if [ -f $feh ]; then
if [ "$DEBUG" != "1" ]; then
strip $feh
fi
180
mv $feh "$BASEDIR/image/guis/"
181
182
183
184
185
fi
done
# Compile the Lua scripts, put them in the base archive.
for feh in ../scripts/*.lua ; do
186
./mojoluac $LUASTRIPOPT -o "$BASEDIR/image/scripts/${feh}c" $feh
187
188
189
done
# Don't want the example config...use our's instead.
190
191
rm -f "$BASEDIR/image/scripts/config.luac"
./mojoluac $LUASTRIPOPT -o "$BASEDIR/image/scripts/config.luac" "$BASEDIR/scripts/config.lua"
192
193
194
195
196
197
# Don't want the example app_localization...use ours instead if it exists.
if [ -f "$BASEDIR/scripts/app_localization.lua" ]; then
rm -f "$BASEDIR/image/scripts/app_localization.luac"
./mojoluac $LUASTRIPOPT -o "$BASEDIR/image/scripts/app_localization.luac" "$BASEDIR/scripts/app_localization.lua"
fi
198
199
# Fill in the rest of the Base Archive...
200
cd "$BASEDIR"
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
cp -R data/* image/data/
cp meta/* image/meta/
# Need these scripts to do things like install menu items, etc, on Unix.
if [ "$OSTYPE" = "Linux" ]; then
USE_XDG_UTILS=1
fi
if [ "$OSTYPE" = "SunOS" ]; then
USE_XDG_UTILS=1
fi
if [ "x$USE_XDG_UTILS" = "x1" ]; then
mkdir image/meta/xdg-utils
cp ../../meta/xdg-utils/* image/meta/xdg-utils/
chmod a+rx image/meta/xdg-utils/*
fi
218
219
220
221
222
# Tweak up the permissions in the final image...
chmod -R a+r image
chmod -R go-w image
find image -type d -exec chmod a+x {} \;
223
224
if [ "$OSTYPE" = "Darwin" ]; then
# Build up the application bundle for Mac OS X...
225
APPBUNDLE="$APPTITLE.app"
226
227
rm -rf "$APPBUNDLE"
cp -Rv ../../misc/MacAppBundleSkeleton "$APPBUNDLE"
228
229
perl -w -pi -e 's/YOUR_APPLICATION_NAME_HERE/'"$APPTITLE"'/g;' "${APPBUNDLE}/Contents/Info.plist"
mv "$APPID-installer" "${APPBUNDLE}/Contents/MacOS/mojosetup"
230
231
232
233
234
235
236
237
238
239
mv image/* "${APPBUNDLE}/Contents/MacOS/"
rmdir image
ibtool --compile "${APPBUNDLE}/Contents/Resources/MojoSetup.nib" ../../misc/MojoSetup.xib
else
# Make a .zip archive of the Base Archive dirs and nuke the originals...
cd image
zip -9r ../pdata.zip *
cd ..
rm -rf image
# Append the .zip archive to the mojosetup binary, so it's "self-extracting."
240
../../cmake-build/make_self_extracting "$APPID-installer" pdata.zip
241
242
243
244
245
246
247
rm -f pdata.zip
fi
# ...and that's that.
set +e
set +x
echo "Successfully built!"
248
echo "The installer is in '$BASEDIR/$APPID-installer' ..."
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
if [ "$DEBUG" = "1" ]; then
echo
echo
echo
echo 'ATTENTION: THIS IS A DEBUG BUILD!'
echo " DON'T DISTRIBUTE TO THE PUBLIC."
echo ' THIS IS PROBABLY BIGGER AND SLOWER THAN IT SHOULD BE.'
echo ' YOU HAVE BEEN WARNED!'
echo
echo
echo
fi
exit 0