1 dnl @synopsis VL_LIB_READLINE
3 dnl Searches for a readline compatible library. If found, defines
4 dnl `HAVE_LIBREADLINE'. If the found library has the `add_history'
5 dnl function, sets also `HAVE_READLINE_HISTORY'. Also checks for the
6 dnl locations of the necessary include files and sets `HAVE_READLINE_H'
7 dnl or `HAVE_READLINE_READLINE_H' and `HAVE_READLINE_HISTORY_H' or
8 dnl 'HAVE_HISTORY_H' if the corresponding include files exists.
10 dnl The libraries that may be readline compatible are `libedit',
11 dnl `libeditline' and `libreadline'. Sometimes we need to link a
12 dnl termcap library for readline to work, this macro tests these cases
13 dnl too by trying to link with `libtermcap', `libcurses' or
14 dnl `libncurses' before giving up.
16 dnl Here is an example of how to use the information provided by this
17 dnl macro to perform the necessary includes or declarations in a C
20 dnl #ifdef HAVE_LIBREADLINE
21 dnl # if defined(HAVE_READLINE_READLINE_H)
22 dnl # include <readline/readline.h>
23 dnl # elif defined(HAVE_READLINE_H)
24 dnl # include <readline.h>
25 dnl # else /* !defined(HAVE_READLINE_H) */
26 dnl extern char *readline ();
27 dnl # endif /* !defined(HAVE_READLINE_H) */
28 dnl char *cmdline = NULL;
29 dnl #else /* !defined(HAVE_READLINE_READLINE_H) */
31 dnl #endif /* HAVE_LIBREADLINE */
33 dnl #ifdef HAVE_READLINE_HISTORY
34 dnl # if defined(HAVE_READLINE_HISTORY_H)
35 dnl # include <readline/history.h>
36 dnl # elif defined(HAVE_HISTORY_H)
37 dnl # include <history.h>
38 dnl # else /* !defined(HAVE_HISTORY_H) */
39 dnl extern void add_history ();
40 dnl extern int write_history ();
41 dnl extern int read_history ();
42 dnl # endif /* defined(HAVE_READLINE_HISTORY_H) */
44 dnl #endif /* HAVE_READLINE_HISTORY */
46 dnl @category InstalledPackages
47 dnl @author Ville Laurikari <vl@iki.fi>
48 dnl @version 2002-04-04
49 dnl @license AllPermissive
51 AC_DEFUN([VL_LIB_READLINE], [
52 AC_CACHE_CHECK([for a readline compatible library],
55 for readline_lib in readline edit editline; do
56 for termcap_lib in "" termcap curses ncurses; do
57 if test -z "$termcap_lib"; then
58 TRY_LIB="-l$readline_lib"
60 TRY_LIB="-l$readline_lib -l$termcap_lib"
62 LIBS="$ORIG_LIBS $TRY_LIB"
63 AC_TRY_LINK_FUNC(readline, vl_cv_lib_readline="$TRY_LIB")
64 if test -n "$vl_cv_lib_readline"; then
68 if test -n "$vl_cv_lib_readline"; then
72 if test -z "$vl_cv_lib_readline"; then
73 vl_cv_lib_readline="no"
78 if test "$vl_cv_lib_readline" != "no"; then
79 AC_DEFINE(HAVE_LIBREADLINE, 1,
80 [Define if you have a readline compatible library])
81 AC_CHECK_HEADERS(readline.h readline/readline.h)
82 AC_CACHE_CHECK([whether readline supports history],
83 vl_cv_lib_readline_history, [
84 vl_cv_lib_readline_history="no"
85 AC_TRY_LINK_FUNC(add_history, vl_cv_lib_readline_history="yes")
87 if test "$vl_cv_lib_readline_history" = "yes"; then
88 AC_DEFINE(HAVE_READLINE_HISTORY, 1,
89 [Define if your readline library has \`add_history'])
90 AC_CHECK_HEADERS(history.h readline/history.h)