xref: /freebsd/contrib/ntp/sntp/m4/ntp_lineeditlibs.m4 (revision 416ba5c74546f32a993436a99516d35008e9f384)
1*2b15cb3dSCy SchubertAC_DEFUN([NTP_LINEEDITLIBS], [
2*2b15cb3dSCy Schubert    NTP_ORIG_LIBS="$LIBS"
3*2b15cb3dSCy Schubert    AC_ARG_WITH(
4*2b15cb3dSCy Schubert	[lineeditlibs],
5*2b15cb3dSCy Schubert	[AS_HELP_STRING(
6*2b15cb3dSCy Schubert	    [--with-lineeditlibs],
7*2b15cb3dSCy Schubert	    [edit,editline (readline may be specified if desired)]
8*2b15cb3dSCy Schubert	)],
9*2b15cb3dSCy Schubert	[use_lineeditlibs="$withval"],
10*2b15cb3dSCy Schubert	[use_lineeditlibs="edit,editline"]
11*2b15cb3dSCy Schubert    )
12*2b15cb3dSCy Schubert    AC_MSG_CHECKING([line editing libraries])
13*2b15cb3dSCy Schubert    AC_MSG_RESULT([$use_lineeditlibs])
14*2b15cb3dSCy Schubert    case "$use_lineeditlibs" in
15*2b15cb3dSCy Schubert     no)
16*2b15cb3dSCy Schubert	ntp_lib_lineedit=no
17*2b15cb3dSCy Schubert	;;
18*2b15cb3dSCy Schubert     *)
19*2b15cb3dSCy Schubert	for lineedit_lib in `echo $use_lineeditlibs | sed -e 's/,/ /'`; do
20*2b15cb3dSCy Schubert	    for term_lib in "" termcap curses ncurses; do
21*2b15cb3dSCy Schubert		case "$term_lib" in
22*2b15cb3dSCy Schubert		 '')
23*2b15cb3dSCy Schubert		    TRY_LIB="-l$lineedit_lib"
24*2b15cb3dSCy Schubert		    ;;
25*2b15cb3dSCy Schubert		 *)
26*2b15cb3dSCy Schubert		    TRY_LIB="-l$lineedit_lib -l$term_lib"
27*2b15cb3dSCy Schubert		    ;;
28*2b15cb3dSCy Schubert		esac
29*2b15cb3dSCy Schubert		LIBS="$NTP_ORIG_LIBS $TRY_LIB"
30*2b15cb3dSCy Schubert		AC_MSG_CHECKING([for readline() with $TRY_LIB])
31*2b15cb3dSCy Schubert		AC_TRY_LINK_FUNC([readline], [ntp_lib_lineedit="$TRY_LIB"])
32*2b15cb3dSCy Schubert		case "$ntp_lib_lineedit" in
33*2b15cb3dSCy Schubert		 '')
34*2b15cb3dSCy Schubert		    AC_MSG_RESULT([no])
35*2b15cb3dSCy Schubert		    ;;
36*2b15cb3dSCy Schubert		 *)
37*2b15cb3dSCy Schubert		    # Use readline()
38*2b15cb3dSCy Schubert		    AC_MSG_RESULT([yes])
39*2b15cb3dSCy Schubert		    break
40*2b15cb3dSCy Schubert		esac
41*2b15cb3dSCy Schubert		case "$term_lib" in
42*2b15cb3dSCy Schubert		 '')
43*2b15cb3dSCy Schubert		    # do not try el_gets without a terminal library
44*2b15cb3dSCy Schubert		    ;;
45*2b15cb3dSCy Schubert		 *)
46*2b15cb3dSCy Schubert		    AC_MSG_CHECKING([for el_gets() with $TRY_LIB])
47*2b15cb3dSCy Schubert		    AC_TRY_LINK_FUNC([el_gets], [ntp_lib_lineedit="$TRY_LIB"])
48*2b15cb3dSCy Schubert		    case "$ntp_lib_lineedit" in
49*2b15cb3dSCy Schubert		     '')
50*2b15cb3dSCy Schubert			AC_MSG_RESULT([no])
51*2b15cb3dSCy Schubert			;;
52*2b15cb3dSCy Schubert		     *) # Use el_gets()
53*2b15cb3dSCy Schubert			AC_MSG_RESULT([yes])
54*2b15cb3dSCy Schubert			break
55*2b15cb3dSCy Schubert			;;
56*2b15cb3dSCy Schubert		    esac	# $ntp_lib_lineedit
57*2b15cb3dSCy Schubert		esac		# $term_lib
58*2b15cb3dSCy Schubert	    done
59*2b15cb3dSCy Schubert	    case "$ntp_lib_lineedit" in
60*2b15cb3dSCy Schubert	     '')
61*2b15cb3dSCy Schubert		;;
62*2b15cb3dSCy Schubert	     *)
63*2b15cb3dSCy Schubert		break
64*2b15cb3dSCy Schubert		;;
65*2b15cb3dSCy Schubert	    esac
66*2b15cb3dSCy Schubert	done
67*2b15cb3dSCy Schubert	LIBS="$NTP_ORIG_LIBS"
68*2b15cb3dSCy Schubert	;;
69*2b15cb3dSCy Schubert    esac	# $use_lineeditlibs
70*2b15cb3dSCy Schubert
71*2b15cb3dSCy Schubert    case "$ntp_lib_lineedit" in
72*2b15cb3dSCy Schubert     '')
73*2b15cb3dSCy Schubert	ntp_lib_lineedit="no"
74*2b15cb3dSCy Schubert	;;
75*2b15cb3dSCy Schubert     no)
76*2b15cb3dSCy Schubert	;;
77*2b15cb3dSCy Schubert     *)
78*2b15cb3dSCy Schubert	EDITLINE_LIBS="$ntp_lib_lineedit"
79*2b15cb3dSCy Schubert	AC_SUBST([EDITLINE_LIBS])
80*2b15cb3dSCy Schubert	;;
81*2b15cb3dSCy Schubert    esac	# $ntp_lib_lineedit
82*2b15cb3dSCy Schubert
83*2b15cb3dSCy Schubert    case "$ntp_lib_lineedit" in
84*2b15cb3dSCy Schubert     no)
85*2b15cb3dSCy Schubert	;;
86*2b15cb3dSCy Schubert     *)
87*2b15cb3dSCy Schubert	AC_CHECK_HEADERS([readline.h readline/readline.h histedit.h])
88*2b15cb3dSCy Schubert	AC_CHECK_HEADERS([history.h readline/history.h])
89*2b15cb3dSCy Schubert
90*2b15cb3dSCy Schubert	case "$ac_cv_header_histedit_h" in
91*2b15cb3dSCy Schubert	 yes)
92*2b15cb3dSCy Schubert	    AC_CACHE_CHECK(
93*2b15cb3dSCy Schubert		[number of arguments to el_init()],
94*2b15cb3dSCy Schubert		[ntp_cv_el_init_args],
95*2b15cb3dSCy Schubert		[AC_COMPILE_IFELSE(
96*2b15cb3dSCy Schubert		    [AC_LANG_PROGRAM(
97*2b15cb3dSCy Schubert			[[
98*2b15cb3dSCy Schubert			    #include <stdio.h>
99*2b15cb3dSCy Schubert			    #include <histedit.h>
100*2b15cb3dSCy Schubert			]],
101*2b15cb3dSCy Schubert			[[
102*2b15cb3dSCy Schubert			    el_init("conftest", stdin, stdout, stderr);
103*2b15cb3dSCy Schubert			]]
104*2b15cb3dSCy Schubert		    )],
105*2b15cb3dSCy Schubert		    [ntp_cv_el_init_args=4],
106*2b15cb3dSCy Schubert		    [ntp_cv_el_init_args=3]
107*2b15cb3dSCy Schubert		)]
108*2b15cb3dSCy Schubert	    )
109*2b15cb3dSCy Schubert	    AC_DEFINE_UNQUOTED(
110*2b15cb3dSCy Schubert		[EL_INIT_ARGS],
111*2b15cb3dSCy Schubert		[$ntp_cv_el_init_args],
112*2b15cb3dSCy Schubert		[number of args to el_init()]
113*2b15cb3dSCy Schubert		)
114*2b15cb3dSCy Schubert	esac
115*2b15cb3dSCy Schubert
116*2b15cb3dSCy Schubert	AC_MSG_CHECKING([whether readline supports history])
117*2b15cb3dSCy Schubert
118*2b15cb3dSCy Schubert	ntp_lib_lineedit_history="no"
119*2b15cb3dSCy Schubert	ORIG_LIBS="$LIBS"
120*2b15cb3dSCy Schubert	LIBS="$ORIG_LIBS $ntp_lib_lineedit"
121*2b15cb3dSCy Schubert	AC_TRY_LINK_FUNC([add_history], [ntp_lib_lineedit_history="yes"])
122*2b15cb3dSCy Schubert	LIBS="$ORIG_LIBS"
123*2b15cb3dSCy Schubert
124*2b15cb3dSCy Schubert	AC_MSG_RESULT([$ntp_lib_lineedit_history])
125*2b15cb3dSCy Schubert
126*2b15cb3dSCy Schubert	case "$ntp_lib_lineedit_history" in
127*2b15cb3dSCy Schubert	 yes)
128*2b15cb3dSCy Schubert	    AC_DEFINE([HAVE_READLINE_HISTORY], [1],
129*2b15cb3dSCy Schubert		[Define if your readline library has \`add_history'])
130*2b15cb3dSCy Schubert	esac
131*2b15cb3dSCy Schubert    esac	# $ntp_lib_lineedit
132*2b15cb3dSCy Schubert    AS_UNSET([NTP_ORIG_LIBS])
133*2b15cb3dSCy Schubert    AS_UNSET([ORIG_LIBS])
134*2b15cb3dSCy Schubert    AS_UNSET([TRY_LIB])
135*2b15cb3dSCy Schubert    AS_UNSET([use_lineeditlibs])
136*2b15cb3dSCy Schubert])dnl
137