pwmc: always save with the keyfile as key material.
[libpwmd.git] / m4 / vl_lib_readline.m4
blobf466dbf79240d5cf8903969fad4879f2db946084
1 dnl @synopsis VL_LIB_READLINE
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 @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],
53                  vl_cv_lib_readline, [
54     ORIG_LIBS="$LIBS"
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"
59         else
60           TRY_LIB="-l$readline_lib -l$termcap_lib"
61         fi
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
65           break
66         fi
67       done
68       if test -n "$vl_cv_lib_readline"; then
69         break
70       fi
71     done
72     if test -z "$vl_cv_lib_readline"; then
73       vl_cv_lib_readline="no"
74       LIBS="$ORIG_LIBS"
75     fi
76   ])
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")
86     ])
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)
91     fi
92   fi
93 ])dnl