|
#!/bin/sh |
|
|
|
:<<'########################################################################' |
|
|
|
Usage: build-haserl-luajit.sh /path/to/LuaJIT/Distribution/Directory/ |
|
|
|
This script modifies the Haserl 0.9.29 distribution so Haserl is built |
|
with an embedded copy of LuaJIT. |
|
|
|
------------------------------------------------------------------------ |
|
|
|
Change-log: |
|
2012-12-07 First version. |
|
|
|
------------------------------------------------------------------------ |
|
|
|
This script was written in 2012 by third07 at gmail dot com. |
|
|
|
To the extent possible under law, the author(s) have dedicated all |
|
copyright and related and neighboring rights to this software to the |
|
public domain worldwide. This software is distributed without any |
|
warranty. |
|
|
|
See http://creativecommons.org/publicdomain/zero/1.0/ for a copy of |
|
the CC0 Public Domain Dedication under which this work is distributed. |
|
|
|
######################################################################## |
|
|
|
# Print an error message and exit. |
|
function die () { printf "=== $@ ===\n" ; exit 1 ; } |
|
|
|
# Ensure that this script is executing in the top-level Haserl directory. |
|
if [ ! -r src/haserl_lualib.lua ] ; then |
|
die 'Execute this script in the top-level Haserl directory.' |
|
fi |
|
|
|
# Ensure that this is the Haserl 0.9.29 release. |
|
! grep -qv 0.9.29 configure.ac && |
|
die 'This script only works with Haserl 0.9.29.' |
|
|
|
# Determine the directory of the Lua distribution. |
|
LUADIR="$1" |
|
[ -z "$LUADIR" ] && |
|
die 'Specify the LuaJIT distribution directory on the command line.' |
|
[ ! -d "$LUADIR" ] && die "$LUADIR is not a directory." |
|
LUADIR=$(cd "$LUADIR" ; pwd) |
|
|
|
# Determine which Lua interpreter is in LUADIR. |
|
if [ -x $LUADIR/src/lua ] ; then |
|
LUAPROG='lua' |
|
elif [ -x $LUADIR/src/luajit ]; then |
|
LUAPROG='luajit' |
|
else |
|
die "There is not a Lua interpreter in $LUADIR/src." |
|
fi |
|
|
|
# Verify the existence of the other Lua files that will be used. |
|
for FILE in lua.h lauxlib.h lualib.h "lib$LUAPROG.a" ; do |
|
[ ! -f "$LUADIR/src/$FILE" ] && |
|
die "The file $LUADIR/src/$FILE does not exit." |
|
done |
|
|
|
# Check for Lua 5.2. |
|
[ "$($LUADIR/src/$LUAPROG -e 'io.write(_VERSION)')" = 'Lua 5.2' ] && |
|
die 'This script does not work with Lua 5.2.' |
|
|
|
# Patch configure.ac. |
|
[ ! -r configure.ac.orig ] && cp -a configure.ac configure.ac.orig |
|
cp -a configure.ac.orig configure.ac |
|
cat <<'EOF' | patch |
|
--- configure.ac.orig 2011-05-10 11:31:21.000000000 -0500 |
|
+++ configure.ac 2012-12-05 16:01:00.000000000 -0600 |
|
@@ -61,22 +61,17 @@ |
|
no) ac_report_have_lua=disabled |
|
;; |
|
*) AC_SEARCH_LIBS(dlopen, dl) |
|
- # ubuntu has lua5.1 rather than just lua |
|
- if pkg-config --exists lua5.1; then |
|
- LUALIB=lua5.1 |
|
- else |
|
- LUALIB=lua |
|
- fi |
|
- if test -z "$LUA_HDR_DIR"; then |
|
- CFLAGS="$CFLAGS `pkg-config $LUALIB --cflags`" |
|
- fi |
|
- LIBS="$LIBS -lm" |
|
+ LUALIB=$(cd $withval; ls liblua* | grep -Eo "luajit|lua" | head -n 1) |
|
+ LIBS="$LIBS -lm" |
|
LDFLAGS="$LDFLAGS -Wl,-E -L$withval" |
|
AC_DEFINE(USE_LUA, , [Enable Lua]) |
|
|
|
- AC_CHECK_LIB($LUALIB, luaL_newstate, , [ |
|
- AC_MSG_ERROR([The Lua runtime library cannot be found!]) |
|
- ], $LIBS) |
|
+ AC_CHECK_LIB($LUALIB, |
|
+ luaL_newstate, |
|
+ [ LIBS="-Wl,-Bstatic -l$LUALIB -Wl,-Bdynamic $LIBS" ], |
|
+ [ AC_MSG_ERROR([The Lua runtime library cannot be found!]) ], |
|
+ $LIBS) |
|
+ |
|
luashell=true |
|
luacshell=true |
|
ac_report_have_lua=enabled |
|
EOF |
|
|
|
# Configure Haserl to include LuaJIT (or Lua). |
|
autoreconf |
|
./configure \ |
|
--with-lua="$LUADIR/src" \ |
|
--with-lua-headers="$LUADIR/src" |
|
|
|
# Create a test script |
|
cat >test.cgi <<EOF |
|
#!$(pwd)/src/haserl --shell=lua |
|
<% io.write('Content-Type: text/html\r\n\r\n') -- Mandatory text %> |
|
<html> |
|
<head> <title>Haserl+LuaJIT Test Script</title> </head> |
|
<body> |
|
<h2><% io.write(os.date()) %></h2> |
|
<h2><% io.write('This version of Haserl includes ') |
|
io.write(jit == nil and _VERSION or jit.version) %></h2> |
|
</body> |
|
</html> |
|
EOF |
|
chmod +x test.cgi |
|
|
|
# Build Haserl. |
|
make clean ; make |
|
|
|
|
|
# Test Haserl. |
|
./test.cgi |