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 termcap
12 dnl library for readline to work, this macro tests these cases too by
13 dnl trying to link with `libtermcap', `libcurses', `libncurses' or
14 dnl `libtinfo' 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 file:
19 dnl #ifdef HAVE_LIBREADLINE
20 dnl # if defined(HAVE_READLINE_READLINE_H)
21 dnl # include <readline/readline.h>
22 dnl # elif defined(HAVE_READLINE_H)
23 dnl # include <readline.h>
24 dnl # else /* !defined(HAVE_READLINE_H) */
25 dnl extern char *readline ();
26 dnl # endif /* !defined(HAVE_READLINE_H) */
27 dnl char *cmdline = NULL;
28 dnl #else /* !defined(HAVE_READLINE_READLINE_H) */
30 dnl #endif /* HAVE_LIBREADLINE */
32 dnl #ifdef HAVE_READLINE_HISTORY
33 dnl # if defined(HAVE_READLINE_HISTORY_H)
34 dnl # include <readline/history.h>
35 dnl # elif defined(HAVE_HISTORY_H)
36 dnl # include <history.h>
37 dnl # else /* !defined(HAVE_HISTORY_H) */
38 dnl extern void add_history ();
39 dnl extern int write_history ();
40 dnl extern int read_history ();
41 dnl # endif /* defined(HAVE_READLINE_HISTORY_H) */
43 dnl #endif /* HAVE_READLINE_HISTORY */
47 dnl @author Ville Laurikari <vl@iki.fi>
48 dnl @author Ville Voipio <vv@iki.fi>; check for readline completion (not available in, e.g. Leopard)
50 AC_DEFUN([VL_LIB_READLINE], [
51 AC_CACHE_CHECK([for a readline compatible library],
54 for readline_lib in readline edit editline; do
55 for termcap_lib in "" termcap curses ncurses tinfo; do
56 if test -z "$termcap_lib"; then
57 TRY_LIB="-l$readline_lib"
59 TRY_LIB="-l$readline_lib -l$termcap_lib"
61 LIBS="$ORIG_LIBS $TRY_LIB"
62 AC_TRY_LINK_FUNC(readline, vl_cv_lib_readline="$TRY_LIB")
63 if test -n "$vl_cv_lib_readline"; then
67 if test -n "$vl_cv_lib_readline"; then
71 if test -z "$vl_cv_lib_readline"; then
72 vl_cv_lib_readline="no"
77 if test "$vl_cv_lib_readline" != "no"; then
78 AC_DEFINE(HAVE_LIBREADLINE, 1,
79 [Define if you have a readline compatible library])
80 AC_CHECK_HEADERS(readline.h readline/readline.h)
81 AC_CACHE_CHECK([whether readline supports history],
82 vl_cv_lib_readline_history,
83 [vl_cv_lib_readline_history="no"
84 AC_TRY_LINK_FUNC(add_history, vl_cv_lib_readline_history="yes")])
85 if test "$vl_cv_lib_readline_history" = "yes"; then
86 AC_DEFINE(HAVE_READLINE_HISTORY, 1, [Define if your readline library has \`add_history'])
87 AC_CHECK_HEADERS(history.h readline/history.h)
90 AC_CACHE_CHECK([whether readline supports completion],
91 vl_cv_lib_readline_completion,
92 [vl_cv_lib_readline_completion="no"
93 AC_TRY_LINK_FUNC(rl_completion_matches, vl_cv_lib_readline_completion="yes")])
94 if test "$vl_cv_lib_readline_completion" = "yes"; then
95 AC_DEFINE(HAVE_READLINE_COMPLETION, 1, [Define if your readline library has \`rl_completion_matches'])
103 # Check for a fully functional sed program that truncates
104 # as few characters as possible. Prefer GNU sed if found.
106 # Copyright (C) Free Software Foundation
108 # Copied here from autoconf-2.60 programs.m4 (AC_PROG_SED) to maintain
109 # compatibility with autoconf-2.59. Can be removed from acinclude.m4 if
110 # autoconf-2.60 or newer is required for other reasons..
112 m4_ifndef([AC_PROG_SED],[dnl
113 AC_DEFUN([AC_PROG_SED],
114 [AC_CACHE_CHECK([for a sed that does not truncate output], ac_cv_path_SED,
115 [dnl ac_script should not contain more than 99 commands (for HP-UX sed),
116 dnl but more than about 7000 bytes, to catch a limit in Solaris 8 /usr/ucb/sed.
117 ac_script=s/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/
118 for ac_i in 1 2 3 4 5 6 7; do
119 ac_script="$ac_script$as_nl$ac_script"
121 echo "$ac_script" | sed 99q >conftest.sed
122 $as_unset ac_script || ac_script=
123 _AC_PATH_PROG_FEATURE_CHECK(SED, [sed gsed],
124 [_AC_FEATURE_CHECK_LENGTH([ac_path_SED], [ac_cv_path_SED],
125 ["$ac_path_SED" -f conftest.sed])])])
126 SED="$ac_cv_path_SED"