source: box/trunk/infrastructure/m4/vl_lib_readline.m4 @ 3009

Revision 3009, 5.6 KB checked in by chris, 8 months ago (diff)

Silence warnings from new MinGW headers that expect MINGW_FEATURES
to be defined.

Check for fcntl.h and include it if we have it, not just on MSVC, now
that MinGW also defines O_BINARY in newer versions.

  • Property svn:eol-style set to native
Line 
1dnl @synopsis VL_LIB_READLINE([ACTION-IF-TRUE], [ACTION-IF-FALSE])
2dnl
3dnl Searches for a readline compatible library. If found, defines
4dnl `HAVE_LIBREADLINE'. If the found library has the `add_history'
5dnl function, sets also `HAVE_READLINE_HISTORY'. Also checks for the
6dnl locations of the necessary include files and sets `HAVE_READLINE_H'
7dnl or `HAVE_READLINE_READLINE_H' and `HAVE_READLINE_HISTORY_H' or
8dnl 'HAVE_HISTORY_H' if the corresponding include files exists.
9dnl
10dnl The libraries that may be readline compatible are `libedit',
11dnl `libeditline' and `libreadline'. Sometimes we need to link a
12dnl termcap library for readline to work, this macro tests these cases
13dnl too by trying to link with `libtermcap', `libcurses' or
14dnl `libncurses' before giving up.
15dnl
16dnl Here is an example of how to use the information provided by this
17dnl macro to perform the necessary includes or declarations in a C
18dnl file:
19dnl
20dnl   #ifdef HAVE_LIBREADLINE
21dnl   #  if defined(HAVE_READLINE_READLINE_H)
22dnl   #    include <readline/readline.h>
23dnl   #  elif defined(HAVE_READLINE_H)
24dnl   #    include <readline.h>
25dnl   #  else /* !defined(HAVE_READLINE_H) */
26dnl   extern char *readline ();
27dnl   #  endif /* !defined(HAVE_READLINE_H) */
28dnl   char *cmdline = NULL;
29dnl   #else /* !defined(HAVE_READLINE_READLINE_H) */
30dnl     /* no readline */
31dnl   #endif /* HAVE_LIBREADLINE */
32dnl
33dnl   #ifdef HAVE_READLINE_HISTORY
34dnl   #  if defined(HAVE_READLINE_HISTORY_H)
35dnl   #    include <readline/history.h>
36dnl   #  elif defined(HAVE_HISTORY_H)
37dnl   #    include <history.h>
38dnl   #  else /* !defined(HAVE_HISTORY_H) */
39dnl   extern void add_history ();
40dnl   extern int write_history ();
41dnl   extern int read_history ();
42dnl   #  endif /* defined(HAVE_READLINE_HISTORY_H) */
43dnl     /* no history */
44dnl   #endif /* HAVE_READLINE_HISTORY */
45dnl
46dnl Modifications to add --enable-gnu-readline to work around licensing
47dnl problems between the traditional BSD licence and the GPL.
48dnl Martin Ebourne, 2005/7/11
49dnl Rewrite to match headers with libraries and be more selective.
50dnl Martin Ebourne, 2006/1/4
51dnl
52dnl @category InstalledPackages
53dnl @author Ville Laurikari <vl@iki.fi>
54dnl @version 2002-04-04
55dnl @license AllPermissive
56
57AC_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
82dnl BOX_CHECK_VAR(name, where, headers)
83AC_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
92dnl VL_LIB_READLINE_CHECK(name, libraries, headers, history headers)
93AC_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
Note: See TracBrowser for help on using the repository browser.