2 dnl FC_CHECK_READLINE_RUNTIME(EXTRA-LIBS, ACTION-IF-FOUND, ACTION-IF-NOT-FOUND)
4 dnl This tests whether readline works at runtime. Here, "works"
5 dnl means "doesn't dump core", as some versions do if linked
6 dnl against wrong ncurses library. Compiles with LIBS modified
7 dnl to included -lreadline and parameter EXTRA-LIBS.
8 dnl Should already have checked that header and library exist.
10 AC_DEFUN([FC_CHECK_READLINE_RUNTIME],
11 [AC_MSG_CHECKING(whether readline works at runtime)
13 LIBS="-lreadline $1 $LIBS"
14 AC_RUN_IFELSE([AC_LANG_SOURCE([[
18 * Check to make sure that readline works at runtime.
19 * (Specifically, some readline packages link against a wrong
20 * version of ncurses library and dump core at runtime.)
21 * (c) 2000 Jacob Lundberg, jacob@chaos2.org
25 /* We assume that the presence of readline has already been verified. */
26 #include <readline/readline.h>
27 #include <readline/history.h>
29 /* Setup for readline. */
30 #define TEMP_FILE "./conftest.readline.runtime"
32 static void handle_readline_input_callback(char *line) {
33 /* Generally taken from freeciv-1.11.4/server/sernet.c. */
42 /* Try to init readline and see if it barfs. */
44 read_history(TEMP_FILE);
46 rl_callback_handler_install("_ ", handle_readline_input_callback);
47 rl_callback_handler_remove(); /* needed to re-set terminal */
50 ]])],[AC_MSG_RESULT(yes)
51 [$2]],[AC_MSG_RESULT(no)
52 [$3]],[AC_MSG_RESULT(unknown: cross-compiling)
57 AC_DEFUN([FC_HAS_READLINE],
59 dnl Readline library and header files.
60 if test "$WITH_READLINE" = "yes" || test "$WITH_READLINE" = "maybe"; then
63 AC_CHECK_HEADER(readline/readline.h,
64 have_readline_header=1,
65 have_readline_header=0)
66 if test "$have_readline_header" = "0"; then
67 if test "$WITH_READLINE" = "yes"; then
68 AC_MSG_ERROR([Did not find readline header file.
69 You may need to install a readline "development" package.])
71 AC_MSG_WARN(Did not find readline header file.
72 Configuring server without readline support.)
73 feature_readline=missing
76 dnl Readline lib with rl_completion_suppress_append (i.e >= 4.3)
77 AC_CHECK_LIB([readline], [rl_completion_suppress_append],
78 [have_readline_lib=1], [have_readline_lib=0])
79 if test "$have_readline_lib" != "1" ; then
80 dnl Many readline installations are broken in that they
81 dnl don't set the dependency on the curses lib up correctly.
82 dnl We give them a hand by trying to guess what might be needed.
84 dnl Some older Unices may need both -lcurses and -ltermlib,
85 dnl but we don't support that just yet. This check will take
86 dnl the first lib that it finds and just link to that.
87 AC_CHECK_LIB(tinfo, tgetent, HAVE_TERMCAP="-ltinfo",
88 AC_CHECK_LIB(ncurses, tgetent, HAVE_TERMCAP="-lncurses",
89 AC_CHECK_LIB(curses, tgetent, HAVE_TERMCAP="-lcurses",
90 AC_CHECK_LIB(termcap, tgetent, HAVE_TERMCAP="-ltermcap",
91 AC_CHECK_LIB(termlib, tgetent, HAVE_TERMCAP="-ltermlib")
97 if test x"$HAVE_TERMCAP" != "x"; then
98 dnl We can't check for rl_completion_suppress_append again,
99 dnl cause the result is cached. And autoconf doesn't
100 dnl seem to have a way to uncache it.
101 AC_CHECK_LIB([readline], [rl_completion_mode]
102 [have_readline_lib=1], [have_readline_lib=0],
104 if test "$have_readline_lib" = "1"; then
105 AC_MSG_WARN([I had to manually add $HAVE_TERMCAP dependency to
106 make readline library pass the test.])
111 if test "$have_readline_lib" = "1"; then
112 FC_CHECK_READLINE_RUNTIME($HAVE_TERMCAP,
113 have_readline_lib=1, have_readline_lib=0)
114 if test "$have_readline_lib" = "1"; then
115 SRV_LIB_LIBS="-lreadline $SRV_LIB_LIBS $HAVE_TERMCAP"
116 AC_DEFINE_UNQUOTED([HAVE_LIBREADLINE], [1], [Readline support])
118 if test "$WITH_READLINE" = "yes"; then
119 AC_MSG_ERROR(Specified --with-readline but the
120 runtime test of readline failed.)
122 AC_MSG_WARN(Runtime test of readline failed.
123 Configuring server without readline support.)
124 feature_readline=missing
128 if test "$WITH_READLINE" = "yes"; then
129 AC_MSG_ERROR(Specified --with-readline but the
130 test to link against the library failed.)
132 AC_MSG_WARN(Test to link against readline library failed.
133 Configuring server without readline support.)
134 feature_readline=missing