r18208: Mac OS X also doesn't have history_list()
[jelmer/samba4-debian.git] / source / lib / smbreadline / readline.m4
1 ###############################################
2 # Readline included by default unless explicitly asked not to
3 test "${with_readline+set}" != "set" && with_readline=yes
4
5 EXTERNAL_READLINE=no
6 # test for where we get readline() from
7 AC_MSG_CHECKING(whether to use readline)
8 AC_ARG_WITH(readline,
9 [  --with-readline[=DIR]   Look for readline include/libs in DIR (default=auto) ],
10 [  case "$with_readline" in
11   yes)
12     AC_MSG_RESULT(yes)
13
14     AC_CHECK_HEADERS(readline.h history.h readline/readline.h)
15     AC_CHECK_HEADERS(readline/history.h)
16
17     AC_CHECK_HEADERS(readline.h readline/readline.h,[
18       for termlib in ncurses curses termcap terminfo termlib tinfo; do
19        AC_CHECK_LIB(${termlib}, tgetent, [TERMLIBS="-l${termlib}"; break])
20       done
21       AC_CHECK_LIB(readline, rl_callback_handler_install,
22        [TERMLIBS="-lreadline $TERMLIBS"
23        EXTERNAL_READLINE=yes
24        break], [TERMLIBS=], $TERMLIBS)])
25     ;;
26   no)
27     AC_MSG_RESULT(no)
28     ;;
29   *)
30     AC_MSG_RESULT(yes)
31
32     # Needed for AC_CHECK_HEADERS and AC_CHECK_LIB to look at
33     # alternate readline path
34     _ldflags=${LDFLAGS}
35     _cppflags=${CPPFLAGS}
36
37     # Add additional search path
38     LDFLAGS="-L$with_readline/lib $LDFLAGS"
39     CPPFLAGS="-I$with_readline/include $CPPFLAGS"
40
41     AC_CHECK_HEADERS(readline.h history.h readline/readline.h)
42     AC_CHECK_HEADERS(readline/history.h)
43
44     AC_CHECK_HEADERS(readline.h readline/readline.h,[
45       for termlib in ncurses curses termcap terminfo termlib; do
46        AC_CHECK_LIB(${termlib}, tgetent, [TERMLIBS="-l${termlib}"; break])
47       done
48       AC_CHECK_LIB(readline, rl_callback_handler_install,
49        [TERMLDFLAGS="-L$with_readline/lib"
50        TERMCPPFLAGS="-I$with_readline/include"
51        LDFLAGS="-L$with_readline/lib $LDFLAGS"
52        CPPFLAGS="-I$with_readline/include $CPPFLAGS"
53        TERMLIBS="-lreadline $TERMLIBS"
54        EXTERNAL_READLINE=yes
55        break], [TERMLIBS= CPPFLAGS=$_cppflags], $TERMLIBS)])
56
57     ;;
58   esac],
59   AC_MSG_RESULT(no)
60 )
61
62 # The readline API changed slightly from readline3 to readline4, so
63 # code will generate warnings on one of them unless we have a few
64 # special cases.
65 AC_CHECK_LIB(readline, rl_completion_matches,
66              [AC_DEFINE(HAVE_NEW_LIBREADLINE, 1, 
67                         [Do we have rl_completion_matches?])],
68              [],
69              [$TERMLIBS])
70
71 # not all readline libs have rl_event_hook or history_list
72 AC_CHECK_DECLS(rl_event_hook, [], [], [#include <readline/readline.h>])
73 AC_CHECK_LIB(readline, history_list,
74              [AC_DEFINE(HAVE_HISTORY_LIST, 1, [Do we have history_list?])],
75              [],
76              [$TERMLIBS])
77
78 AC_MSG_CHECKING(whether to use extern readline)
79 if test x"$EXTERNAL_READLINE" = x"yes"; then
80         AC_MSG_RESULT(yes)
81         AC_DEFINE(HAVE_LIBREADLINE,1,[Whether the system has readline])
82         SMB_SUBSYSTEM(SMBREADLINE, [lib/smbreadline/smbreadline.o], [READLINE LIBREPLACE])
83         SMB_EXT_LIB(READLINE, [${TERMLIBS}])
84         SMB_ENABLE(READLINE,YES)
85 else
86         SMB_SUBSYSTEM(SMBREADLINE, [lib/smbreadline/smbreadline.o], [LIBREPLACE])
87         AC_MSG_RESULT(no)
88 fi