Patrick Welche <prlw1@cam.ac.uk>
[netbsd-mini2440.git] / external / bsd / ntp / dist / m4 / ntp_lineeditlibs.m4
blob99c79211e8500e0373a8cc6f62ad63286b1cc991
1 AC_DEFUN([NTP_LINEEDITLIBS], [
2     NTP_ORIG_LIBS="$LIBS"
3     AC_ARG_WITH([lineeditlibs],
4         [AC_HELP_STRING([--with-lineeditlibs], [edit,editline (readline may be specified if desired)])],
5         [use_lineeditlibs="$withval"],
6         [use_lineeditlibs="edit,editline"])
8     AC_MSG_CHECKING([line editing libraries])
9     AC_MSG_RESULT([$use_lineeditlibs])
10     case "$use_lineeditlibs" in
11      no) 
12         ntp_lib_lineedit=no
13         ;;
14      *)
15         for lineedit_lib in `echo $use_lineeditlibs | sed -e 's/,/ /'`; do
16             for term_lib in "" termcap curses ncurses; do
17                 case "$term_lib" in
18                  '') 
19                     TRY_LIB="-l$lineedit_lib"
20                     ;;
21                  *) TRY_LIB="-l$lineedit_lib -l$term_lib"
22                 esac    # $term_lib
23                 LIBS="$NTP_ORIG_LIBS $TRY_LIB"
24                 AC_MSG_CHECKING([for readline() with $TRY_LIB])
25                 AC_TRY_LINK_FUNC([readline], [ntp_lib_lineedit="$TRY_LIB"])
26                 case "$ntp_lib_lineedit" in
27                  '')
28                     AC_MSG_RESULT([no])
29                     ;;
30                  *) 
31                     # Use readline()
32                     AC_MSG_RESULT([yes])
33                     break
34                 esac            # $ntp_lib_lineedit
35                 case "$term_lib" in
36                  '')
37                     # do not try el_gets without a terminal library
38                     ;;
39                  *)
40                     AC_MSG_CHECKING([for el_gets() with $TRY_LIB])
41                     AC_TRY_LINK_FUNC([el_gets], [ntp_lib_lineedit="$TRY_LIB"])
42                     case "$ntp_lib_lineedit" in
43                      '')
44                         AC_MSG_RESULT([no])
45                         ;;
46                      *) # Use el_gets()
47                         AC_MSG_RESULT([yes])
48                         break
49                         ;;
50                     esac        # $ntp_lib_lineedit
51                 esac            # $term_lib
52             done
53             case "$ntp_lib_lineedit" in
54              '') ;;
55              *)  break ;;
56             esac
57         done
58         LIBS="$NTP_ORIG_LIBS"
59         ;;
60     esac        # $use_lineeditlibs
62     case "$ntp_lib_lineedit" in
63      '')
64         ntp_lib_lineedit="no"
65         ;;
66      no)
67         ;;
68      *)
69         EDITLINE_LIBS="$ntp_lib_lineedit"
70         AC_SUBST(EDITLINE_LIBS)
71         ;;
72     esac        # $ntp_lib_lineedit
74     case "$ntp_lib_lineedit" in
75      no)
76         ;;
77      *)
78         dnl AC_DEFINE(HAVE_LIBREADLINE, 1,
79         dnl           [Define if you have a readline compatible library])
80         AC_CHECK_HEADERS([readline.h readline/readline.h histedit.h])
81         AC_CHECK_HEADERS([history.h readline/history.h])
82         
83         AC_MSG_CHECKING([whether readline supports history])
84         
85         ntp_lib_lineedit_history="no"
86         ORIG_LIBS="$LIBS"
87         LIBS="$ORIG_LIBS $ntp_lib_lineedit"
88         AC_TRY_LINK_FUNC([add_history], [ntp_lib_lineedit_history="yes"])
89         LIBS="$ORIG_LIBS"
91         AC_MSG_RESULT([$ntp_lib_lineedit_history])
93         case "$ntp_lib_lineedit_history" in
94          yes)
95             AC_DEFINE(HAVE_READLINE_HISTORY, 1,
96                       [Define if your readline library has \`add_history'])
97         esac    # $ntp_lib_lineedit_history
98     esac        # $ntp_lib_lineedit
99     dnl when oldest supported autoconf has AS_UNSET
100     dnl AS_UNSET([NTP_ORIG_LIBS TRY_LIB use_lineeditlibs])
101     $as_unset NTP_ORIG_LIBS TRY_LIB use_lineeditlibs
102 ])dnl