The approach

Jnlua needs to be compiled using liblua, but I encountered some problems during the process. If you compile Jnlua using provided Makefile, the resulting library will depend on the liblua.dylib from your system. To avoid this, I tried compile needed libraries as static ones, but then, their format is not recognized at JNI loading.

So the final trick is to compile both libraries dynamicly with all Lua .o, then as all required symbols are contained in .o files, no external library will be called.

Prerequisites

You need three things

  1. Up to date Xcode ( yes the one from http://developer.apple.com )
  2. Lua source archive
  3. Jnlua source archive

I extracted both archive in /tmp

Compilation

Compiling Lua

$ cd /tmp/lua-5.1.4/
$ make macosx
cd src && make macosx
make all MYCFLAGS=-DLUA_USE_LINUX MYLIBS="-lreadline"
gcc -O2 -Wall -DLUA_USE_LINUX   -c -o lapi.o lapi.c
gcc -O2 -Wall -DLUA_USE_LINUX   -c -o lcode.o lcode.c
gcc -O2 -Wall -DLUA_USE_LINUX   -c -o ldebug.o ldebug.c
gcc -O2 -Wall -DLUA_USE_LINUX   -c -o ldo.o ldo.c
gcc -O2 -Wall -DLUA_USE_LINUX   -c -o ldump.o ldump.c
gcc -O2 -Wall -DLUA_USE_LINUX   -c -o lfunc.o lfunc.c
gcc -O2 -Wall -DLUA_USE_LINUX   -c -o lgc.o lgc.c
gcc -O2 -Wall -DLUA_USE_LINUX   -c -o llex.o llex.c
gcc -O2 -Wall -DLUA_USE_LINUX   -c -o lmem.o lmem.c
gcc -O2 -Wall -DLUA_USE_LINUX   -c -o lobject.o lobject.c
gcc -O2 -Wall -DLUA_USE_LINUX   -c -o lopcodes.o lopcodes.c
gcc -O2 -Wall -DLUA_USE_LINUX   -c -o lparser.o lparser.c
gcc -O2 -Wall -DLUA_USE_LINUX   -c -o lstate.o lstate.c
gcc -O2 -Wall -DLUA_USE_LINUX   -c -o lstring.o lstring.c
gcc -O2 -Wall -DLUA_USE_LINUX   -c -o ltable.o ltable.c
gcc -O2 -Wall -DLUA_USE_LINUX   -c -o ltm.o ltm.c
gcc -O2 -Wall -DLUA_USE_LINUX   -c -o lundump.o lundump.c
gcc -O2 -Wall -DLUA_USE_LINUX   -c -o lvm.o lvm.c
gcc -O2 -Wall -DLUA_USE_LINUX   -c -o lzio.o lzio.c
gcc -O2 -Wall -DLUA_USE_LINUX   -c -o lauxlib.o lauxlib.c
gcc -O2 -Wall -DLUA_USE_LINUX   -c -o lbaselib.o lbaselib.c
gcc -O2 -Wall -DLUA_USE_LINUX   -c -o ldblib.o ldblib.c
gcc -O2 -Wall -DLUA_USE_LINUX   -c -o liolib.o liolib.c
gcc -O2 -Wall -DLUA_USE_LINUX   -c -o lmathlib.o lmathlib.c
gcc -O2 -Wall -DLUA_USE_LINUX   -c -o loslib.o loslib.c
gcc -O2 -Wall -DLUA_USE_LINUX   -c -o ltablib.o ltablib.c
gcc -O2 -Wall -DLUA_USE_LINUX   -c -o lstrlib.o lstrlib.c
gcc -O2 -Wall -DLUA_USE_LINUX   -c -o loadlib.o loadlib.c
gcc -O2 -Wall -DLUA_USE_LINUX   -c -o linit.o linit.c
ar rcu liblua.a lapi.o lcode.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o lmem.o lobject.o lopcodes.o lparser.o lstate.o lstring.o ltable.o ltm.o lundump.o lvm.o lzio.o lauxlib.o lbaselib.o ldblib.o liolib.o lmathlib.o loslib.o ltablib.o lstrlib.o loadlib.o linit.o
ranlib liblua.a
gcc -O2 -Wall -DLUA_USE_LINUX   -c -o lua.o lua.c
gcc -o lua  lua.o liblua.a -lm -lreadline
gcc -O2 -Wall -DLUA_USE_LINUX   -c -o luac.o luac.c
gcc -O2 -Wall -DLUA_USE_LINUX   -c -o print.o print.c
gcc -o luac  luac.o print.o liblua.a -lm -lreadline

Now all needed .o from Lua are available.

Compiling Lua library

Let's compile our own Lua library with all .o, you must not include lua.o and luac.o.

$ cd src
$ libtool -v -dynamic  -o liblua5.1.jnilib -lc lapi.o lauxlib.o lbaselib.o lcode.o ldblib.o ldebug.o ldo.o ldump.o lfunc.o lgc.o linit.o liolib.o llex.o lmathlib.o lmem.o loadlib.o lobject.o lopcodes.o loslib.o lparser.o lstate.o lstring.o lstrlib.o ltable.o ltablib.o ltm.o lundump.o lvm.o lzio.o print.o
+ /usr/bin/ld -arch_multiple -arch x86_64 -dylib -dynamic -all_load -force_cpusubtype_ALL -no_arch_warnings -ldylib1.o -lc lapi.o lauxlib.o lbaselib.o lcode.o ldblib.o ldebug.o ldo.o ldump.o lfunc.o lgc.o linit.o liolib.o llex.o lmathlib.o lmem.o loadlib.o lobject.o lopcodes.o loslib.o lparser.o lstate.o lstring.o lstrlib.o ltable.o ltablib.o ltm.o lundump.o lvm.o lzio.o print.o -o liblua5.1.jnilib
$ ls *lib
liblua5.1.jnilib

Compiling jnlua

I edited the Makefile available at src/main/c/MacOSX.
I added a variable name LUA_FILES it is all .o available from /tmp/lua-5.1.4/src, except lua.o and luac.o. Now it look like this


# Paths
JDK_DIR=/Developer//SDKs/MacOSX10.6.sdk/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0
LUA_LIB_DIR=/tmp/lua-5.1.4/src/
LUA_INC_DIR=/tmp/lua-5.1.4/src/
VERSION=5.1
LUA_FILES=/tmp/lua-5.1.4/src//lapi.o /tmp/lua-5.1.4/src//lauxlib.o /tmp/lua-5.1.4/src//lbaselib.o /tmp/lua-5.1.4/src//lcode.o /tmp/lua-5.1.4/src//ldblib.o /tmp/lua-5.1.4/src//ldebug.o /tmp/lua-5.1.4/src//ldo.o /tmp/lua-5.1.4/src//ldump.o /tmp/lua-5.1.4/src//lfunc.o /tmp/lua-5.1.4/src//lgc.o /tmp/lua-5.1.4/src//linit.o /tmp/lua-5.1.4/src//liolib.o /tmp/lua-5.1.4/src//llex.o /tmp/lua-5.1.4/src//lmathlib.o /tmp/lua-5.1.4/src//lmem.o /tmp/lua-5.1.4/src//loadlib.o /tmp/lua-5.1.4/src//lobject.o /tmp/lua-5.1.4/src//lopcodes.o /tmp/lua-5.1.4/src//loslib.o /tmp/lua-5.1.4/src//lparser.o /tmp/lua-5.1.4/src//lstate.o /tmp/lua-5.1.4/src//lstring.o /tmp/lua-5.1.4/src//lstrlib.o /tmp/lua-5.1.4/src//ltable.o /tmp/lua-5.1.4/src//ltablib.o /tmp/lua-5.1.4/src//ltm.o /tmp/lua-5.1.4/src//lundump.o /tmp/lua-5.1.4/src//lvm.o /tmp/lua-5.1.4/src//lzio.o /tmp/lua-5.1.4/src//print.o

# Tools
CC=gcc
LD=gcc

# Default arguments
CFLAGS=-c -fno-strict-aliasing -m64 -fPIC -O2 -Wall -DNDEBUG -D_REENTRANT -DLUA_USE_LINUX
LDFLAGS=-dynamiclib -m64

# Description blocks
all: libjnlua$(VERSION).jnilib

libjnlua$(VERSION).jnilib: jnlua.o
    $(LD) $(LDFLAGS) -o libjnlua$(VERSION).jnilib -L$(LUA_LIB_DIR) -lc  jnlua.o $(LUA_FILES)

jnlua.o: ../jnlua.c
    $(CC) $(CFLAGS) -I$(JDK_DIR)/Headers -I$(LUA_INC_DIR) ../jnlua.c

clean:
    -rm libjnlua$(VERSION).jnilib jnlua.o

Run make and you will have the library you searching for


$ make
gcc -c -fno-strict-aliasing -m64 -fPIC -O2 -Wall -DNDEBUG -D_REENTRANT -DLUA_USE_LINUX -I/Developer//SDKs/MacOSX10.6.sdk/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Headers -I/tmp/lua-5.1.4/src/ ../jnlua.c
gcc -dynamiclib -m64 -o libjnlua5.1.jnilib -L/tmp/lua-5.1.4/src/ -lc  jnlua.o /tmp/lua-5.1.4/src//lapi.o /tmp/lua-5.1.4/src//lauxlib.o /tmp/lua-5.1.4/src//lbaselib.o /tmp/lua-5.1.4/src//lcode.o /tmp/lua-5.1.4/src//ldblib.o /tmp/lua-5.1.4/src//ldebug.o /tmp/lua-5.1.4/src//ldo.o /tmp/lua-5.1.4/src//ldump.o /tmp/lua-5.1.4/src//lfunc.o /tmp/lua-5.1.4/src//lgc.o /tmp/lua-5.1.4/src//linit.o /tmp/lua-5.1.4/src//liolib.o /tmp/lua-5.1.4/src//llex.o /tmp/lua-5.1.4/src//lmathlib.o /tmp/lua-5.1.4/src//lmem.o /tmp/lua-5.1.4/src//loadlib.o /tmp/lua-5.1.4/src//lobject.o /tmp/lua-5.1.4/src//lopcodes.o /tmp/lua-5.1.4/src//loslib.o /tmp/lua-5.1.4/src//lparser.o /tmp/lua-5.1.4/src//lstate.o /tmp/lua-5.1.4/src//lstring.o /tmp/lua-5.1.4/src//lstrlib.o /tmp/lua-5.1.4/src//ltable.o /tmp/lua-5.1.4/src//ltablib.o /tmp/lua-5.1.4/src//ltm.o /tmp/lua-5.1.4/src//lundump.o /tmp/lua-5.1.4/src//lvm.o /tmp/lua-5.1.4/src//lzio.o /tmp/lua-5.1.4/src//print.o
$ ls
Makefile        jnlua.o         libjnlua5.1.jnilib

Final

You can now copy libjnlua5.1.jnilib and liblua5.1.jnilib in your plugin, load them in MANIFEST.MF using Bundle-NativeCode.

source : http://developer.apple.com/library/mac/#documentation/java/conceptual/java14development/05-corejavaapis/corejavaapis.html

Ressources

See a JNLua bug about compilation for MacOSX: http://code.google.com/p/jnlua/issues/detail?id=6