From b612039cf843b06028badae4b4a914a758326894 Mon Sep 17 00:00:00 2001 From: Daniel Sawka Date: Fri, 5 Jul 2024 15:05:01 +0200 Subject: [PATCH] lua: Make building more generic (build for any arch) Default version changed from 5.3.5 to 5.3.6. luaconf_local.h is required to be present in project's directory and can be used to override configuration values in e.g. luaconf.h Added port build options: - PORTS_LUA_CONFIG_DIR - path to a directory where luaconf_local.h is located. If not provided, the port's directory is used; - PORTS_LUA_VERSION - version to download (must be supported by respective patches); - PORTS_LUA_TESTS_VERSION - version of tests to download; - PORTS_LUA_BIN_CSTACK_SIZE - convenience option to set `-z stack-size` for lua binary built in this port; - PORTS_LUA_INSTALL_TESTS - download and install external Lua test scripts; - PORTS_LUA_SAFE - disable Lua features which may be used to crash the interpreter or perform side-effects in the operating system. JIRA: NIL-595 --- lua/Makefile | 194 ------------------- lua/build.sh | 66 +++++-- lua/checksums/lua-5.3.4-tests.tar.gz.sha256 | 1 + lua/checksums/lua-5.3.6.tar.gz.sha256 | 1 + lua/luaconf_local.h | 22 +++ lua/patches/5.3.6/01-Makefile.patch | 68 +++++++ lua/patches/5.3.6/02-src-Makefile.patch | 48 +++++ lua/patches/5.3.6/03-luaconf.h.patch | 95 +++++++++ lua/patches/5.3.6/safe/01-src-loslib.c.patch | 90 +++++++++ lua/patches/5.3.6/safe/02-src-linit.c.patch | 17 ++ 10 files changed, 389 insertions(+), 213 deletions(-) delete mode 100644 lua/Makefile create mode 100644 lua/checksums/lua-5.3.4-tests.tar.gz.sha256 create mode 100644 lua/checksums/lua-5.3.6.tar.gz.sha256 create mode 100644 lua/luaconf_local.h create mode 100644 lua/patches/5.3.6/01-Makefile.patch create mode 100644 lua/patches/5.3.6/02-src-Makefile.patch create mode 100644 lua/patches/5.3.6/03-luaconf.h.patch create mode 100644 lua/patches/5.3.6/safe/01-src-loslib.c.patch create mode 100644 lua/patches/5.3.6/safe/02-src-linit.c.patch diff --git a/lua/Makefile b/lua/Makefile deleted file mode 100644 index 54e71750..00000000 --- a/lua/Makefile +++ /dev/null @@ -1,194 +0,0 @@ -# Makefile for building Lua -# See ../doc/readme.html for installation and customization instructions. - -# == CHANGE THE SETTINGS BELOW TO SUIT YOUR ENVIRONMENT ======================= - -SIL ?= @ -MAKEFLAGS += --no-print-directory - -### Compliation options for ARMv7a architecture ### -CROSS ?= arm-phoenix- -CC = $(CROSS)gcc - -CFLAGS += -DLUA_USE_POSIX - -AR = $(CROSS)ar -ARFLAGS = -r - -RANLIB = $(CROSS)ranlib - -LD = $(CROSS)ld -LDFLAGS += $(CFLAGS) -Wl,-z,max-page-size=0x1000 -LDFLAGS += -Wl,--gc-sections - -# == END OF USER SETTINGS -- NO NEED TO CHANGE ANYTHING BELOW THIS LINE ======= - -PLATS= aix bsd c89 freebsd generic linux macosx mingw posix solaris - -LUA_A= liblua.a -CORE_O= lapi.o lcode.o lctype.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 -LIB_O= lauxlib.o lbaselib.o lbitlib.o lcorolib.o ldblib.o liolib.o \ - lmathlib.o loslib.o lstrlib.o ltablib.o lutf8lib.o loadlib.o linit.o -BASE_O= $(CORE_O) $(LIB_O) $(MYOBJS) - -LUA_T= lua -LUA_O= lua.o - -LUAC_T= luac -LUAC_O= luac.o - -ALL_O= $(BASE_O) $(LUA_O) $(LUAC_O) -ALL_T= $(LUA_A) $(LUA_T) $(LUAC_T) -ALL_A= $(LUA_A) - -# Targets start here. -default: $(PLAT) - -all: $(ALL_T) - -o: $(ALL_O) - -a: $(ALL_A) - -$(LUA_A): $(BASE_O) - $(AR) $(ARFLAGS) $@ $(BASE_O) - $(RANLIB) $@ - -$(LUA_T): $(LUA_O) $(LUA_A) - $(CC) -o $@ $(LDFLAGS) $(LUA_O) $(LUA_A) $(LIBS) - -$(LUAC_T): $(LUAC_O) $(LUA_A) - $(CC) -o $@ $(LDFLAGS) $(LUAC_O) $(LUA_A) $(LIBS) - -clean: - $(RM) $(ALL_T) $(ALL_O) - -depend: - @$(CC) $(CFLAGS) -MM l*.c - -echo: - @echo "PLAT= $(PLAT)" - @echo "CC= $(CC)" - @echo "CFLAGS= $(CFLAGS)" - @echo "LDFLAGS= $(SYSLDFLAGS)" - @echo "LIBS= $(LIBS)" - @echo "AR= $(AR)" - @echo "RANLIB= $(RANLIB)" - @echo "RM= $(RM)" - -# Convenience targets for popular platforms -ALL= all - -none: - @echo "Please do 'make PLATFORM' where PLATFORM is one of these:" - @echo " $(PLATS)" - -aix: - $(MAKE) $(ALL) CC="xlc" CFLAGS="-O2 -DLUA_USE_POSIX -DLUA_USE_DLOPEN" SYSLIBS="-ldl" SYSLDFLAGS="-brtl -bexpall" - -bsd: - $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_POSIX -DLUA_USE_DLOPEN" SYSLIBS="-Wl,-E" - -c89: - $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_C89" CC="gcc -std=c89" - @echo '' - @echo '*** C89 does not guarantee 64-bit integers for Lua.' - @echo '' - - -freebsd: - $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_LINUX -DLUA_USE_READLINE -I/usr/include/edit" SYSLIBS="-Wl,-E -ledit" CC="cc" - -generic: $(ALL) - -linux: - $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_LINUX" SYSLIBS="-Wl,-E -ldl -lreadline" - -macosx: - $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_MACOSX" SYSLIBS="-lreadline" - -mingw: - $(MAKE) "LUA_A=lua53.dll" "LUA_T=lua.exe" \ - "AR=$(CC) -shared -o" "RANLIB=strip --strip-unneeded" \ - "SYSCFLAGS=-DLUA_BUILD_AS_DLL" "SYSLIBS=" "SYSLDFLAGS=-s" lua.exe - $(MAKE) "LUAC_T=luac.exe" luac.exe - -posix: - $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_POSIX" - -solaris: - $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_POSIX -DLUA_USE_DLOPEN -D_REENTRANT" SYSLIBS="-ldl" - -# list targets that do not create files (but not all makes understand .PHONY) -.PHONY: all $(PLATS) default o a clean depend echo none - -# DO NOT DELETE - -lapi.o: lapi.c lprefix.h lua.h luaconf.h lapi.h llimits.h lstate.h \ - lobject.h ltm.h lzio.h lmem.h ldebug.h ldo.h lfunc.h lgc.h lstring.h \ - ltable.h lundump.h lvm.h -lauxlib.o: lauxlib.c lprefix.h lua.h luaconf.h lauxlib.h -lbaselib.o: lbaselib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h -lbitlib.o: lbitlib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h -lcode.o: lcode.c lprefix.h lua.h luaconf.h lcode.h llex.h lobject.h \ - llimits.h lzio.h lmem.h lopcodes.h lparser.h ldebug.h lstate.h ltm.h \ - ldo.h lgc.h lstring.h ltable.h lvm.h -lcorolib.o: lcorolib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h -lctype.o: lctype.c lprefix.h lctype.h lua.h luaconf.h llimits.h -ldblib.o: ldblib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h -ldebug.o: ldebug.c lprefix.h lua.h luaconf.h lapi.h llimits.h lstate.h \ - lobject.h ltm.h lzio.h lmem.h lcode.h llex.h lopcodes.h lparser.h \ - ldebug.h ldo.h lfunc.h lstring.h lgc.h ltable.h lvm.h -ldo.o: ldo.c lprefix.h lua.h luaconf.h lapi.h llimits.h lstate.h \ - lobject.h ltm.h lzio.h lmem.h ldebug.h ldo.h lfunc.h lgc.h lopcodes.h \ - lparser.h lstring.h ltable.h lundump.h lvm.h -ldump.o: ldump.c lprefix.h lua.h luaconf.h lobject.h llimits.h lstate.h \ - ltm.h lzio.h lmem.h lundump.h -lfunc.o: lfunc.c lprefix.h lua.h luaconf.h lfunc.h lobject.h llimits.h \ - lgc.h lstate.h ltm.h lzio.h lmem.h -lgc.o: lgc.c lprefix.h lua.h luaconf.h ldebug.h lstate.h lobject.h \ - llimits.h ltm.h lzio.h lmem.h ldo.h lfunc.h lgc.h lstring.h ltable.h -linit.o: linit.c lprefix.h lua.h luaconf.h lualib.h lauxlib.h -liolib.o: liolib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h -llex.o: llex.c lprefix.h lua.h luaconf.h lctype.h llimits.h ldebug.h \ - lstate.h lobject.h ltm.h lzio.h lmem.h ldo.h lgc.h llex.h lparser.h \ - lstring.h ltable.h -lmathlib.o: lmathlib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h -lmem.o: lmem.c lprefix.h lua.h luaconf.h ldebug.h lstate.h lobject.h \ - llimits.h ltm.h lzio.h lmem.h ldo.h lgc.h -loadlib.o: loadlib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h -lobject.o: lobject.c lprefix.h lua.h luaconf.h lctype.h llimits.h \ - ldebug.h lstate.h lobject.h ltm.h lzio.h lmem.h ldo.h lstring.h lgc.h \ - lvm.h -lopcodes.o: lopcodes.c lprefix.h lopcodes.h llimits.h lua.h luaconf.h -loslib.o: loslib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h -lparser.o: lparser.c lprefix.h lua.h luaconf.h lcode.h llex.h lobject.h \ - llimits.h lzio.h lmem.h lopcodes.h lparser.h ldebug.h lstate.h ltm.h \ - ldo.h lfunc.h lstring.h lgc.h ltable.h -lstate.o: lstate.c lprefix.h lua.h luaconf.h lapi.h llimits.h lstate.h \ - lobject.h ltm.h lzio.h lmem.h ldebug.h ldo.h lfunc.h lgc.h llex.h \ - lstring.h ltable.h -lstring.o: lstring.c lprefix.h lua.h luaconf.h ldebug.h lstate.h \ - lobject.h llimits.h ltm.h lzio.h lmem.h ldo.h lstring.h lgc.h -lstrlib.o: lstrlib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h -ltable.o: ltable.c lprefix.h lua.h luaconf.h ldebug.h lstate.h lobject.h \ - llimits.h ltm.h lzio.h lmem.h ldo.h lgc.h lstring.h ltable.h lvm.h -ltablib.o: ltablib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h -ltm.o: ltm.c lprefix.h lua.h luaconf.h ldebug.h lstate.h lobject.h \ - llimits.h ltm.h lzio.h lmem.h ldo.h lstring.h lgc.h ltable.h lvm.h -lua.o: lua.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h -luac.o: luac.c lprefix.h lua.h luaconf.h lauxlib.h lobject.h llimits.h \ - lstate.h ltm.h lzio.h lmem.h lundump.h ldebug.h lopcodes.h -lundump.o: lundump.c lprefix.h lua.h luaconf.h ldebug.h lstate.h \ - lobject.h llimits.h ltm.h lzio.h lmem.h ldo.h lfunc.h lstring.h lgc.h \ - lundump.h -lutf8lib.o: lutf8lib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h -lvm.o: lvm.c lprefix.h lua.h luaconf.h ldebug.h lstate.h lobject.h \ - llimits.h ltm.h lzio.h lmem.h ldo.h lfunc.h lgc.h lopcodes.h lstring.h \ - ltable.h lvm.h -lzio.o: lzio.c lprefix.h lua.h luaconf.h llimits.h lmem.h lstate.h \ - lobject.h ltm.h lzio.h - -# (end of Makefile) diff --git a/lua/build.sh b/lua/build.sh index f903b8a1..85545837 100755 --- a/lua/build.sh +++ b/lua/build.sh @@ -2,31 +2,59 @@ set -e -LUA=lua-5.3.5 -PKG_URL="https://www.lua.org/ftp/${LUA}.tar.gz" -PKG_MIRROR_URL="https://files.phoesys.com/ports/${LUA}.tar.gz" +version="${PORTS_LUA_VERSION:-5.3.6}" +archive_filename="lua-${version}.tar.gz" +tests_version="${PORTS_LUA_TESTS_VERSION:-5.3.4}" # There is no 5.3.6 tag for tests -PREFIX_LUA_SRC="${PREFIX_PORT_BUILD}/${LUA}" +PREFIX_PORT_SRC="${PREFIX_PORT_BUILD}/${version}" +PREFIX_PORT_TESTS="${PREFIX_PORT_BUILD}/${tests_version}-tests" +: "${PORTS_LUA_CONFIG_DIR:=${PREFIX_PORT}}" +b_port_download "https://www.lua.org/ftp/" "${archive_filename}" -mkdir -p "$PREFIX_PORT_BUILD" -if [ ! -f "$PREFIX_PORT/${LUA}.tar.gz" ]; then - if ! wget "$PKG_URL" -P "${PREFIX_PORT}" --no-check-certificate; then - wget "$PKG_MIRROR_URL" -P "${PREFIX_PORT}" --no-check-certificate - fi +if [ ! -d "${PREFIX_PORT_SRC}" ]; then + echo "Extracting sources from ${archive_filename}" + mkdir -p "${PREFIX_PORT_SRC}" + tar -axf "${PREFIX_PORT}/${archive_filename}" --strip-components 1 -C "${PREFIX_PORT_SRC}" +fi + +b_port_apply_patches "${PREFIX_PORT_SRC}" "${version}" + +if [ "${PORTS_LUA_SAFE}" = "y" ]; then + b_port_apply_patches "${PREFIX_PORT_SRC}" "${version}/safe" fi -if [ ! -d "$PREFIX_LUA_SRC" ]; then - tar zxf "$PREFIX_PORT/${LUA}.tar.gz" -C "$PREFIX_PORT_BUILD" - cp "$PREFIX_PORT/Makefile" "$PREFIX_LUA_SRC/src/" + +# shellcheck disable=SC2206 +mycflags=( + ${CFLAGS} # Split intended + "-I${PORTS_LUA_CONFIG_DIR}" +) + +if [ -n "${PORTS_LUA_BIN_CSTACK_SIZE}" ]; then + LDFLAGS+=" -Wl,-z,stack-size=${PORTS_LUA_BIN_CSTACK_SIZE}" fi # FIXME: no out-of-tree building -make -C "$PREFIX_LUA_SRC" posix +make -C "${PREFIX_PORT_SRC}/src" MYCFLAGS="${mycflags[*]}" MYLDFLAGS="${LDFLAGS}" +make -C "${PREFIX_PORT_SRC}" install INSTALL_TOP="${PREFIX_BUILD}" -$STRIP -o "$PREFIX_PROG_STRIPPED/lua" "$PREFIX_LUA_SRC/src/lua" -$STRIP -o "$PREFIX_PROG_STRIPPED/luac" "$PREFIX_LUA_SRC/src/luac" -cp -a "$PREFIX_LUA_SRC/src/lua" "$PREFIX_PROG/lua" -cp -a "$PREFIX_LUA_SRC/src/luac" "$PREFIX_PROG/luac" +cp -a "${PORTS_LUA_CONFIG_DIR}/luaconf_local.h" "${PREFIX_H}/" -b_install "$PREFIX_PORTS_INSTALL/lua" /bin -b_install "$PREFIX_PORTS_INSTALL/luac" /bin +$STRIP -o "${PREFIX_PROG_STRIPPED}/lua" "${PREFIX_PROG}/lua" +$STRIP -o "${PREFIX_PROG_STRIPPED}/luac" "${PREFIX_PROG}/luac" + +b_install "${PREFIX_PORTS_INSTALL}/lua" /usr/bin +b_install "${PREFIX_PORTS_INSTALL}/luac" /usr/bin + +if [ "${PORTS_LUA_INSTALL_TESTS}" = "y" ]; then + tests_filename="lua-${tests_version}-tests.tar.gz" + b_port_download "https://www.lua.org/tests/" "${tests_filename}" + + if [ ! -d "${PREFIX_PORT_TESTS}" ]; then + echo "Extracting tests from ${tests_filename}" + mkdir -p "${PREFIX_PORT_TESTS}" + tar -axf "${PREFIX_PORT}/${tests_filename}" --strip-components 1 -C "${PREFIX_PORT_TESTS}" + fi + + b_install "${PREFIX_PORT_TESTS}"/*.lua /usr/share/lua/tests +fi diff --git a/lua/checksums/lua-5.3.4-tests.tar.gz.sha256 b/lua/checksums/lua-5.3.4-tests.tar.gz.sha256 new file mode 100644 index 00000000..4abc6ee0 --- /dev/null +++ b/lua/checksums/lua-5.3.4-tests.tar.gz.sha256 @@ -0,0 +1 @@ +b80771238271c72565e5a1183292ef31bd7166414cd0d43a8eb79845fa7f599f \ No newline at end of file diff --git a/lua/checksums/lua-5.3.6.tar.gz.sha256 b/lua/checksums/lua-5.3.6.tar.gz.sha256 new file mode 100644 index 00000000..53545eaa --- /dev/null +++ b/lua/checksums/lua-5.3.6.tar.gz.sha256 @@ -0,0 +1 @@ +fc5fd69bb8736323f026672b1b7235da613d7177e72558893a0bdcd320466d60 \ No newline at end of file diff --git a/lua/luaconf_local.h b/lua/luaconf_local.h new file mode 100644 index 00000000..4f1387ad --- /dev/null +++ b/lua/luaconf_local.h @@ -0,0 +1,22 @@ +/* Examples of configuration options which may be set to override defaults +used in luaconf.h. Some of these are not specified in luaconf.h, but in +source files and can be overridden too (as long as they are ifdef'ed). */ + +/* +#define LUA_COMPAT_5_2 +#define LUA_COMPAT_5_1 + +#define LUAI_MAXSTACK 4000 +#define LUA_MAXCAPTURES 32 +#define MAXCCALLS 5 + +#define LUA_32BITS +#define LUA_FLOAT_TYPE LUA_FLOAT_DOUBLE +#define LUA_INT_TYPE LUA_INT_INT +#define LUAL_BUFFERSIZE 512 +#define LUA_IDSIZE 30 + +#define LUA_USE_APICHECK +#define LUA_PATH_DEFAULT "/syspage/?.lua;" "/syspage/?/init.lua" +#define LUA_CPATH_DEFAULT "/syspage/?.so" +*/ diff --git a/lua/patches/5.3.6/01-Makefile.patch b/lua/patches/5.3.6/01-Makefile.patch new file mode 100644 index 00000000..0c983d47 --- /dev/null +++ b/lua/patches/5.3.6/01-Makefile.patch @@ -0,0 +1,68 @@ +diff --git a/Makefile b/Makefile +index a2820e0..52a1c51 100644 +--- a/Makefile ++++ b/Makefile +@@ -4,19 +4,16 @@ + # == CHANGE THE SETTINGS BELOW TO SUIT YOUR ENVIRONMENT ======================= + + # Your platform. See PLATS for possible values. +-PLAT= none ++PLAT= posix + + # Where to install. The installation starts in the src and doc directories, + # so take care if INSTALL_TOP is not an absolute path. See the local target. + # You may want to make INSTALL_LMOD and INSTALL_CMOD consistent with + # LUA_ROOT, LUA_LDIR, and LUA_CDIR in luaconf.h. + INSTALL_TOP= /usr/local +-INSTALL_BIN= $(INSTALL_TOP)/bin ++INSTALL_BIN= $(INSTALL_TOP)/prog + INSTALL_INC= $(INSTALL_TOP)/include + INSTALL_LIB= $(INSTALL_TOP)/lib +-INSTALL_MAN= $(INSTALL_TOP)/man/man1 +-INSTALL_LMOD= $(INSTALL_TOP)/share/lua/$V +-INSTALL_CMOD= $(INSTALL_TOP)/lib/lua/$V + + # How to install. If your install program does not support "-p", then + # you may have to run ranlib on the installed liblua.a. +@@ -42,7 +39,6 @@ PLATS= aix bsd c89 freebsd generic linux macosx mingw posix solaris + TO_BIN= lua luac + TO_INC= lua.h luaconf.h lualib.h lauxlib.h lua.hpp + TO_LIB= liblua.a +-TO_MAN= lua.1 luac.1 + + # Lua version and release. + V= 5.3 +@@ -58,17 +54,15 @@ test: dummy + src/lua -v + + install: dummy +- cd src && $(MKDIR) $(INSTALL_BIN) $(INSTALL_INC) $(INSTALL_LIB) $(INSTALL_MAN) $(INSTALL_LMOD) $(INSTALL_CMOD) ++ cd src && $(MKDIR) $(INSTALL_BIN) $(INSTALL_INC) $(INSTALL_LIB) + cd src && $(INSTALL_EXEC) $(TO_BIN) $(INSTALL_BIN) + cd src && $(INSTALL_DATA) $(TO_INC) $(INSTALL_INC) + cd src && $(INSTALL_DATA) $(TO_LIB) $(INSTALL_LIB) +- cd doc && $(INSTALL_DATA) $(TO_MAN) $(INSTALL_MAN) + + uninstall: + cd src && cd $(INSTALL_BIN) && $(RM) $(TO_BIN) + cd src && cd $(INSTALL_INC) && $(RM) $(TO_INC) + cd src && cd $(INSTALL_LIB) && $(RM) $(TO_LIB) +- cd doc && cd $(INSTALL_MAN) && $(RM) $(TO_MAN) + + local: + $(MAKE) install INSTALL_TOP=../install +@@ -90,14 +84,10 @@ echo: + @echo "TO_BIN= $(TO_BIN)" + @echo "TO_INC= $(TO_INC)" + @echo "TO_LIB= $(TO_LIB)" +- @echo "TO_MAN= $(TO_MAN)" + @echo "INSTALL_TOP= $(INSTALL_TOP)" + @echo "INSTALL_BIN= $(INSTALL_BIN)" + @echo "INSTALL_INC= $(INSTALL_INC)" + @echo "INSTALL_LIB= $(INSTALL_LIB)" +- @echo "INSTALL_MAN= $(INSTALL_MAN)" +- @echo "INSTALL_LMOD= $(INSTALL_LMOD)" +- @echo "INSTALL_CMOD= $(INSTALL_CMOD)" + @echo "INSTALL_EXEC= $(INSTALL_EXEC)" + @echo "INSTALL_DATA= $(INSTALL_DATA)" + diff --git a/lua/patches/5.3.6/02-src-Makefile.patch b/lua/patches/5.3.6/02-src-Makefile.patch new file mode 100644 index 00000000..7b4bb221 --- /dev/null +++ b/lua/patches/5.3.6/02-src-Makefile.patch @@ -0,0 +1,48 @@ +diff --git a/src/Makefile b/src/Makefile +index a13afb9..8e178c7 100644 +--- a/src/Makefile ++++ b/src/Makefile +@@ -4,26 +4,24 @@ + # == CHANGE THE SETTINGS BELOW TO SUIT YOUR ENVIRONMENT ======================= + + # Your platform. See PLATS for possible values. +-PLAT= none ++PLAT= posix + +-CC= gcc -std=gnu99 +-CFLAGS= -O2 -Wall -Wextra -DLUA_COMPAT_5_2 $(SYSCFLAGS) $(MYCFLAGS) +-LDFLAGS= $(SYSLDFLAGS) $(MYLDFLAGS) ++CC= $(CROSS)gcc ++# MYCFLAGS and MYLDFLAGS are provided by the caller ++MYLIBS := ++ ++CFLAGS= -std=gnu99 -O2 -Wall -Wextra $(SYSCFLAGS) $(MYCFLAGS) ++LDFLAGS= $(SYSLDFLAGS) $(MYCFLAGS) $(MYLDFLAGS) + LIBS= -lm $(SYSLIBS) $(MYLIBS) + +-AR= ar rcu +-RANLIB= ranlib ++AR= $(CROSS)ar rcs ++RANLIB= $(CROSS)ranlib + RM= rm -f + + SYSCFLAGS= + SYSLDFLAGS= + SYSLIBS= + +-MYCFLAGS= +-MYLDFLAGS= +-MYLIBS= +-MYOBJS= +- + # == END OF USER SETTINGS -- NO NEED TO CHANGE ANYTHING BELOW THIS LINE ======= + + PLATS= aix bsd c89 freebsd generic linux macosx mingw posix solaris +@@ -57,7 +55,6 @@ a: $(ALL_A) + + $(LUA_A): $(BASE_O) + $(AR) $@ $(BASE_O) +- $(RANLIB) $@ + + $(LUA_T): $(LUA_O) $(LUA_A) + $(CC) -o $@ $(LDFLAGS) $(LUA_O) $(LUA_A) $(LIBS) diff --git a/lua/patches/5.3.6/03-luaconf.h.patch b/lua/patches/5.3.6/03-luaconf.h.patch new file mode 100644 index 00000000..28c9a342 --- /dev/null +++ b/lua/patches/5.3.6/03-luaconf.h.patch @@ -0,0 +1,95 @@ +diff --git a/src/luaconf.h b/src/luaconf.h +index 9eeeea6..af10bb2 100644 +--- a/src/luaconf.h ++++ b/src/luaconf.h +@@ -11,6 +11,7 @@ + #include + #include + ++#include + + /* + ** =================================================================== +@@ -119,19 +120,27 @@ + /* + ** 32-bit integers and 'float' + */ ++#if !defined(LUA_INT_TYPE) + #if LUAI_BITSINT >= 32 /* use 'int' if big enough */ + #define LUA_INT_TYPE LUA_INT_INT + #else /* otherwise use 'long' */ + #define LUA_INT_TYPE LUA_INT_LONG + #endif ++#endif ++#if !defined(LUA_FLOAT_TYPE) + #define LUA_FLOAT_TYPE LUA_FLOAT_FLOAT ++#endif + + #elif defined(LUA_C89_NUMBERS) /* }{ */ + /* + ** largest types available for C89 ('long' and 'double') + */ ++#if !defined(LUA_INT_TYPE) + #define LUA_INT_TYPE LUA_INT_LONG ++#endif ++#if !defined(LUA_FLOAT_TYPE) + #define LUA_FLOAT_TYPE LUA_FLOAT_DOUBLE ++#endif + + #endif /* } */ + +@@ -203,12 +212,16 @@ + #define LUA_ROOT "/usr/local/" + #define LUA_LDIR LUA_ROOT "share/lua/" LUA_VDIR "/" + #define LUA_CDIR LUA_ROOT "lib/lua/" LUA_VDIR "/" ++#if !defined(LUA_PATH_DEFAULT) + #define LUA_PATH_DEFAULT \ + LUA_LDIR"?.lua;" LUA_LDIR"?/init.lua;" \ + LUA_CDIR"?.lua;" LUA_CDIR"?/init.lua;" \ + "./?.lua;" "./?/init.lua" ++#endif ++#if !defined(LUA_CPATH_DEFAULT) + #define LUA_CPATH_DEFAULT \ + LUA_CDIR"?.so;" LUA_CDIR"loadall.so;" "./?.so" ++#endif + #endif /* } */ + + +@@ -725,11 +738,13 @@ + ** its only purpose is to stop Lua from consuming unlimited stack + ** space (and to reserve some numbers for pseudo-indices). + */ ++#if !defined(LUAI_MAXSTACK) + #if LUAI_BITSINT >= 32 + #define LUAI_MAXSTACK 1000000 + #else + #define LUAI_MAXSTACK 15000 + #endif ++#endif + + + /* +@@ -745,7 +760,9 @@ + @@ of a function in debug information. + ** CHANGE it if you want a different size. + */ ++#if !defined(LUA_IDSIZE) + #define LUA_IDSIZE 60 ++#endif + + + /* +@@ -755,11 +772,13 @@ + ** smaller buffer would force a memory allocation for each call to + ** 'string.format'.) + */ ++#if !defined(LUAL_BUFFERSIZE) + #if LUA_FLOAT_TYPE == LUA_FLOAT_LONGDOUBLE + #define LUAL_BUFFERSIZE 8192 + #else + #define LUAL_BUFFERSIZE ((int)(0x80 * sizeof(void*) * sizeof(lua_Integer))) + #endif ++#endif + + /* }================================================================== */ + diff --git a/lua/patches/5.3.6/safe/01-src-loslib.c.patch b/lua/patches/5.3.6/safe/01-src-loslib.c.patch new file mode 100644 index 00000000..cbc7a9d9 --- /dev/null +++ b/lua/patches/5.3.6/safe/01-src-loslib.c.patch @@ -0,0 +1,90 @@ +diff --git a/src/loslib.c b/src/loslib.c +index de590c6..99fa2ad 100644 +--- a/src/loslib.c ++++ b/src/loslib.c +@@ -138,41 +138,6 @@ static time_t l_checktime (lua_State *L, int arg) { + + + +-static int os_execute (lua_State *L) { +- const char *cmd = luaL_optstring(L, 1, NULL); +- int stat = system(cmd); +- if (cmd != NULL) +- return luaL_execresult(L, stat); +- else { +- lua_pushboolean(L, stat); /* true if there is a shell */ +- return 1; +- } +-} +- +- +-static int os_remove (lua_State *L) { +- const char *filename = luaL_checkstring(L, 1); +- return luaL_fileresult(L, remove(filename) == 0, filename); +-} +- +- +-static int os_rename (lua_State *L) { +- const char *fromname = luaL_checkstring(L, 1); +- const char *toname = luaL_checkstring(L, 2); +- return luaL_fileresult(L, rename(fromname, toname) == 0, NULL); +-} +- +- +-static int os_tmpname (lua_State *L) { +- char buff[LUA_TMPNAMBUFSIZE]; +- int err; +- lua_tmpnam(buff, err); +- if (err) +- return luaL_error(L, "unable to generate a unique filename"); +- lua_pushstring(L, buff); +- return 1; +-} +- + + static int os_getenv (lua_State *L) { + lua_pushstring(L, getenv(luaL_checkstring(L, 1))); /* if NULL push nil */ +@@ -358,43 +323,12 @@ static int os_difftime (lua_State *L) { + /* }====================================================== */ + + +-static int os_setlocale (lua_State *L) { +- static const int cat[] = {LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY, +- LC_NUMERIC, LC_TIME}; +- static const char *const catnames[] = {"all", "collate", "ctype", "monetary", +- "numeric", "time", NULL}; +- const char *l = luaL_optstring(L, 1, NULL); +- int op = luaL_checkoption(L, 2, "all", catnames); +- lua_pushstring(L, setlocale(cat[op], l)); +- return 1; +-} +- +- +-static int os_exit (lua_State *L) { +- int status; +- if (lua_isboolean(L, 1)) +- status = (lua_toboolean(L, 1) ? EXIT_SUCCESS : EXIT_FAILURE); +- else +- status = (int)luaL_optinteger(L, 1, EXIT_SUCCESS); +- if (lua_toboolean(L, 2)) +- lua_close(L); +- if (L) exit(status); /* 'if' to avoid warnings for unreachable 'return' */ +- return 0; +-} +- +- + static const luaL_Reg syslib[] = { + {"clock", os_clock}, + {"date", os_date}, + {"difftime", os_difftime}, +- {"execute", os_execute}, +- {"exit", os_exit}, + {"getenv", os_getenv}, +- {"remove", os_remove}, +- {"rename", os_rename}, +- {"setlocale", os_setlocale}, + {"time", os_time}, +- {"tmpname", os_tmpname}, + {NULL, NULL} + }; + diff --git a/lua/patches/5.3.6/safe/02-src-linit.c.patch b/lua/patches/5.3.6/safe/02-src-linit.c.patch new file mode 100644 index 00000000..e49f5127 --- /dev/null +++ b/lua/patches/5.3.6/safe/02-src-linit.c.patch @@ -0,0 +1,17 @@ +diff --git a/src/linit.c b/src/linit.c +index 480da52..ce37175 100644 +--- a/src/linit.c ++++ b/src/linit.c +@@ -44,12 +44,10 @@ static const luaL_Reg loadedlibs[] = { + {LUA_LOADLIBNAME, luaopen_package}, + {LUA_COLIBNAME, luaopen_coroutine}, + {LUA_TABLIBNAME, luaopen_table}, +- {LUA_IOLIBNAME, luaopen_io}, + {LUA_OSLIBNAME, luaopen_os}, + {LUA_STRLIBNAME, luaopen_string}, + {LUA_MATHLIBNAME, luaopen_math}, + {LUA_UTF8LIBNAME, luaopen_utf8}, +- {LUA_DBLIBNAME, luaopen_debug}, + #if defined(LUA_COMPAT_BITLIB) + {LUA_BITLIBNAME, luaopen_bit32}, + #endif