]> git.ipfire.org Git - people/ms/libloc.git/blob - m4/ax_prog_lua_modules.m4
lua: Fix raising an exception if no network was found
[people/ms/libloc.git] / m4 / ax_prog_lua_modules.m4
1 #
2 # SYNOPSIS
3 #
4 # AX_PROG_LUA_MODULES([MODULES], [ACTION-IF-TRUE], [ACTION-IF-FALSE])
5 #
6 # DESCRIPTION
7 #
8 # Checks to see if the given Lua modules are available. If true the shell
9 # commands in ACTION-IF-TRUE are executed. If not the shell commands in
10 # ACTION-IF-FALSE are run. Note if $LUA is not set (for example by
11 # calling AC_CHECK_PROG, or AC_PATH_PROG), AC_CHECK_PROG(LUA, lua, lua)
12 # will be run.
13 #
14 # MODULES is a space separated list of module names. To check for a
15 # minimum version of a module, append the version number to the module
16 # name, separated by an equals sign.
17 #
18 # Example:
19 #
20 # AX_PROG_LUA_MODULES(module=1.0.3,, AC_MSG_WARN(Need some Lua modules)
21 #
22 # LICENSE
23 #
24 # Copyright (c) 2024 Michael Tremer <michael.tremer@lightningwirelabs.com>
25 #
26 # Copying and distribution of this file, with or without modification, are
27 # permitted in any medium without royalty provided the copyright notice
28 # and this notice are preserved. This file is offered as-is, without any
29 # warranty.
30
31 AU_ALIAS([AC_PROG_LUA_MODULES], [AX_PROG_LUA_MODULES])
32 AC_DEFUN([AX_PROG_LUA_MODULES], [dnl
33 m4_define([ax_lua_modules])
34 m4_foreach([ax_lua_module], m4_split(m4_normalize([$1])), [
35 m4_append([ax_lua_modules], [']m4_bpatsubst(ax_lua_module,=,[ ])[' ])
36 ])
37
38 # Make sure we have Lua
39 if test -z "$LUA"; then
40 AC_CHECK_PROG(LUA, lua, lua)
41 fi
42
43 if test "x$LUA" != x; then
44 ax_lua_modules_failed=0
45 for ax_lua_module in ax_lua_modules; do
46 AC_MSG_CHECKING(for Lua module $ax_lua_module)
47
48 # Would be nice to log result here, but can't rely on autoconf internals
49 $LUA -e "require('$ax_lua_module')" > /dev/null 2>&1
50 if test $? -ne 0; then
51 AC_MSG_RESULT(no);
52 ax_lua_modules_failed=1
53 else
54 AC_MSG_RESULT(ok);
55 fi
56 done
57
58 # Run optional shell commands
59 if test "$ax_lua_modules_failed" = 0; then
60 :; $2
61 else
62 :; $3
63 fi
64 else
65 AC_MSG_WARN(could not find Lua)
66 fi
67 ])dnl