Skip to content

Commit

Permalink
lua: Make building more generic (build for any arch)
Browse files Browse the repository at this point in the history
Default version changed from 5.3.5 to 5.3.6.

Added port build options:
 - PORTS_LUA_VERSION - version to download (must be supported by
   respective patches);
 - PORTS_LUA_STACK_SIZE - size of Lua's internal stack;
 - PORTS_LUA_CSTACK_SIZE - size of stack (when using linked lua binary);
 - PORTS_LUA_COMPAT_5_2 - backward compatibility with Lua 5.2;
 - PORTS_LUA_DEBUG - enable debug features, e.g. API checks;
 - PORTS_LUA_INSTALL_TESTS - download and install external Lua test
   scripts;
 - PORTS_LUA_RESTRAIN - disable Lua features which may be used to crash
   the interpreter or perform side-effects in the operating system.

JIRA: NIL-595
  • Loading branch information
Darchiv authored and mateuszkobak committed Jul 25, 2024
1 parent 97f89f0 commit d19244f
Show file tree
Hide file tree
Showing 9 changed files with 258 additions and 216 deletions.
194 changes: 0 additions & 194 deletions lua/Makefile

This file was deleted.

69 changes: 47 additions & 22 deletions lua/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +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="5.4.6"

b_log "Building lua"
PREFIX_LUA="${PREFIX_PROJECT}/phoenix-rtos-ports/lua"
PREFIX_LUA_BUILD="${PREFIX_BUILD}/lua"
PREFIX_LUA_SRC="${PREFIX_LUA_BUILD}/${LUA}"
PREFIX_PORT_SRC="${PREFIX_PORT_BUILD}/${version}"
PREFIX_PORT_TESTS="${PREFIX_PORT_BUILD}/${tests_version}-tests"

b_port_download "https://www.lua.org/ftp/" "${archive_filename}"

mkdir -p "$PREFIX_LUA_BUILD"
if [ ! -f "$PREFIX_LUA/${LUA}.tar.gz" ]; then
if ! wget "$PKG_URL" -P "${PREFIX_LUA}" --no-check-certificate; then
wget "$PKG_MIRROR_URL" -P "${PREFIX_LUA}" --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
if [ ! -d "$PREFIX_LUA_SRC" ]; then
tar zxf "$PREFIX_LUA/${LUA}.tar.gz" -C "$PREFIX_LUA_BUILD"
cp "$PREFIX_LUA/Makefile" "$PREFIX_LUA_SRC/src/"

b_port_apply_patches "${PREFIX_PORT_SRC}" "${version}"

if [ "${PORTS_LUA_RESTRAIN}" = "y" ]; then
b_port_apply_patches "${PREFIX_PORT_SRC}" "${version}/restrain"
fi

mycflags=(
${CFLAGS}
-DLUAI_MAXSTACK=${PORTS_LUA_STACK_SIZE:-2000}
)

if [ "${PORTS_LUA_COMPAT_5_2}" = "y" ]; then mycflags+=("-DLUA_COMPAT_5_2"); fi
if [ "${PORTS_LUA_DEBUG}" = "y" ]; then mycflags+=("-DLUA_USE_APICHECK"); fi

myldflags=(
${LDFLAGS}
-Wl,-z,stack-size=${PORTS_LUA_CSTACK_SIZE:-4096}
)

# FIXME: no out-of-tree building
make -C "$PREFIX_LUA_SRC" posix
make -C "${PREFIX_PORT_SRC}/src" MYCFLAGS="${mycflags[*]}" MYLDFLAGS="${myldflags[*]}"
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"
$STRIP -o "${PREFIX_PROG_STRIPPED}/lua" "${PREFIX_PROG}/lua"
$STRIP -o "${PREFIX_PROG_STRIPPED}/luac" "${PREFIX_PROG}/luac"

b_install "$PREFIX_PORTS_INSTALL/lua" /bin
b_install "$PREFIX_PORTS_INSTALL/luac" /bin
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
2 changes: 2 additions & 0 deletions lua/checksums.sha256
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
fc5fd69bb8736323f026672b1b7235da613d7177e72558893a0bdcd320466d60 *lua-5.3.6.tar.gz
63ed5f5bcfd15dfd2f72e04c2f8c10585bb8de9e558df62b335cb9e5c1a4ef34 *lua-5.4.6-tests.tar.gz
68 changes: 68 additions & 0 deletions lua/patches/5.3.6/01-Makefile.patch
Original file line number Diff line number Diff line change
@@ -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)"

48 changes: 48 additions & 0 deletions lua/patches/5.3.6/02-src-Makefile.patch
Original file line number Diff line number Diff line change
@@ -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)
Loading

0 comments on commit d19244f

Please sign in to comment.