From 5bbff3c91e99f87a806888c6f8ddc1c308c6e158 Mon Sep 17 00:00:00 2001 From: Guillem Jover Date: Sat, 23 Mar 2024 00:39:12 +0100 Subject: [PATCH] build: Add support for linking against a system lua5.1 Add a new USE_SYSTEM_LUA make variable to select whether to link against the system liblua5.1, liblua5.1-bitop and liblua5.1-cjson. FIXME: Missing liblua5.1-struct and liblua5.1-cmsgpack in Debian. https://luarocks.org/modules/luarocks/struct https://luarocks.org/modules/antirez/lua-cmsgpack --- deps/Makefile | 2 + ...dd-support-for-a-USE_SYSTEM_LUA-flag.patch | 71 ------------------- pkg/deb/debian_dh9/patches/series | 1 - src/Makefile | 22 ++++-- 4 files changed, 20 insertions(+), 76 deletions(-) delete mode 100644 pkg/deb/debian_dh9/patches/0011-Add-support-for-a-USE_SYSTEM_LUA-flag.patch diff --git a/deps/Makefile b/deps/Makefile index 7ef872784..1d0335f7e 100644 --- a/deps/Makefile +++ b/deps/Makefile @@ -38,7 +38,9 @@ ifneq ($(USE_SYSTEM_HIREDIS),yes) -(cd hiredis && $(MAKE) clean) > /dev/null || true endif -(cd linenoise && $(MAKE) clean) > /dev/null || true +ifneq ($(USE_SYSTEM_LUA),yes) -(cd lua && $(MAKE) clean) > /dev/null || true +endif ifneq ($(USE_SYSTEM_JEMALLOC),yes) -(cd jemalloc && [ -f Makefile ] && $(MAKE) distclean) > /dev/null || true endif diff --git a/pkg/deb/debian_dh9/patches/0011-Add-support-for-a-USE_SYSTEM_LUA-flag.patch b/pkg/deb/debian_dh9/patches/0011-Add-support-for-a-USE_SYSTEM_LUA-flag.patch deleted file mode 100644 index 7e57c48f7..000000000 --- a/pkg/deb/debian_dh9/patches/0011-Add-support-for-a-USE_SYSTEM_LUA-flag.patch +++ /dev/null @@ -1,71 +0,0 @@ -From: Chris Lamb -Date: Sun, 26 Aug 2018 12:57:32 +0200 -Subject: Add support for a USE_SYSTEM_LUA flag. - -https://github.com/antirez/redis/pull/5280 ---- - deps/Makefile | 2 ++ - src/Makefile | 15 ++++++++++++--- - 2 files changed, 14 insertions(+), 3 deletions(-) - -diff --git a/deps/Makefile b/deps/Makefile -index 1342fac..2ed7736 100644 ---- a/deps/Makefile -+++ b/deps/Makefile -@@ -35,7 +35,9 @@ endif - distclean: - -(cd hiredis && $(MAKE) clean) > /dev/null || true - -(cd linenoise && $(MAKE) clean) > /dev/null || true -+ifneq ($(USE_SYSTEM_LUA),yes) - -(cd lua && $(MAKE) clean) > /dev/null || true -+endif - ifneq ($(USE_SYSTEM_JEMALLOC),yes) - -(cd jemalloc && [ -f Makefile ] && $(MAKE) distclean) > /dev/null || true - endif -diff --git a/src/Makefile b/src/Makefile -index 51363fe..49085f2 100644 ---- a/src/Makefile -+++ b/src/Makefile -@@ -16,7 +16,7 @@ release_hdr := $(shell sh -c './mkreleasehdr.sh') - uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not') - uname_M := $(shell sh -c 'uname -m 2>/dev/null || echo not') - OPTIMIZATION?=-O2 --DEPENDENCY_TARGETS=hiredis linenoise lua -+DEPENDENCY_TARGETS=hiredis linenoise - NODEPS:=clean distclean - - # Default settings -@@ -107,7 +107,7 @@ endif - endif - endif - # Include paths to dependencies --FINAL_CFLAGS+= -I../deps/hiredis -I../deps/linenoise -I../deps/lua/src -+FINAL_CFLAGS+= -I../deps/hiredis -I../deps/linenoise - - ifeq ($(MALLOC),tcmalloc) - FINAL_CFLAGS+= -DUSE_TCMALLOC -@@ -130,6 +130,15 @@ else - endif - endif - -+ifeq ($(USE_SYSTEM_LUA),yes) -+ FINAL_CFLAGS+= -I/usr/include/lua5.1 -+ FINAL_LIBS := -llua5.1 $(FINAL_LIBS) -+else -+ FINAL_CFLAGS+= -I../deps/lua/src -+ DEPENDENCY_TARGETS+= lua -+ FINAL_LIBS := ../deps/lua/src/liblua.a $(FINAL_LIBS) -+endif -+ - REDIS_CC=$(QUIET_CC)$(CC) $(FINAL_CFLAGS) $(CPPFLAGS) - REDIS_LD=$(QUIET_LINK)$(CC) $(FINAL_LDFLAGS) - REDIS_INSTALL=$(QUIET_INSTALL)$(INSTALL) -@@ -201,7 +210,7 @@ endif - - # redis-server - $(REDIS_SERVER_NAME): $(REDIS_SERVER_OBJ) -- $(REDIS_LD) -o $@ $^ ../deps/hiredis/libhiredis.a ../deps/lua/src/liblua.a $(FINAL_LIBS) -+ $(REDIS_LD) -o $@ $^ ../deps/hiredis/libhiredis.a $(FINAL_LIBS) - - # redis-sentinel - $(REDIS_SENTINEL_NAME): $(REDIS_SERVER_NAME) diff --git a/pkg/deb/debian_dh9/patches/series b/pkg/deb/debian_dh9/patches/series index 2da3b11e1..aee658d4e 100644 --- a/pkg/deb/debian_dh9/patches/series +++ b/pkg/deb/debian_dh9/patches/series @@ -2,5 +2,4 @@ #debian-packaging/0003-dpkg-buildflags.patch #debian-packaging/0007-Set-Debian-configuration-defaults.patch #0010-Use-get_current_dir_name-over-PATHMAX-etc.patch -#0011-Add-support-for-a-USE_SYSTEM_LUA-flag.patch #test diff --git a/src/Makefile b/src/Makefile index 587a265fd..72f81167f 100644 --- a/src/Makefile +++ b/src/Makefile @@ -20,7 +20,7 @@ release_hdr := $(shell sh -c './mkreleasehdr.sh') uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not') uname_M := $(shell sh -c 'uname -m 2>/dev/null || echo not') OPTIMIZATION?=-O2 -flto -DEPENDENCY_TARGETS=linenoise lua hdr_histogram +DEPENDENCY_TARGETS=linenoise hdr_histogram NODEPS:=clean distclean # Default settings @@ -274,8 +274,8 @@ ifdef OPENSSL_PREFIX endif # Include paths to dependencies -FINAL_CFLAGS+= -I../deps/linenoise -I../deps/lua/src -I../deps/hdr_histogram -FINAL_CXXFLAGS+= -I../deps/linenoise -I../deps/lua/src -I../deps/hdr_histogram +FINAL_CFLAGS+= -I../deps/linenoise -I../deps/hdr_histogram +FINAL_CXXFLAGS+= -I../deps/linenoise -I../deps/hdr_histogram ifeq ($(USE_SYSTEM_CONCURRENTQUEUE),yes) FINAL_CXXFLAGS+= -I/usr/include/concurrentqueue/moodycamel @@ -379,6 +379,19 @@ endif endif endif +ifeq ($(USE_SYSTEM_LUA),yes) + LUA_PC = lua5.1 lua5.1-bitop lua5.1-cjson + LUA_CFLAGS := $(shell $(PKG_CONFIG) --cflags $(LUA_PC)) + FINAL_CFLAGS+= $(LUA_CFLAGS) + FINAL_CXXFLAGS+= $(LUA_CFLAGS) + SERVER_LIBS+= $(shell $(PKG_CONFIG) --libs $(LUA_PC)) +else + DEPENDENCY_TARGETS+= lua + FINAL_CFLAGS+= -I../deps/lua/src + FINAL_CXXFLAGS+= -I../deps/lua/src + SERVER_LIBS+= ../deps/lua/src/liblua.a +endif + ifndef V define MAKE_INSTALL @printf ' %b %b\n' $(LINKCOLOR)INSTALL$(ENDCOLOR) $(BINCOLOR)$(1)$(ENDCOLOR) 1>&2 @@ -456,6 +469,7 @@ persist-settings: distclean echo BUILD_TLS=$(BUILD_TLS) >> .make-settings echo USE_SYSTEMD=$(USE_SYSTEMD) >> .make-settings echo USE_SYSTEM_HIREDIS=$(USE_SYSTEM_HIREDIS) >> .make-settings + echo USE_SYSTEM_LUA=$(USE_SYSTEM_LUA) >> .make-settings echo CFLAGS=$(CFLAGS) >> .make-settings echo CXXFLAGS=$(CXXFLAGS) >> .make-settings echo LDFLAGS=$(LDFLAGS) >> .make-settings @@ -485,7 +499,7 @@ endif # keydb-server $(REDIS_SERVER_NAME): $(REDIS_SERVER_OBJ) $(KEYDB_SERVER_OBJ) - $(REDIS_LD) -o $@ $^ ../deps/lua/src/liblua.a $(FINAL_LIBS) + $(REDIS_LD) -o $@ $^ $(SERVER_LIBS) $(FINAL_LIBS) # keydb-sentinel $(REDIS_SENTINEL_NAME): $(REDIS_SERVER_NAME)