Fix "Trying to put -1529999752 into 8 bits" type warnings after loading
[freeciv.git] / m4 / readline.m4
blobdfc2be3c678226908ea42c62fe35861054eeac39
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     /* printf(line); */
38   }
41 int main(void) {
42 /* Try to init readline and see if it barfs. */
43   using_history();
44   read_history(TEMP_FILE);
45   rl_initialize();
46   rl_callback_handler_install("_ ", handle_readline_input_callback);
47   rl_callback_handler_remove();  /* needed to re-set terminal */
48   return(0);
50 ]])],[AC_MSG_RESULT(yes)
51   [$2]],[AC_MSG_RESULT(no)
52   [$3]],[AC_MSG_RESULT(unknown: cross-compiling)
53   [$2]])
54 LIBS="$templibs"
57 AC_DEFUN([FC_HAS_READLINE],
59     dnl Readline library and header files.
60     if test "$WITH_READLINE" = "yes" || test "$WITH_READLINE" = "maybe"; then
61        HAVE_TERMCAP="";
62        dnl Readline header
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.])
70            else
71                AC_MSG_WARN(Did not find readline header file. 
72 Configuring server without readline support.)
73                feature_readline=missing
74            fi
75        else
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.
83                dnl
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")
92                      )
93                    )
94                  )
95                )
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],
103                         ["$HAVE_TERMCAP"])
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.])
107                    fi
108                fi
109            fi
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])
117                else
118                    if test "$WITH_READLINE" = "yes"; then
119                        AC_MSG_ERROR(Specified --with-readline but the 
120 runtime test of readline failed.)
121                    else
122                        AC_MSG_WARN(Runtime test of readline failed. 
123 Configuring server without readline support.)
124                        feature_readline=missing
125                    fi
126                fi
127            else
128                if test "$WITH_READLINE" = "yes"; then
129                    AC_MSG_ERROR(Specified --with-readline but the 
130 test to link against the library failed.)
131                else
132                    AC_MSG_WARN(Test to link against readline library failed. 
133 Configuring server without readline support.)
134                    feature_readline=missing
135                fi
136            fi
137        fi
138     fi