From 5e4e8ec429381a8d1eebe31647e9daaaae42c54b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Linus=20M=C3=A5rtensson?= Date: Wed, 8 May 2013 14:10:07 +0200 Subject: [PATCH] build: add android support Resolves minor discrepancies between android and standard POSIX systems. In addition, some configure parameters were added, and a helper-script for android configuration. Ideally, this script should be merged into the standard configure script. To build for android, source the android-configure script with an NDK path: source ./android-configure ~/android-ndk-r8d This will create an android standalone toolchain and export the necessary environment parameters. After that, build as normal: make -j8 After the build, you should now have android-compatible NodeJS binaries. --- android-configure | 19 +++++++++++++++++++ common.gypi | 14 +++++++++++--- configure | 5 ++++- doc/api/process.markdown | 21 ++++++++++++++------- src/cares_wrap.cc | 5 ++++- src/node.cc | 10 +++++----- 6 files changed, 57 insertions(+), 17 deletions(-) create mode 100755 android-configure diff --git a/android-configure b/android-configure new file mode 100755 index 0000000..7acb7f3 --- /dev/null +++ b/android-configure @@ -0,0 +1,19 @@ +#!/bin/bash + +export TOOLCHAIN=$PWD/android-toolchain +mkdir -p $TOOLCHAIN +$1/build/tools/make-standalone-toolchain.sh \ + --toolchain=arm-linux-androideabi-4.7 \ + --arch=arm \ + --install-dir=$TOOLCHAIN \ + --platform=android-9 +export PATH=$TOOLCHAIN/bin:$PATH +export AR=arm-linux-androideabi-ar +export CC=arm-linux-androideabi-gcc +export CXX=arm-linux-androideabi-g++ +export LINK=arm-linux-androideabi-g++ + +./configure \ + --without-snapshot \ + --dest-cpu=arm \ + --dest-os=android diff --git a/common.gypi b/common.gypi index 3b08a7f..043a267 100644 --- a/common.gypi +++ b/common.gypi @@ -161,10 +161,14 @@ 'BUILDING_UV_SHARED=1', ], }], - [ 'OS=="linux" or OS=="freebsd" or OS=="openbsd" or OS=="solaris"', { - 'cflags': [ '-Wall', '-Wextra', '-Wno-unused-parameter', '-pthread', ], + [ 'OS in "linux freebsd openbsd solaris"', { + 'cflags': [ '-pthread', ], + 'ldflags': [ '-pthread' ], + }], + [ 'OS in "linux freebsd openbsd solaris android"', { + 'cflags': [ '-Wall', '-Wextra', '-Wno-unused-parameter', ], 'cflags_cc': [ '-fno-rtti', '-fno-exceptions' ], - 'ldflags': [ '-pthread', '-rdynamic' ], + 'ldflags': [ '-rdynamic' ], 'target_conditions': [ ['_type=="static_library"', { 'standalone_static_library': 1, # disable thin archive which needs binutils >= 2.19 @@ -187,6 +191,10 @@ }], ], }], + [ 'OS=="android"', { + 'defines': ['_GLIBCXX_USE_C99_MATH'], + 'libraries': [ '-llog' ], + }], ['OS=="mac"', { 'defines': ['_DARWIN_USE_64_BIT_INODE=1'], 'xcode_settings': { diff --git a/configure b/configure index 012b77f..885de4b 100755 --- a/configure +++ b/configure @@ -237,7 +237,7 @@ parser.add_option("--dest-os", action="store", dest="dest_os", help="Operating system to build for. Valid values are: " - "win, mac, solaris, freebsd, openbsd, linux") + "win, mac, solaris, freebsd, openbsd, linux, android") parser.add_option("--no-ifaddrs", action="store_true", @@ -434,6 +434,8 @@ def configure_arm(o): def configure_node(o): + if options.dest_os == 'android': + o['variables']['OS'] = "android" o['variables']['v8_enable_gdbjit'] = 1 if options.gdb else 0 o['variables']['v8_no_strict_aliasing'] = 1 # work around compiler bugs o['variables']['node_prefix'] = os.path.expanduser(options.prefix or '') @@ -641,6 +643,7 @@ configure_v8(output) configure_openssl(output) configure_winsdk(output) + # variables should be a root level element, # move everything else to target_defaults variables = output['variables'] diff --git a/doc/api/process.markdown b/doc/api/process.markdown index 7add27e..43fd8be 100644 --- a/doc/api/process.markdown +++ b/doc/api/process.markdown @@ -213,7 +213,8 @@ The shell that executed node should see the exit code as 1. ## process.getgid() -Note: this function is only available on POSIX platforms (i.e. not Windows) +Note: this function is only available on POSIX platforms (i.e. not Windows, +Android) Gets the group identity of the process. (See getgid(2).) This is the numerical group id, not the group name. @@ -225,7 +226,8 @@ This is the numerical group id, not the group name. ## process.setgid(id) -Note: this function is only available on POSIX platforms (i.e. not Windows) +Note: this function is only available on POSIX platforms (i.e. not Windows, +Android) Sets the group identity of the process. (See setgid(2).) This accepts either a numerical ID or a groupname string. If a groupname is specified, this method @@ -245,7 +247,8 @@ blocks while resolving it to a numerical ID. ## process.getuid() -Note: this function is only available on POSIX platforms (i.e. not Windows) +Note: this function is only available on POSIX platforms (i.e. not Windows, +Android) Gets the user identity of the process. (See getuid(2).) This is the numerical userid, not the username. @@ -257,7 +260,8 @@ This is the numerical userid, not the username. ## process.setuid(id) -Note: this function is only available on POSIX platforms (i.e. not Windows) +Note: this function is only available on POSIX platforms (i.e. not Windows, +Android) Sets the user identity of the process. (See setuid(2).) This accepts either a numerical ID or a username string. If a username is specified, this method @@ -277,7 +281,8 @@ blocks while resolving it to a numerical ID. ## process.getgroups() -Note: this function is only available on POSIX platforms (i.e. not Windows) +Note: this function is only available on POSIX platforms (i.e. not Windows, +Android) Returns an array with the supplementary group IDs. POSIX leaves it unspecified if the effective group ID is included but node.js ensures it always is. @@ -285,7 +290,8 @@ if the effective group ID is included but node.js ensures it always is. ## process.setgroups(groups) -Note: this function is only available on POSIX platforms (i.e. not Windows) +Note: this function is only available on POSIX platforms (i.e. not Windows, +Android) Sets the supplementary group IDs. This is a privileged operation, meaning you need to be root or have the CAP_SETGID capability. @@ -295,7 +301,8 @@ The list can contain group IDs, group names or both. ## process.initgroups(user, extra_group) -Note: this function is only available on POSIX platforms (i.e. not Windows) +Note: this function is only available on POSIX platforms (i.e. not Windows, +Android) Reads /etc/group and initializes the group access list, using all groups of which the user is a member. This is a privileged operation, meaning you need diff --git a/src/cares_wrap.cc b/src/cares_wrap.cc index 6b83ecb..d80c93a 100644 --- a/src/cares_wrap.cc +++ b/src/cares_wrap.cc @@ -31,7 +31,10 @@ #include "tree.h" #include "uv.h" -#if defined(__OpenBSD__) || defined(__MINGW32__) || defined(_MSC_VER) +#if defined(__ANDROID__) || \ + defined(__MINGW32__) || \ + defined(__OpenBSD__) || \ + defined(_MSC_VER) # include #else # include diff --git a/src/node.cc b/src/node.cc index 07b42f4..6aa0eda 100644 --- a/src/node.cc +++ b/src/node.cc @@ -61,7 +61,7 @@ typedef int mode_t; #include #include "zlib.h" -#ifdef __POSIX__ +#if defined(__POSIX__) && !defined(__ANDROID__) # include /* getpwnam() */ # include /* getgrnam() */ #endif @@ -1374,7 +1374,7 @@ static Handle Umask(const Arguments& args) { } -#ifdef __POSIX__ +#if defined(__POSIX__) && !defined(__ANDROID__) static const uid_t uid_not_found = static_cast(-1); static const gid_t gid_not_found = static_cast(-1); @@ -1650,7 +1650,7 @@ static Handle InitGroups(const Arguments& args) { return Undefined(node_isolate); } -#endif // __POSIX__ +#endif // __POSIX__ && !defined(__ANDROID__) v8::Handle Exit(const v8::Arguments& args) { @@ -2349,7 +2349,7 @@ Handle SetupProcessObject(int argc, char *argv[]) { NODE_SET_METHOD(process, "umask", Umask); -#ifdef __POSIX__ +#if defined(__POSIX__) && !defined(__ANDROID__) NODE_SET_METHOD(process, "getuid", GetUid); NODE_SET_METHOD(process, "setuid", SetUid); @@ -2359,7 +2359,7 @@ Handle SetupProcessObject(int argc, char *argv[]) { NODE_SET_METHOD(process, "getgroups", GetGroups); NODE_SET_METHOD(process, "setgroups", SetGroups); NODE_SET_METHOD(process, "initgroups", InitGroups); -#endif // __POSIX__ +#endif // __POSIX__ && !defined(__ANDROID__) NODE_SET_METHOD(process, "_kill", Kill); -- 2.7.4