From 1fbacdcd01a374cd67021f12df25e1491e7e9c80 Mon Sep 17 00:00:00 2001 From: Robert Chiras Date: Thu, 3 Mar 2016 12:02:44 +0200 Subject: [PATCH 1/2] build: Add suport for x86 architecture Modified android-configure script to support also x86 arch. Currently added support only for ia32 target arch. Also, compile openssl without asm, since using the asm sources will make node fail to run on Android, because it adds text relocations. Signed-off-by: Robert Chiras --- android-configure | 47 +++++++++++++++++++++++++++++++++++++++-------- common.gypi | 8 ++++++++ 2 files changed, 47 insertions(+), 8 deletions(-) diff --git a/android-configure b/android-configure index 5cdfa70bbafba7..cbf137f47174c7 100755 --- a/android-configure +++ b/android-configure @@ -1,18 +1,49 @@ #!/bin/bash +if [ -z "$2" ]; then + ARCH=arm +else + ARCH="$2" +fi + +CC_VER="4.9" +case $ARCH in + arm) + DEST_CPU="$ARCH" + SUFFIX="$ARCH-linux-androideabi" + TOOLCHAIN_NAME="$SUFFIX" + ;; + x86) + DEST_CPU="ia32" + SUFFIX="i686-linux-android" + TOOLCHAIN_NAME="$ARCH" + ;; + x86_64) + DEST_CPU="ia32" + SUFFIX="$ARCH-linux-android" + TOOLCHAIN_NAME="$ARCH" + ;; + *) + echo "Unsupported architecture provided: $ARCH" + exit 1 + ;; +esac + export TOOLCHAIN=$PWD/android-toolchain mkdir -p $TOOLCHAIN $1/build/tools/make-standalone-toolchain.sh \ - --toolchain=arm-linux-androideabi-4.9 \ - --arch=arm \ + --toolchain=$TOOLCHAIN_NAME-$CC_VER \ + --arch=$ARCH \ --install-dir=$TOOLCHAIN \ --platform=android-21 export PATH=$TOOLCHAIN/bin:$PATH -export AR=$TOOLCHAIN/bin/arm-linux-androideabi-ar -export CC=$TOOLCHAIN/bin/arm-linux-androideabi-gcc -export CXX=$TOOLCHAIN/bin/arm-linux-androideabi-g++ -export LINK=$TOOLCHAIN/bin/arm-linux-androideabi-g++ +export AR=$TOOLCHAIN/bin/$SUFFIX-ar +export CC=$TOOLCHAIN/bin/$SUFFIX-gcc +export CXX=$TOOLCHAIN/bin/$SUFFIX-g++ +export LINK=$TOOLCHAIN/bin/$SUFFIX-g++ ./configure \ - --dest-cpu=arm \ - --dest-os=android + --dest-cpu=$DEST_CPU \ + --dest-os=android \ + --without-snapshot \ + --openssl-no-asm diff --git a/common.gypi b/common.gypi index 5b8b2c09d6b4a9..db719ef0eead52 100644 --- a/common.gypi +++ b/common.gypi @@ -68,6 +68,10 @@ 'cflags': [ '-gxcoff' ], 'ldflags': [ '-Wl,-bbigtoc' ], }], + ['OS == "android"', { + 'cflags': [ '-fPIE' ], + 'ldflags': [ '-fPIE', '-pie' ] + }] ], 'msvs_settings': { 'VCCLCompilerTool': { @@ -101,6 +105,10 @@ ['OS!="mac" and OS!="win"', { 'cflags': [ '-fno-omit-frame-pointer' ], }], + ['OS == "android"', { + 'cflags': [ '-fPIE' ], + 'ldflags': [ '-fPIE', '-pie' ] + }] ], 'msvs_settings': { 'VCCLCompilerTool': { From 289ea4b0254d5b737337f0f253bcff8a62d2c539 Mon Sep 17 00:00:00 2001 From: Robert Chiras Date: Thu, 3 Mar 2016 17:13:12 +0200 Subject: [PATCH 2/2] build: Add script to create Android .mk files The create_android_makefiles script will create .mk files for node and all of its dependencies ready to be build using Android build system. Signed-off-by: Robert Chiras --- tools/create_android_makefiles | 46 ++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100755 tools/create_android_makefiles diff --git a/tools/create_android_makefiles b/tools/create_android_makefiles new file mode 100755 index 00000000000000..abf2ecf083c307 --- /dev/null +++ b/tools/create_android_makefiles @@ -0,0 +1,46 @@ +#!/bin/bash +# Run this script ONLY inside an Android build system +# and after you ran lunch command! + +if [ -z "$ANDROID_BUILD_TOP" ]; then + echo "Run lunch before running this script!" + exit 1 +fi + +if [ -z "$1" ]; then + ARCH="arm" +else + ARCH="$1" +fi + +if [ $ARCH = "x86" ]; then + TARGET_ARCH="ia32" +else + TARGET_ARCH="$ARCH" +fi + +cd $(dirname $0)/.. + +./configure \ + --without-snapshot \ + --openssl-no-asm \ + --dest-cpu=$TARGET_ARCH \ + --dest-os=android + +export GYP_GENERATORS="android" +export GYP_GENERATOR_FLAGS="limit_to_target_all=true" +GYP_DEFINES="target_arch=$TARGET_ARCH" +GYP_DEFINES+=" v8_target_arch=$TARGET_ARCH" +GYP_DEFINES+=" android_target_arch=$ARCH" +GYP_DEFINES+=" host_os=linux OS=android" +export GYP_DEFINES + +./deps/npm/node_modules/node-gyp/gyp/gyp \ + -Icommon.gypi \ + -Iconfig.gypi \ + --depth=. \ + -Dcomponent=static_library \ + -Dlibrary=static_library \ + node.gyp + +echo -e "LOCAL_PATH := \$(call my-dir)\n\ninclude \$(LOCAL_PATH)/GypAndroid.mk" > Android.mk