1
1
# ===========================================================================
2
- # http ://www.gnu.org/software/autoconf-archive/ax_lua.html
2
+ # https ://www.gnu.org/software/autoconf-archive/ax_lua.html
3
3
# ===========================================================================
4
4
#
5
5
# SYNOPSIS
19
19
# header is checked to match the Lua interpreter version exactly. When
20
20
# searching for Lua libraries, the version number is used as a suffix.
21
21
# 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).
23
23
#
24
24
# A note on compatibility with previous versions: This file has been
25
25
# mostly rewritten for serial 18. Most developers should be able to use
49
49
# interpreter. If LUA is blank, the user's path is searched for an
50
50
# suitable interpreter.
51
51
#
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
+ #
52
60
# If MINIMUM-VERSION is supplied, then only Lua interpreters with a
53
61
# version number greater or equal to MINIMUM-VERSION will be accepted. If
54
62
# TOO-BIG-VERSION is also supplied, then only Lua interpreters with a
152
160
#
153
161
# LICENSE
154
162
#
163
+ # Copyright (c) 2023 Caleb Maclennan <[email protected] >
155
164
# Copyright (c) 2015 Reuben Thomas <[email protected] >
156
165
# Copyright (c) 2014 Tim Perkins <[email protected] >
157
166
#
166
175
# Public License for more details.
167
176
#
168
177
# 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/>.
170
179
#
171
180
# As a special exception, the respective Autoconf Macro's copyright owner
172
181
# gives unlimited permission to copy, distribute and modify the configure
181
190
# modified version of the Autoconf Macro, you may extend this special
182
191
# exception to the GPL to apply to your modified version as well.
183
192
184
- # serial 39
193
+ # serial 47
185
194
186
195
dnl =========================================================================
187
196
dnl AX_PROG_LUA([MINIMUM-VERSION], [TOO-BIG-VERSION],
@@ -197,13 +206,14 @@ AC_DEFUN([AX_PROG_LUA],
197
206
AC_ARG_VAR ( [ LUA] , [ The Lua interpreter, e.g. /usr/bin/lua5.1] )
198
207
199
208
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'] )
202
212
203
213
m4_if ( [ $1 ] , [ ] ,
204
214
[ dnl No version check is needed. Find any Lua interpreter.
205
215
AS_IF ( [ test "x$LUA" = 'x'] ,
206
- [ AC_PATH_PROGS ( [ LUA] , [ _AX_LUA_INTERPRETER_LIST ] , [ :] ) ] )
216
+ [ AC_PATH_PROGS ( [ LUA] , [ $_ax_lua_interpreter_list ] , [ :] ) ] )
207
217
ax_display_LUA='lua'
208
218
209
219
AS_IF ( [ test "x$LUA" != 'x:'] ,
@@ -242,7 +252,7 @@ AC_DEFUN([AX_PROG_LUA],
242
252
[ _ax_check_text="for a Lua interpreter with version >= $1 , < $2 "] )
243
253
AC_CACHE_CHECK ( [ $_ax_check_text] ,
244
254
[ 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
246
256
test "x$ax_cv_pathless_LUA" = 'xnone' && break
247
257
_AX_LUA_CHK_IS_INTRP([ $ax_cv_pathless_LUA] , [ ] , [ continue] )
248
258
_AX_LUA_CHK_VER([ $ax_cv_pathless_LUA] , [ $1 ] , [ $2 ] , [ break] )
@@ -268,13 +278,25 @@ AC_DEFUN([AX_PROG_LUA],
268
278
ax_cv_lua_version=[ `$LUA -e '
269
279
-- return a version number in X.Y format
270
280
local _, _, ver = string.find(_VERSION, "^Lua (%d+%.%d+)")
271
- print(ver)'`]
281
+ print(ver or "" )'`]
272
282
] )
273
283
AS_IF ( [ test "x$ax_cv_lua_version" = 'x'] ,
274
284
[ AC_MSG_ERROR ( [ invalid Lua version number] ) ] )
275
285
AC_SUBST ( [ LUA_VERSION] , [ $ax_cv_lua_version] )
276
286
AC_SUBST ( [ LUA_SHORT_VERSION] , [ `echo "$LUA_VERSION" | $SED 's|\.||'`] )
277
287
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
+
278
300
dnl The following check is not supported:
279
301
dnl At times (like when building shared libraries) you may want to know
280
302
dnl which OS platform Lua thinks this is.
@@ -464,33 +486,50 @@ AC_DEFUN([AX_LUA_HEADERS],
464
486
AC_MSG_ERROR ( [ cannot check Lua headers without knowing LUA_VERSION] )
465
487
] )
466
488
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
+
467
499
dnl Make LUA_INCLUDE a precious variable.
468
500
AC_ARG_VAR ( [ LUA_INCLUDE] , [ The Lua includes, e.g. -I/usr/include/lua5.1] )
469
501
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"] )
482
518
483
519
dnl Try to find the headers.
484
520
_ax_lua_saved_cppflags=$CPPFLAGS
485
521
CPPFLAGS="$CPPFLAGS $LUA_INCLUDE"
486
522
AC_CHECK_HEADERS ( [ lua.h lualib.h lauxlib.h luaconf.h] )
523
+ AM_COND_IF([ LUAJIT] , [ AC_CHECK_HEADERS ( [ luajit.h] ) ] )
487
524
CPPFLAGS=$_ax_lua_saved_cppflags
488
525
489
526
dnl Try some other directories if LUA_INCLUDE was not set.
490
527
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'] ,
492
531
[ 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
494
533
test ! -d "$_ax_include_path" && continue
495
534
496
535
AC_MSG_CHECKING ( [ for Lua headers in] )
@@ -500,10 +539,12 @@ AC_DEFUN([AX_LUA_HEADERS],
500
539
AS_UNSET ( [ ac_cv_header_lualib_h] )
501
540
AS_UNSET ( [ ac_cv_header_lauxlib_h] )
502
541
AS_UNSET ( [ ac_cv_header_luaconf_h] )
542
+ AS_UNSET ( [ ac_cv_header_luajit_h] )
503
543
504
544
_ax_lua_saved_cppflags=$CPPFLAGS
505
545
CPPFLAGS="$CPPFLAGS -I$_ax_include_path"
506
546
AC_CHECK_HEADERS ( [ lua.h lualib.h lauxlib.h luaconf.h] )
547
+ AM_COND_IF([ LUAJIT] , [ AC_CHECK_HEADERS ( [ luajit.h] ) ] )
507
548
CPPFLAGS=$_ax_lua_saved_cppflags
508
549
509
550
AS_IF ( [ test "x$ac_cv_header_lua_h" = 'xyes'] ,
@@ -524,22 +565,17 @@ AC_DEFUN([AX_LUA_HEADERS],
524
565
[ ax_cv_lua_header_version] ,
525
566
[ _ax_lua_saved_cppflags=$CPPFLAGS
526
567
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
529
569
#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
+ ] )
543
579
CPPFLAGS=$_ax_lua_saved_cppflags
544
580
] )
545
581
@@ -626,16 +662,26 @@ AC_DEFUN([AX_LUA_LIBS],
626
662
dnl Try to find the Lua libs.
627
663
_ax_lua_saved_libs=$LIBS
628
664
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] ) ] )
639
685
LIBS=$_ax_lua_saved_libs
640
686
641
687
AS_IF ( [ test "x$ac_cv_search_lua_load" != 'xno' &&
0 commit comments