Skip to content

Instantly share code, notes, and snippets.

@marslo
Last active January 5, 2024 03:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marslo/767e339e32e0dbc038a3e00e3c8a7cba to your computer and use it in GitHub Desktop.
Save marslo/767e339e32e0dbc038a3e00e3c8a7cba to your computer and use it in GitHub Desktop.
patch for build lua v5.4.6 as a shared library (liblua.so)
--- Makefile 2024-01-04 18:12:26.836000000 -0800
+++ Makefile.patched 2024-01-04 18:14:09.840000000 -0800
@@ -38,21 +38,21 @@
# Convenience platforms targets.
PLATS= guess aix bsd c89 freebsd generic ios linux linux-readline macosx mingw posix solaris
+# Lua version and release.
+V= 5.4
+R= $V.6
+
# What to install.
TO_BIN= lua luac
TO_INC= lua.h luaconf.h lualib.h lauxlib.h lua.hpp
-TO_LIB= liblua.a
+TO_LIB= liblua.a liblua$(R).so
TO_MAN= lua.1 luac.1
-# Lua version and release.
-V= 5.4
-R= $V.6
-
# Targets start here.
all: $(PLAT)
$(PLATS) help test clean:
- @cd src && $(MAKE) $@
+ @cd src && $(MAKE) $@ V=$(V) R=$(R)
install: dummy
cd src && $(MKDIR) $(INSTALL_BIN) $(INSTALL_INC) $(INSTALL_LIB) $(INSTALL_MAN) $(INSTALL_LMOD) $(INSTALL_CMOD)
@@ -60,6 +60,8 @@
cd src && $(INSTALL_DATA) $(TO_INC) $(INSTALL_INC)
cd src && $(INSTALL_DATA) $(TO_LIB) $(INSTALL_LIB)
cd doc && $(INSTALL_DATA) $(TO_MAN) $(INSTALL_MAN)
+ ln -s $(INSTALL_LIB)/liblua$(R).so $(INSTALL_LIB)/liblua.so.$(V)
+ ln -s $(INSTALL_LIB)/liblua$(R).so $(INSTALL_LIB)/liblua.so
uninstall:
cd src && cd $(INSTALL_BIN) && $(RM) $(TO_BIN)
--- src/Makefile 2023-02-03 02:43:14.000000000 -0800
+++ src/Makefile.patched 2024-01-04 18:47:16.755000000 -0800
@@ -20,7 +20,7 @@
SYSLDFLAGS=
SYSLIBS=
-MYCFLAGS=
+MYCFLAGS= -fPIC
MYLDFLAGS=
MYLIBS=
MYOBJS=
@@ -59,6 +59,8 @@
$(LUA_A): $(BASE_O)
$(AR) $@ $(BASE_O)
$(RANLIB) $@
+ $(CC) -shared -ldl -Wl,-soname,liblua$R.so -o liblua$R.so $? -lm $(MYLDFLAGS)
+ ln -sf liblua$R.so liblua.so
$(LUA_T): $(LUA_O) $(LUA_A)
$(CC) -o $@ $(LDFLAGS) $(LUA_O) $(LUA_A) $(LIBS)
@marslo
Copy link
Author

marslo commented Jan 5, 2024

way to build lua 5.4.6

$ mkdir /opt/lua
$ curl -fsSL https://www.lua.org/ftp/lua-5.4.6.tar.gz | tar xzf - -C /opt/lua
$ cd /opt/lua/lua-5.4.6

$ patch --ignore-whitespace < <(curl -fsSL https://gist.githubusercontent.com/marslo/767e339e32e0dbc038a3e00e3c8a7cba/raw/01f29ac774a468221082f4d504b013d264435567/Makefile.patch)
$ cd src
$ patch --ignore-whitespace < <(curl -fsSL https://gist.githubusercontent.com/marslo/767e339e32e0dbc038a3e00e3c8a7cba/raw/01f29ac774a468221082f4d504b013d264435567/src.Makefile.patch)

# build
$ make all test
# install
$ sudo make install

references:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment