Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100755 260 lines (216 sloc) 6.244 kb
c8b09b2 @marshall added a build script for building v8 against our patch / the NDK, and…
marshall authored
1 #!/bin/sh
2 #
3 # Appcelerator Titanium Mobile
4 # Copyright (c) 2011 by Appcelerator, Inc. All Rights Reserved.
5 # Licensed under the terms of the Apache Public License
6 # Please see the LICENSE included with this distribution for details.
7 #
8 # Build and bundling script for v8 / NDK toolchain
9
10 usage()
11 {
12 cat <<EOF
13 Usage: $0 options
14
fb2475e @marshall quoted more paths, and exit the build script if scons fails. added LI…
marshall authored
15 This script builds v8 against the Android NDK.
c8b09b2 @marshall added a build script for building v8 against our patch / the NDK, and…
marshall authored
16 Options:
5e921ac @marshall build emulator (armeabi=soft) and device (armeabi=softfp) versions of
marshall authored
17 -h Show this help message and exit
18 -n <ndk_dir> The path to the Android NDK. Alternatively, you may set the ANDROID_NDK environment variable
19 -j <num-cpus> The number of processors to use in building (passed on to scons)
20 -m <mode> The v8 build mode (release, debug, all. default: release)
d7d22cc @sptramer [TIMOB-9170] Support for building v8 for Android x86. Updated v8 to l…
sptramer authored
21 -l <lib-version> Architectures to build for (armeabi, armeabi-v7a, x86, all. default: armeabi-v7a)
5e921ac @marshall build emulator (armeabi=soft) and device (armeabi=softfp) versions of
marshall authored
22 -t Package a thirdparty tarball for uploading (don't build)
be96e38 @joshthecoder Upgrade V8 to latest 3.9. Enable snapshot builds.
joshthecoder authored
23 -s Enable V8 snapshot. Improves performance, but takes longer to compile. (default: off)
f67b17b @marshall update libv8 packaging to use android naming conventions
marshall authored
24 -c Clean the V8 build
29b6a98 @sptramer [TIMOB-9170] Add -p to USAGE
sptramer authored
25 -p The Android SDK version to support (android-8, android-9, etc.)
c8b09b2 @marshall added a build script for building v8 against our patch / the NDK, and…
marshall authored
26 EOF
27 }
28
29 NUM_CPUS=1
30 MODE=release
f67b17b @marshall update libv8 packaging to use android naming conventions
marshall authored
31 LIB_VERSION=armeabi-v7a
32 THIRDPARTY=0
33 CLEAN=0
be96e38 @joshthecoder Upgrade V8 to latest 3.9. Enable snapshot builds.
joshthecoder authored
34 USE_V8_SNAPSHOT=0
d7d22cc @sptramer [TIMOB-9170] Support for building v8 for Android x86. Updated v8 to l…
sptramer authored
35 PLATFORM_VERSION=android-8
36
37 while getopts "htscn:j:m:l:p:" OPTION; do
c8b09b2 @marshall added a build script for building v8 against our patch / the NDK, and…
marshall authored
38 case $OPTION in
39 h)
40 usage
41 exit
42 ;;
43 n)
44 NDK_DIR=$OPTARG
45 ;;
46 m)
47 MODE=$OPTARG
48 ;;
49 j)
50 NUM_CPUS=$OPTARG
51 ;;
52 t)
53 THIRDPARTY=1
54 ;;
be96e38 @joshthecoder Upgrade V8 to latest 3.9. Enable snapshot builds.
joshthecoder authored
55 s)
56 USE_V8_SNAPSHOT=1
57 ;;
5e921ac @marshall build emulator (armeabi=soft) and device (armeabi=softfp) versions of
marshall authored
58 l)
59 LIB_VERSION=$OPTARG
60 ;;
f67b17b @marshall update libv8 packaging to use android naming conventions
marshall authored
61 c)
62 CLEAN=1
63 ;;
d7d22cc @sptramer [TIMOB-9170] Support for building v8 for Android x86. Updated v8 to l…
sptramer authored
64 p)
65 PLATFORM_VERSION=$OPTARG
66 ;;
c8b09b2 @marshall added a build script for building v8 against our patch / the NDK, and…
marshall authored
67 ?)
68 usage
69 exit
70 ;;
71 esac
72 done
73
74 if [ "$NDK_DIR" = "" ]; then
75 NDK_DIR=$ANDROID_NDK
76 fi
77
78 if [ "$NDK_DIR" = "" ]; then
79 echo "Error: No Android NDK directory was specified, supply '-n </path/to/ndk>' or set ANDROID_NDK"
80 usage
81 exit 1
82 fi
83
84 echo "Building against Android NDK: $NDK_DIR"
85
86 THIS_DIR=$(cd "$(dirname "$0")"; pwd)
87 BUILD_DIR=$THIS_DIR/build
88
89 if [ ! -d "$BUILD_DIR" ]; then
fb2475e @marshall quoted more paths, and exit the build script if scons fails. added LI…
marshall authored
90 mkdir "$BUILD_DIR"
c8b09b2 @marshall added a build script for building v8 against our patch / the NDK, and…
marshall authored
91 fi
92
93 V8_DIR=$THIS_DIR/v8
94 TOOLCHAIN_DIR=$BUILD_DIR/ndk_toolchain
d7d22cc @sptramer [TIMOB-9170] Support for building v8 for Android x86. Updated v8 to l…
sptramer authored
95
c8b09b2 @marshall added a build script for building v8 against our patch / the NDK, and…
marshall authored
96
97 buildToolchain()
98 {
99 # remove the previous toolchain
fb2475e @marshall quoted more paths, and exit the build script if scons fails. added LI…
marshall authored
100 rm -rf "$TOOLCHAIN_DIR"
c8b09b2 @marshall added a build script for building v8 against our patch / the NDK, and…
marshall authored
101
102 # create stand alone toolchain
d7d22cc @sptramer [TIMOB-9170] Support for building v8 for Android x86. Updated v8 to l…
sptramer authored
103 "$NDK_DIR/build/tools/make-standalone-toolchain.sh" --platform=$PLATFORM_VERSION --ndk-dir="$NDK_DIR" --install-dir="$TOOLCHAIN_DIR" --arch="$ARCH"
2c7fc3f @sptramer [TIMOB-9170] Enable x86 snapshot and improve error handling
sptramer authored
104 if [ $? -ne 0 ]; then
105 exit 1
106 fi
c8b09b2 @marshall added a build script for building v8 against our patch / the NDK, and…
marshall authored
107 }
108
109 applyPatch()
110 {
111 # we assume that errors are just an existing applied patch, so we remove rejects..
fb2475e @marshall quoted more paths, and exit the build script if scons fails. added LI…
marshall authored
112 patch -p0 -N -i "$THIS_DIR/patches/ndk_v8.patch" || find v8 -name '*.rej' -exec rm \{\} \;
c8b09b2 @marshall added a build script for building v8 against our patch / the NDK, and…
marshall authored
113 }
114
115 buildV8()
5e921ac @marshall build emulator (armeabi=soft) and device (armeabi=softfp) versions of
marshall authored
116 {
117 BUILD_MODE=$1
118 BUILD_LIB_VERSION=$2
119
d7d22cc @sptramer [TIMOB-9170] Support for building v8 for Android x86. Updated v8 to l…
sptramer authored
120 if [ $IS_ARM -eq 0 ]; then
121 TOOLCHAIN_PREFIX="arm-linux-androideabi"
122 else
123 TOOLCHAIN_PREFIX="i686-android-linux"
124 fi
5e921ac @marshall build emulator (armeabi=soft) and device (armeabi=softfp) versions of
marshall authored
125
d7d22cc @sptramer [TIMOB-9170] Support for building v8 for Android x86. Updated v8 to l…
sptramer authored
126 AR=${TOOLCHAIN_DIR}/bin/${TOOLCHAIN_PREFIX}-ar
127 CXX="${TOOLCHAIN_DIR}/bin/${TOOLCHAIN_PREFIX}-g++ -DANDROID=1 -D__STDC_INT64__=1 -DV8_SHARED=1"
128 RANLIB=${TOOLCHAIN_DIR}/bin/${TOOLCHAIN_PREFIX}-ranlib
c8b09b2 @marshall added a build script for building v8 against our patch / the NDK, and…
marshall authored
129
f67b17b @marshall update libv8 packaging to use android naming conventions
marshall authored
130 if [ "$BUILD_LIB_VERSION" = "armeabi" ]; then
131 # Build with software FPU (armeabi)
5e921ac @marshall build emulator (armeabi=soft) and device (armeabi=softfp) versions of
marshall authored
132 ARMEABI="soft"
133 else
f67b17b @marshall update libv8 packaging to use android naming conventions
marshall authored
134 # Build with mixed software / hardware delegating FPU (armeabi-v7a)
5e921ac @marshall build emulator (armeabi=soft) and device (armeabi=softfp) versions of
marshall authored
135 ARMEABI="softfp"
136 fi
137
d7d22cc @sptramer [TIMOB-9170] Support for building v8 for Android x86. Updated v8 to l…
sptramer authored
138 echo "Building V8 mode: $BUILD_MODE, lib: $BUILD_LIB_VERSION, arch: $ARCH, armeabi: $ARMEABI"
f67b17b @marshall update libv8 packaging to use android naming conventions
marshall authored
139
fb2475e @marshall quoted more paths, and exit the build script if scons fails. added LI…
marshall authored
140 cd "$V8_DIR"
5e921ac @marshall build emulator (armeabi=soft) and device (armeabi=softfp) versions of
marshall authored
141
efbbc01 @joshthecoder Fix builds with snapshot disabled.
joshthecoder authored
142 SNAPSHOT="off"
143
be96e38 @joshthecoder Upgrade V8 to latest 3.9. Enable snapshot builds.
joshthecoder authored
144 if [ $USE_V8_SNAPSHOT = 1 ]; then
efbbc01 @joshthecoder Fix builds with snapshot disabled.
joshthecoder authored
145 SNAPSHOT="nobuild"
146
2c7fc3f @sptramer [TIMOB-9170] Enable x86 snapshot and improve error handling
sptramer authored
147 if [ $IS_ARM -eq 0 ]; then
148 BUILD_SIMULATOR="simulator=$ARCH"
149 else
150 BUILD_SIMULATOR=""
151 fi
152
be96e38 @joshthecoder Upgrade V8 to latest 3.9. Enable snapshot builds.
joshthecoder authored
153 # Build Host VM to generate the snapshot.
2c7fc3f @sptramer [TIMOB-9170] Enable x86 snapshot and improve error handling
sptramer authored
154 scons -j $NUM_CPUS mode=$BUILD_MODE $BUILD_SIMULATOR snapshot=on armeabi=$ARMEABI || exit 1
be96e38 @joshthecoder Upgrade V8 to latest 3.9. Enable snapshot builds.
joshthecoder authored
155
156 # We need to move the snapshot now into the V8 src folder
157 # before we build the target VM.
158 mv obj/release/snapshot.cc src/
159
160 # Clean build before moving onto the target VM compile.
161 scons -c
162 fi
163
164 # Build the Target VM.
fb2475e @marshall quoted more paths, and exit the build script if scons fails. added LI…
marshall authored
165 AR=$AR CXX=$CXX RANLIB=$RANLIB \
d7d22cc @sptramer [TIMOB-9170] Support for building v8 for Android x86. Updated v8 to l…
sptramer authored
166 scons -j $NUM_CPUS mode=$BUILD_MODE snapshot=$SNAPSHOT library=static arch=$BUILD_ARCH os=linux usepthread=off android=on armeabi=$ARMEABI || exit 1
5e921ac @marshall build emulator (armeabi=soft) and device (armeabi=softfp) versions of
marshall authored
167
168 LIB_SUFFIX=""
169 if [ "$BUILD_MODE" = "debug" ]; then
170 # Append _g for debug builds
171 LIB_SUFFIX="_g"
172 fi
173
174 DEST_DIR="$BUILD_DIR/$BUILD_MODE"
f67b17b @marshall update libv8 packaging to use android naming conventions
marshall authored
175 mkdir -p "$DEST_DIR/libs/$BUILD_LIB_VERSION" 2>/dev/null || echo
176 cp "$V8_DIR/libv8$LIB_SUFFIX.a" "$DEST_DIR/libs/$BUILD_LIB_VERSION/libv8$LIB_SUFFIX.a"
c8b09b2 @marshall added a build script for building v8 against our patch / the NDK, and…
marshall authored
177 }
178
179 buildThirdparty()
180 {
5e921ac @marshall build emulator (armeabi=soft) and device (armeabi=softfp) versions of
marshall authored
181 BUILD_MODE=$1
182
183 # Copied from v8/tools/push-to-trunk.sh
184 VERSION_FILE=$V8_DIR/src/version.cc
185 MAJOR=$(grep "#define MAJOR_VERSION" "$VERSION_FILE" | awk '{print $NF}')
186 MINOR=$(grep "#define MINOR_VERSION" "$VERSION_FILE" | awk '{print $NF}')
187 BUILD=$(grep "#define BUILD_NUMBER" "$VERSION_FILE" | awk '{print $NF}')
188
189 cd "$V8_DIR"
190 V8_VERSION="$MAJOR.$MINOR.$BUILD"
191 V8_GIT_REVISION=$(git rev-parse HEAD)
192 V8_GIT_BRANCH=$(git status -s -b | grep \#\# | sed 's/\#\# //')
193 V8_SVN_REVISION=$(git log -n 1 | grep git-svn-id | perl -ne 's/\s+git-svn-id: [^@]+@([^\s]+) .+/\1/; print')
194
be96e38 @joshthecoder Upgrade V8 to latest 3.9. Enable snapshot builds.
joshthecoder authored
195 DEST_DIR="$BUILD_DIR/$BUILD_MODE"
5e921ac @marshall build emulator (armeabi=soft) and device (armeabi=softfp) versions of
marshall authored
196 DATE=$(date '+%Y-%m-%d %H:%M:%S')
be96e38 @joshthecoder Upgrade V8 to latest 3.9. Enable snapshot builds.
joshthecoder authored
197
198 cat <<EOF > "$DEST_DIR/libv8.json"
c8b09b2 @marshall added a build script for building v8 against our patch / the NDK, and…
marshall authored
199 {
200 "version": "$V8_VERSION",
201 "git_revision": "$V8_GIT_REVISION",
202 "git_branch": "$V8_GIT_BRANCH",
203 "svn_revision": "$V8_SVN_REVISION",
204 "timestamp": "$DATE"
205 }
206 EOF
207
f67b17b @marshall update libv8 packaging to use android naming conventions
marshall authored
208 mkdir -p "$DEST_DIR/libs" "$DEST_DIR/include" 2>/dev/null
5e921ac @marshall build emulator (armeabi=soft) and device (armeabi=softfp) versions of
marshall authored
209 cp -R "$V8_DIR/include" "$DEST_DIR"
c8b09b2 @marshall added a build script for building v8 against our patch / the NDK, and…
marshall authored
210
5e921ac @marshall build emulator (armeabi=soft) and device (armeabi=softfp) versions of
marshall authored
211 cd "$DEST_DIR"
212 echo "Building libv8-$V8_VERSION-$BUILD_MODE.tar.bz2..."
f67b17b @marshall update libv8 packaging to use android naming conventions
marshall authored
213 tar -cvj -f libv8-$V8_VERSION-$BUILD_MODE.tar.bz2 libv8.json libs include
c8b09b2 @marshall added a build script for building v8 against our patch / the NDK, and…
marshall authored
214 }
215
f67b17b @marshall update libv8 packaging to use android naming conventions
marshall authored
216 if [ "$CLEAN" = "1" ]; then
217 cd v8 && scons -c
218 exit;
219 fi
220
5e921ac @marshall build emulator (armeabi=soft) and device (armeabi=softfp) versions of
marshall authored
221 if [ "$LIB_VERSION" = "all" ]; then
d7d22cc @sptramer [TIMOB-9170] Support for building v8 for Android x86. Updated v8 to l…
sptramer authored
222 LIB_VERSION="armeabi armeabi-v7a x86"
5e921ac @marshall build emulator (armeabi=soft) and device (armeabi=softfp) versions of
marshall authored
223 fi
224
225 if [ "$MODE" = "all" ]; then
226 MODE="release debug"
227 fi
c8b09b2 @marshall added a build script for building v8 against our patch / the NDK, and…
marshall authored
228
5e921ac @marshall build emulator (armeabi=soft) and device (armeabi=softfp) versions of
marshall authored
229 if [ "$THIRDPARTY" = "0" ]; then
230 applyPatch
231 for build_lib_version in $LIB_VERSION; do
d7d22cc @sptramer [TIMOB-9170] Support for building v8 for Android x86. Updated v8 to l…
sptramer authored
232 # Switch between arm and x86/ia32 arch
233 echo $build_lib_version | grep '^arm' 1>/dev/null 2>/dev/null
234 IS_ARM=$?
235
236 if [ $IS_ARM -eq 0 ]; then
237 ARCH='arm'
238 BUILD_ARCH='arm'
239 else
240 REV=`echo ${PLATFORM_VERSION} | sed s/android-//`
241 if [ $REV -lt 9 ]; then
242 echo "Cannot build x86 with android rev lower than SDK 9; use -p option to specify a different SDK"
243 exit 1
244 fi;
245 ARCH='x86'
246 BUILD_ARCH='ia32'
247 fi
248
249 buildToolchain
250
5e921ac @marshall build emulator (armeabi=soft) and device (armeabi=softfp) versions of
marshall authored
251 for build_mode in $MODE; do
252 buildV8 $build_mode $build_lib_version
253 done
254 done
255 else
256 for build_mode in $MODE; do
257 buildThirdparty $build_mode
258 done
c8b09b2 @marshall added a build script for building v8 against our patch / the NDK, and…
marshall authored
259 fi
Something went wrong with that request. Please try again.