Skip to content

Instantly share code, notes, and snippets.

@kergoth
Forked from rjpcomputing/install.sh
Last active December 3, 2020 18:25
Show Gist options
  • Save kergoth/048450249e3ea288a85d to your computer and use it in GitHub Desktop.
Save kergoth/048450249e3ea288a85d to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -e
die() {
echo "$1";
exit 1;
}
# Fetch and install Lua/LuaRocks/Kepler into the local directory
luarocks_version=2.2.2
lua_version=5.1.4
ROOT=`pwd`
SANDBOX="${1:-${ROOT}/sandbox}"
TMP_DIR="${SANDBOX}/src"
if [ ! -d "${TMP_DIR}" ]; then mkdir -p "${TMP_DIR}"; fi
pushd "${TMP_DIR}"
PREFIX="${ROOT}"
rm -fr "lua-$lua_version"
wget http://www.lua.org/ftp/lua-$lua_version.tar.gz;
tar -zxf "lua-$lua_version.tar.gz"
pushd lua-$lua_version
# Patch the LUA install to allow LUA_ROOT to be overridden by variable
patch -p0 << ENDPATCH
diff -Naur src_orig/luaconf.h src/luaconf.h
--- src_orig/luaconf.h 2008-02-11 11:25:08.000000000 -0500
+++ src/luaconf.h 2011-06-21 11:48:41.000000000 -0400
@@ -88,17 +88,26 @@
#define LUA_LDIR "!\\\\lua\\\\"
#define LUA_CDIR "!\\\\"
#define LUA_PATH_DEFAULT \\
- ".\\\\?.lua;" LUA_LDIR"?.lua;" LUA_LDIR"?\\\\init.lua;" \\
+ ".\\\\?.lua;" ".\\\\?\\\\init.lua;" LUA_LDIR"?.lua;" LUA_LDIR"?\\\\init.lua;" \\
LUA_CDIR"?.lua;" LUA_CDIR"?\\\\init.lua"
#define LUA_CPATH_DEFAULT \\
".\\\\?.dll;" LUA_CDIR"?.dll;" LUA_CDIR"loadall.dll"
#else
+#ifndef LUA_ROOT
#define LUA_ROOT "/usr/local/"
+#endif
+
+#ifndef LUA_LDIR
#define LUA_LDIR LUA_ROOT "share/lua/5.1/"
+#endif
+
+#ifndef LUA_CDIR
#define LUA_CDIR LUA_ROOT "lib/lua/5.1/"
+#endif
+
#define LUA_PATH_DEFAULT \\
- "./?.lua;" LUA_LDIR"?.lua;" LUA_LDIR"?/init.lua;" \\
+ "./?.lua;" "./?/init.lua;" LUA_LDIR"?.lua;" LUA_LDIR"?/init.lua;" \\
LUA_CDIR"?.lua;" LUA_CDIR"?/init.lua"
#define LUA_CPATH_DEFAULT \\
"./?.so;" LUA_CDIR"?.so;" LUA_CDIR"loadall.so"
ENDPATCH
patch -p0 << ENDPATCH
diff -Naur src.orig/Makefile src/Makefile
--- src.orig/Makefile 2008-03-23 12:28:40.000000000 +0000
+++ src/Makefile 2008-03-23 12:29:07.000000000 +0000
@@ -8,7 +8,7 @@
PLAT= none
CC= gcc
-CFLAGS= -O2 -Wall \$(MYCFLAGS)
+CFLAGS= -O2 -DLUA_ROOT=\"${SANDBOX}/\" -Wall \$(MYCFLAGS)
AR= ar rcu
RANLIB= ranlib
RM= rm -f
ENDPATCH
# Compile and install Lua
case `uname` in
'Linux')
LUA_TARGET="linux"
;;
'Darwin')
LUA_TARGET="macosx"
;;
esac
make ${LUA_TARGET} INSTALL_TOP="${SANDBOX}"
make install INSTALL_TOP="${SANDBOX}"
make clean
# Download and install Luarocks
popd
wget http://luarocks.org/releases/luarocks-$luarocks_version.tar.gz;
if [ -d "luarocks-$luarocks_version" ]; then rm -fr luarocks-$luarocks_version; fi
tar -zxf "luarocks-$luarocks_version.tar.gz"
pushd luarocks-$luarocks_version
./configure --with-lua="${SANDBOX}" --prefix="${SANDBOX}" --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