| 1 | dnl @synopsis VL_LIB_READLINE([ACTION-IF-TRUE], [ACTION-IF-FALSE]) |
|---|
| 2 | dnl |
|---|
| 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. |
|---|
| 9 | dnl |
|---|
| 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. |
|---|
| 15 | dnl |
|---|
| 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 |
|---|
| 18 | dnl file: |
|---|
| 19 | dnl |
|---|
| 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) */ |
|---|
| 30 | dnl /* no readline */ |
|---|
| 31 | dnl #endif /* HAVE_LIBREADLINE */ |
|---|
| 32 | dnl |
|---|
| 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) */ |
|---|
| 43 | dnl /* no history */ |
|---|
| 44 | dnl #endif /* HAVE_READLINE_HISTORY */ |
|---|
| 45 | dnl |
|---|
| 46 | dnl Modifications to add --enable-gnu-readline to work around licensing |
|---|
| 47 | dnl problems between the traditional BSD licence and the GPL. |
|---|
| 48 | dnl Martin Ebourne, 2005/7/11 |
|---|
| 49 | dnl Rewrite to match headers with libraries and be more selective. |
|---|
| 50 | dnl Martin Ebourne, 2006/1/4 |
|---|
| 51 | dnl |
|---|
| 52 | dnl @category InstalledPackages |
|---|
| 53 | dnl @author Ville Laurikari <vl@iki.fi> |
|---|
| 54 | dnl @version 2002-04-04 |
|---|
| 55 | dnl @license AllPermissive |
|---|
| 56 | |
|---|
| 57 | AC_DEFUN([VL_LIB_READLINE], [ |
|---|
| 58 | AC_ARG_ENABLE( |
|---|
| 59 | [gnu-readline], |
|---|
| 60 | AC_HELP_STRING([--enable-gnu-readline], |
|---|
| 61 | [Use GNU readline if present (may violate GNU licence)]) |
|---|
| 62 | ) |
|---|
| 63 | vl_cv_lib_readline_compat_found=no |
|---|
| 64 | if test "x$enable_gnu_readline" = "xyes"; then |
|---|
| 65 | VL_LIB_READLINE_CHECK([readline], |
|---|
| 66 | [readline], |
|---|
| 67 | [readline/readline.h readline.h], |
|---|
| 68 | [readline/history.h history.h]) |
|---|
| 69 | fi |
|---|
| 70 | if test "x$vl_cv_lib_readline_compat_found" = "xno"; then |
|---|
| 71 | VL_LIB_READLINE_CHECK([editline], |
|---|
| 72 | [edit editline], |
|---|
| 73 | [editline/readline.h], |
|---|
| 74 | [editline/readline.h]) |
|---|
| 75 | fi |
|---|
| 76 | if test "x$vl_cv_lib_readline_compat_found" = "xyes"; then |
|---|
| 77 | m4_ifvaln([$1],[$1],[:])dnl |
|---|
| 78 | m4_ifvaln([$2],[else $2])dnl |
|---|
| 79 | fi |
|---|
| 80 | ]) |
|---|
| 81 | |
|---|
| 82 | dnl BOX_CHECK_VAR(name, where, headers) |
|---|
| 83 | AC_DEFUN([BOX_CHECK_VAR], [ |
|---|
| 84 | AC_CACHE_CHECK([for $1 $2], [vl_cv_var_$1], |
|---|
| 85 | [AC_TRY_LINK([$3], [(void) $1], [vl_cv_var_$1=yes], [vl_cv_var_$1=no]) |
|---|
| 86 | ]) |
|---|
| 87 | if test "${vl_cv_var_$1}" = "yes"; then |
|---|
| 88 | AC_DEFINE_UNQUOTED(AS_TR_CPP(HAVE_$1), 1, [Define if you have $1 $2]) |
|---|
| 89 | fi |
|---|
| 90 | ]) |
|---|
| 91 | |
|---|
| 92 | dnl VL_LIB_READLINE_CHECK(name, libraries, headers, history headers) |
|---|
| 93 | AC_DEFUN([VL_LIB_READLINE_CHECK], [ |
|---|
| 94 | ORIG_LIBS="$LIBS" |
|---|
| 95 | AC_CACHE_CHECK([for $1 library], |
|---|
| 96 | [vl_cv_lib_$1], [ |
|---|
| 97 | vl_cv_lib_$1="" |
|---|
| 98 | for readline_lib in $2; do |
|---|
| 99 | for termcap_lib in "" termcap curses ncurses pdcurses; do |
|---|
| 100 | if test -z "$termcap_lib"; then |
|---|
| 101 | TRY_LIB="-l$readline_lib" |
|---|
| 102 | else |
|---|
| 103 | TRY_LIB="-l$readline_lib -l$termcap_lib" |
|---|
| 104 | fi |
|---|
| 105 | LIBS="$ORIG_LIBS $TRY_LIB" |
|---|
| 106 | AC_TRY_LINK_FUNC([readline], [vl_cv_lib_$1="$TRY_LIB"]) |
|---|
| 107 | if test -n "$vl_cv_lib_$1"; then |
|---|
| 108 | break |
|---|
| 109 | fi |
|---|
| 110 | done |
|---|
| 111 | if test -n "$vl_cv_lib_$1"; then |
|---|
| 112 | break |
|---|
| 113 | fi |
|---|
| 114 | done |
|---|
| 115 | if test -z "$vl_cv_lib_$1"; then |
|---|
| 116 | vl_cv_lib_$1=no |
|---|
| 117 | LIBS="$ORIG_LIBS" |
|---|
| 118 | fi |
|---|
| 119 | ]) |
|---|
| 120 | |
|---|
| 121 | vl_cv_lib_includes="" |
|---|
| 122 | |
|---|
| 123 | vl_cv_lib_readline_compat_found=no |
|---|
| 124 | if test "x$vl_cv_lib_$1" != "xno"; then |
|---|
| 125 | AC_CHECK_HEADERS([$3], [ |
|---|
| 126 | vl_cv_lib_readline_compat_found=yes |
|---|
| 127 | vl_cv_lib_includes="$vl_cv_lib_headers #include <$ac_header>" |
|---|
| 128 | ]) |
|---|
| 129 | fi |
|---|
| 130 | |
|---|
| 131 | AC_TRY_LINK([$vl_cv_lib_includes], [(void) readline;], |
|---|
| 132 | [vl_compiles=yes], [vl_compiles=no]) |
|---|
| 133 | if test "x$vl_compiles" = "xno"; then |
|---|
| 134 | AC_TRY_LINK([#include <stdio.h> |
|---|
| 135 | $vl_cv_lib_includes], [(void) readline;], |
|---|
| 136 | [vl_compiles_with_stdio=yes], [vl_compiles_with_stdio=no]) |
|---|
| 137 | if test "x$vl_compiles_with_stdio" = "xyes"; then |
|---|
| 138 | vl_cv_lib_includes="#include <stdio.h> |
|---|
| 139 | $vl_cv_lib_includes" |
|---|
| 140 | fi |
|---|
| 141 | fi |
|---|
| 142 | |
|---|
| 143 | if test "x$vl_cv_lib_readline_compat_found" = "xyes"; then |
|---|
| 144 | BOX_CHECK_VAR([rl_completion_matches], [in readline headers], |
|---|
| 145 | [$vl_cv_lib_includes]) |
|---|
| 146 | |
|---|
| 147 | BOX_CHECK_VAR([completion_matches], [in readline headers], |
|---|
| 148 | [$vl_cv_lib_includes]) |
|---|
| 149 | |
|---|
| 150 | AC_DEFINE([HAVE_LIBREADLINE], 1, |
|---|
| 151 | [Define if you have a readline compatible library]) |
|---|
| 152 | |
|---|
| 153 | AC_CACHE_CHECK([whether $1 supports history], |
|---|
| 154 | [vl_cv_lib_$1_history], [ |
|---|
| 155 | vl_cv_lib_$1_history=no |
|---|
| 156 | AC_TRY_LINK_FUNC([add_history], [vl_cv_lib_$1_history=yes]) |
|---|
| 157 | ]) |
|---|
| 158 | if test "x$vl_cv_lib_$1_history" = "xyes"; then |
|---|
| 159 | vl_cv_lib_$1_history=no |
|---|
| 160 | AC_CHECK_HEADERS( |
|---|
| 161 | [$4], |
|---|
| 162 | [AC_DEFINE([HAVE_READLINE_HISTORY], [1], |
|---|
| 163 | [Define if your readline library has add_history])]) |
|---|
| 164 | fi |
|---|
| 165 | else |
|---|
| 166 | LIBS="$ORIG_LIBS" |
|---|
| 167 | fi |
|---|
| 168 | ])dnl |
|---|