xref: /freebsd/contrib/ntp/sntp/m4/ntp_libntp.m4 (revision a03411e84728e9b267056fd31c7d1d9d1dc1b01e)
1dnl ######################################################################
2dnl Common m4sh code for libntp and clients
3dnl
4dnl Any configure tests which libntp or libisc code depends upon should
5dnl be here or in another m4 macro used by the top-level and sntp
6dnl configure.ac files, so that libntp can be moved into the sntp
7dnl subpackage while retaining access to such test results.
8dnl
9AC_DEFUN([NTP_LIBNTP], [
10
11AC_REQUIRE([NTP_CROSSCOMPILE])
12
13# HMS: Save $LIBS and empty it.
14# any LIBS we add here should go in to LDADD_LIBNTP
15AC_SUBST([LDADD_LIBNTP])
16__LIBS=$LIBS
17LIBS=
18
19dnl The contents of NTP_PROG_CC used to be here...
20
21AC_PROG_INSTALL
22# [Bug 2332] because we need to know if we are using GNU ld...
23LT_PATH_LD
24
25NTP_DIR_SEP
26NTP_LINEEDITLIBS
27NTP_LIB_M
28
29AC_FUNC_FORK
30AC_FUNC_ALLOCA
31AC_FUNC_STRERROR_R
32
33ac_busted_vpath_in_make=no
34case "$build" in
35 *-*-irix6.1*)	# 64 bit only
36    # busted vpath?
37    ;;
38 *-*-irix6*)	# 6.2 (and later?)
39    ac_busted_vpath_in_make=yes
40    ;;
41 *-*-solaris2.5.1)
42    ac_busted_vpath_in_make=yes
43    ;;
44 *-*-unicosmp*)
45    ac_busted_vpath_in_make=yes
46    ;;
47esac
48
49case "$ac_busted_vpath_in_make$srcdir" in
50 yes.|no*)
51    ;;
52 *) case "`${MAKE-make} -v -f /dev/null 2>/dev/null | grep 'GNU Make'`" in
53     '')
54	AC_MSG_ERROR([building outside of the main directory requires GNU make])
55    esac
56    ;;
57esac
58
59case "$host" in
60 *-*-aix4*)
61	# Bug 2516:
62	# Was *-*-aix[[4-9]]*
63	# XXX only verified thru AIX6.  But...
64	# Ken Link says this is fine for AIX 5.3 and 7.1, and sees no reason
65	# that this support would be in 5.3, removed in 6, and added back.
66	#
67	# (prr) aix 4.1 doesn't have clock_settime, but in aix 4.3 it's a stub
68	# (returning ENOSYS).  I didn't check 4.2.  If, in the future,
69	# IBM pulls its thumbs out long enough to implement clock_settime,
70	# this conditional will need to change.  Maybe use AC_TRY_RUN
71	# instead to try to set the time to itself and check errno.
72    ;;
73 *)
74    HMS_SEARCH_LIBS([LDADD_LIBNTP], [clock_gettime], [rt])
75    AC_CHECK_FUNCS([clock_getres clock_gettime clock_settime])
76    ;;
77esac
78
79AC_CHECK_FUNCS([getclock stime timegm strlcpy strlcat])
80
81# Bug 2713
82LDADD_LIBUTIL=
83AC_SUBST([LDADD_LIBUTIL])
84HMS_SEARCH_LIBS([LDADD_LIBUTIL], [snprintb], [util],
85		[AC_DEFINE([USE_SNPRINTB], 1, [OK to use snprintb()?])])
86
87dnl  HP-UX 11.31 on HPPA has a net/if.h that can't be compiled with gcc4
88dnl  due to an incomplete type (a union) mpinfou used in an array.  gcc3
89dnl  compiles it without complaint.  The mpinfou union is defined later
90dnl  in the resulting preprocessed source than the spu_info array in
91dnl  /usr/include/machine/sys/getppdp.h:
92dnl	extern union mpinfou spu_info[];
93dnl  triggering the error.  Our strategy is on HP-UX only, test compile
94dnl  net/if.h.  If that fails, try adding a duplicate definition of
95dnl  mpinfou, and if that helps add it to confdefs.h (used for further
96dnl  configure tests) and config.h.
97#
98AC_CHECK_HEADERS([errno.h sys/socket.h sys/types.h time.h])
99AC_CHECK_HEADERS([net/if.h], [], [], [
100    #ifdef HAVE_SYS_SOCKET_H
101    # include <sys/socket.h>
102    #endif
103])
104case "$host" in
105 *-hp-hpux*)
106    AC_CACHE_CHECK(
107	[if net/if.h requires mpinfou predeclaration],
108	[ntp_cv_predecl_mpinfou],
109	[
110	    np_cv_predecl_mpinfou=no
111	    case "$ac_cv_header_net_if_h" in
112	     no)
113		AC_COMPILE_IFELSE(
114		    [AC_LANG_PROGRAM(
115			[[
116			    typedef union mpinfou {
117				    struct pdk_mpinfo *pdkptr;
118				    struct mpinfo *pikptr;
119			    } mpinfou_t;
120			    #ifdef HAVE_SYS_SOCKET_H
121			    # include <sys/socket.h>
122			    #endif
123			    #include <net/if.h>
124			]],
125			[[
126			]]
127		    )],
128		    [
129			ntp_cv_predecl_mpinfou=yes
130			ac_cv_header_net_if_h=yes
131		    ]
132		)
133	    esac
134	]
135    )
136    case "$ntp_cv_predecl_mpinfou" in
137     yes)
138	cat >>confdefs.h <<_ACEOF
139#ifndef MPINFOU_PREDECLARED
140# define MPINFOU_PREDECLARED
141typedef union mpinfou {
142	struct pdk_mpinfo *pdkptr;
143	struct mpinfo *pikptr;
144} mpinfou_t;
145#endif
146_ACEOF
147	AH_BOTTOM([
148#ifndef MPINFOU_PREDECLARED
149# define MPINFOU_PREDECLARED
150typedef union mpinfou {
151	struct pdk_mpinfo *pdkptr;
152	struct mpinfo *pikptr;
153} mpinfou_t;
154#endif
155])
156    esac
157esac
158
159case "$host" in
160 *-linux*)
161    AC_CHECK_HEADERS([linux/if_addr.h], [], [], [
162	#ifdef HAVE_SYS_SOCKET_H
163	# include <sys/socket.h>
164	#endif
165    ])
166    AC_DEFINE([NEED_EARLY_FORK], [1], [having to fork the DNS worker early when doing chroot?])
167esac
168
169AC_CHECK_HEADERS([arpa/nameser.h sys/param.h sys/time.h sys/timers.h])
170# sys/sysctl.h depends on sys/param.h on OpenBSD - Bug 1576
171AC_CHECK_HEADERS([sys/sysctl.h], [], [], [
172    #if defined HAVE_SYS_PARAM_H
173    # include <sys/param.h>
174    #endif
175])
176AC_CHECK_HEADERS([netinet/in_system.h netinet/in_systm.h netinet/in.h])
177
178AC_CHECK_HEADERS([resolv.h], [], [], [
179    #ifdef HAVE_SYS_TYPES_H
180    # include <sys/types.h>
181    #endif
182    #ifdef HAVE_NETINET_IN_H
183    # include <netinet/in.h>
184    #endif
185    #ifdef HAVE_ARPA_NAMESER_H
186    # include <arpa/nameser.h>
187    #endif
188])
189
190AC_CHECK_HEADERS([net/if_var.h], [], [], [
191    #if HAVE_SYS_TYPES_H
192    # include <sys/types.h>
193    #endif
194    #ifdef HAVE_SYS_SOCKET_H
195    # include <sys/socket.h>
196    #endif
197    #ifdef HAVE_NETINET_IN_H
198    # include <netinet/in.h>
199    #endif
200    #ifdef HAVE_NET_IF_H
201    # include <net/if.h>
202    #endif
203])
204
205AC_CHECK_HEADERS([netinet/ip.h netinet/in_var.h], [], [], [
206    #ifdef HAVE_SYS_TYPES_H
207    # include <sys/types.h>
208    #endif
209    #ifdef HAVE_SYS_SOCKET_H
210    # include <sys/socket.h>
211    #endif
212    #ifdef HAVE_NET_IF_H
213    # include <net/if.h>
214    #endif
215    #ifdef HAVE_NETINET_IN_H
216    # include <netinet/in.h>
217    #endif
218    #ifdef HAVE_NET_IF_VAR_H
219    # include <net/if_var.h>
220    #endif
221    #ifdef HAVE_NETINET_IN_SYSTM_H
222    # include <netinet/in_systm.h>
223    #endif
224])
225
226# HMS: Do we need to check for -lsocket before or after these tests?
227HMS_SEARCH_LIBS([LDADD_LIBNTP], [inet_pton], [nsl])
228HMS_SEARCH_LIBS([LDADD_LIBNTP], [inet_ntop], [resolv], , , [-lnsl])
229
230# [Bug 1628] On Solaris, we need -lxnet -lsocket.  Generalize this to
231# avoid keying on the OS name:  If we find socket functions in
232# libsocket, next try for them in libxnet without libsocket, if found,
233# list both.  If we simply tested libxnet first, we would find the
234# functions there and never add libsocket.  See also [Bug 660]
235# http://bugs.ntp.org/show_bug.cgi?id=660#c9
236saved_LIBS=$LIBS
237HMS_SEARCH_LIBS([LDADD_LIBNTP], [setsockopt], [socket])
238case "$ac_cv_search_setsockopt" in
239 -lsocket)
240    LIBS="$saved_LIBS"
241    HMS_SEARCH_LIBS([LDADD_LIBNTP], [getsockopt], [xnet])
242    # XXX Possible trouble here - reading the comments above and looking at the
243    # code below I wonder if we'll add -lxnet when we don't need it.
244    # Also, do we need to add -lxnet to LDADD_LIBNTP, or perhaps see if it's
245    # there when it is not needed?
246    case "$ac_cv_search_getsockopt" in
247     -lxnet)
248	LIBS="-lxnet -lsocket $saved_LIBS"
249	;;
250     *) LIBS="-lsocket $saved_LIBS"
251	;;
252    esac
253    ;;
254esac
255AS_UNSET([saved_LIBS])
256
257# Bug 2427 - look for recvmsg here.
258AC_CHECK_FUNCS([recvmsg])
259
260AC_C_INLINE
261
262case "$ac_cv_c_inline" in
263 '')
264    ;;
265 *)
266    AC_DEFINE([HAVE_INLINE], [1], [inline keyword or macro available])
267    AC_SUBST([HAVE_INLINE])
268esac
269
270AC_HEADER_TIME
271AC_CHECK_SIZEOF([time_t])
272AC_C_CHAR_UNSIGNED		dnl CROSS_COMPILE?
273AC_CHECK_SIZEOF([signed char])
274AC_CHECK_TYPES([s_char, long long])
275AC_CHECK_SIZEOF([short])
276AC_CHECK_SIZEOF([int])
277AC_CHECK_SIZEOF([long])
278
279case "$ac_cv_type_long_long" in
280 no)
281    ;;
282 *)
283    AC_CHECK_SIZEOF([long long])
284    ;;
285esac
286
287case "$ac_cv_c_char_unsigned$ac_cv_sizeof_signed_char$ac_cv_type_s_char" in
288 *yes)
289    # We have a typedef for s_char.  Might as well believe it...
290    ;;
291 no0no)
292    # We have signed chars, can't say 'signed char', no s_char typedef.
293    AC_DEFINE([NEED_S_CHAR_TYPEDEF], [1],
294	[Do we need an s_char typedef?])
295    ;;
296 no1no)
297    # We have signed chars, can say 'signed char', no s_char typedef.
298    AC_DEFINE([NEED_S_CHAR_TYPEDEF], [1],
299	[Do we need an s_char typedef?])
300    ;;
301 yes0no)
302    # We have unsigned chars, can't say 'signed char', no s_char typedef.
303    AC_MSG_ERROR([No way to specify a signed character!])
304    ;;
305 yes1no)
306    # We have unsigned chars, can say 'signed char', no s_char typedef.
307    AC_DEFINE([NEED_S_CHAR_TYPEDEF], [1],
308	[Do we need an s_char typedef?])
309    ;;
310esac
311
312AC_TYPE_UID_T
313
314m4_divert_text([HELP_ENABLE],
315[AS_HELP_STRING([defaults:],
316    [+ yes, - no, s system-specific])])
317
318NTP_DEBUG
319
320# check if we can compile with pthreads
321AC_CHECK_HEADERS([semaphore.h])
322AC_CHECK_FUNCS([socketpair])
323AC_ARG_ENABLE(
324    [thread-support],
325    [AS_HELP_STRING([--enable-thread-support],
326		    [s use threads (+ if available)])],
327    [],
328    [enable_thread_support=yes]
329    )
330have_pthreads=no
331case "$enable_thread_support" in
332 no) ;;
333 *)
334    ol_found_pthreads=no
335    OL_THREAD_CHECK([ol_found_pthreads=yes])
336    case "$ol_found_pthreads" in
337     yes)
338	saved_LIBS="$LIBS"
339	LIBS="$LTHREAD_LIBS $LIBS"
340	saved_CFLAGS="$CFLAGS"
341	CFLAGS="$PTHREAD_CFLAGS $CFLAGS"
342	AC_CHECK_FUNCS([sem_timedwait])
343	LIBS="$saved_LIBS"
344	AS_UNSET([saved_LIBS])
345	CFLAGS="$saved_CFLAGS"
346	AS_UNSET([saved_CFLAGS])
347	case "$ac_cv_func_sem_timedwait" in
348	 yes)
349	    PTHREAD_LIBS="$LTHREAD_LIBS"
350	    have_pthreads=yes
351	esac
352    esac
353esac
354AC_SUBST([PTHREAD_LIBS])
355case "$have_pthreads" in
356 yes)
357    CFLAGS_NTP="$CFLAGS_NTP $PTHREAD_CFLAGS"
358    saved_LIBS="$LIBS"
359    LIBS="$LTHREAD_LIBS $LIBS"
360    saved_CFLAGS="$CFLAGS"
361    CFLAGS="$PTHREAD_CFLAGS $CFLAGS"
362    AC_CHECK_SIZEOF(
363	[pthread_t],
364	,
365	[
366	    AC_INCLUDES_DEFAULT()
367	    #include <pthread.h>
368	]
369    )
370    LIBISC_PTHREADS_NOTHREADS=pthreads
371    AC_DEFINE([ISC_PLATFORM_USETHREADS], [1],
372	      [enable libisc thread support?])
373    #
374    # We'd like to use sigwait() too
375    #
376    AC_CHECK_FUNC(
377	[sigwait],
378	[have_sigwait=yes],
379	[AC_CHECK_LIB(
380	    [c],
381	    [sigwait],
382	    [have_sigwait=yes],
383	    [AC_CHECK_LIB(
384		[pthread],
385		[sigwait],
386		[have_sigwait=yes],
387		[AC_CHECK_LIB(
388		    [pthread],
389		    [_Psigwait],
390		    [have_sigwait=yes],
391		    [have_sigwait=no]
392		)]
393	    )]
394	)]
395    )
396    case "$host:$have_sigwait" in
397     *-freebsd*:no)
398	AC_CHECK_LIB(
399	    [c_r],
400	    [sigwait],
401	    [have_sigwait=yes]
402	)
403    esac
404    case "$have_sigwait" in
405     yes)
406	ac_cv_func_sigwait=yes
407	AC_DEFINE([HAVE_SIGWAIT], [1], [sigwait() available?])
408    esac
409
410    AC_CHECK_FUNCS([pthread_attr_getstacksize])
411    AC_CHECK_FUNCS([pthread_attr_setstacksize sysconf])
412
413    case "$host" in
414     *-freebsd5.[[012]]|*-freebsd5.[[012]].*)
415	;;
416     *-freebsd5.[[3456789]]|*-freebsd5.[[3456789]].*|*-freebsd6.*)
417	AC_DEFINE([NEED_PTHREAD_SCOPE_SYSTEM], [1],
418		  [use PTHREAD_SCOPE_SYSTEM?])
419	;;
420     *-bsdi3.*|*-bsdi4.0*)
421	AC_DEFINE([NEED_PTHREAD_INIT], [1], [pthread_init() required?])
422	;;
423     *-linux*)
424	AC_DEFINE([HAVE_LINUXTHREADS], [1], [using Linux pthread?])
425	;;
426     *-solaris*)
427	AC_DEFINE([_POSIX_PTHREAD_SEMANTICS], [1])
428	AC_CHECK_FUNCS([pthread_setconcurrency])
429	case "$ac_cv_func_pthread_setconcurrency" in
430	 yes)
431	    AC_DEFINE([CALL_PTHREAD_SETCONCURRENCY], [1],
432		      [why not HAVE_P_S?])
433	esac
434	;;
435     *-sco-sysv*uw*|*-*-sysv*UnixWare*|*-*-sysv*OpenUNIX*)
436	AC_DEFINE([HAVE_UNIXWARE_SIGWAIT], [1], [deviant sigwait?])
437	;;
438    esac
439    hack_shutup_pthreadonceinit=no
440    case "$host" in
441     *-aix5.[[123]].*)
442	hack_shutup_pthreadonceinit=yes
443	;;
444     *-solaris2.[[89]])
445	hack_shutup_pthreadonceinit=yes
446	;;
447     *-solaris2.1[[0-9]])
448	AC_CACHE_CHECK(
449	    [if extra braces are needed for PTHREAD_ONCE_INIT],
450	    [ntp_cv_braces_around_pthread_once_init],
451	    [AC_COMPILE_IFELSE(
452		[AC_LANG_PROGRAM(
453		    [[
454			#include <pthread.h>
455		    ]],
456		    [[
457		        static pthread_once_t once_test =
458						PTHREAD_ONCE_INIT;
459		    ]]
460		)],
461		[ntp_cv_braces_around_pthread_once_init=no],
462		[ntp_cv_braces_around_pthread_once_init=yes]
463	    )]
464	)
465	case "$ntp_cv_braces_around_pthread_once_init" in
466	 yes)
467	    hack_shutup_pthreadonceinit=yes
468	esac
469	;;
470    esac
471    case "$hack_shutup_pthreadonceinit" in
472     yes)
473	AC_DEFINE([ISC_PLATFORM_BRACEPTHREADONCEINIT], [1],
474		  [Enclose PTHREAD_ONCE_INIT in extra braces?])
475    esac
476    LIBS="$saved_LIBS"
477    AS_UNSET([saved_LIBS])
478    CFLAGS="$saved_CFLAGS"
479    AS_UNSET([saved_CFLAGS])
480    ;;
481 *)
482    LIBISC_PTHREADS_NOTHREADS=nothreads
483    ;;
484esac
485AC_SUBST([LIBISC_PTHREADS_NOTHREADS])
486AM_CONDITIONAL([PTHREADS], [test "$have_pthreads" != "no"])
487
488AC_DEFUN([NTP_BEFORE_HW_FUNC_VSNPRINTF], [
489    AC_BEFORE([$0], [HW_FUNC_VSNPRINTF])dnl
490    AC_BEFORE([$0], [HW_FUNC_SNPRINTF])dnl
491    AC_ARG_ENABLE(
492	[c99-snprintf],
493	[AS_HELP_STRING([--enable-c99-snprintf], [s force replacement])],
494	[force_c99_snprintf=$enableval],
495	[force_c99_snprintf=no]
496	)
497    case "$force_c99_snprintf" in
498     yes)
499	hw_force_rpl_snprintf=yes
500	hw_force_rpl_vsnprintf=yes
501    esac
502    AH_VERBATIM(
503	[snprinte],dnl	sorted in config.h just before #define snprintf
504	[
505	    #if !defined(_KERNEL) && !defined(PARSESTREAM)
506	    /*
507	     * stdio.h must be included after _GNU_SOURCE is defined
508	     * but before #define snprintf rpl_snprintf
509	     */
510	    # include <stdio.h>
511	    #endif
512	])
513    AH_BOTTOM([
514	#if !defined(_KERNEL) && !defined(PARSESTREAM)
515	# if defined(HW_WANT_RPL_VSNPRINTF)
516	#  if defined(__cplusplus)
517	extern "C" {
518	# endif
519	# include <stdarg.h>
520	int rpl_vsnprintf(char *, size_t, const char *, va_list);
521	# if defined(__cplusplus)
522	}
523	#  endif
524	# endif
525	# if defined(HW_WANT_RPL_SNPRINTF)
526	#  if defined(__cplusplus)
527	extern "C" {
528	#  endif
529	int rpl_snprintf(char *, size_t, const char *, ...);
530	#  if defined(__cplusplus)
531	}
532	#  endif
533	# endif
534	#endif	/* !defined(_KERNEL) && !defined(PARSESTREAM) */
535	])
536]) dnl end of AC_DEFUN of NTP_BEFORE_HW_FUNC_VSNPRINTF
537
538AC_DEFUN([NTP_C99_SNPRINTF], [
539    AC_REQUIRE([NTP_BEFORE_HW_FUNC_VSNPRINTF])dnl
540    AC_REQUIRE([HW_FUNC_VSNPRINTF])dnl
541    AC_REQUIRE([HW_FUNC_SNPRINTF])dnl
542]) dnl end of DEFUN of NTP_C99_SNPRINTF
543
544NTP_C99_SNPRINTF
545
546dnl C99-snprintf does not handle %m
547case "$hw_use_rpl_vsnprintf:$hw_cv_func_vsnprintf" in
548 no:yes)
549    AC_CACHE_CHECK(
550	[if vsnprintf expands "%m" to strerror(errno)],
551	[ntp_cv_vsnprintf_percent_m],
552	[AC_RUN_IFELSE(
553	    [AC_LANG_PROGRAM(
554		[[
555		    #include <stdarg.h>
556		    #include <errno.h>
557		    #include <stdio.h>
558		    #include <string.h>
559
560		    int call_vsnprintf(
561			    char *	dst,
562			    size_t	sz,
563			    const char *fmt,
564			    ...
565			    );
566
567		    int call_vsnprintf(
568			    char *	dst,
569			    size_t	sz,
570			    const char *fmt,
571			    ...
572			    )
573		    {
574			    va_list	ap;
575			    int		rc;
576
577			    va_start(ap, fmt);
578			    rc = vsnprintf(dst, sz, fmt, ap);
579			    va_end(ap);
580
581			    return rc;
582		    }
583		]],
584		[[
585		    char	sbuf[512];
586		    char	pbuf[512];
587		    int		slen;
588
589		    strcpy(sbuf, strerror(ENOENT));
590		    errno = ENOENT;
591		    slen = call_vsnprintf(pbuf, sizeof(pbuf), "%m",
592					  "wrong");
593		    return strcmp(sbuf, pbuf);
594		]]
595	    )],
596	    [ntp_cv_vsnprintf_percent_m=yes],
597	    [ntp_cv_vsnprintf_percent_m=no],
598	    [ntp_cv_vsnprintf_percent_m=no]
599	)]
600    )
601    case "$ntp_cv_vsnprintf_percent_m" in
602     yes)
603	AC_DEFINE([VSNPRINTF_PERCENT_M], [1],
604		  [vsnprintf expands "%m" to strerror(errno)])
605    esac
606esac
607
608AC_CHECK_HEADERS([sys/clockctl.h])
609
610AC_ARG_ENABLE(
611    [clockctl],
612    [AS_HELP_STRING(
613	[--enable-clockctl],
614	[s Use /dev/clockctl for non-root clock control]
615    )],
616    [ntp_use_dev_clockctl=$enableval],
617    [ntp_use_dev_clockctl=$ac_cv_header_sys_clockctl_h]
618)
619
620AC_MSG_CHECKING([if we should use /dev/clockctl])
621AC_MSG_RESULT([$ntp_use_dev_clockctl])
622
623
624AC_CHECK_HEADERS([sys/capability.h sys/prctl.h])
625
626AC_MSG_CHECKING([if we have linux capabilities (libcap)])
627
628case "$ac_cv_header_sys_capability_h$ac_cv_header_sys_prctl_h" in
629 yesyes)
630    case "$host" in
631     mips-sgi-irix*)
632	ntp_have_linuxcaps=no
633	;;
634     *) ntp_have_linuxcaps=yes
635	;;
636    esac
637    ;;
638 *)
639    ntp_have_linuxcaps=no
640    ;;
641esac
642
643AC_ARG_ENABLE(
644    [linuxcaps],
645    [AS_HELP_STRING(
646	[--enable-linuxcaps],
647	[+ Use Linux capabilities for non-root clock control]
648    )],
649    [ntp_have_linuxcaps=$enableval]
650)
651
652AC_MSG_RESULT([$ntp_have_linuxcaps])
653
654case "$ntp_have_linuxcaps" in
655 yes)
656    AC_DEFINE([HAVE_LINUX_CAPABILITIES], [1],
657	[Do we have Linux capabilities?])
658    LIBS="$LIBS -lcap"
659    ;;
660esac
661
662
663AC_CHECK_HEADERS([priv.h])
664case "$ac_cv_header_priv_h" in
665 yes)
666    case "$host" in
667     *-solaris*)
668	AC_CHECK_FUNC(
669    	    [setppriv],
670    	    [ntp_have_solarisprivs=yes],
671    	    [ntp_have_solarisprivs=no]
672	)
673	;;
674    esac
675esac
676
677AC_ARG_ENABLE(
678    [solarisprivs],
679    [AS_HELP_STRING(
680	[--enable-solarisprivs],
681	[+ Use Solaris privileges for non-root clock control]
682    )],
683    [ntp_have_solarisprivs=$enableval]
684)
685
686AC_MSG_CHECKING([if we have solaris privileges])
687
688case "$ntp_have_solarisprivs" in
689 yes)
690    AC_DEFINE([HAVE_SOLARIS_PRIVS], [1],
691	[Are Solaris privileges available?])
692    ;;
693 '') ntp_have_solarisprivs="no"
694    ;;
695esac
696
697AC_MSG_RESULT([$ntp_have_solarisprivs])
698
699AC_CHECK_HEADERS([sys/mac.h])
700
701AC_ARG_ENABLE(
702    [trustedbsd_mac],
703    [AS_HELP_STRING(
704	[--enable-trustedbsd-mac],
705	[s Use TrustedBSD MAC policy for non-root clock control]
706    )],
707    [ntp_use_trustedbsd_mac=$enableval]
708)
709
710AC_MSG_CHECKING([if we should use TrustedBSD MAC privileges])
711
712case "$ntp_use_trustedbsd_mac$ac_cv_header_sys_mac_h" in
713 yesyes)
714    AC_DEFINE([HAVE_TRUSTEDBSD_MAC], [1],
715	[Are TrustedBSD MAC policy privileges available?])
716    ;;
717 *) ntp_use_trustedbsd_mac="no";
718    ;;
719esac
720
721AC_MSG_RESULT([$ntp_use_trustedbsd_mac])
722
723case "$ntp_use_dev_clockctl$ntp_have_linuxcaps$ntp_have_solarisprivs$ntp_use_trustedbsd_mac" in
724 *yes*)
725    AC_DEFINE([HAVE_DROPROOT], [1],
726	[Can we drop root privileges?])
727esac
728
729case "$host" in
730 *-*-darwin*)
731    AC_SEARCH_LIBS([res_9_init], [resolv])
732    ;;
733 *) AC_SEARCH_LIBS([res_init], [resolv])
734    ;;
735esac
736AC_HEADER_RESOLV
737#HMS: Why do we do this check so "early"?
738AC_CHECK_FUNCS([res_init], , [AC_CHECK_FUNCS([__res_init])])
739
740# We also need -lsocket, but we have tested for that already.
741AC_CHECK_FUNC([inet_ntop], [],
742    [AC_DEFINE([ISC_PLATFORM_NEEDNTOP], [1], [ISC: provide inet_ntop()])])
743AC_CHECK_FUNC([inet_pton], [],
744    [AC_DEFINE([ISC_PLATFORM_NEEDPTON], [1], [ISC: provide inet_pton()])])
745
746AC_CHECK_TYPES([uintptr_t, int32, u_int32])
747
748AH_VERBATIM([TYPEDEF_UINTPTR_T],
749[/* Provide a typedef for uintptr_t? */
750#ifndef HAVE_UINTPTR_T
751typedef unsigned int	uintptr_t;
752#define HAVE_UINTPTR_T	1
753#endif])
754
755case "$ac_cv_type_int32::$ac_cv_header_resolv_h" in
756 no::yes)
757    AC_CACHE_CHECK(
758	[for int32 with DNS headers included],
759	[ntp_cv_type_int32_with_dns],
760	[AC_COMPILE_IFELSE(
761	    [AC_LANG_PROGRAM(
762		[[
763		    #ifdef HAVE_ARPA_NAMESER_H
764		    # include <arpa/nameser.h>
765		    #endif
766		    #include <resolv.h>
767		]],
768		[[
769		    size_t cb = sizeof(int32);
770		]]
771	    )],
772	    [ntp_cv_type_int32_with_dns=yes],
773	    [ntp_cv_type_int32_with_dns=no]
774	)]
775    )
776    case "$ntp_cv_type_int32_with_dns" in
777     yes)
778	AC_DEFINE([HAVE_INT32_ONLY_WITH_DNS], [1],
779	    [int32 type in DNS headers, not others.])
780    esac
781esac
782
783case "$ac_cv_type_u_int32::$ac_cv_header_resolv_h" in
784 no::yes)
785    AC_CACHE_CHECK(
786	[for u_int32 with DNS headers included],
787	[ntp_cv_type_u_int32_with_dns],
788	[AC_COMPILE_IFELSE(
789	    [AC_LANG_PROGRAM(
790		[[
791		    #ifdef HAVE_ARPA_NAMESER_H
792		    # include <arpa/nameser.h>
793		    #endif
794		    #include <resolv.h>
795		]],
796		[[
797		    size_t cb = sizeof(u_int32);
798		]]
799	    )],
800	    [ntp_cv_type_u_int32_with_dns=yes],
801	    [ntp_cv_type_u_int32_with_dns=no]
802	)]
803    )
804    case "$ntp_cv_type_u_int32_with_dns" in
805     yes)
806	AC_DEFINE([HAVE_U_INT32_ONLY_WITH_DNS], [1],
807	    [u_int32 type in DNS headers, not others.])
808    esac
809esac
810
811AC_CHECK_HEADERS(
812    [sys/timepps.h],
813    [],
814    [],
815    [
816	#ifdef HAVE_SYS_TIME_H
817	# include <sys/time.h>
818	#endif
819	#ifdef HAVE_ERRNO_H
820	# include <errno.h>
821	#endif
822    ]
823)
824
825AC_CACHE_CHECK(
826    [for struct timespec],
827    [ntp_cv_struct_timespec],
828    [AC_COMPILE_IFELSE(
829	[AC_LANG_PROGRAM(
830	    [[
831		#include <sys/time.h>
832		/* Under SunOS, timespec is in sys/timepps.h,
833		   which needs errno.h and FRAC */
834		#ifdef HAVE_ERRNO_H
835		# include <errno.h>
836		#endif
837		#ifdef HAVE_SYS_TIMEPPS_H
838		# define FRAC 4294967296
839		# include <sys/timepps.h>
840		#endif
841	    ]],
842	    [[
843		struct timespec n;
844	    ]]
845	)],
846	[ntp_cv_struct_timespec=yes],
847	[ntp_cv_struct_timespec=no]
848    )]
849)
850case "$ntp_cv_struct_timespec" in
851 yes)
852    AC_DEFINE([HAVE_STRUCT_TIMESPEC], [1], [struct timespec declared?])
853esac
854
855AC_CACHE_CHECK(
856    [for struct ntptimeval],
857    [ntp_cv_struct_ntptimeval],
858    [AC_COMPILE_IFELSE(
859	[AC_LANG_PROGRAM(
860	    [[
861		#include <sys/time.h>
862		#include <sys/timex.h>
863	    ]],
864	    [[
865		struct ntptimeval n;
866	    ]]
867	)],
868	[ntp_cv_struct_ntptimeval=yes],
869	[ntp_cv_struct_ntptimeval=no]
870    )]
871)
872case "$ntp_cv_struct_ntptimeval" in
873 yes)
874    AC_DEFINE([HAVE_STRUCT_NTPTIMEVAL], [1],
875	[Do we have struct ntptimeval?])
876esac
877
878AC_CHECK_HEADERS(
879    [md5.h],
880    [],
881    [],
882    [
883	#ifdef HAVE_SYS_TYPES_H
884	# include <sys/types.h>
885	#endif
886    ]
887)
888
889AC_SEARCH_LIBS([MD5Init], [md5 md])
890AC_CHECK_FUNCS([MD5Init sysconf getdtablesize sigaction sigset sigvec])
891
892# HMS: does this need to be a cached variable?
893AC_ARG_ENABLE(
894    [signalled-io],
895    [AS_HELP_STRING([--enable-signalled-io], [s Use signalled IO if we can])],
896    [use_signalled_io=$enableval],
897    [use_signalled_io=yes]
898    )
899
900AC_CACHE_CHECK(
901    [for SIGIO],
902    [ntp_cv_hdr_def_sigio],
903    [AC_PREPROC_IFELSE(
904	[AC_LANG_SOURCE([
905	    #include <signal.h>
906
907	    #ifndef SIGIO
908	    # error
909	    #endif
910	])],
911	[ntp_cv_hdr_def_sigio=yes],
912	[ntp_cv_hdr_def_sigio=no]
913    )]
914 )
915
916dnl Override those system that have a losing SIGIO
917AC_MSG_CHECKING([if we want to use SIGIO])
918ans=no
919case "$ntp_cv_hdr_def_sigio" in
920 yes)
921    ans=yes
922    case "$host" in
923     alpha*-dec-osf4*|alpha*-dec-osf5*)
924	ans=no
925	;;
926     *-convex-*)
927	ans=no
928	;;
929     *-dec-*)
930	ans=no
931	;;
932     *-pc-cygwin*)
933	ans=no
934	;;
935     *-sni-sysv*)
936	ans=no
937	;;
938     *-stratus-vos)
939	ans=no
940	;;
941     *-univel-sysv*)
942	ans=no
943	;;
944     *-*-irix6*)
945	ans=no
946	;;
947     *-*-freebsd*)
948	ans=no
949	;;
950     *-*-*linux*)
951	ans=no
952	;;
953     *-*-unicosmp*)
954	ans=no
955	;;
956     *-*-kfreebsd*)
957	ans=no
958	;;
959     m68k-*-mint*)
960	ans=no
961	;;
962    esac
963    case "$ans" in
964     no)
965	ans="Possible for $host but disabled because of reported problems"
966	;;
967    esac
968    ;;
969esac
970case "$ans" in
971 yes)
972    case "$use_signalled_io" in
973     yes)
974	AC_DEFINE([HAVE_SIGNALED_IO], [1],
975	    [Can we use SIGIO for tcp and udp IO?])
976	;;
977     *) ans="Allowed for $host but --disable-signalled-io was given"
978	;;
979    esac
980esac
981AC_MSG_RESULT([$ans])
982
983AC_CACHE_CHECK(
984    [for SIGPOLL],
985    [ntp_cv_hdr_def_sigpoll],
986    [AC_PREPROC_IFELSE(
987	[AC_LANG_SOURCE([
988	    #include <signal.h>
989
990	    #ifndef SIGPOLL
991	    # error
992	    #endif
993	])],
994	[ntp_cv_hdr_def_sigpoll=yes],
995	[ntp_cv_hdr_def_sigpoll=no]
996    )]
997)
998
999AC_MSG_CHECKING([if we can use SIGPOLL for UDP I/O])
1000ans=no
1001case "$ntp_cv_hdr_def_sigpoll" in
1002 yes)
1003    case "$host" in
1004     mips-sgi-irix*)
1005	ans=no
1006	;;
1007     vax-dec-bsd)
1008	ans=no
1009	;;
1010     *-pc-cygwin*)
1011	ans=no
1012	;;
1013     *-sni-sysv*)
1014	ans=no
1015	;;
1016     *-stratus-vos)
1017	ans=no
1018	;;
1019     *-*-aix[[4-9]]*)
1020	# XXX Only verified thru AIX6
1021	ans=no
1022	;;
1023     *-*-hpux*)
1024	ans=no
1025	;;
1026     *-*-*linux*)
1027	ans=no
1028	;;
1029     *-*-osf*)
1030	ans=no
1031	;;
1032     *-*-qnx*)
1033	ans=no
1034	;;
1035     *-*-sunos*)
1036	ans=no
1037	;;
1038     *-*-solaris*)
1039	ans=no
1040	;;
1041     *-*-ultrix*)
1042	ans=no
1043	;;
1044     *-*-unicosmp*)
1045	ans=no
1046	;;
1047     *-*-kfreebsd*)
1048	ans=no
1049	;;
1050     *) ans=yes
1051	;;
1052    esac
1053    ;;
1054esac
1055case "$ans" in
1056 yes)
1057    AC_DEFINE([USE_UDP_SIGPOLL], [1], [Can we use SIGPOLL for UDP?])
1058esac
1059AC_MSG_RESULT([$ans])
1060
1061AC_MSG_CHECKING([if we can use SIGPOLL for TTY I/O])
1062ans=no
1063case "$ntp_cv_hdr_def_sigpoll" in
1064 yes)
1065    case "$host" in
1066     mips-sgi-irix*)
1067	ans=no
1068	;;
1069     vax-dec-bsd)
1070	ans=no
1071	;;
1072     *-pc-cygwin*)
1073	ans=no
1074	;;
1075     *-sni-sysv*)
1076	ans=no
1077	;;
1078     *-stratus-vos)
1079	ans=no
1080	;;
1081     *-*-aix[[4-9]]*)
1082	# XXX Only verified thru AIX6
1083	ans=no
1084	;;
1085     *-*-hpux*)
1086	ans=no
1087	;;
1088     *-*-*linux*)
1089	ans=no
1090	;;
1091     *-*-osf*)
1092	ans=no
1093	;;
1094     *-*-sunos*)
1095	ans=no
1096	;;
1097     *-*-ultrix*)
1098	ans=no
1099	;;
1100     *-*-qnx*)
1101	ans=no
1102	;;
1103     *-*-unicosmp*)
1104	ans=no
1105	;;
1106     *-*-kfreebsd*)
1107	ans=no
1108	;;
1109     *) ans=yes
1110	;;
1111    esac
1112    ;;
1113esac
1114case "$ans" in
1115 yes)
1116    AC_DEFINE([USE_TTY_SIGPOLL], [1], [Can we use SIGPOLL for tty IO?])
1117esac
1118AC_MSG_RESULT([$ans])
1119
1120AC_CACHE_CHECK(
1121    [number of arguments to gettimeofday()],
1122    [ntp_cv_func_Xettimeofday_nargs],
1123    [AC_COMPILE_IFELSE(
1124	[AC_LANG_PROGRAM(
1125	    [[
1126		#include <sys/time.h>
1127	    ]],
1128	    [[
1129		gettimeofday(0, 0);
1130		settimeofday(0, 0);
1131	    ]]
1132	)],
1133	[ntp_cv_func_Xettimeofday_nargs=2],
1134	[ntp_cv_func_Xettimeofday_nargs=1]
1135    )]
1136)
1137case "$ntp_cv_func_Xettimeofday_nargs" in
1138 1)
1139    AC_DEFINE([SYSV_TIMEOFDAY], [1], [Does Xettimeofday take 1 arg?])
1140esac
1141
1142AC_CHECK_FUNCS([settimeofday], ,[
1143    case "$host" in
1144     *-*-mpeix*) ac_cv_func_settimeofday=yes
1145    esac
1146])
1147
1148AC_MSG_CHECKING([if we'll use clock_settime or settimeofday or stime])
1149ntp_warning='GRONK'
1150ans=none
1151case "$ac_cv_func_clock_settime$ac_cv_func_settimeofday$ac_cv_func_stime" in
1152 yes*)
1153    ntp_warning=''
1154    ans='clock_settime()'
1155    ;;
1156 noyes*)
1157    ntp_warning='But clock_settime() would be better (if we had it)'
1158    ans='settimeofday()'
1159    ;;
1160 nonoyes)
1161    ntp_warning='Which is the worst of the three'
1162    ans='stime()'
1163    ;;
1164 *)
1165    case "$build" in
1166     $host)
1167	ntp_warning='Which leaves us with nothing to use!'
1168    esac
1169esac
1170AC_MSG_RESULT([$ans])
1171case "$ntp_warning" in
1172 '')
1173    ;;
1174 *)
1175    AC_MSG_WARN([*** $ntp_warning ***])
1176    ;;
1177esac
1178
1179
1180dnl add to LDADD_LIBNTP set by ntp_compiler.m4
1181LDADD_LIBNTP="$LDADD_LIBNTP $LIBS"
1182LIBS=$__LIBS
1183AS_UNSET([__LIBS])
1184
1185])dnl
1186dnl ======================================================================
1187