forked from moritz-wundke/Boost-for-Android
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-android.sh
executable file
·339 lines (284 loc) · 9.47 KB
/
build-android.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
333
334
335
336
337
338
339
#!/bin/sh
# Copyright (C) 2010 Mystic Tree Games
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Author: Moritz "Moss" Wundke ([email protected])
#
# <License>
#
# Build boost for android completly. It will download boost 1.45.0
# prepare the build system and finally build it for android
# Add common build methods
. `dirname $0`/build-common.sh
# -----------------------
# Command line arguments
# -----------------------
BOOST_VER1=1
BOOST_VER2=53
BOOST_VER3=0
register_option "--boost=<version>" boost_version "Boost version to be used, one of {1.53.0,1.49.0, 1.48.0, 1.45.0}, default is 1.53.0."
boost_version()
{
if [ "$1" = "1.53.0" ]; then
BOOST_VER1=1
BOOST_VER2=53
BOOST_VER3=0
elif [ "$1" = "1.49.0" ]; then
BOOST_VER1=1
BOOST_VER2=49
BOOST_VER3=0
elif [ "$1" = "1.48.0" ]; then
BOOST_VER1=1
BOOST_VER2=48
BOOST_VER3=0
elif [ "$1" = "1.45.0" ]; then
BOOST_VER1=1
BOOST_VER2=45
BOOST_VER3=0
else
echo "Unsupported boost version '$1'."
exit 1
fi
}
CLEAN=no
register_option "--clean" do_clean "Delete all previously downloaded and built files, then exit."
do_clean () { CLEAN=yes; }
DOWNLOAD=no
register_option "--download" do_download "Only download required files and clean up previus build. No build will be performed."
do_download ()
{
DOWNLOAD=yes
# Clean previus stuff too!
CLEAN=yes
}
LIBRARIES=--with-libraries=date_time,filesystem,program_options,regex,signals,system,thread,iostreams
register_option "--with-libraries=<list>" do_with_libraries "Comma separated list of libraries to build."
do_with_libraries () { LIBRARIES="--with-libraries=$1"; }
register_option "--without-libraries=<list>" do_without_libraries "Comma separated list of libraries to exclude from the build."
do_without_libraries () { LIBRARIES="--without-libraries=$1"; }
register_option "--prefix=<path>" do_prefix "Prefix to be used when installing libraries and includes."
do_prefix () {
if [ -d $1 ]; then
PREFIX=$1;
fi
}
PROGRAM_PARAMETERS="<ndk-root>"
PROGRAM_DESCRIPTION=\
" Boost For Android\n"\
"Copyright (C) 2010 Mystic Tree Games\n"\
extract_parameters $@
echo "Building boost version: $BOOST_VER1.$BOOST_VER2.$BOOST_VER3"
# -----------------------
# Build constants
# -----------------------
BOOST_DOWNLOAD_LINK="http://downloads.sourceforge.net/project/boost/boost/$BOOST_VER1.$BOOST_VER2.$BOOST_VER3/boost_${BOOST_VER1}_${BOOST_VER2}_${BOOST_VER3}.tar.bz2?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fboost%2Ffiles%2Fboost%2F${BOOST_VER1}.${BOOST_VER2}.${BOOST_VER3}%2F&ts=1291326673&use_mirror=garr"
BOOST_TAR="boost_${BOOST_VER1}_${BOOST_VER2}_${BOOST_VER3}.tar.bz2"
BOOST_DIR="boost_${BOOST_VER1}_${BOOST_VER2}_${BOOST_VER3}"
BUILD_DIR="./build/"
# -----------------------
if [ $CLEAN = yes ] ; then
echo "Cleaning: $BUILD_DIR"
rm -f -r $PROGDIR/$BUILD_DIR
echo "Cleaning: $BOOST_DIR"
rm -f -r $PROGDIR/$BOOST_DIR
echo "Cleaning: $BOOST_TAR"
rm -f $PROGDIR/$BOOST_TAR
echo "Cleaning: logs"
rm -f -r logs
rm -f build.log
[ "$DOWNLOAD" = "yes" ] || exit 0
fi
# It is almost never desirable to have the boost-X_Y_Z directory from
# previous builds as this script doesn't check in which state it's
# been left (bootstrapped, patched, built, ...). Unless maybe during
# a debug, in which case it's easy for a developer to comment out
# this code.
if [ -d "$PROGDIR/$BOOST_DIR" ]; then
echo "Cleaning: $BOOST_DIR"
rm -f -r $PROGDIR/$BOOST_DIR
fi
if [ -d "$PROGDIR/$BUILD_DIR" ]; then
echo "Cleaning: $BUILD_DIR"
rm -f -r $PROGDIR/$BUILD_DIR
fi
export AndroidNDKRoot=$PARAMETERS
if [ -z "$AndroidNDKRoot" ] ; then
if [ -z "`which ndk-build`" ]; then
dump "ERROR: You need to provide a <ndk-root>!"
exit 1
fi
AndroidNDKRoot=`which ndk-build`
AndroidNDKRoot=`dirname $AndroidNDKRoot`
echo "Using AndroidNDKRoot = $AndroidNDKRoot"
fi
# Check platform patch
case "$HOST_OS" in
linux)
PlatformOS=linux
;;
darwin|freebsd)
PlatformOS=darwin
;;
windows|cygwin)
PlatformOS=windows
;;
*) # let's play safe here
PlatformOS=linux
esac
NDK_RELEASE_FILE=$AndroidNDKRoot"/RELEASE.TXT"
NDK_RN=`cat $NDK_RELEASE_FILE | sed 's/^r\(.*\)$/\1/g'`
echo "Detected Android NDK version $NDK_RN"
case "$NDK_RN" in
4*)
CXXPATH=$AndroidNDKRoot/build/prebuilt/$PlatformOS-x86/arm-eabi-4.4.0/bin/arm-eabi-g++
TOOLSET=gcc-androidR4
;;
5*)
CXXPATH=$AndroidNDKRoot/toolchains/arm-linux-androideabi-4.4.3/prebuilt/$PlatformOS-x86/bin/arm-linux-androideabi-g++
TOOLSET=gcc-androidR5
;;
7-crystax-5.beta3)
EABI_VER=4.6.3
CXXPATH=$AndroidNDKRoot/toolchains/arm-linux-androideabi-$EABI_VER/prebuilt/$PlatformOS-x86/bin/arm-linux-androideabi-g++
TOOLSET=gcc-androidR7crystax5beta3
;;
8)
CXXPATH=$AndroidNDKRoot/toolchains/arm-linux-androideabi-4.4.3/prebuilt/$PlatformOS-x86/bin/arm-linux-androideabi-g++
TOOLSET=gcc-androidR8
;;
8b|8c|8d)
CXXPATH=$AndroidNDKRoot/toolchains/arm-linux-androideabi-4.6/prebuilt/$PlatformOS-x86/bin/arm-linux-androideabi-g++
TOOLSET=gcc-androidR8b
;;
8e|9*)
CXXPATH=$AndroidNDKRoot/toolchains/arm-linux-androideabi-4.6/prebuilt/$PlatformOS-x86/bin/arm-linux-androideabi-g++
TOOLSET=gcc-androidR8e
;;
"8e (64-bit)")
CXXPATH=$AndroidNDKRoot/toolchains/arm-linux-androideabi-4.6/prebuilt/${PlatformOS}-x86_64/bin/arm-linux-androideabi-g++
TOOLSET=gcc-androidR8e
;;
*)
echo "Undefined or not supported Android NDK version!"
exit 1
esac
echo Building with TOOLSET=$TOOLSET CXXPATH=$CXXPATH CXXFLAGS=$CXXFLAGS | tee $PROGDIR/build.log
# Check if the ndk is valid or not
if [ ! -f $CXXPATH ]
then
echo "Cannot find C++ compiler at: $CXXPATH"
exit 1
fi
# -----------------------
# Download required files
# -----------------------
# Downalod and unzip boost in a temporal folder and
if [ ! -f $BOOST_TAR ]
then
echo "Downloading boost ${BOOST_VER1}.${BOOST_VER2}.${BOOST_VER3} please wait..."
prepare_download
download_file $BOOST_DOWNLOAD_LINK $PROGDIR/$BOOST_TAR
fi
if [ ! -f $PROGDIR/$BOOST_TAR ]
then
echo "Failed to download boost! Please download boost ${BOOST_VER1}.${BOOST_VER2}.${BOOST_VER3} manually\nand save it in this directory as $BOOST_TAR"
exit 1
fi
if [ ! -d $PROGDIR/$BOOST_DIR ]
then
echo "Unpacking boost"
tar xjf $PROGDIR/$BOOST_TAR
fi
if [ $DOWNLOAD = yes ] ; then
echo "All required files has been downloaded and unpacked!"
exit 0
fi
# ---------
# Bootstrap
# ---------
if [ ! -f ./$BOOST_DIR/bjam ]
then
# Make the initial bootstrap
echo "Performing boost bootstrap"
cd $BOOST_DIR
./bootstrap.sh --prefix="./../$BUILD_DIR/" \
$LIBRARIES \
2>&1 | tee -a $PROGDIR/build.log
if [ $? != 0 ] ; then
dump "ERROR: Could not perform boostrap! See $TMPLOG for more info."
exit 1
fi
cd $PROGDIR
# -------------------------------------------------------------
# Patching will be done only if we had a successfull bootstrap!
# -------------------------------------------------------------
# Apply patches to boost
BOOST_VER=${BOOST_VER1}_${BOOST_VER2}_${BOOST_VER3}
PATCH_BOOST_DIR=$PROGDIR/patches/boost-${BOOST_VER}
cp configs/user-config-boost-${BOOST_VER}.jam $BOOST_DIR/tools/build/v2/user-config.jam
for dir in $PATCH_BOOST_DIR; do
if [ ! -d "$dir" ]; then
echo "Could not find directory '$dir' while looking for patches"
exit 1
fi
PATCHES=`(cd $dir && ls *.patch | sort) 2> /dev/null`
if [ -z "$PATCHES" ]; then
echo "No patches found in directory '$dir'"
exit 1
fi
for PATCH in $PATCHES; do
PATCH=`echo $PATCH | sed -e s%^\./%%g`
SRC_DIR=$PROGDIR/$BOOST_DIR
PATCHDIR=`dirname $PATCH`
PATCHNAME=`basename $PATCH`
log "Applying $PATCHNAME into $SRC_DIR/$PATCHDIR"
cd $SRC_DIR && patch -p1 < $dir/$PATCH && cd $PROGDIR
if [ $? != 0 ] ; then
dump "ERROR: Patch failure !! Please check your patches directory!"
dump " Try to perform a clean build using --clean ."
dump " Problem patch: $dir/$PATCHNAME"
exit 1
fi
done
done
fi
echo "# ---------------"
echo "# Build using NDK"
echo "# ---------------"
# Build boost for android
echo "Building boost for android"
(
cd $BOOST_DIR
export PATH=`dirname $CXXPATH`:$PATH
export AndroidNDKRoot
export NO_BZIP2=1
cxxflags=""
for flag in $CXXFLAGS; do cxxflags="$cxxflags cxxflags=$flag"; done
{ ./bjam -q \
toolset=$TOOLSET \
$cxxflags \
link=static \
threading=multi \
--layout=versioned \
install 2>&1 \
|| { dump "ERROR: Failed to build boost for android!" ; exit 1 ; }
} | tee -a $PROGDIR/build.log
# PIPESTATUS variable is defined only in Bash, and we are using /bin/sh, which is not Bash on newer Debian/Ubuntu
)
dump "Done!"
if [ $PREFIX ]; then
echo "Prefix set, copying files to $PREFIX"
cp -r $PROGDIR/$BUILD_DIR/lib $PREFIX
cp -r $PROGDIR/$BUILD_DIR/include $PREFIX
fi