forked from tidev/v8_titanium
/
build_v8.sh
executable file
·144 lines (121 loc) · 3.35 KB
/
build_v8.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
#!/bin/sh
#
# Appcelerator Titanium Mobile
# Copyright (c) 2011 by Appcelerator, Inc. All Rights Reserved.
# Licensed under the terms of the Apache Public License
# Please see the LICENSE included with this distribution for details.
#
# Build and bundling script for v8 / NDK toolchain
# set this to the where the NDK is installed
usage()
{
cat <<EOF
Usage: $0 options
This script builds v8 against the Android NDK.
Options:
-h Show this help message and exit
-n <ndk_dir> The path to the Android NDK. Alternatively, you may set the ANDROID_NDK environment variable
-j <num-cpus> The number of processors to use in building (passed on to scons)
-m <mode> The v8 build mode (release, debug. default: release)
-t Build a thirdparty tarball for uploading
EOF
}
NUM_CPUS=1
MODE=release
while getopts "htn:j:m:" OPTION; do
case $OPTION in
h)
usage
exit
;;
n)
NDK_DIR=$OPTARG
;;
m)
MODE=$OPTARG
;;
j)
NUM_CPUS=$OPTARG
;;
t)
THIRDPARTY=1
;;
?)
usage
exit
;;
esac
done
if [ "$NDK_DIR" = "" ]; then
NDK_DIR=$ANDROID_NDK
fi
if [ "$NDK_DIR" = "" ]; then
echo "Error: No Android NDK directory was specified, supply '-n </path/to/ndk>' or set ANDROID_NDK"
usage
exit 1
fi
echo "Building against Android NDK: $NDK_DIR"
THIS_DIR=$(cd "$(dirname "$0")"; pwd)
BUILD_DIR=$THIS_DIR/build
if [ ! -d "$BUILD_DIR" ]; then
mkdir "$BUILD_DIR"
fi
V8_DIR=$THIS_DIR/v8
TOOLCHAIN_DIR=$BUILD_DIR/ndk_toolchain
PLATFORM_VERSION=android-8
buildToolchain()
{
# remove the previous toolchain
rm -rf "$TOOLCHAIN_DIR"
# create stand alone toolchain
"$NDK_DIR/build/tools/make-standalone-toolchain.sh" --platform=$PLATFORM_VERSION --ndk-dir="$NDK_DIR" --install-dir="$TOOLCHAIN_DIR"
}
applyPatch()
{
# we assume that errors are just an existing applied patch, so we remove rejects..
patch -p0 -N -i "$THIS_DIR/patches/ndk_v8.patch" || find v8 -name '*.rej' -exec rm \{\} \;
}
buildV8()
{
AR=${TOOLCHAIN_DIR}/bin/arm-linux-androideabi-ar
CXX="${TOOLCHAIN_DIR}/bin/arm-linux-androideabi-g++ -DANDROID=1 -D__STDC_INT64__=1"
RANLIB=${TOOLCHAIN_DIR}/bin/arm-linux-androideabi-ranlib
cd "$V8_DIR"
AR=$AR CXX=$CXX RANLIB=$RANLIB \
scons -j $NUM_CPUS mode=$MODE snapshot=off library=static arch=arm os=linux || exit 1
}
buildThirdparty()
{
# Copied from v8/tools/push-to-trunk.sh
VERSION_FILE=$V8_DIR/src/version.cc
MAJOR=$(grep "#define MAJOR_VERSION" "$VERSION_FILE" | awk '{print $NF}')
MINOR=$(grep "#define MINOR_VERSION" "$VERSION_FILE" | awk '{print $NF}')
BUILD=$(grep "#define BUILD_NUMBER" "$VERSION_FILE" | awk '{print $NF}')
cd "$V8_DIR"
V8_VERSION="$MAJOR.$MINOR.$BUILD"
V8_GIT_REVISION=$(git rev-parse HEAD)
V8_GIT_BRANCH=$(git status -s -b | grep \#\# | sed 's/\#\# //')
V8_SVN_REVISION=$(git log -n 1 | grep git-svn-id | perl -ne 's/\s+git-svn-id: [^@]+@([^\s]+) .+/\1/; print')
DATE=$(date '+%Y-%m-%d %H:%M:%S')
cat <<EOF > "$BUILD_DIR/libv8.json"
{
"version": "$V8_VERSION",
"git_revision": "$V8_GIT_REVISION",
"git_branch": "$V8_GIT_BRANCH",
"svn_revision": "$V8_SVN_REVISION",
"timestamp": "$DATE"
}
EOF
cp "$V8_DIR/libv8.a" "$BUILD_DIR"
cd "$BUILD_DIR"
echo "Building libv8-$V8_VERSION.tar.bz2..."
tar -cvj -f libv8-$V8_VERSION.tar.bz2 libv8.json libv8.a
}
if [ ! -d "$TOOLCHAIN_DIR" ]; then
buildToolchain
fi
applyPatch
buildV8
if [ "$THIRDPARTY" = "1" ]; then
buildThirdparty
fi