I just compiled LuaJIT with devkitARM, a toolchain for making homebrew Nintendo DS ROMs. The steps are:
The following notes are really hacky; follow them at your own risk.
Install the devkitARM toolchain from the devkitPro website.
Grab it from LuaJIT's downloads page. I cloned the git repo, but the tarballs should work too.
There are two changes to be made.
First, change BUILDMODE from mixed to static. This creates just a static library, since the DS doesn't have dynamic linking.
Then uncomment XCFLAGS+= -DLUAJIT_USE_SYSMALLOC. If you don't change this, the build will fail at lj_alloc.c when trying to include sys/mman.h, which devkitARM doesn't have for whatever reason.
If you set up devkitARM correctly, you'll have DEVKITPRO and DEVKITARM defined, so the following command will build the static library:
make HOST_CC="gcc" \
CC="arm-eabi-gcc" \
AR="arm-eabi-ar" \
AS="arm-eabi-as" \
LD="arm-eabi-gcc" \
PATH="$DEVKITARM/bin:$DEVKITPRO/portlibs/arm/bin:$PATH" \
TARGET_CFLAGS="-g -Wall -O2 -march=armv5te -mtune=arm946e-s \
-fomit-frame-pointer -ffast-math -mthumb -mthumb-interwork \
-I$DEVKITPRO/libnds/include -DARM9" \
TARGET=arm
This will end with an error about not finding libdl, but it creates src/libluajit.a which is what we want.
cp src/lua.h src/lauxlib.h src/lualib.h src/luaconf.h \
$DEVKITPRO/libnds/include/
cp src/libluajit.a $DEVKITPRO/libnds/lib/
The LuaJIT API is binary-compatible with stock Lua, so Part IV of Programming in Lua covers that.
To compile with LuaJIT, include -lluajit and -lm in the LIBS line of the stock libnds makefile.