2013-05-08 12:10:07 +00: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 15:35:23 +00: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>'
|
|
|
|
|
2020-01-26 12:29:10 +00:00
|
|
|
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
|
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 15:35:23 +00:00
|
|
|
|
2020-01-26 12:29:10 +00:00
|
|
|
if [ $ANDROID_SDK_VERSION -lt 23 ]; then
|
|
|
|
echo "$ANDROID_SDK_VERSION should equal or later than 23(Android 6.0)"
|
2016-03-03 10:02:44 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
CC_VER="4.9"
|
2020-01-26 12:29:10 +00:00
|
|
|
|
2016-03-03 10:02:44 +00:00
|
|
|
case $ARCH in
|
|
|
|
arm)
|
2020-01-26 12:29:10 +00:00
|
|
|
DEST_CPU="arm"
|
|
|
|
TOOLCHAIN_NAME="armv7-linux-androideabi"
|
2016-03-03 10:02:44 +00:00
|
|
|
;;
|
|
|
|
x86)
|
|
|
|
DEST_CPU="ia32"
|
2020-01-26 12:29:10 +00:00
|
|
|
TOOLCHAIN_NAME="i686-linux-android"
|
2016-03-03 10:02:44 +00:00
|
|
|
;;
|
|
|
|
x86_64)
|
2020-01-26 12:29:10 +00:00
|
|
|
DEST_CPU="x64"
|
|
|
|
TOOLCHAIN_NAME="x86_64-linux-android"
|
|
|
|
ARCH="x64"
|
|
|
|
;;
|
|
|
|
arm64|aarch64)
|
|
|
|
DEST_CPU="arm64"
|
|
|
|
TOOLCHAIN_NAME="aarch64-linux-android"
|
|
|
|
ARCH="arm64"
|
2016-03-03 10:02:44 +00:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Unsupported architecture provided: $ARCH"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2020-01-26 12:29:10 +00:00
|
|
|
HOST_OS="linux"
|
|
|
|
HOST_ARCH="x86_64"
|
2020-11-14 15:20:03 +00:00
|
|
|
export CC_host=$(command -v gcc)
|
|
|
|
export CXX_host=$(command -v g++)
|
2017-03-21 09:02:26 +00:00
|
|
|
|
2020-01-26 12:29:10 +00:00
|
|
|
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
|
2017-03-21 09:02:26 +00:00
|
|
|
fi
|
2020-01-26 12:29:10 +00:00
|
|
|
|
|
|
|
SUFFIX="$TOOLCHAIN_NAME$ANDROID_SDK_VERSION"
|
|
|
|
TOOLCHAIN=$NDK_PATH/toolchains/llvm/prebuilt/$HOST_OS-$HOST_ARCH
|
|
|
|
|
2013-05-08 12:10:07 +00:00
|
|
|
export PATH=$TOOLCHAIN/bin:$PATH
|
2020-01-26 12:29:10 +00:00
|
|
|
export CC=$TOOLCHAIN/bin/$SUFFIX-clang
|
|
|
|
export CXX=$TOOLCHAIN/bin/$SUFFIX-clang++
|
|
|
|
|
2013-05-08 12:10:07 +00: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 15:35:23 +00:00
|
|
|
GYP_DEFINES="target_arch=$ARCH"
|
|
|
|
GYP_DEFINES+=" v8_target_arch=$ARCH"
|
|
|
|
GYP_DEFINES+=" android_target_arch=$ARCH"
|
2020-01-26 12:29:10 +00:00
|
|
|
GYP_DEFINES+=" host_os=$HOST_OS OS=android"
|
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 15:35:23 +00:00
|
|
|
export GYP_DEFINES
|
|
|
|
|
|
|
|
if [ -f "configure" ]; then
|
|
|
|
./configure \
|
|
|
|
--dest-cpu=$DEST_CPU \
|
|
|
|
--dest-os=android \
|
|
|
|
--without-snapshot \
|
2020-01-26 12:29:10 +00:00
|
|
|
--openssl-no-asm \
|
|
|
|
--cross-compiling
|
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 15:35:23 +00:00
|
|
|
fi
|