webperimental: enable restrictinfra by default...
[freeciv.git] / m4 / readline.m4
blobf23104b649522654b15bbf4490a8752678019648
2 dnl FC_CHECK_READLINE_RUNTIME(EXTRA-LIBS, ACTION-IF-FOUND, ACTION-IF-NOT-FOUND)
3 dnl
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.
9 dnl
10 AC_DEFUN([FC_CHECK_READLINE_RUNTIME],
11 [AC_MSG_CHECKING(whether readline works at runtime)
12 templibs="$LIBS"
13 LIBS="-lreadline $1 $LIBS"
14 AC_RUN_IFELSE([AC_LANG_SOURCE([[
16  * testrl.c
17  * File revision 0
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
22  */
24 #include <stdio.h>
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. */
34   if (line) {
35     if (*line) {
36       add_history(line);
37     }
38     /* printf(line); */
39   }
42 int main(void) {
43 /* Try to init readline and see if it barfs. */
44   using_history();
45   read_history(TEMP_FILE);
46   rl_initialize();
47   rl_callback_handler_install("_ ", handle_readline_input_callback);
48   rl_callback_handler_remove();  /* needed to re-set terminal */
49   return(0);
51 ]])],[AC_MSG_RESULT(yes)
52   [$2]],[AC_MSG_RESULT(no)
53   [$3]],[AC_MSG_RESULT(unknown: cross-compiling)
54   [$2]])
55 LIBS="$templibs"
58 AC_DEFUN([FC_HAS_READLINE],
60     dnl Readline library and header files.
61     if test "$WITH_READLINE" = "yes" || test "$WITH_READLINE" = "maybe"; then
62        HAVE_TERMCAP="";
63        dnl Readline header
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.])
71            else
72                AC_MSG_WARN(Did not find readline header file. 
73 Configuring server without readline support.)
74                feature_readline=missing
75            fi
76        else
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.
84                dnl
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")
93                      )
94                    )
95                  )
96                )
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],
104                         ["$HAVE_TERMCAP"])
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.])
108                    fi
109                fi
110            fi
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])
118                else
119                    if test "$WITH_READLINE" = "yes"; then
120                        AC_MSG_ERROR(Specified --with-readline but the 
121 runtime test of readline failed.)
122                    else
123                        AC_MSG_WARN(Runtime test of readline failed. 
124 Configuring server without readline support.)
125                        feature_readline=missing
126                    fi
127                fi
128            else
129                if test "$WITH_READLINE" = "yes"; then
130                    AC_MSG_ERROR(Specified --with-readline but the 
131 test to link against the library failed.)
132                else
133                    AC_MSG_WARN(Test to link against readline library failed. 
134 Configuring server without readline support.)
135                    feature_readline=missing
136                fi
137            fi
138        fi
139     fi