From 99936889540a62aad41a80e1f57b478b271ed899 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Tue, 2 Jun 2026 16:34:37 +0200 Subject: [PATCH] BUILD: makefile/lua: use the system's default library before all other variants The recent update to the makefile in commit bfbca23dc2 ("BUILD: makefile: search for Lua 5.5 as well") to enable searching for Lua 5.5 revealed a problem by which we were using the fallback versions before the main one (e.g. /usr/include/lua-5.4/lua.h before /usr/include/lua.h). However, the libs often contain the version in their name so that we can end up linking with 5.5 while 5.4 was used in the include. This was detected only when enabling lua 5.5 because in Lua 5.4 "luaL_openlibs()" was a symbol and became an inline in 5.5, preventing from using a mix of the two versions. The current change is minimal in that it skips all fallbacks when lua.h is present in /usr/include, and includes it in the test to make sure that the directory found contains valid C. LUA_LIB checks for lua before the variants so as to remain consistent with the system provided version. Thanks to @gene-git for reporting this problem in GH issue #3404. This may have to be backported after a period of observation if users face build issues for older releases on newer distros. In this case, backporting 1c0f781994 ("MINOR: hlua: Add support for lua 5.5") would equally be needed. However this will result in the system's version being used first, which may or may not be desired. --- Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index b975e01a9..e33f8f4c5 100644 --- a/Makefile +++ b/Makefile @@ -684,15 +684,15 @@ OPTIONS_OBJS += src/quic_openssl_compat.o endif ifneq ($(USE_LUA:0=),) - check_lua_inc = $(shell if [ -d $(2)$(1) ]; then echo $(2)$(1); fi;) + check_lua_inc = $(shell if [ ! -e /usr/include/lua.h -a -e $(2)$(1)/lua.h ]; then echo $(2)$(1); fi;) LUA_INC := $(firstword $(foreach lib,lua5.5 lua55 lua5.4 lua54 lua5.3 lua53 lua,$(call check_lua_inc,$(lib),"/usr/include/"))) - check_lua_lib = $(shell echo "int main(){}" | $(CC) -o /dev/null -x c - $(2) -l$(1) 2>/dev/null && echo $(1)) + check_lua_lib = $(shell (echo "#include ";echo "int main(){}") | $(CC) $(if $(LUA_INC),-I$(LUA_INC)) -o /dev/null -x c - $(2) -l$(1) 2>/dev/null && echo $(1)) LUA_LD_FLAGS := -Wl,$(if $(EXPORT_SYMBOL),$(EXPORT_SYMBOL),--export-dynamic) $(if $(LUA_LIB),-L$(LUA_LIB)) # Try to automatically detect the Lua library if not set ifeq ($(LUA_LIB_NAME),) - LUA_LIB_NAME := $(firstword $(foreach lib,lua5.5 lua55 lua5.4 lua54 lua5.3 lua53 lua,$(call check_lua_lib,$(lib),$(LUA_LD_FLAGS)))) + LUA_LIB_NAME := $(firstword $(foreach lib,lua lua5.5 lua55 lua5.4 lua54 lua5.3 lua53,$(call check_lua_lib,$(lib),$(LUA_LD_FLAGS)))) endif # Lua lib name must be set now (forced/detected above) -- 2.47.3