* configure.in, configure, sdccconf_in.h, src/SDCCglobal,
[fw/sdcc] / debugger / mcs51 / acinclude.m4
1 dnl Scott Dattalo
2 dnl
3 dnl  This is copied from the NcFTP distribution.
4 dnl  Author Mike Gleason mgleason@NcFTP.com
5 dnl
6 dnl This macro will check for the presence and version
7 dnl of the readline library. To get it into the aclocal.m4
8 dnl file, do this:
9 dnl   aclocal -I . --verbose
10 dnl
11 dnl The --verbose will show all of the files that are searched
12 dnl for .m4 macros.
13 AC_DEFUN([wi_LIB_READLINE], [
14 AC_MSG_CHECKING([for GNU Readline library, version 2.0 or newer])
15
16 wi_cv_lib_readline=no
17 wi_cv_lib_readline_result=no
18 ac_save_LIBS="$LIBS"
19 # Note: $LIBCURSES is permitted to be empty.
20 for LIBREADLINE in "-lreadline" "-lreadline $LIBCURSES" "-lreadline -ltermcap" "-lreadline -lncurses" "-lreadline -lcurses"
21 do
22         LIBS="$ac_save_LIBS $LIBREADLINE"
23         AC_TRY_RUN([
24         /* program */
25 #include <stdio.h>
26 #include <stdlib.h>
27
28 main(int argc, char **argv)
29 {
30         /* Note:  don't actually call readline, since it may block;
31          * We just want to see if it (dynamic) linked in okay.
32          */
33         if (argc == 0)  /* never true */
34                 readline(0);
35         exit(0);
36 }
37 ],[
38         # action if true
39         wi_cv_lib_readline=yes
40 ],[
41         # action if false
42         wi_cv_lib_readline=no
43 ],[
44         # action if cross compiling
45         wi_cv_lib_readline=no
46 ])
47
48         if test "$wi_cv_lib_readline" = yes ; then break ; fi
49 done
50
51 # Now try it again, to be sure it is recent enough.
52 # rl_function_of_keyseq appeared in version 2.0
53 #
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)"
56 dnl ])
57         AC_TRY_LINK([
58                 /* includes */
59         ],[
60                 /* function-body */
61                 readline(0);
62                 rl_function_of_keyseq(0);
63         ],[
64                 wi_cv_lib_readline=yes
65         ],[
66                 wi_cv_lib_readline=no
67                 wi_cv_lib_readline_result="no (it is present but too old to use)"
68         ])
69
70 if test "$wi_cv_lib_readline" = no ; then
71         LIBREADLINE=""
72         # restore LIBS
73         LIBS="$ac_save_LIBS"
74 else
75         /bin/rm -f readline.ver
76         touch readline.ver
77
78         AC_TRY_RUN([
79         /* program */
80 #include <unistd.h>
81 #include <sys/types.h>
82 #include <stdio.h>
83
84 extern char *rl_library_version;
85
86 main()
87 {
88         FILE *fp;
89         double d;
90
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);
97         exit(0);
98 }
99         ],[
100                 # action if true
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
104         ],[
105                 # action if false
106                 rl_library_version=''
107                 rlver=''
108                 /bin/rm -f readline.ver
109         ],[
110                 # action if cross compiling
111                 rl_library_version=''
112                 rlver=''
113                 /bin/rm -f readline.ver
114         ])
115
116         case "$rlver" in
117                 ???)
118                         wi_cv_lib_readline_result="yes, installed version is $rl_library_version"
119                         ;;
120                 *)
121                         # Test using current LIBS.
122                         AC_TRY_LINK([
123                                 /* includes */
124                                 extern int rl_completion_append_character;
125                         ],[
126                                 /* function-body */
127                                 readline(0);
128                                 rl_completion_append_character = 0;
129                         ],[
130                                 rlver="210"
131                         ],[
132                                 rlver="200"
133                         ])
134
135                         if test "$rlver" = "210" ; then
136                                 wi_cv_lib_readline_result="yes, version 2.1 or higher"
137                         else
138                                 wi_cv_lib_readline_result="yes, version 2.0"
139                         fi
140                         ;;
141         esac
142
143         wi_cv_lib_readline=yes
144         # restore LIBS
145         LIBS="$ac_save_LIBS"
146 fi
147 AC_MSG_RESULT($wi_cv_lib_readline_result)
148 AC_SUBST(LIBREADLINE)
149
150 if test "$wi_cv_lib_readline" = yes ; then
151         # Now verify that all the headers are installed.
152         #
153         AC_REQUIRE_CPP()
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])
160
161         for xxwi in \
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"
167         do
168                 if test "$xxwi" = no ; then
169                         break
170                 fi
171         done
172
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)"
177         else
178                 AC_DEFINE_UNQUOTED(HAVE_LIBREADLINE, $rlver,[Readline])
179         fi
180 fi
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
184                 ac_save_LIBS="$LIBS"
185                 LIBS="$ac_save_LIBS $LIBREADLINE"
186                 AC_CHECK_FUNCS(rl_completion_matches completion_matches)
187                 # restore LIBS
188                 LIBS="$ac_save_LIBS"
189         fi
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])
192         ac_save_LIBS="$LIBS"
193         LIBS="$ac_save_LIBS $LIBREADLINE"
194         ac_save_CC="$CC"
195         CC="$CXX"
196         AC_TRY_LINK([
197 #include <stdio.h>
198 #include <readline/readline.h>
199 void func(void) { return; }
200         ],[
201                 rl_callback_handler_install(">", (void(*)(char*))func);
202         ],[
203                 AC_DEFINE(READLINE_CB_TAKES_CAST, 1, [callbacks take a cast])
204                 AC_MSG_RESULT([yes])
205         ],[
206                 AC_MSG_RESULT([no])
207         ])
208         # restore LIBS
209         LIBS="$ac_save_LIBS"
210         CC="$ac_save_CC"
211 ])
212 dnl
213 dnl