Full glib porting onto Android
- From: Shuxiang Lim <shohyanglim gmail com>
- To: gtk-devel-list gnome org
- Subject: Full glib porting onto Android
- Date: Wed, 23 Mar 2011 17:37:56 +0800
Hello glib/gtk guys!
Recently I've been trying on a Android porting work for a project which has which uses glibs-2.22+ including libglib/libgio/libgthread/libgmodule. Other than using the
already-on android/bluetooth/glib with only libglib-2.20 built, I have managed to hack by my own for a full glib porting.
I hope such work will be enrolled into master-glib.
N.B, this hacking is based on glib-2.28.1 and is still raw and unstable,be care of use!
Any correcting and improving is appreciated!
This README.android has all the instructions and patches of my hacking:
======README.android=============
Shohyang Lim <
shohyanglim gmail com>
Note that this document is not really maintained in a serious
fashion. Lots of information here might be misleading or outdated. You
have been warned.
This FULL Android porting is hacked by Shohyang Lim in the porting of one
project which uses glibs-2.28 including libglib/libgio/libgthread/libgmodule
other than the already-on android/bluetooth/glib with only libglib-2.20 built.
N.B, this hacking is based on glib-2.28.1 and is still raw and unstable,be care of use!
Any correcting and improving is appreciated!
General
=======
In a POSIXer's view, Android system is CRIPPLED: thus the porting of existing
libraries onto it is TOUGH. Please have this in mind.
The basic obstacles in porting:
1.Android does not have or offers less/no access in its
trimmed bionic C lib :
1>No SYS V shm.h/sem.h
2>Not standard pwd.h and getpwuid_r(),etc. methods
3>No locale.h
4>Not standard IP/IPV6 headers/support such as arpa/*.h ones
5>Not standard pthread.
6>No iconv funcs.
7>No intl/gettext funcs
8>No i18n support and wchar_t.
...
2.Cross compiling troubles such as the typecast of pointers may be the
sin of SIGBUS in ARM,ARM-THUMB troubles,...etc.
Therefore the hacking is mainly focusing on such missings. I suppose you are familiar
with ARM cross compiling and Android NDK development.
Building all glibs prerequisites
=======================================
1>Android souce build system or Android NDK
for me, I use the android NDK r4c for Android 2.2 provided by Mozzila
which has nearly full C++ support:
http://ftp.mozilla.org/pub/mozilla.org/mobile/source/android-ndk-r4c-0moz3.tar.bz2
and I have modified Andrew Ross's agcc to extract and use the toolchain from this NDK:
http://blog.csdn.net/rozenix/archive/2011/02/28/6212994.aspx
2> Cross compile the dependencies of glib2.28.1 onto Android in this order:
1)libiconv-1.13.1.tar.gz:
configured by:
CC=agcc CXX=agcc LD=arm-eabi-ld RANLIB=arm-eabi-ranlib \
PKG_CONFIG_LIBDIR=/data/local/lib/pkgconfig:/data/local/share/pkgconfig/ \
./configure \
--prefix=/data/local \
--host=arm-eabi-linux \
--enable-shared \
make; make install;
2)gettext-0.18.1.1.tar.gz
configured by:
CC=agcc CPPFLAGS="-I/data/local/include" LDFLAGS="-L/data/local/lib" \
CXX=agcc LD=arm-eabi-ld RANLIB=arm-eabi-ranlib \
PKG_CONFIG_LIBDIR=/data/local/lib/pkgconfig:/data/local/share/pkgconfig/ \
./configure \
--prefix=/data/local \
--host=arm-eabi-linux \
--enable-shared \
--cache-file=arm.cache \
--without-included-regex \
--disable-java --disable-openmp --without-libiconv-prefix \
--without-libintl-prefix --without-libglib-2.0-prefix \
--without-libcroco-0.6-prefix --with-included-libxml \
--without-libncurses-prefix --without-libtermcap-prefix \
--without-libcurses-prefix --without-libexpat-prefix --without-emacs
Make,But the build of gettext may not fully succeed,never mind, I need only libintl.so so just make install.
Cross compile glib-2.28.1.tar.gz
=======================================
1. do patching with the glib-android.patch attached in this file
by
#patch -p0 < glib-android.patch
2. write this into the cache file arm.cache:
#cat > arm.cache
glib_cv_stack_grows=no
glib_cv_uscore=no
ac_cv_func_posix_getpwuid_r=no
ac_cv_func_posix_getgrgid_r=no
ctrl-D
3. make sure you have tools such as glib-genmashaller of the correct version
installed in your host machine
4. configured the same as libiconv.
5. remove the -lpthread in gthread/Makefile.
6. change the CFLAGS in agcc,replace "-mthumb" by "-mno-thumb"; make;make install
TODO
========================================
1.Check the patching,especially the definitions from arpa/nameser*.h
2.Write Android.mk for glib to ease its use in NDK/SDK development.
The following is the patch file.
=======================================
-BEGIN------------------------patch file---glib-android.patch-----
--- glib-2.28.1/glib/gstrfuncs.c 2011-02-16 10:55:33.000000000 +0800
+++ aglib-2.28.1/glib/gstrfuncs.c 2011-03-21 16:33:18.000000000 +0800
@@ -442,8 +442,12 @@ g_ascii_strtod (const gchar *nptr,
fail_pos = NULL;
+#ifdef ANDROID
+ decimal_point = ".";
+#else
locale_data = localeconv ();
decimal_point = locale_data->decimal_point;
+#endif
decimal_point_len = strlen (decimal_point);
g_assert (decimal_point_len != 0);
@@ -656,8 +660,12 @@ g_ascii_formatd (gchar *buffer,
_g_snprintf (buffer, buf_len, format, d);
+#ifdef ANDROID
+ decimal_point = ".";
+#else
locale_data = localeconv ();
decimal_point = locale_data->decimal_point;
+#endif
decimal_point_len = strlen (decimal_point);
g_assert (decimal_point_len != 0);
--- glib-2.28.1/glib/gutils.c 2011-02-11 23:23:13.000000000 +0800
+++ aglib-2.28.1/glib/gutils.c 2011-03-21 17:08:09.000000000 +0800
@@ -29,6 +29,9 @@
*/
#include "config.h"
+#ifdef ANDROID
+#undef HAVE_PWD_H
+#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
--- glib-2.28.1/gio/libasyncns/asyncns.c 2010-04-13 21:33:16.000000000 +0800
+++ aglib-2.28.1/gio/libasyncns/asyncns.c 2011-03-21 17:11:43.000000000 +0800
@@ -18,6 +18,30 @@
<
http://www.gnu.org/licenses/>.
***/
+#ifdef ANDROID
+typedef struct {
+ unsigned id :16; /*%< query identification number */
+ /* fields in third byte */
+ unsigned rd :1; /*%< recursion desired */
+ unsigned tc :1; /*%< truncated message */
+ unsigned aa :1; /*%< authoritive answer */
+ unsigned opcode :4; /*%< purpose of message */
+ unsigned qr :1; /*%< response flag */
+ /* fields in fourth byte */
+ unsigned rcode :4; /*%< response code */
+ unsigned cd: 1; /*%< checking disabled by resolver */
+ unsigned ad: 1; /*%< authentic data from named */
+ unsigned unused :1; /*%< unused bits (MBZ as of 4.9.3a3) */
+ unsigned ra :1; /*%< recursion available */
+ /* remaining bytes */
+ unsigned qdcount :16; /*%< number of question entries */
+ unsigned ancount :16; /*%< number of answer entries */
+ unsigned nscount :16; /*%< number of authority entries */
+ unsigned arcount :16; /*%< number of resource entries */
+} HEADER;
+#endif
+
+
#ifdef HAVE_CONFIG_H
#include "g-asyncns.h"
#endif
@@ -57,6 +81,10 @@
#include <inttypes.h>
#endif
+#ifdef ANDROID
+#undef HAVE_SYS_PRCTL_H
+#endif
+
#ifdef HAVE_SYS_PRCTL_H
#include <sys/prctl.h>
#endif
--- glib-2.28.1/gio/gresolver.c 2011-02-11 23:23:11.000000000 +0800
+++ aglib-2.28.1/gio/gresolver.c 2011-03-21 16:42:18.000000000 +0800
@@ -20,6 +20,61 @@
* Boston, MA 02111-1307, USA.
*/
+#ifdef ANDROID
+/*%
+ * Inline versions of get/put short/long. Pointer is advanced.
+ */
+#define NS_INT32SZ 4 /*%< #/bytes of data in a u_int32_t */
+#define NS_INT16SZ 2 /*%< #/bytes of data in a u_int16_t */
+#define NS_GET16(s, cp) do { \
+ register const u_char *t_cp = (const u_char *)(cp); \
+ (s) = ((u_int16_t)t_cp[0] << 8) \
+ | ((u_int16_t)t_cp[1]) \
+ ; \
+ (cp) += NS_INT16SZ; \
+} while (0)
+#define NS_GET32(l, cp) do { \
+ register const u_char *t_cp = (const u_char *)(cp); \
+ (l) = ((u_int32_t)t_cp[0] << 24) \
+ | ((u_int32_t)t_cp[1] << 16) \
+ | ((u_int32_t)t_cp[2] << 8) \
+ | ((u_int32_t)t_cp[3]) \
+ ; \
+ (cp) += NS_INT32SZ; \
+} while (0)
+
+
+#define GETSHORT NS_GET16
+#define GETLONG NS_GET32
+
+#define ns_c_in 1 /*%< Internet. */
+#define ns_t_srv 33 /*%< Internet. */
+#define C_IN ns_c_in
+#define T_SRV ns_t_srv
+
+typedef struct {
+ unsigned id :16; /*%< query identification number */
+ /* fields in third byte */
+ unsigned rd :1; /*%< recursion desired */
+ unsigned tc :1; /*%< truncated message */
+ unsigned aa :1; /*%< authoritive answer */
+ unsigned opcode :4; /*%< purpose of message */
+ unsigned qr :1; /*%< response flag */
+ /* fields in fourth byte */
+ unsigned rcode :4; /*%< response code */
+ unsigned cd: 1; /*%< checking disabled by resolver */
+ unsigned ad: 1; /*%< authentic data from named */
+ unsigned unused :1; /*%< unused bits (MBZ as of 4.9.3a3) */
+ unsigned ra :1; /*%< recursion available */
+ /* remaining bytes */
+ unsigned qdcount :16; /*%< number of question entries */
+ unsigned ancount :16; /*%< number of answer entries */
+ unsigned nscount :16; /*%< number of authority entries */
+ unsigned arcount :16; /*%< number of resource entries */
+} HEADER;
+#endif
+
+
#include "config.h"
#include <glib.h>
#include "glibintl.h"
--- glib-2.28.1/gio/gthreadedresolver.c 2011-02-11 23:23:12.000000000 +0800
+++ aglib-2.28.1/gio/gthreadedresolver.c 2011-03-21 16:44:29.000000000 +0800
@@ -20,6 +20,60 @@
* Boston, MA 02111-1307, USA.
*/
+#ifdef ANDROID
+/*%
+ * Inline versions of get/put short/long. Pointer is advanced.
+ */
+#define NS_INT32SZ 4 /*%< #/bytes of data in a u_int32_t */
+#define NS_INT16SZ 2 /*%< #/bytes of data in a u_int16_t */
+#define NS_GET16(s, cp) do { \
+ register const u_char *t_cp = (const u_char *)(cp); \
+ (s) = ((u_int16_t)t_cp[0] << 8) \
+ | ((u_int16_t)t_cp[1]) \
+ ; \
+ (cp) += NS_INT16SZ; \
+} while (0)
+#define NS_GET32(l, cp) do { \
+ register const u_char *t_cp = (const u_char *)(cp); \
+ (l) = ((u_int32_t)t_cp[0] << 24) \
+ | ((u_int32_t)t_cp[1] << 16) \
+ | ((u_int32_t)t_cp[2] << 8) \
+ | ((u_int32_t)t_cp[3]) \
+ ; \
+ (cp) += NS_INT32SZ; \
+} while (0)
+
+
+#define GETSHORT NS_GET16
+#define GETLONG NS_GET32
+
+#define ns_c_in 1 /*%< Internet. */
+#define ns_t_srv 33 /*%< Internet. */
+#define C_IN ns_c_in
+#define T_SRV ns_t_srv
+
+ typedef struct {
+ unsigned id :16; /*%< query identification number */
+ /* fields in third byte */
+ unsigned rd :1; /*%< recursion desired */
+ unsigned tc :1; /*%< truncated message */
+ unsigned aa :1; /*%< authoritive answer */
+ unsigned opcode :4; /*%< purpose of message */
+ unsigned qr :1; /*%< response flag */
+ /* fields in fourth byte */
+ unsigned rcode :4; /*%< response code */
+ unsigned cd: 1; /*%< checking disabled by resolver */
+ unsigned ad: 1; /*%< authentic data from named */
+ unsigned unused :1; /*%< unused bits (MBZ as of 4.9.3a3) */
+ unsigned ra :1; /*%< recursion available */
+ /* remaining bytes */
+ unsigned qdcount :16; /*%< number of question entries */
+ unsigned ancount :16; /*%< number of answer entries */
+ unsigned nscount :16; /*%< number of authority entries */
+ unsigned arcount :16; /*%< number of resource entries */
+ } HEADER;
+#endif
+
#include "config.h"
#include <glib.h>
#include "glibintl.h"
--- glib-2.28.1/gio/gunixresolver.c 2011-02-11 23:23:12.000000000 +0800
+++ aglib-2.28.1/gio/gunixresolver.c 2011-03-21 16:45:01.000000000 +0800
@@ -20,6 +20,62 @@
* Boston, MA 02111-1307, USA.
*/
+#ifdef ANDROID
+/*%
+ * Inline versions of get/put short/long. Pointer is advanced.
+ */
+#define NS_INT32SZ 4 /*%< #/bytes of data in a u_int32_t */
+#define NS_INT16SZ 2 /*%< #/bytes of data in a u_int16_t */
+#define NS_GET16(s, cp) do { \
+ register const u_char *t_cp = (const u_char *)(cp); \
+ (s) = ((u_int16_t)t_cp[0] << 8) \
+ | ((u_int16_t)t_cp[1]) \
+ ; \
+ (cp) += NS_INT16SZ; \
+} while (0)
+#define NS_GET32(l, cp) do { \
+ register const u_char *t_cp = (const u_char *)(cp); \
+ (l) = ((u_int32_t)t_cp[0] << 24) \
+ | ((u_int32_t)t_cp[1] << 16) \
+ | ((u_int32_t)t_cp[2] << 8) \
+ | ((u_int32_t)t_cp[3]) \
+ ; \
+ (cp) += NS_INT32SZ; \
+} while (0)
+
+
+#define GETSHORT NS_GET16
+#define GETLONG NS_GET32
+
+#define ns_c_in 1 /*%< Internet. */
+#define ns_t_srv 33 /*%< Internet. */
+#define C_IN ns_c_in
+#define T_SRV ns_t_srv
+
+ typedef struct {
+ unsigned id :16; /*%< query identification number */
+ /* fields in third byte */
+ unsigned rd :1; /*%< recursion desired */
+ unsigned tc :1; /*%< truncated message */
+ unsigned aa :1; /*%< authoritive answer */
+ unsigned opcode :4; /*%< purpose of message */
+ unsigned qr :1; /*%< response flag */
+ /* fields in fourth byte */
+ unsigned rcode :4; /*%< response code */
+ unsigned cd: 1; /*%< checking disabled by resolver */
+ unsigned ad: 1; /*%< authentic data from named */
+ unsigned unused :1; /*%< unused bits (MBZ as of 4.9.3a3) */
+ unsigned ra :1; /*%< recursion available */
+ /* remaining bytes */
+ unsigned qdcount :16; /*%< number of question entries */
+ unsigned ancount :16; /*%< number of answer entries */
+ unsigned nscount :16; /*%< number of authority entries */
+ unsigned arcount :16; /*%< number of resource entries */
+ } HEADER;
+#endif
+
+
+
#include "config.h"
#include <glib.h>
#include "glibintl.h"
--- glib-2.28.1/gio/glocalfileinfo.c 2011-02-11 23:23:11.000000000 +0800
+++ aglib-2.28.1/gio/glocalfileinfo.c 2011-03-21 16:55:10.000000000 +0800
@@ -1096,7 +1096,11 @@ lookup_uid_data (uid_t uid)
if (pwbufp->pw_name != NULL && pwbufp->pw_name[0] != 0)
data->user_name = convert_pwd_string_to_utf8 (pwbufp->pw_name);
+#ifdef ANDROID
+ gecos = NULL;
+#else
gecos = pwbufp->pw_gecos;
+#endif
if (gecos)
{
--- glib-2.28.1/gio/ginetaddress.c 2011-02-11 23:23:11.000000000 +0800
+++ aglib-2.28.1/gio/ginetaddress.c 2011-03-21 16:55:45.000000000 +0800
@@ -20,6 +20,27 @@
* Authors: Christian Kellner <
gicmo gnome org>
* Samuel Cormier-Iijima <
sciyoshi gmail com>
*/
+#ifdef ANDROID
+#define IN6_IS_ADDR_MC_NODELOCAL(a) \
+ (IN6_IS_ADDR_MULTICAST(a) \
+ && ((((__const uint8_t *) (a))[1] & 0xf) == 0x1))
+
+#define IN6_IS_ADDR_MC_LINKLOCAL(a) \
+ (IN6_IS_ADDR_MULTICAST(a) \
+ && ((((__const uint8_t *) (a))[1] & 0xf) == 0x2))
+
+#define IN6_IS_ADDR_MC_SITELOCAL(a) \
+ (IN6_IS_ADDR_MULTICAST(a) \
+ && ((((__const uint8_t *) (a))[1] & 0xf) == 0x5))
+
+#define IN6_IS_ADDR_MC_ORGLOCAL(a) \
+ (IN6_IS_ADDR_MULTICAST(a) \
+ && ((((__const uint8_t *) (a))[1] & 0xf) == 0x8))
+
+#define IN6_IS_ADDR_MC_GLOBAL(a) \
+ (IN6_IS_ADDR_MULTICAST(a) \
+ && ((((__const uint8_t *) (a))[1] & 0xf) == 0xe))
+#endif
#include <config.h>
--- glib-2.28.1/glib/glibintl.h 2011-02-11 23:23:12.000000000 +0800
+++ aglib-2.28.1/glib/glibintl.h 2011-03-23 16:54:51.000000000 +0800
@@ -7,6 +7,9 @@
G_CONST_RETURN gchar *glib_gettext (const gchar *str) G_GNUC_FORMAT(1);
+#ifdef ANDROID
+#undef ENABLE_NLS
+#endif
#ifdef ENABLE_NLS
#include <libintl.h>
-END------------------------patch file---glib-android.patch-----
================================
That's it! Happy hacking!
===================
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]