lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi,

Lua 5.2.4 could be cross-compiled without patching the sources, just
with some options `-D` in the compiler command line; even if I prefer
patching src/luaconf.h, like that:
+#if defined(__ANDROID__)
+#define getlocaledecpoint()    ('.')
+#define LUA_USE_POSIX
+#define LUA_USE_DLOPEN        /* needs an extra library: -ldl */
+#define LUA_USE_LONGLONG    /* assume support for long long */
+#endif

Lua 5.3.3 requires some patches.
The implementation of strtod() in the Android Bionic C library doesn't
handle the hex format.
So, we must define LUA_USE_C89.
Currently, LUA_USE_C89 implies LUA_USE_C89.
LUA_C89_NUMBERS gives sizeof(lua_Number)==8 and sizeof(lua_Integer)==4
which is a bad mix between LUA_32BITS (both at 4) and the "standard"
(both at 8). And the cross-compiler supports 'long long', so we don't
need LUA_C89_NUMBERS.

I write 2 variants of a patch of luaconf.h, the second removes the
dependency between LUA_USE_C89 and LUA_USE_C89.

A 3rd patch allows to cross compile from the command line `make android`.

And the last patch fixes an issue detected by the official test suite.
The implementation of mkstemp() in Bionic is dummy, so fallback to
tmpnam().

The implementation of setlocale() seems also dummy, but I have no patch.

François

Note: The issue with strtod() was detected here :
https://github.com/fperrad/lua-MessagePack/pull/21
v1 luaconf: android support

--- a/src/luaconf.h
+++ b/src/luaconf.h
@@ -72,12 +72,20 @@
 #endif
 
 
+#if defined(__ANDROID__)
+#define lua_getlocaledecpoint()		('.')
+#define LUA_USE_C89		/* Bionic is not C99 compliant (strtod) */
+#define LUA_USE_POSIX
+#define LUA_USE_DLOPEN		/* needs an extra library: -ldl */
+#endif
+
+
 /*
 @@ LUA_C89_NUMBERS ensures that Lua uses the largest types available for
 ** C89 ('long' and 'double'); Windows always has '__int64', so it does
-** not need to use this case.
+** not need to use this case; Android has 'long long'.
 */
-#if defined(LUA_USE_C89) && !defined(LUA_USE_WINDOWS)
+#if defined(LUA_USE_C89) && !defined(LUA_USE_WINDOWS) && !defined(__ANDROID__)
 #define LUA_C89_NUMBERS
 #endif
 
-- 

v2 luaconf: android support

--- a/src/luaconf.h
+++ b/src/luaconf.h
@@ -72,14 +72,19 @@
 #endif
 
 
+#if defined(__ANDROID__)
+#define lua_getlocaledecpoint()		('.')
+#define LUA_USE_C89		/* Bionic is not C99 compliant (strtod) */
+#define LUA_USE_POSIX
+#define LUA_USE_DLOPEN		/* needs an extra library: -ldl */
+#endif
+
+
 /*
 @@ LUA_C89_NUMBERS ensures that Lua uses the largest types available for
-** C89 ('long' and 'double'); Windows always has '__int64', so it does
-** not need to use this case.
+** C89 ('long' and 'double').
 */
-#if defined(LUA_USE_C89) && !defined(LUA_USE_WINDOWS)
-#define LUA_C89_NUMBERS
-#endif
+/* #define LUA_C89_NUMBERS */
 
 
 
-- 

Makefile android cross compilation

--- a/src/Makefile
+++ b/src/Makefile
@@ -6,13 +6,14 @@
 # Your platform. See PLATS for possible values.
 PLAT= none
 
-CC= gcc -std=gnu99
+CROSS=
+CC= $(CROSS)gcc -std=gnu99
 CFLAGS= -O2 -Wall -Wextra -DLUA_COMPAT_5_2 $(SYSCFLAGS) $(MYCFLAGS)
 LDFLAGS= $(SYSLDFLAGS) $(MYLDFLAGS)
 LIBS= -lm $(SYSLIBS) $(MYLIBS)
 
-AR= ar rcu
-RANLIB= ranlib
+AR= $(CROSS)ar rcu
+RANLIB= $(CROSS)ranlib
 RM= rm -f
 
 SYSCFLAGS=
@@ -24,9 +25,18 @@
 MYLIBS=
 MYOBJS=
 
+# Android NDK from https://dl.google.com/android/repository/android-ndk-r13b-linux-x86_64.zip
+# more examples on http://luajit.org/install.html
+NDK=/opt/android/ndk
+NDKABI=14
+NDKVER=$(NDK)/toolchains/arm-linux-androideabi-4.9
+NDKP=$(NDKVER)/prebuilt/linux-x86_64/bin/arm-linux-androideabi-
+NDKF=--sysroot $(NDK)/platforms/android-$(NDKABI)/arch-arm
+NDKARCH=-march=armv7-a -mfloat-abi=softfp -Wl,--fix-cortex-a8
+
 # == END OF USER SETTINGS -- NO NEED TO CHANGE ANYTHING BELOW THIS LINE =======
 
-PLATS= aix bsd c89 freebsd generic linux macosx mingw posix solaris
+PLATS= aix bsd c89 freebsd generic linux macosx mingw posix solaris android
 
 LUA_A=	liblua.a
 CORE_O=	lapi.o lcode.o lctype.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o \
@@ -124,6 +134,10 @@
 solaris:
 	$(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_POSIX -DLUA_USE_DLOPEN -D_REENTRANT" SYSLIBS="-ldl"
 
+android:
+	$(MAKE) $(ALL) CROSS=$(NDKP) SYSCFLAGS="$(NDKF) $(NDKARCH)" SYSLIBS="$(NDKF) $(NDKARCH),-E -ldl"
+
+
 # list targets that do not create files (but not all makes understand .PHONY)
 .PHONY: all $(PLATS) default o a clean depend echo none
 
-- 

fix os.tmpname() on Android 

use C tmpnam() instead of POSIX mkstemp()

> print(os.tmpname())
stdin:1: unable to generate a unique filename

--- a/src/loslib.c
+++ b/src/loslib.c
@@ -108,7 +108,7 @@
 */
 #if !defined(lua_tmpnam)	/* { */
 
-#if defined(LUA_USE_POSIX)	/* { */
+#if defined(LUA_USE_POSIX) && !defined(__ANDROID__)	/* { */
 
 #include <unistd.h>
 
--