From db6b99f1b2cfb235a121519a2419894c2538828c Mon Sep 17 00:00:00 2001
From: Ray Donnelly <mingw.android@gmail.com>
Date: Tue, 21 Jun 2016 14:22:30 +0100
Subject: [PATCH 07/18] Use AC_SEARCH_LIBS to search for ncursesw then ncurses

---
 configure    | 58 +++++++++++++++++++++++++++++++++-------------------
 configure.ac |  2 +-
 2 files changed, 38 insertions(+), 22 deletions(-)

diff --git a/configure b/configure
index e0a536c9be..a2149cae09 100755
--- a/configure
+++ b/configure
@@ -22924,42 +22924,59 @@ fi
   if test "${use_readline}" = no; then
     ## only need ncurses if libreadline is not statically linked against it
     unset ac_cv_lib_readline_rl_callback_read_char
-    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for main in -lncurses" >&5
-$as_echo_n "checking for main in -lncurses... " >&6; }
-if ${ac_cv_lib_ncurses_main+:} false; then :
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing initscr" >&5
+$as_echo_n "checking for library containing initscr... " >&6; }
+if ${ac_cv_search_initscr+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  ac_check_lib_save_LIBS=$LIBS
-LIBS="-lncurses  $LIBS"
+  ac_func_search_save_LIBS=$LIBS
 cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 
-
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char initscr ();
 int
 main ()
 {
-return main ();
+return initscr ();
   ;
   return 0;
 }
 _ACEOF
-if ac_fn_c_try_link "$LINENO"; then :
-  ac_cv_lib_ncurses_main=yes
-else
-  ac_cv_lib_ncurses_main=no
+for ac_lib in '' ncursesw curses; do
+  if test -z "$ac_lib"; then
+    ac_res="none required"
+  else
+    ac_res=-l$ac_lib
+    LIBS="-l$ac_lib  $ac_func_search_save_LIBS"
+  fi
+  if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_search_initscr=$ac_res
 fi
 rm -f core conftest.err conftest.$ac_objext \
-    conftest$ac_exeext conftest.$ac_ext
-LIBS=$ac_check_lib_save_LIBS
+    conftest$ac_exeext
+  if ${ac_cv_search_initscr+:} false; then :
+  break
 fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_ncurses_main" >&5
-$as_echo "$ac_cv_lib_ncurses_main" >&6; }
-if test "x$ac_cv_lib_ncurses_main" = xyes; then :
-  cat >>confdefs.h <<_ACEOF
-#define HAVE_LIBNCURSES 1
-_ACEOF
+done
+if ${ac_cv_search_initscr+:} false; then :
 
-  LIBS="-lncurses $LIBS"
+else
+  ac_cv_search_initscr=no
+fi
+rm conftest.$ac_ext
+LIBS=$ac_func_search_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_initscr" >&5
+$as_echo "$ac_cv_search_initscr" >&6; }
+ac_res=$ac_cv_search_initscr
+if test "$ac_res" != no; then :
+  test "$ac_res" = "none required" || LIBS="$ac_res $LIBS"
 
 else
   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for main in -ltermcap" >&5
@@ -44758,7 +44775,6 @@ fi
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $MKDIR_P" >&5
 $as_echo "$MKDIR_P" >&6; }
 
-
 mkdir_p="$MKDIR_P"
 case $mkdir_p in
   [\\/$]* | ?:[\\/]*) ;;
diff --git a/configure.ac b/configure.ac
index 4c1cdbb745..6cfbcf5ee9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -772,7 +772,7 @@ if test "${use_readline}" = yes; then
   if test "${use_readline}" = no; then
     ## only need ncurses if libreadline is not statically linked against it
     unset ac_cv_lib_readline_rl_callback_read_char
-    AC_CHECK_LIB(ncurses, main, [],
+    AC_SEARCH_LIBS([initscr], [ncursesw curses], [],
                  AC_CHECK_LIB(termcap, main, [],
                               AC_CHECK_LIB(termlib, main)))
     AC_CHECK_LIB(readline, rl_callback_read_char)
-- 
2.20.1

