3 # AMANDA_CHECK_READLINE
7 # Check for readline support. Defines HAVE_LIBREADLINE if readline
8 # is available, and also checks for a number of readline headers and
9 # adds readline libraries to READLINE_LIBS.
11 # See common-src/util.{c,h}.
14 # Some idea taken from AX_LIB_READLINE:
15 # ===========================================================================
16 # http://www.gnu.org/software/autoconf-archive/ax_lib_readline.html
17 # ===========================================================================
25 # Searches for a readline compatible library. If found, defines
26 # `HAVE_LIBREADLINE'. If the found library has the `add_history' function,
27 # sets also `HAVE_READLINE_HISTORY'. Also checks for the locations of the
28 # necessary include files and sets `HAVE_READLINE_H' or
29 # `HAVE_READLINE_READLINE_H' and `HAVE_READLINE_HISTORY_H' or
30 # 'HAVE_HISTORY_H' if the corresponding include files exists.
32 # The libraries that may be readline compatible are `libedit',
33 # `libeditline' and `libreadline'. Sometimes we need to link a termcap
34 # library for readline to work, this macro tests these cases too by trying
35 # to link with `libtermcap', `libcurses' or `libncurses' before giving up.
37 # Here is an example of how to use the information provided by this macro
38 # to perform the necessary includes or declarations in a C file:
40 # #ifdef HAVE_LIBREADLINE
41 # # if defined(HAVE_READLINE_READLINE_H)
42 # # include <readline/readline.h>
43 # # elif defined(HAVE_READLINE_H)
44 # # include <readline.h>
45 # # else /* !defined(HAVE_READLINE_H) */
46 # extern char *readline ();
47 # # endif /* !defined(HAVE_READLINE_H) */
48 # char *cmdline = NULL;
49 # #else /* !defined(HAVE_READLINE_READLINE_H) */
51 # #endif /* HAVE_LIBREADLINE */
53 # #ifdef HAVE_READLINE_HISTORY
54 # # if defined(HAVE_READLINE_HISTORY_H)
55 # # include <readline/history.h>
56 # # elif defined(HAVE_HISTORY_H)
57 # # include <history.h>
58 # # else /* !defined(HAVE_HISTORY_H) */
59 # extern void add_history ();
60 # extern int write_history ();
61 # extern int read_history ();
62 # # endif /* defined(HAVE_READLINE_HISTORY_H) */
64 # #endif /* HAVE_READLINE_HISTORY */
68 # Copyright (c) 2008 Ville Laurikari <vl@iki.fi>
70 # Copying and distribution of this file, with or without modification, are
71 # permitted in any medium without royalty provided the copyright notice
72 # and this notice are preserved. This file is offered as-is, without any
77 AC_DEFUN([AMANDA_CHECK_READLINE], [
79 dnl no initial space here, so the results line up properly
80 AS_HELP_STRING([--with-readline], [require readline support (for amrecover)])
81 AS_HELP_STRING([--without-readline], [don't search for readline]),
84 y | ye | yes | n | no) : ;;
85 *) AC_MSG_ERROR([*** --with-readline does not take a value])
87 want_readline="$withval"
89 want_readline="maybe" # meaning "only if we can find it"
93 # unless the user said "no", look for readline.
94 if test x"$want_readline" != x"no"; then
95 AC_CACHE_CHECK([for a readline compatible library],
98 for readline_lib in readline edit editline; do
99 for termcap_lib in "" termcap curses ncurses; do
100 if test -z "$termcap_lib"; then
101 TRY_LIB="-l$readline_lib"
103 TRY_LIB="-l$readline_lib -l$termcap_lib"
105 LIBS="$ORIG_LIBS $TRY_LIB"
106 AC_TRY_LINK_FUNC(readline, ax_cv_lib_readline="$TRY_LIB")
107 if test -n "$ax_cv_lib_readline"; then
111 if test -n "$ax_cv_lib_readline"; then
115 if test -z "$ax_cv_lib_readline"; then
116 ax_cv_lib_readline="no"
121 if test "$ax_cv_lib_readline" != "no"; then
123 LIBS="$LIBS $ax_cv_lib_readline"
124 READLINE_LIBS="$ax_cv_lib_readline"
125 AC_DEFINE(HAVE_LIBREADLINE, 1,
126 [Define if you have a readline compatible library])
127 AC_CHECK_HEADERS(readline.h readline/readline.h)
128 AC_CACHE_CHECK([whether readline supports history],
129 ax_cv_lib_readline_history, [
130 ax_cv_lib_readline_history="no"
131 AC_TRY_LINK_FUNC(add_history, ax_cv_lib_readline_history="yes")
133 if test "$ax_cv_lib_readline_history" = "yes"; then
134 AC_DEFINE(HAVE_READLINE_HISTORY, 1,
135 [Define if your readline library has \`add_history'])
136 AC_CHECK_HEADERS(history.h readline/history.h)
141 # no readline. if the user *really* wanted it, bail out.
142 if test x"$want_readline" = x"yes"; then
143 AC_MSG_ERROR([*** No readline implementation found. Try using --with-libraries and --with-includes])
148 AC_SUBST(READLINE_LIBS)