m4/my_lib_readline: Fix check for additional libraries
authorMarkus Armbruster <armbru@pond.sub.org>
Tue, 29 Dec 2020 04:56:12 +0000 (05:56 +0100)
committerMarkus Armbruster <armbru@pond.sub.org>
Sat, 23 Jan 2021 06:08:21 +0000 (07:08 +0100)
MY_LIB_READLINE tries each readline-compatible library with a sequence
of additional libraries, starting with none.  If the check with none
fails, all the others checks reuse the cached result, and also fail.
Broken in commit 1cbda2c7d "client: Rewrite readline configuration",
v4.4.0.

Avoid the unwanted chaching.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
m4/my_lib_readline.m4

index 37fedec5610681e577bcbf6d52d6991955c5c2eb..34452215c2f137c37575c0dda18f40710f55a90f 100644 (file)
@@ -1,40 +1,52 @@
 AC_DEFUN([MY_LIB_READLINE], [
-    have_readline=no
-    for readline_lib in readline edit editline; do
-       for termcap_lib in "" termlib termcap curses ncurses; do
-         AC_CHECK_LIB([$readline_lib], [add_history],
-             [have_readline=yes; break 2], [], [$termcap_lib])
+    AC_CACHE_CHECK([for a readline compatible library],
+                  my_cv_lib_readline, [
+       my_lib_readline_save_LIBS="$LIBS"
+       for readline_lib in readline edit editline; do
+           for termcap_lib in "" termlib termcap curses ncurses; do
+               if test -z "$termcap_lib"; then
+                   my_cv_lib_readline="-l$readline_lib"
+               else
+                   my_cv_lib_readline="-l$readline_lib -l$termcap_lib"
+               fi
+               LIBS="$my_cv_lib_readline $my_lib_readline_save_LIBS"
+               AC_LINK_IFELSE([AC_LANG_CALL([], [add_history])],
+                              [break 2], [my_cv_lib_readline=no])
+           done
        done
-    done
+    ])
 
-    if test "$have_readline" = yes; then
-       AC_CHECK_HEADER([readline/readline.h], [], [have_readline=no],
+    if test "$my_cv_lib_readline" != no; then
+       AC_CHECK_HEADER([readline/readline.h], [], [my_cv_lib_readline=no],
                        [AC_INCLUDES_DEFAULT])
-       AC_CHECK_HEADER([readline/history.h], [], [have_readline=no],
+    fi
+    if test "$my_cv_lib_readline" != no; then
+       AC_CHECK_HEADER([readline/history.h], [], [my_cv_lib_readline=no],
                        [AC_INCLUDES_DEFAULT])
     fi
 
-    if test "$have_readline" = yes; then
-       if test "x$termcap_lib" != x; then
-           LIBS="-l$termcap_lib $LIBS"
-       fi
-       LIBS="-l$readline_lib $LIBS"
+    if test "$my_cv_lib_readline" = no; then
+       LIBS="$my_lib_readline_save_LIBS"
+    else
        AC_DEFINE([HAVE_LIBREADLINE], [1],
                  [Define if you have libreadline])
     fi
 ])
 
-AC_DEFUN([MY_WITH_READLINE],
-[
-  AC_ARG_WITH([readline],
-    [AS_HELP_STRING([--with-readline],
-      [support fancy command line editing @<:@default=check@:>@])],
-    [],
-    [with_readline=check])
-  if test "x$with_readline" != xno; then
-      MY_LIB_READLINE
-      if test "x$have_readline$with_readline" = xnoyes; then
-         AC_MSG_FAILURE([--with-readline was given, but test for readline failed])
-      fi
-      with_readline="$have_readline"
-  fi])
+AC_DEFUN([MY_WITH_READLINE], [
+    AC_ARG_WITH([readline],
+       [AS_HELP_STRING([--with-readline],
+         [support fancy command line editing @<:@default=check@:>@])],
+       [],
+       [with_readline=check])
+    if test "x$with_readline" != xno; then
+       MY_LIB_READLINE
+       if test "x$my_cv_lib_readline$with_readline" = xnoyes; then
+           AC_MSG_FAILURE([--with-readline was given, but test for readline failed])
+       fi
+       if test "$my_cv_lib_readline" = no; then
+           with_readline=no
+       else
+           with_readline=yes
+       fi
+    fi])