[vlc-commits] configure.ac: refactor lua detection

Alexandre Janniaux git at videolan.org
Sat Apr 11 09:13:21 CEST 2020


vlc | branch: master | Alexandre Janniaux <ajanni at videolabs.io> | Mon Apr  6 11:23:56 2020 +0200| [c30aabf762c6dec3d7ad49e2796fda6ab745c376] | committer: Alexandre Janniaux

configure.ac: refactor lua detection

All checks were nested which was really hard to read and modify
correctly. Instead use a state variable to track the detection status
and chain AS_IF condition for each test.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=c30aabf762c6dec3d7ad49e2796fda6ab745c376
---

 configure.ac | 64 +++++++++++++++++++++++++++++++++---------------------------
 1 file changed, 35 insertions(+), 29 deletions(-)

diff --git a/configure.ac b/configure.ac
index 4fd1240d09..55b898f4fc 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1859,37 +1859,43 @@ AC_ARG_ENABLE([lua],
     [disable LUA scripting support (default enabled)]))
 if test "${enable_lua}" != "no"
 then
-  PKG_CHECK_MODULES(LUA, lua5.2,
-    [ have_lua=yes ],
-    [
+  PKG_CHECK_MODULES(LUA, lua5.2, [ have_lua=yes ], [])
+
+  AS_IF([test "${have_lua}" != "yes"], [
     AC_MSG_WARN([${LUA_PKG_ERRORS}, trying lua 5.1 instead])
+    PKG_CHECK_MODULES(LUA, lua5.1, [ have_lua=yes ], []) ])
+
+  AS_IF([test "${have_lua}" != "yes"], [
+    AC_MSG_WARN([${LUA_PKG_ERRORS}, trying lua >= 5.1 instead])
+    PKG_CHECK_MODULES(LUA, lua >= 5.1, [ have_lua=yes ], []) ])
+
+  AS_IF([test "${have_lua}" != "yes"], [
+     AC_MSG_WARN([${LUA_PKG_ERRORS}, trying manual detection instead])
+     have_lua_lib=no
+     AC_CHECK_LIB( lua5.2 , luaL_newstate, [
+       LUA_LIBS="-llua5.2"
+       have_lua_lib=yes], [])
+
+     AS_IF([test "${have_lua_lib}" != "yes"], [
+       AC_CHECK_LIB( lua5.1 , luaL_newstate, [
+         LUA_LIBS="-llua5.1"
+         have_lua_lib=yes], [] ) ])
+
+     AS_IF([test "${have_lua_lib}" != "yes"], [
+       AC_CHECK_LIB( lua51 , luaL_newstate, [
+         LUA_LIBS="-llua51"
+         have_lua_lib=yes], [] ) ])
+
+     AS_IF([test "${have_lua_lib}" != "yes"], [
+       AC_CHECK_LIB( lua , luaL_newstate,
+         [LUA_LIBS="-llua"],
+         [ have_lua=no ], [-lm] ) ])
+
+     dnl If we found any lib, check that we have the headers too
+     AS_IF([test "${have_lua_lib}" = "yes"], [
+       AC_CHECK_HEADERS([lua.h lauxlib.h lualib.h], [ have_lua=yes ], []) ])
+  ])
 
-    PKG_CHECK_MODULES(LUA, lua5.1,
-      [ have_lua=yes ],
-      [
-      AC_MSG_WARN([${LUA_PKG_ERRORS}, trying lua >= 5.1 instead])
-      PKG_CHECK_MODULES(LUA, lua >= 5.1,
-        [ have_lua=yes ],
-        [
-          AC_MSG_WARN([${LUA_PKG_ERRORS}, trying manual detection instead])
-          have_lua=yes
-          AC_CHECK_HEADERS([lua.h lauxlib.h lualib.h],
-            [],
-            [ have_lua=no ] )
-          AC_CHECK_LIB(  lua5.2 , luaL_newstate,
-            [LUA_LIBS="-llua5.2"],
-          AC_CHECK_LIB( lua5.1 , luaL_newstate,
-            [LUA_LIBS="-llua5.1"],
-            AC_CHECK_LIB( lua51 , luaL_newstate,
-              [LUA_LIBS="-llua51"],
-              AC_CHECK_LIB( lua , luaL_newstate,
-                [LUA_LIBS="-llua"],
-                [ have_lua=no
-                ], [-lm])
-            )))
-        ])
-      ])
-    ])
   if test "x${have_lua}" != "xyes" ;  then
       AC_MSG_ERROR([Could not find lua. Lua is needed for some interfaces (rc, telnet, http) as well as many other custom scripts. Use --disable-lua to ignore this error.])
   fi



More information about the vlc-commits mailing list