-
Notifications
You must be signed in to change notification settings - Fork 23
/
android-configure
107 lines (94 loc) · 2.71 KB
/
android-configure
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
#!/bin/bash
# In order to cross-compile node for Android using NDK, run:
# source android-configure <path_to_ndk> [arch]
#
# By running android-configure with source, will allow environment variables to
# be persistent in current session. This is useful for installing native node
# modules with npm. Also, don't forget to set the arch in npm config using
# 'npm config set arch=<arch>'
# if [ $# -ne 3 ]; then
# echo "$0 should have 3 parameters: ndk_path, target_arch and sdk_version"
# exit 1
# fi
NDK_PATH=$1
ARCH="$2"
ANDROID_SDK_VERSION=$3
WITH_SSL=$4
if [ $ANDROID_SDK_VERSION -lt 23 ]; then
echo "$ANDROID_SDK_VERSION should equal or later than 23(Android 6.0)"
fi
CC_VER="4.9"
case $ARCH in
arm)
DEST_CPU="arm"
TOOLCHAIN_NAME="armv7a-linux-androideabi"
HOST_M32=" -m32"
;;
x86)
DEST_CPU="ia32"
TOOLCHAIN_NAME="i686-linux-android"
HOST_M32=" -m32"
;;
x86_64)
DEST_CPU="x64"
TOOLCHAIN_NAME="x86_64-linux-android"
ARCH="x64"
HOST_M32=""
;;
arm64|aarch64)
DEST_CPU="arm64"
TOOLCHAIN_NAME="aarch64-linux-android"
ARCH="arm64"
HOST_M32=""
;;
*)
echo "Unsupported architecture provided: $ARCH"
exit 1
;;
esac
HOST_OS="linux"
HOST_ARCH="x86_64"
export CC_host=$(command -v gcc)
export CXX_host=$(command -v g++)
host_gcc_version=$($CC_host --version | grep gcc | awk '{print $NF}')
major=$(echo $host_gcc_version | awk -F . '{print $1}')
minor=$(echo $host_gcc_version | awk -F . '{print $2}')
if [ -z $major ] || [ -z $minor ] || [ $major -lt 6 ] || [ $major -eq 6 -a $minor -lt 3 ]; then
echo "host gcc $host_gcc_version is too old, need gcc 6.3.0"
exit 1
fi
SUFFIX="$TOOLCHAIN_NAME$ANDROID_SDK_VERSION"
TOOLCHAIN=$NDK_PATH/toolchains/llvm/prebuilt/$HOST_OS-$HOST_ARCH
export PATH=$TOOLCHAIN/bin:$PATH
export CC=$TOOLCHAIN/bin/$SUFFIX-clang
export CXX=$TOOLCHAIN/bin/$SUFFIX-clang++
export CC_host=$CC_host$HOST_M32
export CXX_host=$CXX_host$HOST_M32
GYP_DEFINES="target_arch=$ARCH"
GYP_DEFINES+=" v8_target_arch=$ARCH"
GYP_DEFINES+=" android_target_arch=$ARCH"
GYP_DEFINES+=" host_os=$HOST_OS OS=android"
export GYP_DEFINES
if [ -f "configure" ]; then
if [ $WITH_SSL == "" ]; then
./configure \
--dest-cpu=$DEST_CPU \
--dest-os=android \
--without-snapshot \
--without-ssl \
--partly-static \
--with-intl=none \
--shared \
--cross-compiling
else
./configure \
--dest-cpu=$DEST_CPU \
--dest-os=android \
--without-snapshot \
--openssl-no-asm \
--partly-static \
--with-intl=none \
--shared \
--cross-compiling
fi
fi