45c3a70f9f6c629740ff1eba990109482b204fdf
[sfrench/samba-autobuild/.git] / source4 / lib / cmdline / config.m4
1 #################################################
2
3 ###############################################
4 # Readline included by default unless explicitly asked not to
5 test "${with_readline+set}" != "set" && with_readline=yes
6
7 # test for where we get readline() from
8 AC_MSG_CHECKING(whether to use readline)
9 AC_ARG_WITH(readline,
10 [  --with-readline[=DIR]   Look for readline include/libs in DIR (default=auto) ],
11 [  case "$with_readline" in
12   yes)
13     AC_MSG_RESULT(yes)
14
15     AC_CHECK_HEADERS(readline.h history.h readline/readline.h)
16     AC_CHECK_HEADERS(readline/history.h)
17
18     AC_CHECK_HEADERS(readline.h readline/readline.h,[
19       for termlib in ncurses curses termcap terminfo termlib tinfo; do
20        AC_CHECK_LIB(${termlib}, tgetent, [TERMLIBS="-l${termlib}"; break])
21       done
22       AC_CHECK_LIB(readline, rl_callback_handler_install,
23        [TERMLIBS="-lreadline $TERMLIBS"
24        AC_DEFINE(HAVE_LIBREADLINE,1,[Whether the system has readline])
25        break], [TERMLIBS=], $TERMLIBS)])
26     ;;
27   no)
28     AC_MSG_RESULT(no)
29     ;;
30   *)
31     AC_MSG_RESULT(yes)
32
33     # Needed for AC_CHECK_HEADERS and AC_CHECK_LIB to look at
34     # alternate readline path
35     _ldflags=${LDFLAGS}
36     _cppflags=${CPPFLAGS}
37
38     # Add additional search path
39     LDFLAGS="-L$with_readline/lib $LDFLAGS"
40     CPPFLAGS="-I$with_readline/include $CPPFLAGS"
41
42     AC_CHECK_HEADERS(readline.h history.h readline/readline.h)
43     AC_CHECK_HEADERS(readline/history.h)
44
45     AC_CHECK_HEADERS(readline.h readline/readline.h,[
46       for termlib in ncurses curses termcap terminfo termlib; do
47        AC_CHECK_LIB(${termlib}, tgetent, [TERMLIBS="-l${termlib}"; break])
48       done
49       AC_CHECK_LIB(readline, rl_callback_handler_install,
50        [TERMLDFLAGS="-L$with_readline/lib"
51        TERMCPPFLAGS="-I$with_readline/include"
52        LDFLAGS="-L$with_readline/lib $LDFLAGS"
53        CPPFLAGS="-I$with_readline/include $CPPFLAGS"
54        TERMLIBS="-lreadline $TERMLIBS"
55        AC_DEFINE(HAVE_LIBREADLINE,1,[Whether the system has readline])
56        break], [TERMLIBS= CPPFLAGS=$_cppflags], $TERMLIBS)])
57
58     ;;
59   esac],
60   AC_MSG_RESULT(no)
61 )
62
63 # The readline API changed slightly from readline3 to readline4, so
64 # code will generate warnings on one of them unless we have a few
65 # special cases.
66 AC_CHECK_LIB(readline, rl_completion_matches,
67              [AC_DEFINE(HAVE_NEW_LIBREADLINE, 1, 
68                         [Do we have rl_completion_matches?])],
69              [],
70              [$TERMLIBS])
71
72 TMP_LIBCMDLINE_OBJS="lib/cmdline/readline.o lib/cmdline/popt_common.o"
73 TMP_LIBCMDLINE_LIBS="$TERMLIBS"
74
75 SMB_EXT_LIB(READLINE, [${TMP_LIBCMDLINE_LIBS}])
76
77 SMB_SUBSYSTEM(LIBCMDLINE,[],
78                 [${TMP_LIBCMDLINE_OBJS}],
79                 [],
80                 [LIBPOPT EXT_LIB_READLINE EXT_LIB_ALLLIBS LIBCMDLINE_CREDENTIALS])
81
82 AC_CACHE_CHECK([whether getpass should be replaced],samba_cv_REPLACE_GETPASS,[
83 SAVE_CPPFLAGS="$CPPFLAGS"
84 CPPFLAGS="$CPPFLAGS -I${srcdir-.}/ -I${srcdir-.}/include -I${srcdir-.}/ubiqx -I${srcdir-.}/popt  -I${srcdir-.}/smbwrapper"
85 AC_TRY_COMPILE([
86 #define REPLACE_GETPASS 1
87 #define NO_CONFIG_H 1
88 #define main dont_declare_main
89 #include "${srcdir-.}/lib/cmdline/getsmbpass.c"
90 #undef main
91 ],[],samba_cv_REPLACE_GETPASS=yes,samba_cv_REPLACE_GETPASS=no)
92 CPPFLAGS="$SAVE_CPPFLAGS"
93 ])
94 if test x"$samba_cv_REPLACE_GETPASS" = x"yes"; then
95         AC_DEFINE(REPLACE_GETPASS,1,[Whether getpass should be replaced])
96 fi
97