Building libev and libeio with Android NDK

First, libeio: I beat autoconf, autoreconf and automake until I was able to get a config.h. Surprise! It’s equivalent to config.in with all options on.  Next, I added this lines in the xthread.h file, just after include <pthread>

#ifdef ANDROID
#include <asm/page.h>
#endif

This takes care of the PAGE_SIZE definition missing from <limits.h> (it’s defined as itself in that file, I kid you not…)

And since bionic is built non-posix, I added these lines after include <sys/select.h>, in the unix section (!WIN32):

  #ifndef ANDROID
  #include <sys/statvfs.h>
  #else
  #include <sys/vfs.h>
  #define statvfs statfs
  #define fstatvfs fstatfs
  #endif

The Android.mk is very straightforward, I just build the eio.c file pointing local includes to the same dir.

To build libev, you’ll need to add the following lines to ev_select.h:

#ifdef ANDROID
typedef int fd_mask;
#endif

That’s how the openssl people apparently solved this missing type definition.

We are almost there. Next, add the following lines just after EV_USE_CLOCK_SYSCALL:

#ifndef ANDROID
# include <syscall.h>
#else
# include <sys/syscall.h>
#endif

Finally, the next thing to do is to compile two files: ev.c & event.c with local includes set to the same dir. That sounds simple when you read this, but since the extra c files are included by the ev.c main file, compiling them directly with their headers will result in undefining variables, and this won’t compile. It would have been nice to wrap the .c files around an #ifdef #endif, to avoid this. The configuration works with all setting turned on (including latest GCC and libc).

Leave a comment