Skip to content

Instantly share code, notes, and snippets.

@jnwhiteh
Created August 4, 2011 14:49
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jnwhiteh/1125331 to your computer and use it in GitHub Desktop.
Save jnwhiteh/1125331 to your computer and use it in GitHub Desktop.
Install luajit+luarocks in sandboxed environment
#!/usr/bin/env bash
set -e
die() {
echo "$1";
exit 1;
}
# Fetch and install LuaJIT/LuaRocks into the local directory
ROOT=`pwd`
SANDBOX="${ROOT}/sandbox"
TMP_DIR="${ROOT}/sandbox/src"
if [ ! -d "${TMP_DIR}" ]; then mkdir -p "${TMP_DIR}"; fi
pushd "${TMP_DIR}"
rm -fr "luajit-2.0"
git clone http://luajit.org/git/luajit-2.0.git
pushd luajit-2.0
# Fix for an issue compiling LuaJIT with llvm
LLVM_FIX=''
case `uname` in
'Darwin')
case `gcc --version` in
*llvm*)
LLVM_FIX='TARGET_CC="gcc-4.2"'
;;
esac
;;
esac
# Patch the LuaJIT install to allow LUA_ROOT to be overridden by variable
git apply << ENDPATCH
diff --git a/Makefile b/Makefile
index c8d3429..5e4f855 100644
--- a/Makefile
+++ b/Makefile
@@ -26,7 +26,7 @@ NODOTABIVER= 51
# Change the installation path as needed. This automatically adjusts
# the paths in src/luaconf.h, too. Note: PREFIX must be an absolute path!
#
-export PREFIX= /usr/local
+export PREFIX= ${SANDBOX}
##############################################################################
DPREFIX= \$(DESTDIR)\$(PREFIX)
diff --git a/src/luaconf.h b/src/luaconf.h
index 4a243ff..40fa9c6 100644
--- a/src/luaconf.h
+++ b/src/luaconf.h
@@ -22,7 +22,7 @@
#define LUA_CPATH_DEFAULT \\
".\\\\?.dll;" LUA_CDIR"?.dll;" LUA_CDIR"loadall.dll"
#else
-#define LUA_ROOT "/usr/local/"
+#define LUA_ROOT "${SANDBOX}"
#define LUA_LDIR LUA_ROOT "share/lua/5.1/"
#define LUA_CDIR LUA_ROOT "lib/lua/5.1/"
#ifdef LUA_XROOT
ENDPATCH
# Compile and install Lua
echo $LLVM_FIX
make ${LLVM_FIX} clean install
ln -sf ${SANDBOX}/bin/luajit-2.0.0-beta8 ${SANDBOX}/bin/luajit
# Download and install Luarocks
popd
rm -fr "luarocks-2.0.2.tar.gz"
wget http://luarocks.org/releases/luarocks-2.0.2.tar.gz;
if [ -d "luarocks-2.0.2" ]; then rm -fr luarocks-2.0.2; fi
tar -zxf "luarocks-2.0.2.tar.gz"
pushd luarocks-2.0.2
./configure --with-lua="${SANDBOX}" --prefix="${SANDBOX}" --lua-suffix="jit" --with-lua-include="${SANDBOX}/include/luajit-2.0" --force-config
make && make install && make clean
popd # Back to tmp
popd # Back to the original directory
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment