Node_Escargot_Release_210713_97834f7
[platform/framework/web/lwnode.git] / android-configure
1 #!/bin/bash
2
3 # In order to cross-compile node for Android using NDK, run:
4 #   source android-configure <path_to_ndk> [arch]
5 #
6 # By running android-configure with source, will allow environment variables to
7 # be persistent in current session. This is useful for installing native node
8 # modules with npm. Also, don't forget to set the arch in npm config using
9 # 'npm config set arch=<arch>'
10
11 if [ $# -ne 3 ]; then
12   echo "$0 should have 3 parameters: ndk_path, target_arch and sdk_version"
13   exit 1
14 fi
15
16 NDK_PATH=$1
17 ARCH="$2"
18 ANDROID_SDK_VERSION=$3
19
20 if [ $ANDROID_SDK_VERSION -lt 23 ]; then
21   echo "$ANDROID_SDK_VERSION should equal or later than 23(Android 6.0)"
22 fi
23
24 CC_VER="4.9"
25
26 case $ARCH in
27     arm)
28         DEST_CPU="arm"
29         TOOLCHAIN_NAME="armv7-linux-androideabi"
30         ;;
31     x86)
32         DEST_CPU="ia32"
33         TOOLCHAIN_NAME="i686-linux-android"
34         ;;
35     x86_64)
36         DEST_CPU="x64"
37         TOOLCHAIN_NAME="x86_64-linux-android"
38         ARCH="x64"
39         ;;
40     arm64|aarch64)
41         DEST_CPU="arm64"
42         TOOLCHAIN_NAME="aarch64-linux-android"
43         ARCH="arm64"
44         ;;
45     *)
46         echo "Unsupported architecture provided: $ARCH"
47         exit 1
48         ;;
49 esac
50
51 HOST_OS="linux"
52 HOST_ARCH="x86_64"
53 export CC_host=$(which gcc)
54 export CXX_host=$(which g++)
55
56 host_gcc_version=$($CC_host --version | grep gcc | awk '{print $NF}')
57 major=$(echo $host_gcc_version | awk -F . '{print $1}')
58 minor=$(echo $host_gcc_version | awk -F . '{print $2}')
59 if [ -z $major ] || [ -z $minor ] || [ $major -lt 6 ] || [ $major -eq 6 -a $minor -lt 3 ]; then
60   echo "host gcc $host_gcc_version is too old, need gcc 6.3.0"
61   exit 1
62 fi
63
64 SUFFIX="$TOOLCHAIN_NAME$ANDROID_SDK_VERSION"
65 TOOLCHAIN=$NDK_PATH/toolchains/llvm/prebuilt/$HOST_OS-$HOST_ARCH
66
67 export PATH=$TOOLCHAIN/bin:$PATH
68 export CC=$TOOLCHAIN/bin/$SUFFIX-clang
69 export CXX=$TOOLCHAIN/bin/$SUFFIX-clang++
70
71
72 GYP_DEFINES="target_arch=$ARCH"
73 GYP_DEFINES+=" v8_target_arch=$ARCH"
74 GYP_DEFINES+=" android_target_arch=$ARCH"
75 GYP_DEFINES+=" host_os=$HOST_OS OS=android"
76 export GYP_DEFINES
77
78 if [ -f "configure" ]; then
79     ./configure \
80         --dest-cpu=$DEST_CPU \
81         --dest-os=android \
82         --without-snapshot \
83         --openssl-no-asm \
84         --cross-compiling
85 fi