Skip to content

Commit

Permalink
add libpomelo android ndk build support
Browse files Browse the repository at this point in the history
  • Loading branch information
fantasyni committed Apr 19, 2013
1 parent 0f28ee5 commit 00f92ad
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 7 deletions.
52 changes: 52 additions & 0 deletions Android.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := pomelo_static

LOCAL_MODULE_FILENAME := libpomelo

LOCAL_SRC_FILES := \
src/client.c \
src/message.c \
src/package.c \
src/pkg-handshake.c \
src/transport.c \
src/common.c \
src/msg-json.c \
src/pb-decode.c \
src/pkg-heartbeat.c \
src/listener.c \
src/msg-pb.c \
src/pb-encode.c \
src/protocol.c \
src/map.c \
src/network.c \
src/pb-util.c \
src/thread.c \





LOCAL_EXPORT_C_INCLUDES :=$(LOCAL_PATH)/include \
$(LOCAL_PATH)/include/pomelo-protobuf \
$(LOCAL_PATH)/include/pomelo-protocol



LOCAL_C_INCLUDES := $(LOCAL_PATH)/include \
$(LOCAL_PATH)/include/pomelo-protobuf \
$(LOCAL_PATH)/include/pomelo-protocol \
$(LOCAL_PATH)/include/pomelo-private

LOCAL_WHOLE_STATIC_LIBRARIES := uv_static jansson_static



include $(BUILD_STATIC_LIBRARY)

LOCAL_CFLAGS := -D__ANDROID__

$(call import-module,libpomelo/deps/uv) \
$(call import-module,libpomelo/deps/jansson)
2 changes: 1 addition & 1 deletion deps/jansson/src/jansson_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@

/* If locale.h and localeconv() are available, define to 1,
otherwise to 0. */
#define JSON_HAVE_LOCALECONV 1
#define JSON_HAVE_LOCALECONV 0

#endif
6 changes: 4 additions & 2 deletions deps/uv/include/uv-private/uv-unix.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,10 @@ typedef struct {

#else /* defined(__APPLE__) && defined(__MACH__) */

typedef pthread_barrier_t uv_barrier_t;

#ifndef __ANDROID__
typedef pthread_barrier_t uv_barrier_t;
#endif

#endif /* defined(__APPLE__) && defined(__MACH__) */

/* Platform-specific definitions for uv_spawn support. */
Expand Down
2 changes: 2 additions & 0 deletions deps/uv/include/uv.h
Original file line number Diff line number Diff line change
Expand Up @@ -1888,9 +1888,11 @@ UV_EXTERN void uv_cond_wait(uv_cond_t* cond, uv_mutex_t* mutex);
UV_EXTERN int uv_cond_timedwait(uv_cond_t* cond, uv_mutex_t* mutex,
uint64_t timeout);

#ifndef __ANDROID__
UV_EXTERN int uv_barrier_init(uv_barrier_t* barrier, unsigned int count);
UV_EXTERN void uv_barrier_destroy(uv_barrier_t* barrier);
UV_EXTERN void uv_barrier_wait(uv_barrier_t* barrier);
#endif

/* Runs a function once and only once. Concurrent calls to uv_once() with the
* same guard will block all callers except one (it's unspecified which one).
Expand Down
9 changes: 7 additions & 2 deletions deps/uv/src/unix/linux/linux-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@
# endif
#endif
#ifdef HAVE_IFADDRS_H
# include <ifaddrs.h>
#ifndef __ANDROID__
#include <ifaddrs.h>
#endif
#endif

#undef NANOSEC
Expand Down Expand Up @@ -712,6 +714,7 @@ void uv_free_cpu_info(uv_cpu_info_t* cpu_infos, int count) {

uv_err_t uv_interface_addresses(uv_interface_address_t** addresses,
int* count) {
#ifndef __ANDROID__
#ifndef HAVE_IFADDRS_H
return uv__new_artificial_error(UV_ENOSYS);
#else
Expand Down Expand Up @@ -776,19 +779,21 @@ uv_err_t uv_interface_addresses(uv_interface_address_t** addresses,
}

freeifaddrs(addrs);

#endif
return uv_ok_;
#endif
}


void uv_free_interface_addresses(uv_interface_address_t* addresses,
int count) {
#ifndef __ANDROID__
int i;

for (i = 0; i < count; i++) {
free(addresses[i].name);
}

free(addresses);
#endif
}
3 changes: 2 additions & 1 deletion deps/uv/src/unix/linux/syscalls.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
#include <sys/types.h>
#include <sys/socket.h>
#include <linux/types.h>

#include <time.h>

#define UV__O_NONBLOCK 0x800
#define UV__O_CLOEXEC 0x80000

Expand Down
7 changes: 6 additions & 1 deletion deps/uv/src/unix/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,11 @@ int uv_cond_init(uv_cond_t* cond) {

if (pthread_condattr_init(&attr))
return -1;

#ifndef __ANDROID__
if (pthread_condattr_setclock(&attr, CLOCK_MONOTONIC))
#else
if (pthread_condattr_setpshared(&attr, CLOCK_MONOTONIC))
#endif
goto error2;

if (pthread_cond_init(cond, &attr))
Expand Down Expand Up @@ -429,6 +432,7 @@ void uv_barrier_wait(uv_barrier_t* barrier) {

#else /* !(defined(__APPLE__) && defined(__MACH__)) */

#ifndef __ANDROID__
int uv_barrier_init(uv_barrier_t* barrier, unsigned int count) {
if (pthread_barrier_init(barrier, NULL, count))
return -1;
Expand All @@ -449,4 +453,5 @@ void uv_barrier_wait(uv_barrier_t* barrier) {
abort();
}

#endif
#endif /* defined(__APPLE__) && defined(__MACH__) */

2 comments on commit 00f92ad

@miroda
Copy link

@miroda miroda commented on 00f92ad Apr 21, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

你们这个地方的是已经成功了的东西吗,直接在android里面能运行

@fantasyni
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是的,在 android ndk 下编译成功,并在真实机子上测试过

Please sign in to comment.