Skip to content

Commit 12265fd

Browse files
authored
Merge pull request Hamlib#1720 from N0NB/lua_macro
Update ax_lua.m4 macro file
2 parents 7c5c715 + 5cf8755 commit 12265fd

File tree

2 files changed

+98
-48
lines changed

2 files changed

+98
-48
lines changed

configure.ac

+4
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,10 @@ AC_SUBST([TCL_CFLAGS])
667667

668668

669669
dnl Check for lua availability, so we can enable HamlibLua
670+
671+
dnl Newer ax_lua.m4 macro, at least Serial 47, requires LUAJIT be present.
672+
AM_CONDITIONAL([LUAJIT], [false])
673+
670674
# Lua bindings
671675
AC_MSG_CHECKING([whether to build lua binding])
672676
AC_ARG_WITH([lua-binding],

macros/ax_lua.m4

+94-48
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# ===========================================================================
2-
# http://www.gnu.org/software/autoconf-archive/ax_lua.html
2+
# https://www.gnu.org/software/autoconf-archive/ax_lua.html
33
# ===========================================================================
44
#
55
# SYNOPSIS
@@ -19,7 +19,7 @@
1919
# header is checked to match the Lua interpreter version exactly. When
2020
# searching for Lua libraries, the version number is used as a suffix.
2121
# This is done with the goal of supporting multiple Lua installs (5.1,
22-
# 5.2, and 5.3 side-by-side).
22+
# 5.2, 5.3, and 5.4 side-by-side).
2323
#
2424
# A note on compatibility with previous versions: This file has been
2525
# mostly rewritten for serial 18. Most developers should be able to use
@@ -49,6 +49,14 @@
4949
# interpreter. If LUA is blank, the user's path is searched for an
5050
# suitable interpreter.
5151
#
52+
# Optionally a LUAJIT option may be set ahead of time to look for and
53+
# validate a LuaJIT install instead of PUC Lua. Usage might look like:
54+
#
55+
# AC_ARG_WITH(luajit, [AS_HELP_STRING([--with-luajit],
56+
# [Prefer LuaJIT over PUC Lua, even if the latter is newer. Default: no])
57+
# ])
58+
# AM_CONDITIONAL([LUAJIT], [test "x$with_luajit" != 'xno'])
59+
#
5260
# If MINIMUM-VERSION is supplied, then only Lua interpreters with a
5361
# version number greater or equal to MINIMUM-VERSION will be accepted. If
5462
# TOO-BIG-VERSION is also supplied, then only Lua interpreters with a
@@ -152,6 +160,7 @@
152160
#
153161
# LICENSE
154162
#
163+
# Copyright (c) 2023 Caleb Maclennan <[email protected]>
155164
# Copyright (c) 2015 Reuben Thomas <[email protected]>
156165
# Copyright (c) 2014 Tim Perkins <[email protected]>
157166
#
@@ -166,7 +175,7 @@
166175
# Public License for more details.
167176
#
168177
# You should have received a copy of the GNU General Public License along
169-
# with this program. If not, see <http://www.gnu.org/licenses/>.
178+
# with this program. If not, see <https://www.gnu.org/licenses/>.
170179
#
171180
# As a special exception, the respective Autoconf Macro's copyright owner
172181
# gives unlimited permission to copy, distribute and modify the configure
@@ -181,7 +190,7 @@
181190
# modified version of the Autoconf Macro, you may extend this special
182191
# exception to the GPL to apply to your modified version as well.
183192

184-
#serial 39
193+
#serial 47
185194

186195
dnl =========================================================================
187196
dnl AX_PROG_LUA([MINIMUM-VERSION], [TOO-BIG-VERSION],
@@ -197,13 +206,14 @@ AC_DEFUN([AX_PROG_LUA],
197206
AC_ARG_VAR([LUA], [The Lua interpreter, e.g. /usr/bin/lua5.1])
198207
199208
dnl Find a Lua interpreter.
200-
m4_define_default([_AX_LUA_INTERPRETER_LIST],
201-
[lua lua5.3 lua53 lua5.2 lua52 lua5.1 lua51 lua50])
209+
AM_COND_IF([LUAJIT],
210+
[_ax_lua_interpreter_list='luajit luajit-2.1.0-beta3 luajit-2.0.5 luajit-2.0.4 luajit-2.0.3'],
211+
[_ax_lua_interpreter_list='lua lua5.4 lua54 lua5.3 lua53 lua5.2 lua52 lua5.1 lua51 lua5.0 lua50'])
202212
203213
m4_if([$1], [],
204214
[ dnl No version check is needed. Find any Lua interpreter.
205215
AS_IF([test "x$LUA" = 'x'],
206-
[AC_PATH_PROGS([LUA], [_AX_LUA_INTERPRETER_LIST], [:])])
216+
[AC_PATH_PROGS([LUA], [$_ax_lua_interpreter_list], [:])])
207217
ax_display_LUA='lua'
208218
209219
AS_IF([test "x$LUA" != 'x:'],
@@ -242,7 +252,7 @@ AC_DEFUN([AX_PROG_LUA],
242252
[_ax_check_text="for a Lua interpreter with version >= $1, < $2"])
243253
AC_CACHE_CHECK([$_ax_check_text],
244254
[ax_cv_pathless_LUA],
245-
[ for ax_cv_pathless_LUA in _AX_LUA_INTERPRETER_LIST none; do
255+
[ for ax_cv_pathless_LUA in $_ax_lua_interpreter_list none; do
246256
test "x$ax_cv_pathless_LUA" = 'xnone' && break
247257
_AX_LUA_CHK_IS_INTRP([$ax_cv_pathless_LUA], [], [continue])
248258
_AX_LUA_CHK_VER([$ax_cv_pathless_LUA], [$1], [$2], [break])
@@ -268,13 +278,25 @@ AC_DEFUN([AX_PROG_LUA],
268278
ax_cv_lua_version=[`$LUA -e '
269279
-- return a version number in X.Y format
270280
local _, _, ver = string.find(_VERSION, "^Lua (%d+%.%d+)")
271-
print(ver)'`]
281+
print(ver or "")'`]
272282
])
273283
AS_IF([test "x$ax_cv_lua_version" = 'x'],
274284
[AC_MSG_ERROR([invalid Lua version number])])
275285
AC_SUBST([LUA_VERSION], [$ax_cv_lua_version])
276286
AC_SUBST([LUA_SHORT_VERSION], [`echo "$LUA_VERSION" | $SED 's|\.||'`])
277287
288+
AM_COND_IF([LUAJIT], [
289+
AC_CACHE_CHECK([for $ax_display_LUA jit version], [ax_cv_luajit_version],
290+
[ ax_cv_luajit_version=[`$LUA -e '
291+
local _, _, ver = string.find(jit and jit.version, "(%d+%..+)")
292+
print(ver or "")'`]
293+
])
294+
AS_IF([test "x$ax_cv_luajit_version" = 'x'],
295+
[AC_MSG_ERROR([invalid Lua jit version number])])
296+
AC_SUBST([LUAJIT_VERSION], [$ax_cv_luajit_version])
297+
AC_SUBST([LUAJIT_SHORT_VERSION], [$(echo "$LUAJIT_VERSION" | $SED 's|\.|§|;s|\..*||;s|§|.|')])
298+
])
299+
278300
dnl The following check is not supported:
279301
dnl At times (like when building shared libraries) you may want to know
280302
dnl which OS platform Lua thinks this is.
@@ -464,33 +486,50 @@ AC_DEFUN([AX_LUA_HEADERS],
464486
AC_MSG_ERROR([cannot check Lua headers without knowing LUA_VERSION])
465487
])
466488
489+
AM_COND_IF([LUAJIT],[
490+
dnl Check for LUAJIT_VERSION.
491+
AC_MSG_CHECKING([if LUAJIT_VERSION is defined])
492+
AS_IF([test "x$LUAJIT_VERSION" != 'x'],
493+
[AC_MSG_RESULT([yes])],
494+
[ AC_MSG_RESULT([no])
495+
AC_MSG_ERROR([cannot check Lua jit headers without knowing LUAJIT_VERSION])
496+
])
497+
])
498+
467499
dnl Make LUA_INCLUDE a precious variable.
468500
AC_ARG_VAR([LUA_INCLUDE], [The Lua includes, e.g. -I/usr/include/lua5.1])
469501
470-
dnl Some default directories to search.
471-
LUA_SHORT_VERSION=`echo "$LUA_VERSION" | $SED 's|\.||'`
472-
m4_define_default([_AX_LUA_INCLUDE_LIST],
473-
[ /usr/include/lua$LUA_VERSION \
474-
/usr/include/lua-$LUA_VERSION \
475-
/usr/include/lua/$LUA_VERSION \
476-
/usr/include/lua$LUA_SHORT_VERSION \
477-
/usr/local/include/lua$LUA_VERSION \
478-
/usr/local/include/lua-$LUA_VERSION \
479-
/usr/local/include/lua/$LUA_VERSION \
480-
/usr/local/include/lua$LUA_SHORT_VERSION \
481-
])
502+
dnl Some default directories to search.
503+
AM_COND_IF([LUAJIT],
504+
[_ax_lua_include_list="
505+
/usr/include/luajit-$LUAJIT_VERSION
506+
/usr/include/luajit-$LUAJIT_SHORT_VERSION
507+
/usr/local/include/luajit-$LUAJIT_VERSION
508+
/usr/local/include/luajit-$LUAJIT_SHORT_VERSION"],
509+
[_ax_lua_include_list="
510+
/usr/include/lua$LUA_VERSION
511+
/usr/include/lua-$LUA_VERSION
512+
/usr/include/lua/$LUA_VERSION
513+
/usr/include/lua$LUA_SHORT_VERSION
514+
/usr/local/include/lua$LUA_VERSION
515+
/usr/local/include/lua-$LUA_VERSION
516+
/usr/local/include/lua/$LUA_VERSION
517+
/usr/local/include/lua$LUA_SHORT_VERSION"])
482518
483519
dnl Try to find the headers.
484520
_ax_lua_saved_cppflags=$CPPFLAGS
485521
CPPFLAGS="$CPPFLAGS $LUA_INCLUDE"
486522
AC_CHECK_HEADERS([lua.h lualib.h lauxlib.h luaconf.h])
523+
AM_COND_IF([LUAJIT], [AC_CHECK_HEADERS([luajit.h])])
487524
CPPFLAGS=$_ax_lua_saved_cppflags
488525
489526
dnl Try some other directories if LUA_INCLUDE was not set.
490527
AS_IF([test "x$LUA_INCLUDE" = 'x' &&
491-
test "x$ac_cv_header_lua_h" != 'xyes'],
528+
test "x$ac_cv_header_lua_h" != 'xyes' ||
529+
test "x$with_luajit" != 'xno' &&
530+
test "x$ac_cv_header_luajit_h" != 'xyes'],
492531
[ dnl Try some common include paths.
493-
for _ax_include_path in _AX_LUA_INCLUDE_LIST; do
532+
for _ax_include_path in $_ax_lua_include_list; do
494533
test ! -d "$_ax_include_path" && continue
495534
496535
AC_MSG_CHECKING([for Lua headers in])
@@ -500,10 +539,12 @@ AC_DEFUN([AX_LUA_HEADERS],
500539
AS_UNSET([ac_cv_header_lualib_h])
501540
AS_UNSET([ac_cv_header_lauxlib_h])
502541
AS_UNSET([ac_cv_header_luaconf_h])
542+
AS_UNSET([ac_cv_header_luajit_h])
503543
504544
_ax_lua_saved_cppflags=$CPPFLAGS
505545
CPPFLAGS="$CPPFLAGS -I$_ax_include_path"
506546
AC_CHECK_HEADERS([lua.h lualib.h lauxlib.h luaconf.h])
547+
AM_COND_IF([LUAJIT], [AC_CHECK_HEADERS([luajit.h])])
507548
CPPFLAGS=$_ax_lua_saved_cppflags
508549
509550
AS_IF([test "x$ac_cv_header_lua_h" = 'xyes'],
@@ -524,22 +565,17 @@ AC_DEFUN([AX_LUA_HEADERS],
524565
[ax_cv_lua_header_version],
525566
[ _ax_lua_saved_cppflags=$CPPFLAGS
526567
CPPFLAGS="$CPPFLAGS $LUA_INCLUDE"
527-
AC_RUN_IFELSE(
528-
[ AC_LANG_SOURCE([[
568+
AC_COMPUTE_INT(ax_cv_lua_header_version_major,[LUA_VERSION_NUM/100],[AC_INCLUDES_DEFAULT
529569
#include <lua.h>
530-
#include <stdlib.h>
531-
#include <stdio.h>
532-
int main(int argc, char ** argv)
533-
{
534-
if(argc > 1) printf("%s", LUA_VERSION);
535-
exit(EXIT_SUCCESS);
536-
}
537-
]])
538-
],
539-
[ ax_cv_lua_header_version=`./conftest$EXEEXT p | \
540-
$SED -n "s|^Lua \(@<:@0-9@:>@\{1,\}\.@<:@0-9@:>@\{1,\}\).\{0,\}|\1|p"`
541-
],
542-
[ax_cv_lua_header_version='unknown'])
570+
],[ax_cv_lua_header_version_major=unknown])
571+
AC_COMPUTE_INT(ax_cv_lua_header_version_minor,[LUA_VERSION_NUM%100],[AC_INCLUDES_DEFAULT
572+
#include <lua.h>
573+
],[ax_cv_lua_header_version_minor=unknown])
574+
AS_IF([test "x$ax_cv_lua_header_version_major" = xunknown || test "x$ax_cv_lua_header_version_minor" = xunknown],[
575+
ax_cv_lua_header_version=unknown
576+
],[
577+
ax_cv_lua_header_version="$ax_cv_lua_header_version_major.$ax_cv_lua_header_version_minor"
578+
])
543579
CPPFLAGS=$_ax_lua_saved_cppflags
544580
])
545581
@@ -626,16 +662,26 @@ AC_DEFUN([AX_LUA_LIBS],
626662
dnl Try to find the Lua libs.
627663
_ax_lua_saved_libs=$LIBS
628664
LIBS="$LIBS $LUA_LIB"
629-
AC_SEARCH_LIBS([lua_load],
630-
[ lua$LUA_VERSION \
631-
lua$LUA_SHORT_VERSION \
632-
lua-$LUA_VERSION \
633-
lua-$LUA_SHORT_VERSION \
634-
lua \
635-
],
636-
[_ax_found_lua_libs='yes'],
637-
[_ax_found_lua_libs='no'],
638-
[$_ax_lua_extra_libs])
665+
AM_COND_IF([LUAJIT],
666+
[AC_SEARCH_LIBS([lua_load],
667+
[ luajit$LUA_VERSION \
668+
luajit$LUA_SHORT_VERSION \
669+
luajit-$LUA_VERSION \
670+
luajit-$LUA_SHORT_VERSION \
671+
luajit],
672+
[_ax_found_lua_libs='yes'],
673+
[_ax_found_lua_libs='no'],
674+
[$_ax_lua_extra_libs])],
675+
[AC_SEARCH_LIBS([lua_load],
676+
[ lua$LUA_VERSION \
677+
lua$LUA_SHORT_VERSION \
678+
lua-$LUA_VERSION \
679+
lua-$LUA_SHORT_VERSION \
680+
lua \
681+
],
682+
[_ax_found_lua_libs='yes'],
683+
[_ax_found_lua_libs='no'],
684+
[$_ax_lua_extra_libs])])
639685
LIBS=$_ax_lua_saved_libs
640686
641687
AS_IF([test "x$ac_cv_search_lua_load" != 'xno' &&

0 commit comments

Comments
 (0)