7c436e51e118dc595b4ee250a4c1080d5cbce442
[fw/sdcc] / debugger / mcs51 / acinclude.m4
1 dnl This macro will check for the presence of the readline library.
2 dnl To get it into the aclocal.m4 dnl file, do this:
3 dnl   aclocal -I . --verbose
4 dnl
5 dnl The --verbose will show all of the files that are searched
6 dnl for .m4 macros.
7
8 AC_DEFUN([wi_LIB_READLINE], [
9   dnl check for the readline.h header file
10
11   AC_CHECK_HEADER(readline/readline.h)
12
13   if test "$ac_cv_header_readline_readline_h" = yes; then
14     dnl check the readline version
15
16     cat > conftest.$ac_ext <<EOF
17 #include <stdio.h>
18 #include <readline/readline.h>
19 wi_LIB_READLINE_VERSION RL_VERSION_MAJOR RL_VERSION_MINOR
20 EOF
21
22     wi_READLINE_VERSION=$($CPP $CPPFLAGS conftest.$ac_ext | sed -n -e "s/^wi_LIB_READLINE_VERSION  *\([[0-9\]][[0-9\]]*\)  *\([[0-9\]][[0-9\]]*\)$/\1.\2/p")
23     rm -rf conftest*
24
25     if test -n "$wi_READLINE_VERSION"; then
26       wi_MAJOR=$(expr $wi_READLINE_VERSION : '\([[0-9]][[0-9]]*\)\.')
27       wi_MINOR=$(expr $wi_READLINE_VERSION : '[[0-9]][[0-9]]*\.\([[0-9]][[0-9]]*$\)')
28       if test $wi_MINOR -lt 10; then
29         wi_MINOR=$(expr $wi_MINOR \* 10)
30       fi
31       wi_READLINE_VERSION=$(expr $wi_MAJOR \* 100 + $wi_MINOR)
32     else
33       wi_READLINE_VERSION=-1
34     fi
35
36     dnl check for the readline library
37
38     ac_save_LIBS="$LIBS"
39     # Note: $LIBCURSES is permitted to be empty.
40
41     for LIBREADLINE in "-lreadline.dll" "-lreadline" "-lreadline $LIBCURSES" "-lreadline -ltermcap" "-lreadline -lncurses" "-lreadline -lcurses"
42     do
43       AC_MSG_CHECKING([for GNU Readline library $LIBREADLINE])
44
45       LIBS="$ac_save_LIBS $LIBREADLINE"
46
47       AC_TRY_LINK([
48         /* includes */
49         #include <stdio.h>
50         #include <readline/readline.h>
51       ],[
52         /* function-body */
53         readline(NULL);
54         rl_function_of_keyseq(NULL, NULL, NULL);
55       ],[
56         wi_cv_lib_readline=yes
57         AC_MSG_RESULT(yes)
58       ],[
59         wi_cv_lib_readline=no
60         AC_MSG_RESULT(no)
61       ])
62
63       if test "$wi_cv_lib_readline" = yes; then
64         AC_SUBST(LIBREADLINE)
65         AC_DEFINE_UNQUOTED(HAVE_LIBREADLINE, $wi_READLINE_VERSION, [Readline])
66         break
67       fi
68     done
69
70     LIBS="$ac_save_LIBS"
71   fi
72 ])