forked from moritz-wundke/Boost-for-Android
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-android.sh
executable file
·227 lines (194 loc) · 6.07 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
#!/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
# Build constants
# TODO: Make boost stuff be configurable
BOOST_DOWNLOAD_LINK="http://downloads.sourceforge.net/project/boost/boost/1.45.0/boost_1_45_0.tar.bz2?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fboost%2Ffiles%2Fboost%2F1.45.0%2F&ts=1291326673&use_mirror=garr"
BOOST_TAR="boost_1_45_0.tar.bz2"
BOOST_DIR="boost_1_45_0"
BUILD_DIR="./build/"
CLEAN=no
register_option "--clean" do_clean "Perform a clean build deleting all previus build files."
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
}
PROGRAM_PARAMETERS="<ndk-root>"
PROGRAM_DESCRIPTION=\
" Boost For Android\n"\
"Copyright (C) 2010 Mystic Tree Games\n"\
"------------------------------------"
extract_parameters $@
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
NDK_R5=
if [ -n "`echo $AndroidNDKRoot | grep 'android-ndk-r5'`" ]; then
NDK_R5=1
if [ -n "`echo $NDK | grep 'android-ndk-r5-crystax-1.beta3'`" ]; then
CRYSTAX_WCHAR=1
fi
fi
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
fi
# Check if android NDK path has been set
if [ ! -n "${AndroidNDKRoot:+x}" ]
then
echo "Environment variable: AndroidNDKRoot not set! Please enter tell me where you got the NDK root:"
read AndroidNDKPatch
fi
# Check platform patch
case "$HOST_OS" in
linux)
Platfrom=linux-x86
;;
darwin|freebsd)
Platfrom=darwin-x86
;;
windows|cygwin)
Platfrom=windows-x86
;;
*) # let's play safe here
Platfrom=linux-x86
esac
#CXXPATH=$AndroidNDKRoot/build/prebuilt/$Platfrom/arm-eabi-4.4.0/bin/arm-eabi-g++
CXXPATH=$AndroidNDKRoot/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-g++
CXXFLAGS=-I$AndroidNDKRoot/build/platforms/android-8/arch-arm/usr/include
TOOLSET=gcc-androidR4
if [ -n "$NDK_R5" ]; then
CXXPATH=$AndroidNDKRoot/toolchains/arm-linux-androideabi-4.4.3/prebuilt/$Platfrom/bin/arm-linux-androideabi-g++
CXXFLAGS="-I$AndroidNDKRoot/platforms/android-8/arch-arm/usr/include \
-I$AndroidNDKRoot/sources/cxx-stl/gnu-libstdc++/include \
-I$AndroidNDKRoot/sources/cxx-stl/gnu-libstdc++/libs/armeabi/include \
-I$AndroidNDKRoot/sources/wchar-support/include"
TOOLSET=gcc-androidR5
fi
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 1_45_0 in a temporal folder and
if [ ! -f $BOOST_TAR ]
then
echo "Downloading boost 1.45.0 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 1.45.0 manually\nand save it in this directory as $BOOST_TAR"
exit 1
fi
if [ ! -d $PROGDIR/$BOOST_DIR ]
then
echo "Unpack boost"
tar xvjf $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 boostrap"
cd $BOOST_DIR
./bootstrap.sh 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
PATCHES_DIR=$PROGDIR/patches
if [ -d "$PATCHES_DIR" ] ; then
mkdir -p $PROGDIR/patches
fi
PATCHES=`(cd $PATCHES_DIR && find . -name "*.patch" | sort) 2> /dev/null`
if [ -z "$PATCHES" ] ; then
echo "No patches files in $PATCHES_DIR"
exit 0
fi
PATCHES=`echo $PATCHES | sed -e s%^\./%%g`
SRC_DIR=$PROGDIR/$BOOST_DIR
for PATCH in $PATCHES; do
PATCHDIR=`dirname $PATCH`
PATCHNAME=`basename $PATCH`
log "Applying $PATCHNAME into $SRC_DIR/$PATCHDIR"
cd $SRC_DIR && patch -p1 < $PATCHES_DIR/$PATCH && cd $PROGDIR
if [ $? != 0 ] ; then
dump "ERROR: Patch failure !! Please check your patches directory! Try to perform a clean build using --clean"
exit 1
fi
done
fi
# ---------------
# Build using NDK
# ---------------
# Build boost for android
echo "Building boost for android"
cd $BOOST_DIR
env PATH=`dirname $CXXPATH`:$PATH \
AndroidNDKRoot=$AndroidNDKRoot NO_BZIP2=1 \
./bjam toolset=$TOOLSET \
cxxflags="$CXXFLAGS" \
link=static threading=multi --layout=versioned install 2>&1 | tee -a $PROGDIR/build.log
if [ $? != 0 ] ; then
dump "ERROR: Failed to build boost for android!"
exit 1
fi
cd $PROGDIR
dump "Done!"