3 dnl This is copied from the NcFTP distribution.
4 dnl Author Mike Gleason mgleason@NcFTP.com
6 dnl This macro will check for the presence and version
7 dnl of the readline library. To get it into the aclocal.m4
9 dnl aclocal -I . --verbose
11 dnl The --verbose will show all of the files that are searched
13 AC_DEFUN([wi_LIB_READLINE], [
14 AC_MSG_CHECKING([for GNU Readline library, version 2.0 or newer])
17 wi_cv_lib_readline_result=no
19 # Note: $LIBCURSES is permitted to be empty.
20 for LIBREADLINE in "-lreadline" "-lreadline $LIBCURSES" "-lreadline -ltermcap" "-lreadline -lncurses" "-lreadline -lcurses"
22 LIBS="$ac_save_LIBS $LIBREADLINE"
28 main(int argc, char **argv)
30 /* Note: don't actually call readline, since it may block;
31 * We just want to see if it (dynamic) linked in okay.
33 if (argc == 0) /* never true */
39 wi_cv_lib_readline=yes
44 # action if cross compiling
48 if test "$wi_cv_lib_readline" = yes ; then break ; fi
51 # Now try it again, to be sure it is recent enough.
52 # rl_function_of_keyseq appeared in version 2.0
54 dnl AC_CHECK_FUNC(rl_function_of_keyseq, [wi_cv_lib_readline=yes],[
55 dnl wi_cv_lib_readline=no;wi_cv_lib_readline_result="no (it is present but too old to use)"
62 rl_function_of_keyseq(0);
64 wi_cv_lib_readline=yes
67 wi_cv_lib_readline_result="no (it is present but too old to use)"
70 if test "$wi_cv_lib_readline" = no ; then
75 /bin/rm -f readline.ver
81 #include <sys/types.h>
84 extern char *rl_library_version;
91 sscanf(rl_library_version, "%lf", &d);
92 fp = fopen("readline.ver", "w");
93 if (fp == NULL) exit(1);
94 if (fprintf(fp, "%s\n", rl_library_version) < 0) exit(1);
95 if (fprintf(fp, "%03d\n", (int) (d * 100.0)) < 0) exit(1);
96 if (fclose(fp) < 0) exit(1);
101 rl_library_version=`sed -n 1,1p readline.ver 2>/dev/null`
102 rlver=`sed -n 2,2p readline.ver 2>/dev/null`
103 /bin/rm -f readline.ver
106 rl_library_version=''
108 /bin/rm -f readline.ver
110 # action if cross compiling
111 rl_library_version=''
113 /bin/rm -f readline.ver
118 wi_cv_lib_readline_result="yes, installed version is $rl_library_version"
121 # Test using current LIBS.
124 extern int rl_completion_append_character;
128 rl_completion_append_character = 0;
135 if test "$rlver" = "210" ; then
136 wi_cv_lib_readline_result="yes, version 2.1 or higher"
138 wi_cv_lib_readline_result="yes, version 2.0"
143 wi_cv_lib_readline=yes
147 AC_MSG_RESULT($wi_cv_lib_readline_result)
148 AC_SUBST(LIBREADLINE)
150 if test "$wi_cv_lib_readline" = yes ; then
151 # Now verify that all the headers are installed.
154 unset ac_cv_header_readline_chardefs_h
155 unset ac_cv_header_readline_history_h
156 unset ac_cv_header_readline_keymaps_h
157 unset ac_cv_header_readline_readline_h
158 unset ac_cv_header_readline_tilde_h
159 AC_CHECK_HEADERS([readline/chardefs.h readline/history.h readline/keymaps.h readline/readline.h readline/tilde.h])
162 "$ac_cv_header_readline_chardefs_h" \
163 "$ac_cv_header_readline_history_h" \
164 "$ac_cv_header_readline_keymaps_h" \
165 "$ac_cv_header_readline_readline_h" \
166 "$ac_cv_header_readline_tilde_h"
168 if test "$xxwi" = no ; then
173 if test "$xxwi" = no ; then
174 AC_MSG_WARN([GNU Readline headers are not installed or could not be found -- GNU Readline will not be used.])
175 wi_cv_lib_readline=no
176 wi_cv_lib_readline_result="no (headers not installed)"
178 AC_DEFINE_UNQUOTED(HAVE_LIBREADLINE, $rlver,[Readline])
181 dnl Check to see if we have a namespace clean version of readline
182 dnl or not. At least FreeBSD 4.9 ships with non-ns-clean readline.
183 if test "$wi_cv_lib_readline" = "yes" ; then
185 LIBS="$ac_save_LIBS $LIBREADLINE"
186 AC_CHECK_FUNCS(rl_completion_matches completion_matches)
190 dnl Check to see if rl_callback_handler_install takes a cast
191 AC_MSG_CHECKING([to see if readline callbacks take a cast])
193 LIBS="$ac_save_LIBS $LIBREADLINE"
198 #include <readline/readline.h>
199 void func(void) { return; }
201 rl_callback_handler_install(">", (void(*)(char*))func);
203 AC_DEFINE(READLINE_CB_TAKES_CAST, 1, [callbacks take a cast])