1# ===========================================================================
2#          http://www.gnu.org/software/autoconf-archive/ax_lua.html
3# ===========================================================================
4#
5# SYNOPSIS
6#
7#   AX_PROG_LUA[([MINIMUM-VERSION], [TOO-BIG-VERSION], [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])]
8#   AX_LUA_HEADERS[([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])]
9#   AX_LUA_LIBS[([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])]
10#   AX_LUA_READLINE[([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])]
11#
12# DESCRIPTION
13#
14#   Detect a Lua interpreter, optionally specifying a minimum and maximum
15#   version number. Set up important Lua paths, such as the directories in
16#   which to install scripts and modules (shared libraries).
17#
18#   Also detect Lua headers and libraries. The Lua version contained in the
19#   header is checked to match the Lua interpreter version exactly. When
20#   searching for Lua libraries, the version number is used as a suffix.
21#   This is done with the goal of supporting multiple Lua installs (5.1 and
22#   5.2 side-by-side).
23#
24#   A note on compatibility with previous versions: This file has been
25#   mostly rewritten for serial 18. Most developers should be able to use
26#   these macros without needing to modify configure.ac. Care has been taken
27#   to preserve each macro's behavior, but there are some differences:
28#
29#   1) AX_WITH_LUA is deprecated; it now expands to the exact same thing as
30#   AX_PROG_LUA with no arguments.
31#
32#   2) AX_LUA_HEADERS now checks that the version number defined in lua.h
33#   matches the interpreter version. AX_LUA_HEADERS_VERSION is therefore
34#   unnecessary, so it is deprecated and does not expand to anything.
35#
36#   3) The configure flag --with-lua-suffix no longer exists; the user
37#   should instead specify the LUA precious variable on the command line.
38#   See the AX_PROG_LUA description for details.
39#
40#   Please read the macro descriptions below for more information.
41#
42#   This file was inspired by Andrew Dalke's and James Henstridge's
43#   python.m4 and Tom Payne's, Matthieu Moy's, and Reuben Thomas's ax_lua.m4
44#   (serial 17). Basically, this file is a mash-up of those two files. I
45#   like to think it combines the best of the two!
46#
47#   AX_PROG_LUA: Search for the Lua interpreter, and set up important Lua
48#   paths. Adds precious variable LUA, which may contain the path of the Lua
49#   interpreter. If LUA is blank, the user's path is searched for an
50#   suitable interpreter.
51#
52#   If MINIMUM-VERSION is supplied, then only Lua interpreters with a
53#   version number greater or equal to MINIMUM-VERSION will be accepted. If
54#   TOO-BIG- VERSION is also supplied, then only Lua interpreters with a
55#   version number greater or equal to MINIMUM-VERSION and less than
56#   TOO-BIG-VERSION will be accepted.
57#
58#   The Lua version number, LUA_VERSION, is found from the interpreter, and
59#   substituted. LUA_PLATFORM is also found, but not currently supported (no
60#   standard representation).
61#
62#   Finally, the macro finds four paths:
63#
64#     luadir             Directory to install Lua scripts.
65#     pkgluadir          $luadir/$PACKAGE
66#     luaexecdir         Directory to install Lua modules.
67#     pkgluaexecdir      $luaexecdir/$PACKAGE
68#
69#   These paths a found based on $prefix, $exec_prefix, Lua's package.path,
70#   and package.cpath. The first path of package.path beginning with $prefix
71#   is selected as luadir. The first path of package.cpath beginning with
72#   $exec_prefix is used as luaexecdir. This should work on all reasonable
73#   Lua installations. If a path cannot be determined, a default path is
74#   used. Of course, the user can override these later when invoking make.
75#
76#     luadir             Default: $prefix/share/lua/$LUA_VERSION
77#     luaexecdir         Default: $exec_prefix/lib/lua/$LUA_VERSION
78#
79#   These directories can be used by Automake as install destinations. The
80#   variable name minus 'dir' needs to be used as a prefix to the
81#   appropriate Automake primary, e.g. lua_SCRIPS or luaexec_LIBRARIES.
82#
83#   If an acceptable Lua interpreter is found, then ACTION-IF-FOUND is
84#   performed, otherwise ACTION-IF-NOT-FOUND is preformed. If ACTION-IF-NOT-
85#   FOUND is blank, then it will default to printing an error. To prevent
86#   the default behavior, give ':' as an action.
87#
88#   AX_LUA_HEADERS: Search for Lua headers. Requires that AX_PROG_LUA be
89#   expanded before this macro. Adds precious variable LUA_INCLUDE, which
90#   may contain Lua specific include flags, e.g. -I/usr/include/lua5.1. If
91#   LUA_INCLUDE is blank, then this macro will attempt to find suitable
92#   flags.
93#
94#   LUA_INCLUDE can be used by Automake to compile Lua modules or
95#   executables with embedded interpreters. The *_CPPFLAGS variables should
96#   be used for this purpose, e.g. myprog_CPPFLAGS = $(LUA_INCLUDE).
97#
98#   This macro searches for the header lua.h (and others). The search is
99#   performed with a combination of CPPFLAGS, CPATH, etc, and LUA_INCLUDE.
100#   If the search is unsuccessful, then some common directories are tried.
101#   If the headers are then found, then LUA_INCLUDE is set accordingly.
102#
103#   The paths automatically searched are:
104#
105#     * /usr/include/luaX.Y
106#     * /usr/include/lua/X.Y
107#     * /usr/include/luaXY
108#     * /usr/local/include/luaX.Y
109#     * /usr/local/include/lua-X.Y
110#     * /usr/local/include/lua/X.Y
111#     * /usr/local/include/luaXY
112#
113#   (Where X.Y is the Lua version number, e.g. 5.1.)
114#
115#   The Lua version number found in the headers is always checked to match
116#   the Lua interpreter's version number. Lua headers with mismatched
117#   version numbers are not accepted.
118#
119#   If headers are found, then ACTION-IF-FOUND is performed, otherwise
120#   ACTION-IF-NOT-FOUND is performed. If ACTION-IF-NOT-FOUND is blank, then
121#   it will default to printing an error. To prevent the default behavior,
122#   set the action to ':'.
123#
124#   AX_LUA_LIBS: Search for Lua libraries. Requires that AX_PROG_LUA be
125#   expanded before this macro. Adds precious variable LUA_LIB, which may
126#   contain Lua specific linker flags, e.g. -llua5.1. If LUA_LIB is blank,
127#   then this macro will attempt to find suitable flags.
128#
129#   LUA_LIB can be used by Automake to link Lua modules or executables with
130#   embedded interpreters. The *_LIBADD and *_LDADD variables should be used
131#   for this purpose, e.g. mymod_LIBADD = $(LUA_LIB).
132#
133#   This macro searches for the Lua library. More technically, it searches
134#   for a library containing the function lua_load. The search is performed
135#   with a combination of LIBS, LIBRARY_PATH, and LUA_LIB.
136#
137#   If the search determines that some linker flags are missing, then those
138#   flags will be added to LUA_LIB.
139#
140#   If libraries are found, then ACTION-IF-FOUND is performed, otherwise
141#   ACTION-IF-NOT-FOUND is performed. If ACTION-IF-NOT-FOUND is blank, then
142#   it will default to printing an error. To prevent the default behavior,
143#   set the action to ':'.
144#
145#   AX_LUA_READLINE: Search for readline headers and libraries. Requires the
146#   AX_LIB_READLINE macro, which is provided by ax_lib_readline.m4 from the
147#   Autoconf Archive.
148#
149#   If a readline compatible library is found, then ACTION-IF-FOUND is
150#   performed, otherwise ACTION-IF-NOT-FOUND is performed.
151#
152# LICENSE
153#
154#   Copyright (c) 2014 Reuben Thomas <rrt@sc3d.org>
155#   Copyright (c) 2013 Tim Perkins <tprk77@gmail.com>
156#
157#   This program is free software: you can redistribute it and/or modify it
158#   under the terms of the GNU General Public License as published by the
159#   Free Software Foundation, either version 3 of the License, or (at your
160#   option) any later version.
161#
162#   This program is distributed in the hope that it will be useful, but
163#   WITHOUT ANY WARRANTY; without even the implied warranty of
164#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
165#   Public License for more details.
166#
167#   You should have received a copy of the GNU General Public License along
168#   with this program. If not, see <http://www.gnu.org/licenses/>.
169#
170#   As a special exception, the respective Autoconf Macro's copyright owner
171#   gives unlimited permission to copy, distribute and modify the configure
172#   scripts that are the output of Autoconf when processing the Macro. You
173#   need not follow the terms of the GNU General Public License when using
174#   or distributing such scripts, even though portions of the text of the
175#   Macro appear in them. The GNU General Public License (GPL) does govern
176#   all other use of the material that constitutes the Autoconf Macro.
177#
178#   This special exception to the GPL applies to versions of the Autoconf
179#   Macro released by the Autoconf Archive. When you make and distribute a
180#   modified version of the Autoconf Macro, you may extend this special
181#   exception to the GPL to apply to your modified version as well.
182
183#serial 26
184
185dnl =========================================================================
186dnl AX_PROG_LUA([MINIMUM-VERSION], [TOO-BIG-VERSION],
187dnl             [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
188dnl =========================================================================
189AC_DEFUN([AX_PROG_LUA],
190[
191  dnl Make LUA a precious variable.
192  AC_ARG_VAR([LUA], [The Lua interpreter, e.g. /usr/bin/lua5.1])
193
194  dnl Find a Lua interpreter.
195  m4_define_default([_AX_LUA_INTERPRETER_LIST],
196    [lua lua5.3 lua53 lua5.2 lua52 lua5.1 lua51 lua50])
197
198  m4_if([$1], [],
199  [ dnl No version check is needed. Find any Lua interpreter.
200    AS_IF([test "x$LUA" = 'x'],
201      [AC_PATH_PROGS([LUA], [_AX_LUA_INTERPRETER_LIST], [:])])
202    ax_display_LUA='lua'
203
204    dnl At least check if this is a Lua interpreter.
205    AC_MSG_CHECKING([if $LUA is a Lua interpreter])
206    _AX_LUA_CHK_IS_INTRP([$LUA],
207      [AC_MSG_RESULT([yes])],
208      [ AC_MSG_RESULT([no])
209        AC_MSG_ERROR([not a Lua interpreter])
210      ])
211  ],
212  [ dnl A version check is needed.
213    AS_IF([test "x$LUA" != 'x'],
214    [ dnl Check if this is a Lua interpreter.
215      AC_MSG_CHECKING([if $LUA is a Lua interpreter])
216      _AX_LUA_CHK_IS_INTRP([$LUA],
217        [AC_MSG_RESULT([yes])],
218        [ AC_MSG_RESULT([no])
219          AC_MSG_ERROR([not a Lua interpreter])
220        ])
221      dnl Check the version.
222      m4_if([$2], [],
223        [_ax_check_text="whether $LUA version >= $1"],
224        [_ax_check_text="whether $LUA version >= $1, < $2"])
225      AC_MSG_CHECKING([$_ax_check_text])
226      _AX_LUA_CHK_VER([$LUA], [$1], [$2],
227        [AC_MSG_RESULT([yes])],
228        [ AC_MSG_RESULT([no])
229          AC_MSG_ERROR([version is out of range for specified LUA])])
230      ax_display_LUA=$LUA
231    ],
232    [ dnl Try each interpreter until we find one that satisfies VERSION.
233      m4_if([$2], [],
234        [_ax_check_text="for a Lua interpreter with version >= $1"],
235        [_ax_check_text="for a Lua interpreter with version >= $1, < $2"])
236      AC_CACHE_CHECK([$_ax_check_text],
237        [ax_cv_pathless_LUA],
238        [ for ax_cv_pathless_LUA in _AX_LUA_INTERPRETER_LIST none; do
239            test "x$ax_cv_pathless_LUA" = 'xnone' && break
240            _AX_LUA_CHK_IS_INTRP([$ax_cv_pathless_LUA], [], [continue])
241            _AX_LUA_CHK_VER([$ax_cv_pathless_LUA], [$1], [$2], [break])
242          done
243        ])
244      dnl Set $LUA to the absolute path of $ax_cv_pathless_LUA.
245      AS_IF([test "x$ax_cv_pathless_LUA" = 'xnone'],
246        [LUA=':'],
247        [AC_PATH_PROG([LUA], [$ax_cv_pathless_LUA])])
248      ax_display_LUA=$ax_cv_pathless_LUA
249    ])
250  ])
251
252  AS_IF([test "x$LUA" = 'x:'],
253  [ dnl Run any user-specified action, or abort.
254    m4_default([$4], [AC_MSG_ERROR([cannot find suitable Lua interpreter])])
255  ],
256  [ dnl Query Lua for its version number.
257    AC_CACHE_CHECK([for $ax_display_LUA version], [ax_cv_lua_version],
258      [ ax_cv_lua_version=`$LUA -e 'print(_VERSION:match "(%d+%.%d+)")'` ])
259    AS_IF([test "x$ax_cv_lua_version" = 'x'],
260      [AC_MSG_ERROR([invalid Lua version number])])
261    AC_SUBST([LUA_VERSION], [$ax_cv_lua_version])
262    AC_SUBST([LUA_SHORT_VERSION], [`echo "$LUA_VERSION" | sed 's|\.||'`])
263
264    dnl The following check is not supported:
265    dnl At times (like when building shared libraries) you may want to know
266    dnl which OS platform Lua thinks this is.
267    AC_CACHE_CHECK([for $ax_display_LUA platform], [ax_cv_lua_platform],
268      [ax_cv_lua_platform=`$LUA -e "print('unknown')"`])
269    AC_SUBST([LUA_PLATFORM], [$ax_cv_lua_platform])
270
271    dnl Use the values of $prefix and $exec_prefix for the corresponding
272    dnl values of LUA_PREFIX and LUA_EXEC_PREFIX. These are made distinct
273    dnl variables so they can be overridden if need be. However, the general
274    dnl consensus is that you shouldn't need this ability.
275    AC_SUBST([LUA_PREFIX], ['${prefix}'])
276    AC_SUBST([LUA_EXEC_PREFIX], ['${exec_prefix}'])
277
278    dnl Lua provides no way to query the script directory, and instead
279    dnl provides LUA_PATH. However, we should be able to make a safe educated
280    dnl guess. If the built-in search path contains a directory which is
281    dnl prefixed by $prefix, then we can store scripts there. The first
282    dnl matching path will be used.
283    AC_CACHE_CHECK([for $ax_display_LUA script directory],
284      [ax_cv_lua_luadir],
285      [ AS_IF([test "x$prefix" = 'xNONE'],
286          [ax_lua_prefix=$ac_default_prefix],
287          [ax_lua_prefix=$prefix])
288
289        dnl Initialize to the default path.
290        ax_cv_lua_luadir="$LUA_PREFIX/share/lua/$LUA_VERSION"
291
292        dnl Try to find a path with the prefix.
293        _AX_LUA_FND_PRFX_PTH([$LUA], [$ax_lua_prefix], [package.path])
294        AS_IF([test "x$ax_lua_prefixed_path" != 'x'],
295        [ dnl Fix the prefix.
296          _ax_strip_prefix=`echo "$ax_lua_prefix" | sed 's|.|.|g'`
297          ax_cv_lua_luadir=`echo "$ax_lua_prefixed_path" | \
298            sed "s,^$_ax_strip_prefix,$LUA_PREFIX,"`
299        ])
300      ])
301    AC_SUBST([luadir], [$ax_cv_lua_luadir])
302    AC_SUBST([pkgluadir], [\${luadir}/$PACKAGE])
303
304    dnl Lua provides no way to query the module directory, and instead
305    dnl provides LUA_PATH. However, we should be able to make a safe educated
306    dnl guess. If the built-in search path contains a directory which is
307    dnl prefixed by $exec_prefix, then we can store modules there. The first
308    dnl matching path will be used.
309    AC_CACHE_CHECK([for $ax_display_LUA module directory],
310      [ax_cv_lua_luaexecdir],
311      [ AS_IF([test "x$exec_prefix" = 'xNONE'],
312          [ax_lua_exec_prefix=$ax_lua_prefix],
313          [ax_lua_exec_prefix=$exec_prefix])
314
315        dnl Initialize to the default path.
316        ax_cv_lua_luaexecdir="$LUA_EXEC_PREFIX/lib/lua/$LUA_VERSION"
317
318        dnl Try to find a path with the prefix.
319        _AX_LUA_FND_PRFX_PTH([$LUA],
320          [$ax_lua_exec_prefix], [package.cpath])
321        AS_IF([test "x$ax_lua_prefixed_path" != 'x'],
322        [ dnl Fix the prefix.
323          _ax_strip_prefix=`echo "$ax_lua_exec_prefix" | sed 's|.|.|g'`
324          ax_cv_lua_luaexecdir=`echo "$ax_lua_prefixed_path" | \
325            sed "s,^$_ax_strip_prefix,$LUA_EXEC_PREFIX,"`
326        ])
327      ])
328    AC_SUBST([luaexecdir], [$ax_cv_lua_luaexecdir])
329    AC_SUBST([pkgluaexecdir], [\${luaexecdir}/$PACKAGE])
330
331    dnl Run any user specified action.
332    $3
333  ])
334])
335
336dnl AX_WITH_LUA is now the same thing as AX_PROG_LUA.
337AC_DEFUN([AX_WITH_LUA],
338[
339  AC_MSG_WARN([[$0 is deprecated, please use AX_PROG_LUA]])
340  AX_PROG_LUA
341])
342
343
344dnl =========================================================================
345dnl _AX_LUA_CHK_IS_INTRP(PROG, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
346dnl =========================================================================
347AC_DEFUN([_AX_LUA_CHK_IS_INTRP],
348[
349  dnl Just print _VERSION because all Lua interpreters have this global.
350  AS_IF([$1 -e "print('Hello ' .. _VERSION .. '!')" >/dev/null 2>&1],
351    [$2], [$3])
352])
353
354
355dnl =========================================================================
356dnl _AX_LUA_CHK_VER(PROG, MINIMUM-VERSION, [TOO-BIG-VERSION],
357dnl                 [ACTION-IF-TRUE], [ACTION-IF-FALSE])
358dnl =========================================================================
359AC_DEFUN([_AX_LUA_CHK_VER],
360[
361  AS_IF([$1 2>/dev/null -e '
362        function norm (v) i,j=v:match "(%d+)%.(%d+)" return 100 * i + j end
363        v=norm (_VERSION)
364        os.exit ((v >= norm ("$2") and v < norm ("$3")) and 0 or 1)'],
365    [$4], [$5])
366])
367
368
369dnl =========================================================================
370dnl _AX_LUA_FND_PRFX_PTH(PROG, PREFIX, LUA-PATH-VARIABLE)
371dnl =========================================================================
372AC_DEFUN([_AX_LUA_FND_PRFX_PTH],
373[
374  dnl Invokes the Lua interpreter PROG to print the path variable
375  dnl LUA-PATH-VARIABLE, usually package.path or package.cpath. Paths are
376  dnl then matched against PREFIX. The first path to begin with PREFIX is set
377  dnl to ax_lua_prefixed_path.
378
379  ax_lua_prefixed_path=''
380  _ax_package_paths=`$1 -e 'print($3)' 2>/dev/null | sed 's|;|\n|g'`
381  dnl Try the paths in order, looking for the prefix.
382  for _ax_package_path in $_ax_package_paths; do
383    dnl Copy the path, up to the use of a Lua wildcard.
384    _ax_path_parts=`echo "$_ax_package_path" | sed 's|/|\n|g'`
385    _ax_reassembled=''
386    for _ax_path_part in $_ax_path_parts; do
387      echo "$_ax_path_part" | grep '\?' >/dev/null && break
388      _ax_reassembled="$_ax_reassembled/$_ax_path_part"
389    done
390    dnl Check the path against the prefix.
391    _ax_package_path=$_ax_reassembled
392    if echo "$_ax_package_path" | grep "^$2" >/dev/null; then
393      dnl Found it.
394      ax_lua_prefixed_path=$_ax_package_path
395      break
396    fi
397  done
398])
399
400
401dnl =========================================================================
402dnl AX_LUA_HEADERS([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
403dnl =========================================================================
404AC_DEFUN([AX_LUA_HEADERS],
405[
406  dnl Check for LUA_VERSION.
407  AC_MSG_CHECKING([if LUA_VERSION is defined])
408  AS_IF([test "x$LUA_VERSION" != 'x'],
409    [AC_MSG_RESULT([yes])],
410    [ AC_MSG_RESULT([no])
411      AC_MSG_ERROR([cannot check Lua headers without knowing LUA_VERSION])
412    ])
413
414  dnl Make LUA_INCLUDE a precious variable.
415  AC_ARG_VAR([LUA_INCLUDE], [The Lua includes, e.g. -I/usr/include/lua5.1])
416
417  dnl Some default directories to search.
418  LUA_SHORT_VERSION=`echo "$LUA_VERSION" | sed 's|\.||'`
419  m4_define_default([_AX_LUA_INCLUDE_LIST],
420    [ /usr/include/lua$LUA_VERSION \
421      /usr/include/lua/$LUA_VERSION \
422      /usr/include/lua$LUA_SHORT_VERSION \
423      /usr/local/include/lua$LUA_VERSION \
424      /usr/local/include/lua-$LUA_VERSION \
425      /usr/local/include/lua/$LUA_VERSION \
426      /usr/local/include/lua$LUA_SHORT_VERSION \
427    ])
428
429  dnl Try to find the headers.
430  _ax_lua_saved_cppflags=$CPPFLAGS
431  CPPFLAGS="$CPPFLAGS $LUA_INCLUDE"
432  AC_CHECK_HEADERS([lua.h lualib.h lauxlib.h luaconf.h])
433  CPPFLAGS=$_ax_lua_saved_cppflags
434
435  dnl Try some other directories if LUA_INCLUDE was not set.
436  AS_IF([test "x$LUA_INCLUDE" = 'x' &&
437         test "x$ac_cv_header_lua_h" != 'xyes'],
438    [ dnl Try some common include paths.
439      for _ax_include_path in _AX_LUA_INCLUDE_LIST; do
440        test ! -d "$_ax_include_path" && continue
441
442        AC_MSG_CHECKING([for Lua headers in])
443        AC_MSG_RESULT([$_ax_include_path])
444
445        AS_UNSET([ac_cv_header_lua_h])
446        AS_UNSET([ac_cv_header_lualib_h])
447        AS_UNSET([ac_cv_header_lauxlib_h])
448        AS_UNSET([ac_cv_header_luaconf_h])
449
450        _ax_lua_saved_cppflags=$CPPFLAGS
451        CPPFLAGS="$CPPFLAGS -I$_ax_include_path"
452        AC_CHECK_HEADERS([lua.h lualib.h lauxlib.h luaconf.h])
453        CPPFLAGS=$_ax_lua_saved_cppflags
454
455        AS_IF([test "x$ac_cv_header_lua_h" = 'xyes'],
456          [ LUA_INCLUDE="-I$_ax_include_path"
457            break
458          ])
459      done
460    ])
461
462  AS_IF([test "x$ac_cv_header_lua_h" = 'xyes' && test "x$cross_compiling" != 'xyes'],
463    [ dnl Make a program to print LUA_VERSION defined in the header.
464      dnl TODO This probably shouldn't be a runtime test.
465
466      AC_CACHE_CHECK([for Lua header version],
467        [ax_cv_lua_header_version],
468        [ _ax_lua_saved_cppflags=$CPPFLAGS
469          CPPFLAGS="$CPPFLAGS $LUA_INCLUDE"
470          AC_RUN_IFELSE(
471            [ AC_LANG_SOURCE([[
472#include <lua.h>
473#include <stdlib.h>
474#include <stdio.h>
475int main(int argc, char ** argv)
476{
477  if(argc > 1) printf("%s", LUA_VERSION);
478  exit(EXIT_SUCCESS);
479}
480]])
481            ],
482            [ ax_cv_lua_header_version=`./conftest$EXEEXT p | \
483                sed "s|^Lua \(.*\)|\1|" | \
484                grep -E -o "^@<:@0-9@:>@+\.@<:@0-9@:>@+"`
485            ],
486            [ax_cv_lua_header_version='unknown'])
487          CPPFLAGS=$_ax_lua_saved_cppflags
488        ])
489
490      dnl Compare this to the previously found LUA_VERSION.
491      AC_MSG_CHECKING([if Lua header version matches $LUA_VERSION])
492      AS_IF([test "x$ax_cv_lua_header_version" = "x$LUA_VERSION"],
493        [ AC_MSG_RESULT([yes])
494          ax_header_version_match='yes'
495        ],
496        [ AC_MSG_RESULT([no])
497          ax_header_version_match='no'
498        ])
499    ],
500    [
501        ax_header_version_match='yes'
502    ])
503
504  dnl Was LUA_INCLUDE specified?
505  AS_IF([test "x$ax_header_version_match" != 'xyes' &&
506         test "x$LUA_INCLUDE" != 'x'],
507    [AC_MSG_ERROR([cannot find headers for specified LUA_INCLUDE])])
508
509  dnl Test the final result and run user code.
510  AS_IF([test "x$ax_header_version_match" = 'xyes'], [$1],
511    [m4_default([$2], [AC_MSG_ERROR([cannot find Lua includes])])])
512])
513
514dnl AX_LUA_HEADERS_VERSION no longer exists, use AX_LUA_HEADERS.
515AC_DEFUN([AX_LUA_HEADERS_VERSION],
516[
517  AC_MSG_WARN([[$0 is deprecated, please use AX_LUA_HEADERS]])
518])
519
520
521dnl =========================================================================
522dnl AX_LUA_LIBS([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
523dnl =========================================================================
524AC_DEFUN([AX_LUA_LIBS],
525[
526  dnl TODO Should this macro also check various -L flags?
527
528  dnl Check for LUA_VERSION.
529  AC_MSG_CHECKING([if LUA_VERSION is defined])
530  AS_IF([test "x$LUA_VERSION" != 'x'],
531    [AC_MSG_RESULT([yes])],
532    [ AC_MSG_RESULT([no])
533      AC_MSG_ERROR([cannot check Lua libs without knowing LUA_VERSION])
534    ])
535
536  dnl Make LUA_LIB a precious variable.
537  AC_ARG_VAR([LUA_LIB], [The Lua library, e.g. -llua5.1])
538
539  AS_IF([test "x$LUA_LIB" != 'x'],
540  [ dnl Check that LUA_LIBS works.
541    _ax_lua_saved_libs=$LIBS
542    LIBS="$LIBS $LUA_LIB"
543    AC_SEARCH_LIBS([lua_load], [],
544      [_ax_found_lua_libs='yes'],
545      [_ax_found_lua_libs='no'])
546    LIBS=$_ax_lua_saved_libs
547
548    dnl Check the result.
549    AS_IF([test "x$_ax_found_lua_libs" != 'xyes'],
550      [AC_MSG_ERROR([cannot find libs for specified LUA_LIB])])
551  ],
552  [ dnl First search for extra libs.
553    _ax_lua_extra_libs=''
554
555    _ax_lua_saved_libs=$LIBS
556    LIBS="$LIBS $LUA_LIB"
557    AC_SEARCH_LIBS([exp], [m])
558    AC_SEARCH_LIBS([dlopen], [dl])
559    LIBS=$_ax_lua_saved_libs
560
561    AS_IF([test "x$ac_cv_search_exp" != 'xno' &&
562           test "x$ac_cv_search_exp" != 'xnone required'],
563      [_ax_lua_extra_libs="$_ax_lua_extra_libs $ac_cv_search_exp"])
564
565    AS_IF([test "x$ac_cv_search_dlopen" != 'xno' &&
566           test "x$ac_cv_search_dlopen" != 'xnone required'],
567      [_ax_lua_extra_libs="$_ax_lua_extra_libs $ac_cv_search_dlopen"])
568
569    dnl Try to find the Lua libs.
570    _ax_lua_saved_libs=$LIBS
571    LIBS="$LIBS $LUA_LIB"
572    AC_SEARCH_LIBS([lua_load],
573                   [ lua$LUA_VERSION \
574                     lua$LUA_SHORT_VERSION \
575                     lua-$LUA_VERSION \
576                     lua-$LUA_SHORT_VERSION \
577                     lua],
578                   [_ax_found_lua_libs='yes'],
579                   [_ax_found_lua_libs='no'],
580                   [$_ax_lua_extra_libs])
581    LIBS=$_ax_lua_saved_libs
582
583    AS_IF([test "x$ac_cv_search_lua_load" != 'xno' &&
584           test "x$ac_cv_search_lua_load" != 'xnone required'],
585      [LUA_LIB="$ac_cv_search_lua_load $_ax_lua_extra_libs"])
586  ])
587
588  dnl Test the result and run user code.
589  AS_IF([test "x$_ax_found_lua_libs" = 'xyes'], [$1],
590    [m4_default([$2], [AC_MSG_ERROR([cannot find Lua libs])])])
591])
592
593
594dnl =========================================================================
595dnl AX_LUA_READLINE([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
596dnl =========================================================================
597AC_DEFUN([AX_LUA_READLINE],
598[
599  AX_LIB_READLINE
600  AS_IF([test "x$ac_cv_header_readline_readline_h" != 'x' &&
601         test "x$ac_cv_header_readline_history_h" != 'x'],
602    [ LUA_LIBS_CFLAGS="-DLUA_USE_READLINE $LUA_LIBS_CFLAGS"
603      $1
604    ],
605    [$2])
606])
607