diff --git a/README.md b/README.md index a7443c459..f4f3ce2c8 100644 --- a/README.md +++ b/README.md @@ -110,6 +110,16 @@ Note for Linux users: compile your project with `-D_GNU_SOURCE` when you include `uv.h`. GYP builds take care of that automatically. If you use autotools, add a `AC_GNU_SOURCE` declaration to your `configure.ac`. +To build for android, locate your android NDK path, then run: + + source ./android-configure NDK_PATH + make + +To build for android with gyp, add "gyp" to the configuration: + + source ./android-configure NDK_PATH gyp + make -C out + ## Supported Platforms Microsoft Windows operating systems since Windows XP SP2. It can be built diff --git a/android-configure b/android-configure new file mode 100755 index 000000000..20ad6608c --- /dev/null +++ b/android-configure @@ -0,0 +1,20 @@ +#!/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++ +export PLATFORM=android + +if [ $2 -a $2 == 'gyp' ] + then + ./gyp_uv -Dandroid_build=1 -Dtarget_arch=arm +fi diff --git a/common.gypi b/common.gypi index 8693e3ff8..d264a11ba 100644 --- a/common.gypi +++ b/common.gypi @@ -8,6 +8,13 @@ 'msvs_multi_core_compile': '0', # we do enable multicore compiles, but not using the V8 way 'gcc_version%': 'unknown', 'clang%': 0, + + 'conditions': [ + # Workaround for the legacy handling of android in gyp + ['android_build == 1', { + 'OS': 'android', + }], + ], }, 'target_defaults': { @@ -148,7 +155,8 @@ [ 'OS=="solaris"', { 'cflags': [ '-pthreads' ], 'ldflags': [ '-pthreads' ], - }, { + }], + [ 'OS not in "android solaris"', { 'cflags': [ '-pthread' ], 'ldflags': [ '-pthread' ], }], diff --git a/config-unix.mk b/config-unix.mk index ea6a2d608..1674804b2 100644 --- a/config-unix.mk +++ b/config-unix.mk @@ -19,7 +19,7 @@ # IN THE SOFTWARE. E= -CFLAGS += -g -Wall -Wextra -Wno-unused-parameter -std=c89 +CFLAGS += -g -Wall -Wextra -Wno-unused-parameter CPPFLAGS += -I$(SRCDIR)/src LDFLAGS=-lm @@ -104,6 +104,18 @@ OBJS += src/unix/linux-core.o \ src/unix/proctitle.o endif +ifeq (android,$(PLATFORM)) +CFLAGS += -D_GNU_SOURCE +LDFLAGS+=-ldl -lrt +RUNNER_CFLAGS += -D_GNU_SOURCE +OBJS += src/unix/linux-core.o \ + src/unix/linux-inotify.o \ + src/unix/linux-syscalls.o \ + src/unix/proctitle.o +else +CFLAGS += -std=c89 +endif + ifeq (freebsd,$(PLATFORM)) HAVE_DTRACE=1 LDFLAGS+=-lkvm @@ -132,8 +144,10 @@ endif ifeq (sunos,$(PLATFORM)) RUNNER_LDFLAGS += -pthreads else +ifneq (android, $(PLATFORM)) RUNNER_LDFLAGS += -pthread endif +endif ifeq ($(HAVE_DTRACE), 1) DTRACE_HEADER = src/unix/uv-dtrace.h diff --git a/include/uv-private/uv-unix.h b/include/uv-private/uv-unix.h index 4be810054..4c05a714a 100644 --- a/include/uv-private/uv-unix.h +++ b/include/uv-private/uv-unix.h @@ -37,7 +37,7 @@ #include #include -#ifdef ANDROID +#ifdef __ANDROID__ #include "pthread-fixes.h" #endif #include diff --git a/src/unix/linux-core.c b/src/unix/linux-core.c index 157938b22..ed7e428f2 100644 --- a/src/unix/linux-core.c +++ b/src/unix/linux-core.c @@ -36,7 +36,7 @@ #include #include -#ifndef ANDROID +#ifndef __ANDROID__ #define HAVE_IFADDRS_H 1 #endif diff --git a/src/unix/thread.c b/src/unix/thread.c index 4cc5d9893..0cf65a592 100644 --- a/src/unix/thread.c +++ b/src/unix/thread.c @@ -281,7 +281,7 @@ int uv_cond_init(uv_cond_t* cond) { if (pthread_condattr_init(&attr)) return -1; -#if !defined(ANDROID) +#if !defined(__ANDROID__) if (pthread_condattr_setclock(&attr, CLOCK_MONOTONIC)) goto error2; #endif @@ -336,7 +336,7 @@ int uv_cond_timedwait(uv_cond_t* cond, uv_mutex_t* mutex, uint64_t timeout) { timeout += uv__hrtime(); ts.tv_sec = timeout / NANOSEC; ts.tv_nsec = timeout % NANOSEC; -#if defined(ANDROID) +#if defined(__ANDROID__) /* * The bionic pthread implementation doesn't support CLOCK_MONOTONIC, * but has this alternative function instead. @@ -344,7 +344,7 @@ int uv_cond_timedwait(uv_cond_t* cond, uv_mutex_t* mutex, uint64_t timeout) { r = pthread_cond_timedwait_monotonic_np(cond, mutex, &ts); #else r = pthread_cond_timedwait(cond, mutex, &ts); -#endif /* ANDROID */ +#endif /* __ANDROID__ */ #endif