--- a/aclocal.m4
+++ b/aclocal.m4
@@ -932,8 +932,8 @@ _bash_needmsg=
 fi
 AC_CACHE_VAL(bash_cv_termcap_lib,
 [AC_CHECK_FUNC(tgetent, bash_cv_termcap_lib=libc,
-  [AC_CHECK_LIB(termcap, tgetent, bash_cv_termcap_lib=libtermcap,
-    [AC_CHECK_LIB(tinfo, tgetent, bash_cv_termcap_lib=libtinfo,
+  [AC_CHECK_LIB(tinfo, tgetent, bash_cv_termcap_lib=libtinfo,
+     [AC_CHECK_LIB(termcap, tgetent, bash_cv_termcap_lib=libtermcap,
         [AC_CHECK_LIB(curses, tgetent, bash_cv_termcap_lib=libcurses,
 	    [AC_CHECK_LIB(ncursesw, tgetent, bash_cv_termcap_lib=libncursesw,
                 [AC_CHECK_LIB(ncurses, tgetent, bash_cv_termcap_lib=libncurses,
--- a/configure
+++ b/configure
@@ -7141,14 +7141,14 @@ if test "x$ac_cv_func_tgetent" = xyes
 then :
   bash_cv_termcap_lib=libc
 else case e in #(
-  e) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for tgetent in -ltermcap" >&5
-printf %s "checking for tgetent in -ltermcap... " >&6; }
-if test ${ac_cv_lib_termcap_tgetent+y}
+  e) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for tgetent in -ltinfo" >&5
+printf %s "checking for tgetent in -ltinfo... " >&6; }
+if test ${ac_cv_lib_tinfo_tgetent+y}
 then :
   printf %s "(cached) " >&6
 else case e in #(
   e) ac_check_lib_save_LIBS=$LIBS
-LIBS="-ltermcap  $LIBS"
+LIBS="-ltinfo  $LIBS"
 cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 
@@ -7172,9 +7172,9 @@ return tgetent ();
 _ACEOF
 if ac_fn_c_try_link "$LINENO"
 then :
-  ac_cv_lib_termcap_tgetent=yes
+  ac_cv_lib_tinfo_tgetent=yes
 else case e in #(
-  e) ac_cv_lib_termcap_tgetent=no ;;
+  e) ac_cv_lib_tinfo_tgetent=no ;;
 esac
 fi
 rm -f core conftest.err conftest.$ac_objext conftest.beam \
@@ -7182,20 +7182,20 @@ rm -f core conftest.err conftest.$ac_obj
 LIBS=$ac_check_lib_save_LIBS ;;
 esac
 fi
-{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_termcap_tgetent" >&5
-printf "%s\n" "$ac_cv_lib_termcap_tgetent" >&6; }
-if test "x$ac_cv_lib_termcap_tgetent" = xyes
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_tinfo_tgetent" >&5
+printf "%s\n" "$ac_cv_lib_tinfo_tgetent" >&6; }
+if test "x$ac_cv_lib_tinfo_tgetent" = xyes
 then :
-  bash_cv_termcap_lib=libtermcap
+  bash_cv_termcap_lib=libtinfo
 else case e in #(
-  e) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for tgetent in -ltinfo" >&5
-printf %s "checking for tgetent in -ltinfo... " >&6; }
-if test ${ac_cv_lib_tinfo_tgetent+y}
+  e) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for tgetent in -ltermcap" >&5
+printf %s "checking for tgetent in -ltermcap... " >&6; }
+if test ${ac_cv_lib_termcap_tgetent+y}
 then :
   printf %s "(cached) " >&6
 else case e in #(
   e) ac_check_lib_save_LIBS=$LIBS
-LIBS="-ltinfo  $LIBS"
+LIBS="-ltermcap  $LIBS"
 cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 
@@ -7219,9 +7219,9 @@ return tgetent ();
 _ACEOF
 if ac_fn_c_try_link "$LINENO"
 then :
-  ac_cv_lib_tinfo_tgetent=yes
+  ac_cv_lib_termcap_tgetent=yes
 else case e in #(
-  e) ac_cv_lib_tinfo_tgetent=no ;;
+  e) ac_cv_lib_termcap_tgetent=no ;;
 esac
 fi
 rm -f core conftest.err conftest.$ac_objext conftest.beam \
@@ -7229,11 +7229,11 @@ rm -f core conftest.err conftest.$ac_obj
 LIBS=$ac_check_lib_save_LIBS ;;
 esac
 fi
-{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_tinfo_tgetent" >&5
-printf "%s\n" "$ac_cv_lib_tinfo_tgetent" >&6; }
-if test "x$ac_cv_lib_tinfo_tgetent" = xyes
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_termcap_tgetent" >&5
+printf "%s\n" "$ac_cv_lib_termcap_tgetent" >&6; }
+if test "x$ac_cv_lib_termcap_tgetent" = xyes
 then :
-  bash_cv_termcap_lib=libtinfo
+  bash_cv_termcap_lib=libtermcap
 else case e in #(
   e) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for tgetent in -lcurses" >&5
 printf %s "checking for tgetent in -lcurses... " >&6; }
