2013-05-08 14:10:07 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
build: update android-configure script for npm
Now, that we can cross-compile node for Android, we also need to take
care of native node modules installed with npm. Since there is no way to
install and run npm on an Android device, we could instal node on host
and setup an environment for installing node modules and cross-compile
the native sources using Android NDK.
The changes to this script will allow npm, when installing a module, to
compile it using NDK.
In order to do this, the developer should do the following steps:
1. Compile and install node on host, using: configure, make and make
install
2. Build node for Android, using: source android-configure <path_to_ndk>
arch and make
3. Push node binary to Android device
4. Using the same session, configure npm arch using: npm config set
arch=<arch>
5. Install desired node modules using: npm install
6. Push installed node modules to Android device
Signed-off-by: Robert Chiras <robert.chiras@intel.com>
PR-URL: https://github.com/nodejs/node/pull/6349
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2016-04-22 17:35:23 +02:00
|
|
|
# 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>'
|
|
|
|
|
|
|
|
|
2016-03-03 11:02:44 +01:00
|
|
|
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
|
|
|
|
|
2013-05-08 14:10:07 +02:00
|
|
|
export TOOLCHAIN=$PWD/android-toolchain
|
|
|
|
mkdir -p $TOOLCHAIN
|
|
|
|
$1/build/tools/make-standalone-toolchain.sh \
|
2016-03-03 11:02:44 +01:00
|
|
|
--toolchain=$TOOLCHAIN_NAME-$CC_VER \
|
|
|
|
--arch=$ARCH \
|
2013-05-08 14:10:07 +02:00
|
|
|
--install-dir=$TOOLCHAIN \
|
2015-08-23 05:40:41 +02:00
|
|
|
--platform=android-21
|
2013-05-08 14:10:07 +02:00
|
|
|
export PATH=$TOOLCHAIN/bin:$PATH
|
2016-03-03 11:02:44 +01:00
|
|
|
export AR=$TOOLCHAIN/bin/$SUFFIX-ar
|
|
|
|
export CC=$TOOLCHAIN/bin/$SUFFIX-gcc
|
|
|
|
export CXX=$TOOLCHAIN/bin/$SUFFIX-g++
|
|
|
|
export LINK=$TOOLCHAIN/bin/$SUFFIX-g++
|
2013-05-08 14:10:07 +02:00
|
|
|
|
build: update android-configure script for npm
Now, that we can cross-compile node for Android, we also need to take
care of native node modules installed with npm. Since there is no way to
install and run npm on an Android device, we could instal node on host
and setup an environment for installing node modules and cross-compile
the native sources using Android NDK.
The changes to this script will allow npm, when installing a module, to
compile it using NDK.
In order to do this, the developer should do the following steps:
1. Compile and install node on host, using: configure, make and make
install
2. Build node for Android, using: source android-configure <path_to_ndk>
arch and make
3. Push node binary to Android device
4. Using the same session, configure npm arch using: npm config set
arch=<arch>
5. Install desired node modules using: npm install
6. Push installed node modules to Android device
Signed-off-by: Robert Chiras <robert.chiras@intel.com>
PR-URL: https://github.com/nodejs/node/pull/6349
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2016-04-22 17:35:23 +02:00
|
|
|
GYP_DEFINES="target_arch=$ARCH"
|
|
|
|
GYP_DEFINES+=" v8_target_arch=$ARCH"
|
|
|
|
GYP_DEFINES+=" android_target_arch=$ARCH"
|
|
|
|
GYP_DEFINES+=" host_os=linux OS=android"
|
|
|
|
export GYP_DEFINES
|
|
|
|
|
|
|
|
if [ -f "configure" ]; then
|
|
|
|
./configure \
|
|
|
|
--dest-cpu=$DEST_CPU \
|
|
|
|
--dest-os=android \
|
|
|
|
--without-snapshot \
|
|
|
|
--openssl-no-asm
|
|
|
|
fi
|