Skip to content

Commit 7f0d1d8

Browse files
wilhelmyraboof
authored andcommitted
Improved Lua version detection and Lua 5.3 support (#132)
* libtu/Makefile: it's C89, not C98 * Lua 5.3 removed deprecated variadic function `arg' parameter Variadic functions were introduced in 5.0, but the method of accessing them changed in 5.1. This makes the code incompatible with 5.0 (it is already incompatible since at least b2b1755), which will be removed from the build system in a subsequent commit. Fixes #124. See also #90. * Remove Lua 5.0 from the build system and improve lua-detect.mk Lua doesn't include an official pkg-config file, therefore we can't rely on pkg-config variables like "V" or "major_version" - on my system, it detected the 5.3 library/cflags and used the 5.1 lua/luac binaries (I have both installed and there was a fallback to 5.1 if it couldn't query these variables from pkg-config).
1 parent 4d39759 commit 7f0d1d8

File tree

6 files changed

+65
-27
lines changed

6 files changed

+65
-27
lines changed

build/lua-detect.mk

Lines changed: 59 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# It uses pkg-config to do this, but will fail if you have liblua, but
44
# not the corresponding interpreter/compiler. Let's say you have liblua5.2
55
# but want to build with liblua5.1 (for which you have the lib, interpreter
6-
# and compiler), you can override by setting LUA_VERSION=5.0 when invoking
6+
# and compiler), you can override by setting LUA_VERSION=5.1 when invoking
77
# make.
88
#
99
# If successful, sets the following variables:
@@ -12,25 +12,69 @@
1212
# * LUA_INCLUDES (can be appended to CFLAGS directly)
1313
# * LUA (full path to lua interpreter)
1414
# * LUAC (full path to lua compiler)
15+
#
16+
# If unsuccessful, you can set these manually.
17+
18+
ifndef LUA
19+
20+
# first off, some helper functions to $(call) - this one executes lua/luac to match it's version
21+
lua_ver_match_bin = $(shell $2 -v 2>&1 | grep -qFo $1. && echo 1)
22+
# this one is like which(1), which isn't portable - from the gmake manual
23+
pathsearch = $(firstword $(wildcard $(addsuffix /$(1),$(subst :, ,$(PATH)))))
24+
# Extract "5.x" from lua -v
25+
lua_ver_extract = $(shell $1 -v 2>&1 | cut -f2 -d' ' | cut -f-2 -d.)
26+
27+
# Lua does not provide an official .pc file, so finding one at all is tricky,
28+
# and there won't be any guarantees it looks the same as elsewhere.
29+
# We try the package names lua$(ver), lua-$(ver) for all candidate versions in
30+
# descending order and last but not least "lua" here.
31+
PKG_CONFIG_ALL_PACKAGES:= $(shell pkg-config --list-all | cut -f1 -d' ')
32+
33+
# these are in order of preference
34+
LUA_CANDIDATES:= $(or $(LUA_VERSION),5.3 5.2 5.1)
35+
LUA_BIN_CANDIDATES:= $(foreach ver,$(LUA_CANDIDATES),lua$(ver) lua-$(ver))
36+
LUAC_BIN_CANDIDATES:= $(foreach ver,$(LUA_CANDIDATES),luac$(ver) luac-$(ver))
37+
38+
# the binaries might of course also just be called lua and luac
39+
ifndef LUA_VERSION
40+
LUA_BIN_CANDIDATES+= lua
41+
LUAC_BIN_CANDIDATES+= luac
42+
endif
1543

16-
LUA_VERSIONS_CANDIDATES = $(or $(LUA_VERSION),5.3 5.2 5.1 5.0)
44+
# find pkg-config packages in the same order of preference
45+
PKG_CONFIG_LUA_PACKAGES:= $(foreach lua,$(LUA_BIN_CANDIDATES),$(filter $(lua),$(PKG_CONFIG_ALL_PACKAGES)))
46+
PKG_CONFIG_LUA:= $(firstword $(PKG_CONFIG_LUA_PACKAGES))
1747

18-
LUA_PKG := $(firstword $(foreach ver,$(LUA_VERSIONS_CANDIDATES),$(shell \
19-
($(PKG_CONFIG) --exists lua-$(ver) && echo lua-$(ver)) \
20-
|| ($(PKG_CONFIG) --exists lua$(ver:5.0=) && echo lua$(ver:5.0=)))))
48+
ifeq ($(PKG_CONFIG_LUA),)
49+
$(error It seems that pkg-config is not aware of your lua package. Make sure \
50+
the -dev package is installed along with a .pc file within the \
51+
pkg-config search-path. Alternatively, you can set the following \
52+
variables manually: LUA LUAC LUA_VERSION LUA_LIBS LUA_INCLUDES)
53+
endif
54+
55+
PKG_CONFIG_LUA_VERSION:= $(shell pkg-config --modversion $(PKG_CONFIG_LUA) | cut -d. -f-2)
56+
57+
$(info >> pkg-config found Lua $(PKG_CONFIG_LUA_VERSION) (available: $(PKG_CONFIG_LUA_PACKAGES:=)).)
58+
59+
LUA_LIBS= $(shell pkg-config --libs $(PKG_CONFIG_LUA))
60+
LUA_INCLUDES= $(shell pkg-config --cflags $(PKG_CONFIG_LUA))
61+
LUA_VERSION?= $(PKG_CONFIG_LUA_VERSION)
2162

22-
ifeq ($(LUA_PKG),)
23-
$(error Could not find $(or $(LUA_VERSION),any) lua version. (Did you install the -dev package?))
63+
LUA= $(firstword $(foreach bin,$(LUA_BIN_CANDIDATES),$(call pathsearch,$(bin))))
64+
LUAC= $(firstword $(foreach bin,$(LUAC_BIN_CANDIDATES),$(call pathsearch,$(bin))))
65+
66+
$(info >> Lua $(LUA_VERSION) binary is $(LUA) and luac is $(LUAC))
67+
68+
ifneq ($(call lua_ver_match_bin,$(LUA_VERSION),$(LUA)),1)
69+
$(error $(LUA) should be $(LUA_VERSION) but is $(call lua_ver_extract,$(LUA)))
2470
endif
2571

26-
ifeq ($(LUA_VERSION),)
27-
LUA_VERSION := $(or $(shell $(PKG_CONFIG) --variable=V $(LUA_PKG)),$(or $(shell $(PKG_CONFIG) --variable=major_version $(LUA_PKG)),5.0))
72+
ifneq ($(call lua_ver_match_bin,$(LUA_VERSION),$(LUAC)),1)
73+
$(error $(LUAC) should be $(LUA_VERSION) but is $(call lua_ver_extract,$(LUAC)))
2874
endif
2975

30-
# prior to 5.1 the lib didn't include version in name.
31-
LUA_SUFFIX := $(if $(findstring $(LUA_VERSION),5.0),,$(LUA_VERSION))
76+
endif
3277

33-
LUA_LIBS := $(or $(shell $(PKG_CONFIG) --libs $(LUA_PKG)), $(error "pkg-config couldn't find linker flags for lua$(LUA_SUFFIX)!"))
34-
LUA_INCLUDES := $(shell $(PKG_CONFIG) --cflags $(LUA_PKG))
35-
LUA := $(or $(shell which lua$(LUA_SUFFIX)), $(shell which lua), $(error No lua$(LUA_SUFFIX) interpreter found!))
36-
LUAC := $(or $(shell which luac$(LUA_SUFFIX)), $(shell which luac), $(error No lua$(LUA_SUFFIX) compiler found!))
78+
# this is necessary, otherwise the rest of the build process keeps calling
79+
# pkg-config and all these other programs up there
80+
export LUA_VERSION LUA_INCLUDES LUA_LIBS LUA LUAC

build/mkman.lua

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010

1111
local translations={}
1212

13-
local unpack = unpack or table.unpack
14-
1513
local function gettext(x)
1614
local t=translations[x]
1715
if not t or t=="" then
@@ -22,7 +20,7 @@ local function gettext(x)
2220
end
2321

2422
local function TR(x, ...)
25-
return string.format(gettext(x), unpack(arg))
23+
return string.format(gettext(x), ...)
2624
end
2725

2826
local function read_translations(pofile)

ioncore/ioncore_misc.lua

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ local layouts={
1717
default = empty,
1818
}
1919

20-
local unpack = unpack or table.unpack
21-
2220
--DOC
2321
-- Define a new workspace layout with name \var{name}, and
2422
-- attach/creation parameters given in \var{tab}. The layout
@@ -75,8 +73,7 @@ end
7573
--DOC
7674
-- gettext+string.format
7775
function ioncore.TR(s, ...)
78-
local arg = {...}
79-
return string.format(ioncore.gettext(s), unpack(arg))
76+
return string.format(ioncore.gettext(s), ...)
8077
end
8178

8279

libtu/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ include $(TOPDIR)/build/system-inc.mk
1616

1717
#INCLUDES += $(LIBTU_INCLUDES) $(LUA_INCLUDES)
1818

19-
CFLAGS += $(C98_SOURCE) $(POSIX_SOURCE) $(WARN)
19+
CFLAGS += $(C89_SOURCE) $(POSIX_SOURCE) $(WARN)
2020

2121
SOURCES=iterable.c map.c misc.c obj.c objlist.c optparser.c output.c parser.c prefix.c ptrlist.c rb.c setparam.c stringstore.c tokenizer.c util.c errorlog.c
2222

@@ -47,4 +47,4 @@ install:
4747
done
4848

4949
test:
50-
$(MAKE) -C test test
50+
$(MAKE) -C test test

mod_query/mod_query.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,6 +1015,7 @@ function mod_query.do_handle_lua(mplex, env, code)
10151015
local print_res
10161016
local function collect_print(...)
10171017
local tmp=""
1018+
local arg={...}
10181019
local l=#arg
10191020
for i=1,l do
10201021
tmp=tmp..tostring(arg[i])..(i==l and "\n" or "\t")

mod_statusbar/ion-statusd/statusd_mail.lua

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,10 @@ local defaults={
1919
files = {}
2020
}
2121

22-
local unpack = unpack or table.unpack
23-
2422
local settings=table.join(statusd.get_config(mon), defaults)
2523

2624
local function TR(s, ...)
27-
return string.format(statusd.gettext(s), unpack(arg))
25+
return string.format(statusd.gettext(s), ...)
2826
end
2927

3028
local function check_spool()

0 commit comments

Comments
 (0)