+dnl Usage: GINAC_LIBREADLINE
+dnl
+dnl Check if GNU readline library and headers are avialable.
+dnl Defines GINSH_LIBS variable, and HAVE_LIBREADLINE,
+dnl HAVE_READLINE_READLINE_H, HAVE_READLINE_HISTORY_H preprocessor macros.
+dnl
+dnl Note: this macro rejects readline versions <= 4.2 and non-GNU
+dnl implementations.
+dnl
+AC_DEFUN([GINAC_READLINE],[
+AC_REQUIRE([GINAC_TERMCAP])
+GINSH_LIBS=""
+AC_CHECK_HEADERS(readline/readline.h readline/history.h)
+if test "x${ac_cv_header_readline_readline_h}" != "xyes" -o "x${ac_cv_header_readline_history_h}" != "xyes"; then
+ GINAC_WARNING([readline headers could not be found.])
+else
+ AC_CACHE_CHECK([for version of libreadline], [ginac_cv_rl_supported], [
+ ginac_cv_rl_supported="no"
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
+ #include <stdio.h>
+ #include <readline/readline.h>
+ #if !defined(RL_VERSION_MAJOR) || !defined(RL_VERSION_MINOR)
+ #error "Ancient/unsupported version of readline"
+ #endif]])],
+ [ginac_cv_rl_supported="yes"])])
+ if test "x${ginac_cv_rl_supported}" != "xyes"; then
+ GINAC_WARNING([Unsupported version of readline (<= 4.2 or non-GNU).])
+ else
+ save_LIBS="$LIBS"
+ LIBS="$LIBTERMCAP $LIBS"
+ AC_CHECK_LIB(readline, readline)
+ if test "x${ac_cv_lib_readline_readline}" != "xyes"; then
+ GINAC_WARNING([libreadline could not be found.])
+ fi
+ GINSH_LIBS="$LIBS"
+ LIBS="$save_LIBS"
+ fi
+fi
+AC_SUBST(GINSH_LIBS)])
+