forked from nodejs/node-chakracore
-
Notifications
You must be signed in to change notification settings - Fork 182
/
android-configure
executable file
·98 lines (89 loc) · 2.36 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
#!/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 [ -z "$2" ]; then
ARCH=arm
else
ARCH="$2"
fi
CC_VER="4.9"
case $ARCH in
arm)
DEST_CPU="$ARCH"
V8_ARCH="$ARCH"
SUFFIX="$ARCH-linux-androideabi"
TOOLCHAIN_NAME="$SUFFIX"
;;
x86)
DEST_CPU="ia32"
V8_ARCH="ia32"
SUFFIX="i686-linux-android"
TOOLCHAIN_NAME="$ARCH"
;;
x86_64)
DEST_CPU="x64"
V8_ARCH="x64"
SUFFIX="$ARCH-linux-android"
TOOLCHAIN_NAME="$ARCH"
;;
arm64)
DEST_CPU="arm64"
V8_ARCH="arm64"
SUFFIX="aarch64-linux-android"
TOOLCHAIN_NAME="aarch64"
;;
*)
echo "Unsupported architecture provided: $ARCH"
exit 1
;;
esac
NDK_PATH=$1
function make_toolchain {
$NDK_PATH/build/tools/make-standalone-toolchain.sh \
--toolchain=$TOOLCHAIN_NAME-$CC_VER \
--arch=$ARCH \
--install-dir=$TOOLCHAIN \
--stl=libc++ \
--force \
--platform=android-21
}
export TOOLCHAIN=$PWD/android-toolchain
if [ -d "$TOOLCHAIN" ]; then
read -r -p "NDK toolchain already exists. Replace it? [y/N]" response
case "$response" in
[Yy])
rm -rf "$TOOLCHAIN"
make_toolchain
esac
else
make_toolchain
fi
export AR_host="$(which ar)"
export AR=$TOOLCHAIN/bin/$SUFFIX-ar
export AR_target=$TOOLCHAIN/bin/$SUFFIX-ar
export CC_target=$TOOLCHAIN/bin/$SUFFIX-gcc
export CXX_target=$TOOLCHAIN/bin/$SUFFIX-g++
export LINK_target=$TOOLCHAIN/bin/$SUFFIX-g++
GYP_DEFINES="target_arch=$ARCH"
GYP_DEFINES+=" v8_target_arch=$V8_ARCH"
GYP_DEFINES+=" android_target_arch=$ARCH"
if [ "$(uname -s)" == "Darwin" ]; then
GYP_DEFINES+=" host_os=mac target_os=android"
else
GYP_DEFINES+=" host_os=linux target_os=android"
fi
export GYP_DEFINES
if [ -f "configure" ]; then
./configure \
--dest-cpu=$DEST_CPU \
--dest-os=android \
--openssl-no-asm \
--with-intl=none \
--cross-compiling \
--shared
fi