xref: /freebsd/contrib/ntp/sntp/m4/ntp_libntp.m4 (revision 0b3105a37d7adcadcb720112fed4dc4e8040be99)
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    ])
166esac
167
168AC_CHECK_HEADERS([arpa/nameser.h sys/param.h sys/time.h sys/timers.h])
169# sys/sysctl.h depends on sys/param.h on OpenBSD - Bug 1576
170AC_CHECK_HEADERS([sys/sysctl.h], [], [], [
171    #if defined HAVE_SYS_PARAM_H
172    # include <sys/param.h>
173    #endif
174])
175AC_CHECK_HEADERS([netinet/in_system.h netinet/in_systm.h netinet/in.h])
176
177AC_CHECK_HEADERS([resolv.h], [], [], [
178    #ifdef HAVE_SYS_TYPES_H
179    # include <sys/types.h>
180    #endif
181    #ifdef HAVE_NETINET_IN_H
182    # include <netinet/in.h>
183    #endif
184    #ifdef HAVE_ARPA_NAMESER_H
185    # include <arpa/nameser.h>
186    #endif
187])
188
189AC_CHECK_HEADERS([net/if_var.h], [], [], [
190    #if HAVE_SYS_TYPES_H
191    # include <sys/types.h>
192    #endif
193    #ifdef HAVE_SYS_SOCKET_H
194    # include <sys/socket.h>
195    #endif
196    #ifdef HAVE_NETINET_IN_H
197    # include <netinet/in.h>
198    #endif
199    #ifdef HAVE_NET_IF_H
200    # include <net/if.h>
201    #endif
202])
203
204AC_CHECK_HEADERS([netinet/ip.h netinet/in_var.h], [], [], [
205    #ifdef HAVE_SYS_TYPES_H
206    # include <sys/types.h>
207    #endif
208    #ifdef HAVE_SYS_SOCKET_H
209    # include <sys/socket.h>
210    #endif
211    #ifdef HAVE_NET_IF_H
212    # include <net/if.h>
213    #endif
214    #ifdef HAVE_NETINET_IN_H
215    # include <netinet/in.h>
216    #endif
217    #ifdef HAVE_NET_IF_VAR_H
218    # include <net/if_var.h>
219    #endif
220    #ifdef HAVE_NETINET_IN_SYSTM_H
221    # include <netinet/in_systm.h>
222    #endif
223])
224
225# HMS: Do we need to check for -lsocket before or after these tests?
226HMS_SEARCH_LIBS([LDADD_LIBNTP], [inet_pton], [nsl])
227HMS_SEARCH_LIBS([LDADD_LIBNTP], [inet_ntop], [resolv], , , [-lnsl])
228
229# [Bug 1628] On Solaris, we need -lxnet -lsocket.  Generalize this to
230# avoid keying on the OS name:  If we find socket functions in
231# libsocket, next try for them in libxnet without libsocket, if found,
232# list both.  If we simply tested libxnet first, we would find the
233# functions there and never add libsocket.  See also [Bug 660]
234# http://bugs.ntp.org/show_bug.cgi?id=660#c9
235saved_LIBS=$LIBS
236HMS_SEARCH_LIBS([LDADD_LIBNTP], [setsockopt], [socket])
237case "$ac_cv_search_setsockopt" in
238 -lsocket)
239    LIBS="$saved_LIBS"
240    HMS_SEARCH_LIBS([LDADD_LIBNTP], [getsockopt], [xnet])
241    # XXX Possible trouble here - reading the comments above and looking at the
242    # code below I wonder if we'll add -lxnet when we don't need it.
243    # Also, do we need to add -lxnet to LDADD_LIBNTP, or perhaps see if it's
244    # there when it is not needed?
245    case "$ac_cv_search_getsockopt" in
246     -lxnet)
247	LIBS="-lxnet -lsocket $saved_LIBS"
248	;;
249     *) LIBS="-lsocket $saved_LIBS"
250	;;
251    esac
252    ;;
253esac
254AS_UNSET([saved_LIBS])
255
256# Bug 2427 - look for recvmsg here.
257AC_CHECK_FUNCS([recvmsg])
258
259AC_C_INLINE
260
261case "$ac_cv_c_inline" in
262 '')
263    ;;
264 *)
265    AC_DEFINE([HAVE_INLINE], [1], [inline keyword or macro available])
266    AC_SUBST([HAVE_INLINE])
267esac
268
269AC_HEADER_TIME
270AC_CHECK_SIZEOF([time_t])
271AC_C_CHAR_UNSIGNED		dnl CROSS_COMPILE?
272AC_CHECK_SIZEOF([signed char])
273AC_CHECK_TYPES([s_char, long long])
274AC_CHECK_SIZEOF([short])
275AC_CHECK_SIZEOF([int])
276AC_CHECK_SIZEOF([long])
277
278case "$ac_cv_type_long_long" in
279 no)
280    ;;
281 *)
282    AC_CHECK_SIZEOF([long long])
283    ;;
284esac
285
286case "$ac_cv_c_char_unsigned$ac_cv_sizeof_signed_char$ac_cv_type_s_char" in
287 *yes)
288    # We have a typedef for s_char.  Might as well believe it...
289    ;;
290 no0no)
291    # We have signed chars, can't say 'signed char', no s_char typedef.
292    AC_DEFINE([NEED_S_CHAR_TYPEDEF], [1],
293	[Do we need an s_char typedef?])
294    ;;
295 no1no)
296    # We have signed chars, can say 'signed char', no s_char typedef.
297    AC_DEFINE([NEED_S_CHAR_TYPEDEF], [1],
298	[Do we need an s_char typedef?])
299    ;;
300 yes0no)
301    # We have unsigned chars, can't say 'signed char', no s_char typedef.
302    AC_MSG_ERROR([No way to specify a signed character!])
303    ;;
304 yes1no)
305    # We have unsigned chars, can say 'signed char', no s_char typedef.
306    AC_DEFINE([NEED_S_CHAR_TYPEDEF], [1],
307	[Do we need an s_char typedef?])
308    ;;
309esac
310
311AC_TYPE_UID_T
312
313m4_divert_text([HELP_ENABLE],
314[AS_HELP_STRING([defaults:],
315    [+ yes, - no, s system-specific])])
316
317NTP_DEBUG
318
319# check if we can compile with pthreads
320AC_CHECK_HEADERS([semaphore.h])
321AC_CHECK_FUNCS([socketpair])
322AC_ARG_ENABLE(
323    [thread-support],
324    [AS_HELP_STRING([--enable-thread-support],
325		    [s use threads (+ if available)])],
326    [],
327    [enable_thread_support=yes]
328    )
329have_pthreads=no
330case "$enable_thread_support" in
331 no) ;;
332 *)
333    ol_found_pthreads=no
334    OL_THREAD_CHECK([ol_found_pthreads=yes])
335    case "$ol_found_pthreads" in
336     yes)
337	saved_LIBS="$LIBS"
338	LIBS="$LTHREAD_LIBS $LIBS"
339	saved_CFLAGS="$CFLAGS"
340	CFLAGS="$PTHREAD_CFLAGS $CFLAGS"
341	AC_CHECK_FUNCS([sem_timedwait])
342	LIBS="$saved_LIBS"
343	AS_UNSET([saved_LIBS])
344	CFLAGS="$saved_CFLAGS"
345	AS_UNSET([saved_CFLAGS])
346	case "$ac_cv_func_sem_timedwait" in
347	 yes)
348	    PTHREAD_LIBS="$LTHREAD_LIBS"
349	    have_pthreads=yes
350	esac
351    esac
352esac
353AC_SUBST([PTHREAD_LIBS])
354case "$have_pthreads" in
355 yes)
356    CFLAGS_NTP="$CFLAGS_NTP $PTHREAD_CFLAGS"
357    saved_LIBS="$LIBS"
358    LIBS="$LTHREAD_LIBS $LIBS"
359    saved_CFLAGS="$CFLAGS"
360    CFLAGS="$PTHREAD_CFLAGS $CFLAGS"
361    AC_CHECK_SIZEOF(
362	[pthread_t],
363	,
364	[
365	    AC_INCLUDES_DEFAULT()
366	    #include <pthread.h>
367	]
368    )
369    LIBISC_PTHREADS_NOTHREADS=pthreads
370    AC_DEFINE([ISC_PLATFORM_USETHREADS], [1],
371	      [enable libisc thread support?])
372    #
373    # We'd like to use sigwait() too
374    #
375    AC_CHECK_FUNC(
376	[sigwait],
377	[have_sigwait=yes],
378	[AC_CHECK_LIB(
379	    [c],
380	    [sigwait],
381	    [have_sigwait=yes],
382	    [AC_CHECK_LIB(
383		[pthread],
384		[sigwait],
385		[have_sigwait=yes],
386		[AC_CHECK_LIB(
387		    [pthread],
388		    [_Psigwait],
389		    [have_sigwait=yes],
390		    [have_sigwait=no]
391		)]
392	    )]
393	)]
394    )
395    case "$host:$have_sigwait" in
396     *-freebsd*:no)
397	AC_CHECK_LIB(
398	    [c_r],
399	    [sigwait],
400	    [have_sigwait=yes]
401	)
402    esac
403    case "$have_sigwait" in
404     yes)
405	ac_cv_func_sigwait=yes
406	AC_DEFINE([HAVE_SIGWAIT], [1], [sigwait() available?])
407    esac
408
409    AC_CHECK_FUNCS([pthread_attr_getstacksize])
410    AC_CHECK_FUNCS([pthread_attr_setstacksize sysconf])
411
412    case "$host" in
413     *-freebsd5.[[012]]|*-freebsd5.[[012]].*)
414	;;
415     *-freebsd5.[[3456789]]|*-freebsd5.[[3456789]].*|*-freebsd6.*)
416	AC_DEFINE([NEED_PTHREAD_SCOPE_SYSTEM], [1],
417		  [use PTHREAD_SCOPE_SYSTEM?])
418	;;
419     *-bsdi3.*|*-bsdi4.0*)
420	AC_DEFINE([NEED_PTHREAD_INIT], [1], [pthread_init() required?])
421	;;
422     *-linux*)
423	AC_DEFINE([HAVE_LINUXTHREADS], [1], [using Linux pthread?])
424	;;
425     *-solaris*)
426	AC_DEFINE([_POSIX_PTHREAD_SEMANTICS], [1])
427	AC_CHECK_FUNCS([pthread_setconcurrency])
428	case "$ac_cv_func_pthread_setconcurrency" in
429	 yes)
430	    AC_DEFINE([CALL_PTHREAD_SETCONCURRENCY], [1],
431		      [why not HAVE_P_S?])
432	esac
433	;;
434     *-sco-sysv*uw*|*-*-sysv*UnixWare*|*-*-sysv*OpenUNIX*)
435	AC_DEFINE([HAVE_UNIXWARE_SIGWAIT], [1], [deviant sigwait?])
436	;;
437    esac
438    hack_shutup_pthreadonceinit=no
439    case "$host" in
440     *-aix5.[[123]].*)
441	hack_shutup_pthreadonceinit=yes
442	;;
443     *-solaris2.[[89]])
444	hack_shutup_pthreadonceinit=yes
445	;;
446     *-solaris2.1[[0-9]])
447	AC_CACHE_CHECK(
448	    [if extra braces are needed for PTHREAD_ONCE_INIT],
449	    [ntp_cv_braces_around_pthread_once_init],
450	    [AC_COMPILE_IFELSE(
451		[AC_LANG_PROGRAM(
452		    [[
453			#include <pthread.h>
454		    ]],
455		    [[
456		        static pthread_once_t once_test =
457						PTHREAD_ONCE_INIT;
458		    ]]
459		)],
460		[ntp_cv_braces_around_pthread_once_init=no],
461		[ntp_cv_braces_around_pthread_once_init=yes]
462	    )]
463	)
464	case "$ntp_cv_braces_around_pthread_once_init" in
465	 yes)
466	    hack_shutup_pthreadonceinit=yes
467	esac
468	;;
469    esac
470    case "$hack_shutup_pthreadonceinit" in
471     yes)
472	AC_DEFINE([ISC_PLATFORM_BRACEPTHREADONCEINIT], [1],
473		  [Enclose PTHREAD_ONCE_INIT in extra braces?])
474    esac
475    LIBS="$saved_LIBS"
476    AS_UNSET([saved_LIBS])
477    CFLAGS="$saved_CFLAGS"
478    AS_UNSET([saved_CFLAGS])
479    ;;
480 *)
481    LIBISC_PTHREADS_NOTHREADS=nothreads
482    ;;
483esac
484AC_SUBST([LIBISC_PTHREADS_NOTHREADS])
485AM_CONDITIONAL([PTHREADS], [test "$have_pthreads" != "no"])
486
487AC_DEFUN([NTP_BEFORE_HW_FUNC_VSNPRINTF], [
488    AC_BEFORE([$0], [HW_FUNC_VSNPRINTF])dnl
489    AC_BEFORE([$0], [HW_FUNC_SNPRINTF])dnl
490    AC_ARG_ENABLE(
491	[c99-snprintf],
492	[AS_HELP_STRING([--enable-c99-snprintf], [s force replacement])],
493	[force_c99_snprintf=$enableval],
494	[force_c99_snprintf=no]
495	)
496    case "$force_c99_snprintf" in
497     yes)
498	hw_force_rpl_snprintf=yes
499	hw_force_rpl_vsnprintf=yes
500    esac
501    AH_VERBATIM(
502	[snprinte],dnl	sorted in config.h just before #define snprintf
503	[
504	    #if !defined(_KERNEL) && !defined(PARSESTREAM)
505	    /*
506	     * stdio.h must be included after _GNU_SOURCE is defined
507	     * but before #define snprintf rpl_snprintf
508	     */
509	    # include <stdio.h>
510	    #endif
511	])
512    AH_BOTTOM([
513	#if !defined(_KERNEL) && !defined(PARSESTREAM)
514	# if defined(HW_WANT_RPL_VSNPRINTF)
515	#  if defined(__cplusplus)
516	extern "C" {
517	# endif
518	# include <stdarg.h>
519	int rpl_vsnprintf(char *, size_t, const char *, va_list);
520	# if defined(__cplusplus)
521	}
522	#  endif
523	# endif
524	# if defined(HW_WANT_RPL_SNPRINTF)
525	#  if defined(__cplusplus)
526	extern "C" {
527	#  endif
528	int rpl_snprintf(char *, size_t, const char *, ...);
529	#  if defined(__cplusplus)
530	}
531	#  endif
532	# endif
533	#endif	/* !defined(_KERNEL) && !defined(PARSESTREAM) */
534	])
535]) dnl end of AC_DEFUN of NTP_BEFORE_HW_FUNC_VSNPRINTF
536
537AC_DEFUN([NTP_C99_SNPRINTF], [
538    AC_REQUIRE([NTP_BEFORE_HW_FUNC_VSNPRINTF])dnl
539    AC_REQUIRE([HW_FUNC_VSNPRINTF])dnl
540    AC_REQUIRE([HW_FUNC_SNPRINTF])dnl
541]) dnl end of DEFUN of NTP_C99_SNPRINTF
542
543NTP_C99_SNPRINTF
544
545dnl C99-snprintf does not handle %m
546case "$hw_use_rpl_vsnprintf:$hw_cv_func_vsnprintf" in
547 no:yes)
548    AC_CACHE_CHECK(
549	[if vsnprintf expands "%m" to strerror(errno)],
550	[ntp_cv_vsnprintf_percent_m],
551	[AC_RUN_IFELSE(
552	    [AC_LANG_PROGRAM(
553		[[
554		    #include <stdarg.h>
555		    #include <errno.h>
556		    #include <stdio.h>
557		    #include <string.h>
558
559		    int call_vsnprintf(
560			    char *	dst,
561			    size_t	sz,
562			    const char *fmt,
563			    ...
564			    );
565
566		    int call_vsnprintf(
567			    char *	dst,
568			    size_t	sz,
569			    const char *fmt,
570			    ...
571			    )
572		    {
573			    va_list	ap;
574			    int		rc;
575
576			    va_start(ap, fmt);
577			    rc = vsnprintf(dst, sz, fmt, ap);
578			    va_end(ap);
579
580			    return rc;
581		    }
582		]],
583		[[
584		    char	sbuf[512];
585		    char	pbuf[512];
586		    int		slen;
587
588		    strcpy(sbuf, strerror(ENOENT));
589		    errno = ENOENT;
590		    slen = call_vsnprintf(pbuf, sizeof(pbuf), "%m",
591					  "wrong");
592		    return strcmp(sbuf, pbuf);
593		]]
594	    )],
595	    [ntp_cv_vsnprintf_percent_m=yes],
596	    [ntp_cv_vsnprintf_percent_m=no],
597	    [ntp_cv_vsnprintf_percent_m=no]
598	)]
599    )
600    case "$ntp_cv_vsnprintf_percent_m" in
601     yes)
602	AC_DEFINE([VSNPRINTF_PERCENT_M], [1],
603		  [vsnprintf expands "%m" to strerror(errno)])
604    esac
605esac
606
607AC_CHECK_HEADERS([sys/clockctl.h])
608
609AC_ARG_ENABLE(
610    [clockctl],
611    [AS_HELP_STRING(
612	[--enable-clockctl],
613	[s Use /dev/clockctl for non-root clock control]
614    )],
615    [ntp_use_dev_clockctl=$enableval],
616    [ntp_use_dev_clockctl=$ac_cv_header_sys_clockctl_h]
617)
618
619AC_MSG_CHECKING([if we should use /dev/clockctl])
620AC_MSG_RESULT([$ntp_use_dev_clockctl])
621
622
623AC_CHECK_HEADERS([sys/capability.h sys/prctl.h])
624
625AC_MSG_CHECKING([if we have linux capabilities (libcap)])
626
627case "$ac_cv_header_sys_capability_h$ac_cv_header_sys_prctl_h" in
628 yesyes)
629    case "$host" in
630     mips-sgi-irix*)
631	ntp_have_linuxcaps=no
632	;;
633     *) ntp_have_linuxcaps=yes
634	;;
635    esac
636    ;;
637 *)
638    ntp_have_linuxcaps=no
639    ;;
640esac
641
642AC_ARG_ENABLE(
643    [linuxcaps],
644    [AS_HELP_STRING(
645	[--enable-linuxcaps],
646	[+ Use Linux capabilities for non-root clock control]
647    )],
648    [ntp_have_linuxcaps=$enableval]
649)
650
651AC_MSG_RESULT([$ntp_have_linuxcaps])
652
653case "$ntp_have_linuxcaps" in
654 yes)
655    AC_DEFINE([HAVE_LINUX_CAPABILITIES], [1],
656	[Do we have Linux capabilities?])
657    LIBS="$LIBS -lcap"
658    ;;
659esac
660
661
662AC_CHECK_HEADERS([priv.h])
663
664AC_MSG_CHECKING([if we have solaris privileges])
665
666case "$ac_cv_header_priv_h" in
667 yes)
668    case "$host" in
669     *-solaris*)
670	AC_CHECK_FUNC(
671    	    [setppriv],
672    	    [ntp_have_solarisprivs=yes],
673    	    [ntp_have_solarisprivs=no]
674	)
675	;;
676    esac
677esac
678
679AC_ARG_ENABLE(
680    [solarisprivs],
681    [AS_HELP_STRING(
682	[--enable-solarisprivs],
683	[+ Use Solaris privileges for non-root clock control]
684    )],
685    [ntp_have_solarisprivs=$enableval]
686)
687
688
689case "$ntp_have_solarisprivs" in
690 yes)
691    AC_DEFINE([HAVE_SOLARIS_PRIVS], [1],
692	[Are Solaris privileges available?])
693esac
694
695AC_MSG_RESULT([$ntp_have_solarisprivs])
696
697case "$ntp_use_dev_clockctl$ntp_have_linuxcaps$ntp_have_solarisprivs" in
698 *yes*)
699    AC_DEFINE([HAVE_DROPROOT], [1],
700	[Can we drop root privileges?])
701esac
702
703case "$host" in
704 *-*-darwin*)
705    AC_SEARCH_LIBS([res_9_init], [resolv])
706    ;;
707 *) AC_SEARCH_LIBS([res_init], [resolv])
708    ;;
709esac
710AC_HEADER_RESOLV
711#HMS: Why do we do this check so "early"?
712AC_CHECK_FUNCS([res_init], , [AC_CHECK_FUNCS([__res_init])])
713
714# We also need -lsocket, but we have tested for that already.
715AC_CHECK_FUNC([inet_ntop], [],
716    [AC_DEFINE([ISC_PLATFORM_NEEDNTOP], [1], [ISC: provide inet_ntop()])])
717AC_CHECK_FUNC([inet_pton], [],
718    [AC_DEFINE([ISC_PLATFORM_NEEDPTON], [1], [ISC: provide inet_pton()])])
719
720AC_CHECK_TYPES([uintptr_t, int32, u_int32])
721
722AH_VERBATIM([TYPEDEF_UINTPTR_T],
723[/* Provide a typedef for uintptr_t? */
724#ifndef HAVE_UINTPTR_T
725typedef unsigned int	uintptr_t;
726#define HAVE_UINTPTR_T	1
727#endif])
728
729case "$ac_cv_type_int32::$ac_cv_header_resolv_h" in
730 no::yes)
731    AC_CACHE_CHECK(
732	[for int32 with DNS headers included],
733	[ntp_cv_type_int32_with_dns],
734	[AC_COMPILE_IFELSE(
735	    [AC_LANG_PROGRAM(
736		[[
737		    #ifdef HAVE_ARPA_NAMESER_H
738		    # include <arpa/nameser.h>
739		    #endif
740		    #include <resolv.h>
741		]],
742		[[
743		    size_t cb = sizeof(int32);
744		]]
745	    )],
746	    [ntp_cv_type_int32_with_dns=yes],
747	    [ntp_cv_type_int32_with_dns=no]
748	)]
749    )
750    case "$ntp_cv_type_int32_with_dns" in
751     yes)
752	AC_DEFINE([HAVE_INT32_ONLY_WITH_DNS], [1],
753	    [int32 type in DNS headers, not others.])
754    esac
755esac
756
757case "$ac_cv_type_u_int32::$ac_cv_header_resolv_h" in
758 no::yes)
759    AC_CACHE_CHECK(
760	[for u_int32 with DNS headers included],
761	[ntp_cv_type_u_int32_with_dns],
762	[AC_COMPILE_IFELSE(
763	    [AC_LANG_PROGRAM(
764		[[
765		    #ifdef HAVE_ARPA_NAMESER_H
766		    # include <arpa/nameser.h>
767		    #endif
768		    #include <resolv.h>
769		]],
770		[[
771		    size_t cb = sizeof(u_int32);
772		]]
773	    )],
774	    [ntp_cv_type_u_int32_with_dns=yes],
775	    [ntp_cv_type_u_int32_with_dns=no]
776	)]
777    )
778    case "$ntp_cv_type_u_int32_with_dns" in
779     yes)
780	AC_DEFINE([HAVE_U_INT32_ONLY_WITH_DNS], [1],
781	    [u_int32 type in DNS headers, not others.])
782    esac
783esac
784
785AC_CHECK_HEADERS(
786    [sys/timepps.h],
787    [],
788    [],
789    [
790	#ifdef HAVE_SYS_TIME_H
791	# include <sys/time.h>
792	#endif
793	#ifdef HAVE_ERRNO_H
794	# include <errno.h>
795	#endif
796    ]
797)
798
799AC_CACHE_CHECK(
800    [for struct timespec],
801    [ntp_cv_struct_timespec],
802    [AC_COMPILE_IFELSE(
803	[AC_LANG_PROGRAM(
804	    [[
805		#include <sys/time.h>
806		/* Under SunOS, timespec is in sys/timepps.h,
807		   which needs errno.h and FRAC */
808		#ifdef HAVE_ERRNO_H
809		# include <errno.h>
810		#endif
811		#ifdef HAVE_SYS_TIMEPPS_H
812		# define FRAC 4294967296
813		# include <sys/timepps.h>
814		#endif
815	    ]],
816	    [[
817		struct timespec n;
818	    ]]
819	)],
820	[ntp_cv_struct_timespec=yes],
821	[ntp_cv_struct_timespec=no]
822    )]
823)
824case "$ntp_cv_struct_timespec" in
825 yes)
826    AC_DEFINE([HAVE_STRUCT_TIMESPEC], [1], [struct timespec declared?])
827esac
828
829AC_CACHE_CHECK(
830    [for struct ntptimeval],
831    [ntp_cv_struct_ntptimeval],
832    [AC_COMPILE_IFELSE(
833	[AC_LANG_PROGRAM(
834	    [[
835		#include <sys/time.h>
836		#include <sys/timex.h>
837	    ]],
838	    [[
839		struct ntptimeval n;
840	    ]]
841	)],
842	[ntp_cv_struct_ntptimeval=yes],
843	[ntp_cv_struct_ntptimeval=no]
844    )]
845)
846case "$ntp_cv_struct_ntptimeval" in
847 yes)
848    AC_DEFINE([HAVE_STRUCT_NTPTIMEVAL], [1],
849	[Do we have struct ntptimeval?])
850esac
851
852AC_CHECK_HEADERS(
853    [md5.h],
854    [],
855    [],
856    [
857	#ifdef HAVE_SYS_TYPES_H
858	# include <sys/types.h>
859	#endif
860    ]
861)
862
863AC_SEARCH_LIBS([MD5Init], [md5 md])
864AC_CHECK_FUNCS([MD5Init sysconf getdtablesize sigaction sigset sigvec])
865
866AC_CACHE_CHECK(
867    [for SIGIO],
868    [ntp_cv_hdr_def_sigio],
869    [AC_PREPROC_IFELSE(
870	[AC_LANG_SOURCE([
871	    #include <signal.h>
872
873	    #ifndef SIGIO
874	    # error
875	    #endif
876	])],
877	[ntp_cv_hdr_def_sigio=yes],
878	[ntp_cv_hdr_def_sigio=no]
879    )]
880 )
881
882dnl Override those system that have a losing SIGIO
883AC_MSG_CHECKING([if we want to use SIGIO])
884ans=no
885case "$ntp_cv_hdr_def_sigio" in
886 yes)
887    ans=yes
888    case "$host" in
889     alpha*-dec-osf4*|alpha*-dec-osf5*)
890	ans=no
891	;;
892     *-convex-*)
893	ans=no
894	;;
895     *-dec-*)
896	ans=no
897	;;
898     *-pc-cygwin*)
899	ans=no
900	;;
901     *-sni-sysv*)
902	ans=no
903	;;
904     *-stratus-vos)
905	ans=no
906	;;
907     *-univel-sysv*)
908	ans=no
909	;;
910     *-*-irix6*)
911	ans=no
912	;;
913     *-*-freebsd*)
914	ans=no
915	;;
916     *-*-*linux*)
917	ans=no
918	;;
919     *-*-unicosmp*)
920	ans=no
921	;;
922     *-*-kfreebsd*)
923	ans=no
924	;;
925     m68k-*-mint*)
926	ans=no
927	;;
928    esac
929    ;;
930esac
931case "$ans" in
932 yes)
933    AC_DEFINE([HAVE_SIGNALED_IO], [1],
934	[Can we use SIGIO for tcp and udp IO?])
935esac
936AC_MSG_RESULT([$ans])
937
938AC_CACHE_CHECK(
939    [for SIGPOLL],
940    [ntp_cv_hdr_def_sigpoll],
941    [AC_PREPROC_IFELSE(
942	[AC_LANG_SOURCE([
943	    #include <signal.h>
944
945	    #ifndef SIGPOLL
946	    # error
947	    #endif
948	])],
949	[ntp_cv_hdr_def_sigpoll=yes],
950	[ntp_cv_hdr_def_sigpoll=no]
951    )]
952)
953
954AC_MSG_CHECKING([if we can use SIGPOLL for UDP I/O])
955ans=no
956case "$ntp_cv_hdr_def_sigpoll" in
957 yes)
958    case "$host" in
959     mips-sgi-irix*)
960	ans=no
961	;;
962     vax-dec-bsd)
963	ans=no
964	;;
965     *-pc-cygwin*)
966	ans=no
967	;;
968     *-sni-sysv*)
969	ans=no
970	;;
971     *-stratus-vos)
972	ans=no
973	;;
974     *-*-aix[[4-9]]*)
975	# XXX Only verified thru AIX6
976	ans=no
977	;;
978     *-*-hpux*)
979	ans=no
980	;;
981     *-*-*linux*)
982	ans=no
983	;;
984     *-*-osf*)
985	ans=no
986	;;
987     *-*-qnx*)
988	ans=no
989	;;
990     *-*-sunos*)
991	ans=no
992	;;
993     *-*-solaris*)
994	ans=no
995	;;
996     *-*-ultrix*)
997	ans=no
998	;;
999     *-*-unicosmp*)
1000	ans=no
1001	;;
1002     *-*-kfreebsd*)
1003	ans=no
1004	;;
1005     *) ans=yes
1006	;;
1007    esac
1008    ;;
1009esac
1010case "$ans" in
1011 yes)
1012    AC_DEFINE([USE_UDP_SIGPOLL], [1], [Can we use SIGPOLL for UDP?])
1013esac
1014AC_MSG_RESULT([$ans])
1015
1016AC_MSG_CHECKING([if we can use SIGPOLL for TTY I/O])
1017ans=no
1018case "$ntp_cv_hdr_def_sigpoll" in
1019 yes)
1020    case "$host" in
1021     mips-sgi-irix*)
1022	ans=no
1023	;;
1024     vax-dec-bsd)
1025	ans=no
1026	;;
1027     *-pc-cygwin*)
1028	ans=no
1029	;;
1030     *-sni-sysv*)
1031	ans=no
1032	;;
1033     *-stratus-vos)
1034	ans=no
1035	;;
1036     *-*-aix[[4-9]]*)
1037	# XXX Only verified thru AIX6
1038	ans=no
1039	;;
1040     *-*-hpux*)
1041	ans=no
1042	;;
1043     *-*-*linux*)
1044	ans=no
1045	;;
1046     *-*-osf*)
1047	ans=no
1048	;;
1049     *-*-sunos*)
1050	ans=no
1051	;;
1052     *-*-ultrix*)
1053	ans=no
1054	;;
1055     *-*-qnx*)
1056	ans=no
1057	;;
1058     *-*-unicosmp*)
1059	ans=no
1060	;;
1061     *-*-kfreebsd*)
1062	ans=no
1063	;;
1064     *) ans=yes
1065	;;
1066    esac
1067    ;;
1068esac
1069case "$ans" in
1070 yes)
1071    AC_DEFINE([USE_TTY_SIGPOLL], [1], [Can we use SIGPOLL for tty IO?])
1072esac
1073AC_MSG_RESULT([$ans])
1074
1075AC_CACHE_CHECK(
1076    [number of arguments to gettimeofday()],
1077    [ntp_cv_func_Xettimeofday_nargs],
1078    [AC_COMPILE_IFELSE(
1079	[AC_LANG_PROGRAM(
1080	    [[
1081		#include <sys/time.h>
1082	    ]],
1083	    [[
1084		gettimeofday(0, 0);
1085		settimeofday(0, 0);
1086	    ]]
1087	)],
1088	[ntp_cv_func_Xettimeofday_nargs=2],
1089	[ntp_cv_func_Xettimeofday_nargs=1]
1090    )]
1091)
1092case "$ntp_cv_func_Xettimeofday_nargs" in
1093 1)
1094    AC_DEFINE([SYSV_TIMEOFDAY], [1], [Does Xettimeofday take 1 arg?])
1095esac
1096
1097AC_CHECK_FUNCS([settimeofday], ,[
1098    case "$host" in
1099     *-*-mpeix*) ac_cv_func_settimeofday=yes
1100    esac
1101])
1102
1103AC_MSG_CHECKING([if we'll use clock_settime or settimeofday or stime])
1104ntp_warning='GRONK'
1105ans=none
1106case "$ac_cv_func_clock_settime$ac_cv_func_settimeofday$ac_cv_func_stime" in
1107 yes*)
1108    ntp_warning=''
1109    ans='clock_settime()'
1110    ;;
1111 noyes*)
1112    ntp_warning='But clock_settime() would be better (if we had it)'
1113    ans='settimeofday()'
1114    ;;
1115 nonoyes)
1116    ntp_warning='Which is the worst of the three'
1117    ans='stime()'
1118    ;;
1119 *)
1120    case "$build" in
1121     $host)
1122	ntp_warning='Which leaves us with nothing to use!'
1123    esac
1124esac
1125AC_MSG_RESULT([$ans])
1126case "$ntp_warning" in
1127 '')
1128    ;;
1129 *)
1130    AC_MSG_WARN([*** $ntp_warning ***])
1131    ;;
1132esac
1133
1134
1135dnl add to LDADD_LIBNTP set by ntp_compiler.m4
1136LDADD_LIBNTP="$LDADD_LIBNTP $LIBS"
1137LIBS=$__LIBS
1138AS_UNSET([__LIBS])
1139
1140])dnl
1141dnl ======================================================================
1142