-dnl This macro is needed because the generic AC_CHECK_LIB doesn't work because
-dnl C++ is more strongly typed than C. Therefore we need to work with the
-dnl more fundamental AC_TRY_LINK instead.
-AC_DEFUN(GINAC_CHECK_LIBCLN,
- [AC_PROVIDE([$0])
- AC_MSG_CHECKING([for doublefactorial in -lcln])
- saved_LIBS="${LIBS}"
- AC_CACHE_VAL(ginac_cv_lib_cln_link,
- [LIBS="-lcln"
- case "${ac_cv_header_cln_cln_h}" in
- "yes")
- AC_TRY_LINK([#include <cln/cln.h>],
- [doublefactorial(2);],
- ginac_cv_lib_cln_link="-lcln",
- ginac_cv_lib_cln_link="fail")
- ;;
- *)
- AC_TRY_LINK([#include <cln.h>],
- [doublefactorial(2);],
- ginac_cv_lib_cln_link="-lcln",
- ginac_cv_lib_cln_link="fail")
- ;;
- esac
- ])
- case "${ginac_cv_lib_cln_link}" in
-dnl linking worked:
- "-lcln")
- LIBS="${ginac_cv_lib_cln_link} ${saved_LIBS}"
- AC_MSG_RESULT("yes")
- ;;
-dnl linking failed:
- "fail")
- LIBS="${saved_LIBS}"
- AC_MSG_RESULT([no])
- GINAC_ERROR([I could not successfully link a test-program against libcln and run it.
- You either need to set \$LDFLAGS or install/update the CLN library.])
- ;;
- esac
+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([ginsh will not compile, because 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([ginsh will not compile, because of an 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([ginsh will not compile, because libreadline could not be found.])
+ fi
+ GINSH_LIBS="$LIBS"
+ LIBS="$save_LIBS"
+ fi
+fi
+AC_SUBST(GINSH_LIBS)])
+
+dnl Usage: GINAC_TERMCAP
+dnl libreadline is based on the termcap functions.
+dnl Some systems have tgetent(), tgetnum(), tgetstr(), tgetflag(), tputs(),
+dnl tgoto() in libc, some have it in libtermcap, some have it in libncurses.
+dnl When both libtermcap and libncurses exist, we prefer the latter, because
+dnl libtermcap is being phased out.
+AC_DEFUN([GINAC_TERMCAP],
+[LIBTERMCAP=
+case $host_os in
+*mingw32*)
+ ;; dnl no termcap libraries are necessary (need hacked libreadline)
+*)
+AC_CHECK_FUNCS(tgetent)
+if test "x$ac_cv_func_tgetent" = "xyes"; then
+ :
+else
+ AC_CHECK_LIB(ncurses, tgetent, LIBTERMCAP="-lncurses")
+ if test -z "$LIBTERMCAP"; then
+ AC_CHECK_LIB(termcap, tgetent, LIBTERMCAP="-ltermcap")
+ fi
+fi
+;;
+esac
+AC_SUBST(LIBTERMCAP)