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. */
43 /* Try to init readline and see if it barfs. */
45 read_history(TEMP_FILE);
47 rl_callback_handler_install("_ ", handle_readline_input_callback);
48 rl_callback_handler_remove(); /* needed to re-set terminal */
51 ]])],[AC_MSG_RESULT(yes)
52 [$2]],[AC_MSG_RESULT(no)
53 [$3]],[AC_MSG_RESULT(unknown: cross-compiling)
58 AC_DEFUN([FC_HAS_READLINE],
60 dnl Readline library and header files.
61 if test "$WITH_READLINE" = "yes" || test "$WITH_READLINE" = "maybe"; then
64 AC_CHECK_HEADER(readline/readline.h,
65 have_readline_header=1,
66 have_readline_header=0)
67 if test "$have_readline_header" = "0"; then
68 if test "$WITH_READLINE" = "yes"; then
69 AC_MSG_ERROR([Did not find readline header file.
70 You may need to install a readline "development" package.])
72 AC_MSG_WARN(Did not find readline header file.
73 Configuring server without readline support.)
74 feature_readline=missing
77 dnl Readline lib with rl_completion_suppress_append (i.e >= 4.3)
78 AC_CHECK_LIB([readline], [rl_completion_suppress_append],
79 [have_readline_lib=1], [have_readline_lib=0])
80 if test "$have_readline_lib" != "1" ; then
81 dnl Many readline installations are broken in that they
82 dnl don't set the dependency on the curses lib up correctly.
83 dnl We give them a hand by trying to guess what might be needed.
85 dnl Some older Unices may need both -lcurses and -ltermlib,
86 dnl but we don't support that just yet. This check will take
87 dnl the first lib that it finds and just link to that.
88 AC_CHECK_LIB(tinfo, tgetent, HAVE_TERMCAP="-ltinfo",
89 AC_CHECK_LIB(ncurses, tgetent, HAVE_TERMCAP="-lncurses",
90 AC_CHECK_LIB(curses, tgetent, HAVE_TERMCAP="-lcurses",
91 AC_CHECK_LIB(termcap, tgetent, HAVE_TERMCAP="-ltermcap",
92 AC_CHECK_LIB(termlib, tgetent, HAVE_TERMCAP="-ltermlib")
98 if test x"$HAVE_TERMCAP" != "x"; then
99 dnl We can't check for rl_completion_suppress_append again,
100 dnl cause the result is cached. And autoconf doesn't
101 dnl seem to have a way to uncache it.
102 AC_CHECK_LIB([readline], [rl_completion_mode],
103 [have_readline_lib=1], [have_readline_lib=0],
105 if test "$have_readline_lib" = "1"; then
106 AC_MSG_WARN([I had to manually add $HAVE_TERMCAP dependency to
107 make readline library pass the test.])
112 if test "$have_readline_lib" = "1"; then
113 FC_CHECK_READLINE_RUNTIME($HAVE_TERMCAP,
114 have_readline_lib=1, have_readline_lib=0)
115 if test "$have_readline_lib" = "1"; then
116 SRV_LIB_LIBS="-lreadline $SRV_LIB_LIBS $HAVE_TERMCAP"
117 AC_DEFINE_UNQUOTED([FREECIV_HAVE_LIBREADLINE], [1], [Readline support])
119 if test "$WITH_READLINE" = "yes"; then
120 AC_MSG_ERROR(Specified --with-readline but the
121 runtime test of readline failed.)
123 AC_MSG_WARN(Runtime test of readline failed.
124 Configuring server without readline support.)
125 feature_readline=missing
129 if test "$WITH_READLINE" = "yes"; then
130 AC_MSG_ERROR(Specified --with-readline but the
131 test to link against the library failed.)
133 AC_MSG_WARN(Test to link against readline library failed.
134 Configuring server without readline support.)
135 feature_readline=missing