Today someone mentioned Lua the scripting language and how it was a nice embed-able language well suited to small embedded systems. I decided to see how well ELLCC could do building Lua for an ARM Linux target. You can build the ELLCC compiler package by following the instructions here.
I downloaded the latest Lua tarball from their download page and was off to the races. I extracted Lua into my ~/ellcc directory:
[~] dev% cd ~/ellcc [~/ellcc] dev% tar xvfpz Downloads/lua-5.2.2.tar.gz
I made a few small changes to their configuration to use ecc for the ARM:
[~] dev% diff -r -c lua-5.2.2 ellcc/lua-5.2.2/ diff -r -c lua-5.2.2/src/luaconf.h ellcc/lua-5.2.2/src/luaconf.h *** lua-5.2.2/src/luaconf.h 2013-03-16 16:10:18.000000000 -0500 --- ellcc/lua-5.2.2/src/luaconf.h 2013-11-08 09:59:56.000000000 -0600 *************** *** 43,49 **** #if defined(LUA_USE_LINUX) #define LUA_USE_POSIX #define LUA_USE_DLOPEN /* needs an extra library: -ldl */ ! #define LUA_USE_READLINE /* needs some extra libraries */ #define LUA_USE_STRTODHEX /* assume 'strtod' handles hex formats */ #define LUA_USE_AFORMAT /* assume 'printf' handles 'aA' specifiers */ #define LUA_USE_LONGLONG /* assume support for long long */ --- 43,49 ---- #if defined(LUA_USE_LINUX) #define LUA_USE_POSIX #define LUA_USE_DLOPEN /* needs an extra library: -ldl */ ! // #define LUA_USE_READLINE /* needs some extra libraries */ #define LUA_USE_STRTODHEX /* assume 'strtod' handles hex formats */ #define LUA_USE_AFORMAT /* assume 'printf' handles 'aA' specifiers */ #define LUA_USE_LONGLONG /* assume support for long long */ diff -r -c lua-5.2.2/src/Makefile ellcc/lua-5.2.2/src/Makefile *** lua-5.2.2/src/Makefile 2012-12-27 04:51:43.000000000 -0600 --- ellcc/lua-5.2.2/src/Makefile 2013-11-08 21:34:36.494043682 -0600 *************** *** 6,14 **** # Your platform. See PLATS for possible values. PLAT= none ! CC= gcc CFLAGS= -O2 -Wall -DLUA_COMPAT_ALL $(SYSCFLAGS) $(MYCFLAGS) LDFLAGS= $(SYSLDFLAGS) $(MYLDFLAGS) LIBS= -lm $(SYSLIBS) $(MYLIBS) AR= ar rcu --- 6,16 ---- # Your platform. See PLATS for possible values. PLAT= none ! CC= /home/rich/ellcc/bin/ecc CFLAGS= -O2 -Wall -DLUA_COMPAT_ALL $(SYSCFLAGS) $(MYCFLAGS) + CFLAGS+= -target arm-ellcc-linux-eabi -mcpu=armv6z -mfpu=vfp -mfloat-abi=softfp LDFLAGS= $(SYSLDFLAGS) $(MYLDFLAGS) + LDFLAGS+= -target arm-ellcc-linux-eabi LIBS= -lm $(SYSLIBS) $(MYLIBS) AR= ar rcu *************** *** 103,109 **** generic: $(ALL) linux: ! $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_LINUX" SYSLIBS="-Wl,-E -ldl -lreadline" macosx: $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_MACOSX" SYSLIBS="-lreadline" --- 105,111 ---- generic: $(ALL) linux: ! $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_LINUX" SYSLIBS="-Wl,-E -ldl" macosx: $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_MACOSX" SYSLIBS="-lreadline" [~] dev%
Then I just typed:
[~/ellcc] dev% cd lua-5.2.2/ [~/ellcc/lua-5.2.2] dev% make linux
I now have my ARM lua exectiable:
[~/ellcc/lua-5.2.2] dev% file src/lua src/lua: ELF 32-bit LSB executable, ARM, version 1, statically linked, BuildID[sha1]=0x635737dc31e9d493f06b8f9fa5d2e7e3c1fe93ee, not stripped [~/ellcc/lua-5.2.2] dev%
Which I can run with QEMU (I use an x86_64 Linux box and don’t have ARM hardware handy):
[~/ellcc/lua-5.2.2] dev% ~/ellcc/bin/qemu-arm src/lua Lua 5.2.2 Copyright (C) 1994-2013 Lua.org, PUC-Rio >
I then went to Lua’s live demo page and cut and pasted an example program:
> -- hello.lua -- the first program in every language io.write("Hello world, from ",_VERSION,"!\n")> > > Hello world, from Lua 5.2! >
Nice!
diff -u ftw