]> git.ipfire.org Git - thirdparty/chrony.git/blob - configure
cmdmon: save NTS cookies and server keys on dump command
[thirdparty/chrony.git] / configure
1 #!/bin/sh
2 # =======================================================================
3 #
4 # chronyd/chronyc - Programs for keeping computer clocks accurate.
5 #
6 # Copyright (C) Richard P. Curnow 1997-2003
7 # Copyright (C) Bryan Christianson 2016
8 # Copyright (C) Miroslav Lichvar 2009, 2012-2018
9 # Copyright (C) Stefan R. Filipek 2019
10 #
11 # =======================================================================
12
13 # This configure script determines the operating system type and version
14
15 # ======================================================================
16 # FUNCTIONS
17
18 #{{{ test_code
19 test_code () {
20 name=$1
21 headers=$2
22 cflags=$3
23 ldflags=$4
24 code=$5
25
26 printf "%s" "Checking for $name : "
27
28 (
29 echo "#include \"config.h\""
30 for h in $headers; do
31 echo "#include <$h>"
32 done
33 echo "int main(int argc, char **argv) {"
34 echo "$code"
35 echo "return 0; }"
36 ) > docheck.c
37
38 echo "docheck.c:" >> config.log
39 cat docheck.c >> config.log
40 echo $MYCC $MYCFLAGS $MYCPPFLAGS $cflags -o docheck docheck.c $ldflags \
41 $MYLDFLAGS >> config.log
42 $MYCC $MYCFLAGS $MYCPPFLAGS $cflags -o docheck docheck.c $ldflags \
43 $MYLDFLAGS >> config.log 2>&1
44
45 if [ $? -eq 0 ]
46 then
47 echo "Yes"
48 result=0
49 else
50 echo "No"
51 result=1
52 fi
53 rm -f docheck.c docheck
54 echo >> config.log
55 return $result
56 }
57 #}}}
58 #{{{ test_executable
59 test_executable () {
60 name=$1
61 executable=$2
62 options=$3
63
64 printf "%s" "Checking for $name : "
65
66 echo $executable $options >> config.log
67 $executable $options >> config.log 2>&1
68
69 if [ $? -eq 0 ]
70 then
71 echo "Yes"
72 result=0
73 else
74 echo "No"
75 result=1
76 fi
77 echo >> config.log
78 return $result
79 }
80 #}}}
81 #{{{ pkg_config
82 pkg_config () {
83 $PKG_CONFIG "$@" 2>> config.log
84 }
85 #}}}
86 #{{{ usage
87 usage () {
88 cat <<EOF
89 \`configure' configures this package to adapt to many kinds of systems.
90
91 Usage: ./configure [OPTION]...
92
93 Defaults for the options are specified in brackets.
94
95 Configuration:
96 -h, --help display this help and exit
97
98 Installation directories:
99 --prefix=PREFIX install architecture-independent files in PREFIX
100 [/usr/local]
101 --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX
102 [PREFIX]
103
104 By default, \`make install' will install all the files in
105 \`/usr/local/bin', \`/usr/local/lib' etc. You can specify
106 an installation prefix other than \`/usr/local' using \`--prefix',
107 for instance \`--prefix=$HOME'.
108
109 For better control, use the options below.
110 --disable-readline Disable line editing support
111 --without-readline Don't use GNU readline even if it is available
112 --without-editline Don't use editline even if it is available
113 --with-readline-includes=DIR Specify where readline include directory is
114 --with-readline-library=DIR Specify where readline lib directory is
115 --with-ncurses-library=DIR Specify where ncurses lib directory is
116 --disable-sechash Disable support for hashes other than MD5
117 --without-nettle Don't use nettle even if it is available
118 --without-nss Don't use NSS even if it is available
119 --without-tomcrypt Don't use libtomcrypt even if it is available
120 --disable-nts Disable NTS support
121 --without-gnutls Don't use gnutls even if it is available
122 --disable-cmdmon Disable command and monitoring support
123 --disable-ntp Disable NTP support
124 --disable-refclock Disable reference clock support
125 --disable-phc Disable PHC refclock driver
126 --disable-pps Disable PPS refclock driver
127 --disable-ipv6 Disable IPv6 support
128 --disable-rtc Don't include RTC even on Linux
129 --disable-privdrop Disable support for dropping root privileges
130 --without-libcap Don't use libcap even if it is available
131 --enable-scfilter Enable support for system call filtering
132 --without-seccomp Don't use seccomp even if it is available
133 --disable-asyncdns Disable asynchronous name resolving
134 --disable-forcednsretry Don't retry on permanent DNS error
135 --without-clock-gettime Don't use clock_gettime() even if it is available
136 --disable-timestamping Disable support for SW/HW timestamping
137 --enable-ntp-signd Enable support for MS-SNTP authentication in Samba
138 --with-ntp-era=SECONDS Specify earliest assumed NTP time in seconds
139 since 1970-01-01 [50*365 days ago]
140 --with-user=USER Specify default chronyd user [root]
141 --with-hwclockfile=PATH Specify default path to hwclock(8) adjtime file
142 --with-pidfile=PATH Specify default pidfile [/var/run/chrony/chronyd.pid]
143 --with-rtcdevice=PATH Specify default path to RTC device [/dev/rtc]
144 --with-sendmail=PATH Path to sendmail binary [/usr/lib/sendmail]
145 --enable-debug Enable debugging support
146
147 Fine tuning of the installation directories:
148 --sysconfdir=DIR chrony.conf location [/etc]
149 --bindir=DIR user executables [EPREFIX/bin]
150 --sbindir=DIR system admin executables [EPREFIX/sbin]
151 --datarootdir=DIR data root [PREFIX/share]
152 --mandir=DIR man documentation [DATAROOTDIR/man]
153 --docdir=DIR documentation root [DATAROOTDIR/doc/chrony]
154 --localstatedir=DIR modifiable single-machine data [/var]
155 --chronyrundir=DIR location for chrony sockets [LOCALSTATEDIR/run/chrony]
156 --chronyvardir=DIR location for chrony data [LOCALSTATEDIR/lib/chrony]
157
158 Overriding system detection when cross-compiling:
159 --host-system=OS Specify system name (uname -s)
160 --host-release=REL Specify system release (uname -r)
161 --host-machine=CPU Specify machine (uname -m)
162
163 Some influential environment variables:
164 CC C compiler command
165 CFLAGS C compiler flags
166 CPPFLAGS C preprocessor flags, e.g. -I<include dir> if you have
167 headers in a nonstandard directory <include dir>
168 LDFLAGS linker flags, e.g. -L<lib dir> if you have libraries in a
169 nonstandard directory <lib dir>
170 PKG_CONFIG path to pkg-config utility
171 PKG_CONFIG_PATH
172 directories to add to pkg-config's search path
173 PKG_CONFIG_LIBDIR
174 path overriding pkg-config's built-in search path
175
176 Use these variables to override the choices made by \`configure' or to help
177 it to find libraries and programs with nonstandard names/locations.
178
179 EOF
180
181 }
182 #}}}
183 #{{{
184 add_def () {
185 if [ "x$2" = "x" ]; then
186 echo "#define $1 1" >> config.h
187 else
188 echo "#define $1 $2" >> config.h
189 fi
190 }
191 #}}}
192 #{{{ get_features
193 get_features () {
194 ff=1
195 for f; do
196 if [ "$ff" = "0" ]; then
197 printf " "
198 fi
199 if grep "define FEAT_$f" config.h > /dev/null; then
200 printf "%s" "+$f"
201 else
202 printf "%s" "-$f"
203 fi
204 ff=0
205 done
206 }
207 #}}}
208
209 # ======================================================================
210
211
212
213 OPERATINGSYSTEM=`uname -s`
214 VERSION=`uname -r`
215 MACHINE=`uname -m`
216
217 LIBS=""
218 EXTRA_LIBS=""
219 EXTRA_CLI_LIBS=""
220 EXTRA_OBJECTS=""
221 EXTRA_CLI_OBJECTS=""
222
223 feat_debug=0
224 feat_cmdmon=1
225 feat_ntp=1
226 feat_refclock=1
227 feat_readline=1
228 try_readline=1
229 try_editline=1
230 feat_sechash=1
231 try_nettle=1
232 try_nss=1
233 try_tomcrypt=1
234 feat_nts=1
235 try_gnutls=1
236 feat_rtc=1
237 try_rtc=0
238 feat_droproot=1
239 try_libcap=-1
240 try_clockctl=0
241 feat_scfilter=0
242 try_seccomp=-1
243 priv_ops=""
244 readline_lib=""
245 readline_inc=""
246 ncurses_lib=""
247 feat_ipv6=1
248 feat_phc=1
249 try_phc=0
250 feat_pps=1
251 try_setsched=0
252 try_lockmem=0
253 feat_asyncdns=1
254 feat_forcednsretry=1
255 try_clock_gettime=1
256 try_recvmmsg=1
257 feat_timestamping=1
258 try_timestamping=0
259 feat_ntp_signd=0
260 ntp_era_split=""
261 use_pthread=0
262 default_user="root"
263 default_hwclockfile=""
264 default_pidfile="/var/run/chrony/chronyd.pid"
265 default_rtcdevice="/dev/rtc"
266 mail_program="/usr/lib/sendmail"
267
268 for option
269 do
270 case "$option" in
271 --enable-debug )
272 feat_debug=1
273 ;;
274 --disable-readline )
275 feat_readline=0
276 ;;
277 --without-readline )
278 try_readline=0
279 ;;
280 --without-editline )
281 try_editline=0
282 ;;
283 --with-readline-library=* )
284 readline_lib=-L`echo $option | sed -e 's/^.*=//;'`
285 ;;
286 --with-readline-includes=* )
287 readline_inc=-I`echo $option | sed -e 's/^.*=//;'`
288 ;;
289 --with-ncurses-library=* )
290 ncurses_lib=-L`echo $option | sed -e 's/^.*=//;'`
291 ;;
292 --prefix=* | --install_prefix=* )
293 SETPREFIX=`echo $option | sed -e 's/[^=]*=//;'`
294 ;;
295 --exec-prefix=* )
296 SETEPREFIX=`echo $option | sed -e 's/[^=]*=//;'`
297 ;;
298 --sysconfdir=* )
299 SETSYSCONFDIR=`echo $option | sed -e 's/^.*=//;'`
300 ;;
301 --bindir=* )
302 SETBINDIR=`echo $option | sed -e 's/^.*=//;'`
303 ;;
304 --sbindir=* )
305 SETSBINDIR=`echo $option | sed -e 's/^.*=//;'`
306 ;;
307 --datarootdir=* )
308 SETDATAROOTDIR=`echo $option | sed -e 's/^.*=//;'`
309 ;;
310 --mandir=* )
311 SETMANDIR=`echo $option | sed -e 's/^.*=//;'`
312 ;;
313 --docdir=* )
314 SETDOCDIR=`echo $option | sed -e 's/^.*=//;'`
315 ;;
316 --localstatedir=* )
317 SETLOCALSTATEDIR=`echo $option | sed -e 's/^.*=//;'`
318 ;;
319 --chronyrundir=* | --chronysockdir=* )
320 SETCHRONYRUNDIR=`echo $option | sed -e 's/^.*=//;'`
321 ;;
322 --chronyvardir=* )
323 SETCHRONYVARDIR=`echo $option | sed -e 's/^.*=//;'`
324 ;;
325 --disable-cmdmon)
326 feat_cmdmon=0
327 ;;
328 --disable-ntp)
329 feat_ntp=0
330 ;;
331 --disable-refclock)
332 feat_refclock=0
333 ;;
334 --disable-rtc)
335 feat_rtc=0
336 ;;
337 --disable-ipv6)
338 feat_ipv6=0
339 ;;
340 --disable-phc)
341 feat_phc=0
342 ;;
343 --disable-pps)
344 feat_pps=0
345 ;;
346 --disable-privdrop)
347 feat_droproot=0
348 ;;
349 --without-libcap|--disable-linuxcaps)
350 try_libcap=0
351 ;;
352 --enable-scfilter)
353 feat_scfilter=1
354 ;;
355 --disable-scfilter)
356 feat_scfilter=0
357 ;;
358 --without-seccomp)
359 try_seccomp=0
360 ;;
361 --disable-asyncdns)
362 feat_asyncdns=0
363 ;;
364 --disable-forcednsretry)
365 feat_forcednsretry=0
366 ;;
367 --without-clock-gettime)
368 try_clock_gettime=0
369 ;;
370 --disable-timestamping)
371 feat_timestamping=0
372 ;;
373 --enable-ntp-signd)
374 feat_ntp_signd=1
375 ;;
376 --with-ntp-era=* )
377 ntp_era_split=`echo $option | sed -e 's/^.*=//;'`
378 ;;
379 --with-user=* )
380 default_user=`echo $option | sed -e 's/^.*=//;'`
381 ;;
382 --with-hwclockfile=* )
383 default_hwclockfile=`echo $option | sed -e 's/^.*=//;'`
384 ;;
385 --with-pidfile=* )
386 default_pidfile=`echo $option | sed -e 's/^.*=//;'`
387 ;;
388 --with-rtcdevice=* )
389 default_rtcdevice=`echo $option | sed -e 's/^.*=//;'`
390 ;;
391 --with-sendmail=* )
392 mail_program=`echo $option | sed -e 's/^.*=//;'`
393 ;;
394 --disable-sechash )
395 feat_sechash=0
396 ;;
397 --without-nettle )
398 try_nettle=0
399 ;;
400 --without-nss )
401 try_nss=0
402 ;;
403 --without-tomcrypt )
404 try_tomcrypt=0
405 ;;
406 --disable-nts )
407 feat_nts=0
408 ;;
409 --without-gnutls )
410 try_gnutls=0
411 ;;
412 --host-system=* )
413 OPERATINGSYSTEM=`echo $option | sed -e 's/^.*=//;'`
414 ;;
415 --host-release=* )
416 VERSION=`echo $option | sed -e 's/^.*=//;'`
417 ;;
418 --host-machine=* )
419 MACHINE=`echo $option | sed -e 's/^.*=//;'`
420 ;;
421 --help | -h )
422 usage
423 exit 0
424 ;;
425 * )
426 echo "Unrecognized option : " $option
427 esac
428 done
429
430 rm -f config.h config.log
431
432 SYSTEM=${OPERATINGSYSTEM}-${MACHINE}
433
434 case $OPERATINGSYSTEM in
435 Linux)
436 EXTRA_OBJECTS="sys_generic.o sys_linux.o sys_timex.o sys_posix.o"
437 [ $try_libcap != "0" ] && try_libcap=1
438 try_rtc=1
439 [ $try_seccomp != "0" ] && try_seccomp=1
440 try_timestamping=1
441 try_setsched=1
442 try_lockmem=1
443 try_phc=1
444 add_def LINUX
445 echo "Configuring for " $SYSTEM
446 ;;
447 FreeBSD)
448 # recvmmsg() seems to be broken on FreeBSD 11.0 and it's just
449 # a wrapper around recvmsg()
450 try_recvmmsg=0
451 EXTRA_OBJECTS="sys_generic.o sys_netbsd.o sys_timex.o sys_posix.o"
452 try_setsched=1
453 try_lockmem=1
454 add_def FREEBSD
455 if [ $feat_droproot = "1" ]; then
456 add_def FEAT_PRIVDROP
457 priv_ops="ADJUSTTIME ADJUSTTIMEX SETTIME BINDSOCKET"
458 fi
459 echo "Configuring for $SYSTEM"
460 ;;
461 NetBSD)
462 EXTRA_OBJECTS="sys_generic.o sys_netbsd.o sys_timex.o sys_posix.o"
463 try_clockctl=1
464 try_setsched=1
465 try_lockmem=1
466 add_def NETBSD
467 echo "Configuring for $SYSTEM"
468 ;;
469 Darwin)
470 EXTRA_OBJECTS="sys_macosx.o"
471 LIBS="$LIBS -lresolv"
472 add_def MACOSX
473 if [ $feat_droproot = "1" ]; then
474 add_def FEAT_PRIVDROP
475 priv_ops="ADJUSTTIME SETTIME BINDSOCKET"
476 fi
477 major=`echo $VERSION | cut -d. -f1`
478 # ntp_adjtime is not available in macOS 10.12 (Darwin 16.x.x) and earlier
479 if [ $major -gt "16" ]; then
480 add_def HAVE_MACOS_SYS_TIMEX
481 EXTRA_OBJECTS="$EXTRA_OBJECTS sys_generic.o sys_netbsd.o sys_timex.o"
482 if [ $feat_droproot = "1" ]; then
483 priv_ops="$priv_ops ADJUSTTIMEX"
484 fi
485 fi
486 echo "Configuring for macOS (" $SYSTEM "macOS version" $VERSION ")"
487 ;;
488 SunOS)
489 EXTRA_OBJECTS="sys_generic.o sys_solaris.o sys_timex.o sys_posix.o"
490 LIBS="$LIBS -lsocket -lnsl -lresolv"
491 try_setsched=1
492 try_lockmem=1
493 add_def SOLARIS
494 # These are needed to have msg_control in struct msghdr
495 add_def __EXTENSIONS__
496 add_def _XOPEN_SOURCE 1
497 add_def _XOPEN_SOURCE_EXTENDED 1
498 if [ $feat_droproot = "1" ]; then
499 add_def FEAT_PRIVDROP
500 priv_ops="ADJUSTTIMEX SETTIME BINDSOCKET"
501 fi
502 echo "Configuring for Solaris (" $SYSTEM "SunOS version" $VERSION ")"
503 ;;
504 * )
505 echo "error: $SYSTEM is not supported (yet?)"
506 exit 1
507 ;;
508 esac
509
510 if [ $feat_debug = "1" ]; then
511 add_def FEAT_DEBUG
512 fi
513 add_def DEBUG $feat_debug
514
515 if [ $feat_cmdmon = "1" ]; then
516 add_def FEAT_CMDMON
517 EXTRA_OBJECTS="$EXTRA_OBJECTS cmdmon.o manual.o pktlength.o"
518 fi
519
520 if [ $feat_ntp = "1" ]; then
521 add_def FEAT_NTP
522 EXTRA_OBJECTS="$EXTRA_OBJECTS ntp_auth.o ntp_core.o ntp_ext.o ntp_io.o ntp_sources.o"
523 if [ $feat_ntp_signd = "1" ]; then
524 add_def FEAT_SIGND
525 EXTRA_OBJECTS="$EXTRA_OBJECTS ntp_signd.o"
526 fi
527 else
528 feat_asyncdns=0
529 feat_timestamping=0
530 fi
531
532 if [ "$feat_cmdmon" = "1" ] || [ $feat_ntp = "1" ]; then
533 EXTRA_OBJECTS="$EXTRA_OBJECTS addrfilt.o clientlog.o keys.o nameserv.o"
534 else
535 feat_ipv6=0
536 fi
537
538 if [ $feat_refclock = "1" ]; then
539 add_def FEAT_REFCLOCK
540 EXTRA_OBJECTS="$EXTRA_OBJECTS refclock.o refclock_phc.o refclock_pps.o refclock_shm.o refclock_sock.o"
541 fi
542
543 MYCC="$CC"
544 MYCFLAGS="$CFLAGS"
545 MYCPPFLAGS="$CPPFLAGS"
546 MYLDFLAGS="$LDFLAGS"
547
548 if [ "x$MYCC" = "x" ]; then
549 for cc in gcc clang cc ""; do
550 if [ "x$cc" = "x" ]; then
551 echo "error: no C compiler found"
552 exit 1
553 fi
554 MYCC=$cc
555 if test_code "$MYCC" '' '' '' ''; then
556 break
557 fi
558 done
559 else
560 if ! test_code "$MYCC" '' '' '' ''; then
561 echo "error: C compiler $MYCC cannot create executables"
562 exit 1
563 fi
564 fi
565
566 if [ "x$MYCFLAGS" = "x" ]; then
567 MYCFLAGS="-O2 -g"
568
569 TESTCFLAGS="-D_FORTIFY_SOURCE=2 -fPIE"
570 TESTLDFLAGS="-pie -Wl,-z,relro,-z,now"
571 if test_code 'hardening compiler options' '' "$TESTCFLAGS" "$TESTLDFLAGS" ''; then
572 MYCFLAGS="$MYCFLAGS $TESTCFLAGS"
573 MYLDFLAGS="$MYLDFLAGS $TESTLDFLAGS"
574 fi
575 TESTCFLAGS="-fstack-protector-strong --param=ssp-buffer-size=4"
576 if test_code '-fstack-protector-strong' '' "$TESTCFLAGS" '' ''; then
577 MYCFLAGS="$MYCFLAGS $TESTCFLAGS"
578 else
579 TESTCFLAGS="-fstack-protector --param=ssp-buffer-size=4"
580 if test_code '-fstack-protector' '' "$TESTCFLAGS" '' ''; then
581 MYCFLAGS="$MYCFLAGS $TESTCFLAGS"
582 fi
583 fi
584 fi
585
586 if [ "x$MYCC" = "xgcc" ] || [ "x$MYCC" = "xclang" ]; then
587 MYCFLAGS="$MYCFLAGS -Wmissing-prototypes -Wall"
588 fi
589
590 if [ "x$PKG_CONFIG" = "x" ]; then
591 PKG_CONFIG=pkg-config
592 fi
593
594 if ! test_executable "pkg-config" $PKG_CONFIG --version; then
595 try_nettle=0
596 try_nss=0
597 try_gnutls=0
598 fi
599
600 if test_code '64-bit time_t' 'time.h' '' '' '
601 char x[sizeof(time_t) > 4 ? 1 : -1] = {0};
602 return x[0];'
603 then
604 add_def HAVE_LONG_TIME_T 1
605
606 if [ "x$ntp_era_split" != "x" ]; then
607 split_seconds=$ntp_era_split
608 split_days=0
609 else
610 if [ "x$SOURCE_DATE_EPOCH" != "x" ]; then
611 split_seconds=$SOURCE_DATE_EPOCH
612 else
613 split_seconds=`date '+%s'`
614 fi
615 if [ "x$split_seconds" = "x" ]; then
616 echo "error: could not get current time, --with-ntp-era option is needed"
617 exit 1
618 fi
619 split_days=$((50 * 365))
620 fi
621
622 add_def NTP_ERA_SPLIT "(${split_seconds}LL - $split_days * 24 * 3600)"
623
624 date_format='+%Y-%m-%dT%H:%M:%SZ'
625
626 # Print the full NTP interval if a suitable date is found
627 if [ "x`date -u -d '1970-01-01 UTC 9 days ago 5 seconds 3 seconds' \
628 $date_format 2> /dev/null`" = "x1969-12-23T00:00:08Z" ]
629 then
630 time1="`date -u -d "1970-01-01 UTC $split_days days ago $split_seconds seconds" \
631 $date_format`"
632 time2="`date -u -d "1970-01-01 UTC $split_days days ago $split_seconds seconds 4294967296 seconds" \
633 $date_format`"
634 echo "NTP time mapped to $time1/$time2"
635 fi
636 fi
637
638 MATHCODE='return (int) pow(2.0, log(sqrt((double)argc)));'
639 if ! test_code 'math' 'math.h' '' '' "$MATHCODE"; then
640 if test_code 'math in -lm' 'math.h' '' '-lm' "$MATHCODE"; then
641 LIBS="$LIBS -lm"
642 else
643 echo "error: could not compile/link a program which uses sqrt(), log(), pow()"
644 exit 1
645 fi
646 fi
647
648 if test_code 'struct in_pktinfo' 'sys/socket.h netinet/in.h' '' '' '
649 struct in_pktinfo ipi;
650 return sizeof (ipi.ipi_spec_dst.s_addr) + IP_PKTINFO;'
651 then
652 add_def HAVE_IN_PKTINFO
653 fi
654
655 if [ $feat_ipv6 = "1" ] && \
656 test_code 'IPv6 support' 'arpa/inet.h sys/socket.h netinet/in.h' '' "$LIBS" '
657 struct sockaddr_in6 n;
658 char p[100];
659 n.sin6_addr = in6addr_any;
660 return !inet_ntop(AF_INET6, &n.sin6_addr.s6_addr, p, sizeof(p));'
661 then
662 add_def FEAT_IPV6
663 if test_code 'struct in6_pktinfo' 'sys/socket.h netinet/in.h' '' '' '
664 return sizeof (struct in6_pktinfo) + IPV6_PKTINFO;'
665 then
666 add_def HAVE_IN6_PKTINFO
667 else
668 if test_code 'struct in6_pktinfo with _GNU_SOURCE' 'sys/socket.h netinet/in.h' \
669 '-D_GNU_SOURCE' '' 'return sizeof (struct in6_pktinfo) + IPV6_PKTINFO;'
670 then
671 add_def _GNU_SOURCE
672 add_def HAVE_IN6_PKTINFO
673 fi
674 fi
675 fi
676
677 if [ $try_clock_gettime = "1" ]; then
678 if test_code 'clock_gettime()' 'time.h' '' '' \
679 'clock_gettime(CLOCK_REALTIME, NULL);'
680 then
681 add_def HAVE_CLOCK_GETTIME
682 else
683 if test_code 'clock_gettime() in -lrt' 'time.h' '' '-lrt' \
684 'clock_gettime(CLOCK_REALTIME, NULL);'
685 then
686 add_def HAVE_CLOCK_GETTIME
687 EXTRA_LIBS="$EXTRA_LIBS -lrt"
688 fi
689 fi
690 fi
691
692 if test_code 'getaddrinfo()' 'sys/types.h sys/socket.h netdb.h' '' "$LIBS" \
693 'return getaddrinfo(0, 0, 0, 0);'
694 then
695 add_def HAVE_GETADDRINFO
696 fi
697
698 if [ $feat_asyncdns = "1" ] && \
699 test_code 'pthread' 'pthread.h' '-pthread' '' '
700 pthread_t thread;
701 return (int)pthread_create(&thread, NULL, (void *)1, NULL);'
702 then
703 add_def FEAT_ASYNCDNS
704 add_def USE_PTHREAD_ASYNCDNS
705 EXTRA_OBJECTS="$EXTRA_OBJECTS nameserv_async.o"
706 use_pthread=1
707 fi
708
709 if test_code 'arc4random_buf()' 'stdlib.h' '' '' 'arc4random_buf(NULL, 0);'; then
710 add_def HAVE_ARC4RANDOM
711 fi
712
713 if test_code 'getrandom()' 'stdlib.h sys/random.h' '' '' \
714 'return getrandom(NULL, 256, 0);'; then
715 add_def HAVE_GETRANDOM
716 fi
717
718 RECVMMSG_CODE='
719 struct mmsghdr hdr;
720 return !recvmmsg(0, &hdr, 1, MSG_DONTWAIT, 0);'
721 if [ $try_recvmmsg = "1" ]; then
722 if test_code 'recvmmsg()' 'sys/socket.h' '' "$LIBS" "$RECVMMSG_CODE"; then
723 add_def HAVE_RECVMMSG
724 else
725 if test_code 'recvmmsg() with _GNU_SOURCE' 'sys/socket.h' '-D_GNU_SOURCE' \
726 "$LIBS" "$RECVMMSG_CODE"
727 then
728 add_def _GNU_SOURCE
729 add_def HAVE_RECVMMSG
730 fi
731 fi
732 fi
733
734 if [ $feat_timestamping = "1" ] && [ $try_timestamping = "1" ] &&
735 test_code 'SW/HW timestamping' 'sys/types.h sys/socket.h linux/net_tstamp.h
736 linux/errqueue.h linux/ptp_clock.h' '' '' '
737 int val = SOF_TIMESTAMPING_SOFTWARE | SOF_TIMESTAMPING_RX_SOFTWARE |
738 SOF_TIMESTAMPING_RAW_HARDWARE | SOF_TIMESTAMPING_OPT_CMSG;
739 return sizeof (struct scm_timestamping) + SCM_TSTAMP_SND + PTP_SYS_OFFSET +
740 setsockopt(0, SOL_SOCKET, SO_SELECT_ERR_QUEUE + SO_TIMESTAMPING,
741 &val, sizeof (val));'
742 then
743 add_def HAVE_LINUX_TIMESTAMPING
744 EXTRA_OBJECTS="$EXTRA_OBJECTS hwclock.o ntp_io_linux.o"
745
746 if test_code 'other timestamping options' \
747 'sys/types.h sys/socket.h linux/net_tstamp.h' '' '' '
748 struct scm_ts_pktinfo pktinfo;
749 pktinfo.if_index = pktinfo.pkt_length = 0;
750 return pktinfo.if_index + pktinfo.pkt_length + HWTSTAMP_FILTER_NTP_ALL +
751 SCM_TIMESTAMPING_PKTINFO +
752 SOF_TIMESTAMPING_OPT_PKTINFO + SOF_TIMESTAMPING_OPT_TX_SWHW;'; then
753 add_def HAVE_LINUX_TIMESTAMPING_RXFILTER_NTP 1
754 add_def HAVE_LINUX_TIMESTAMPING_OPT_PKTINFO 1
755 add_def HAVE_LINUX_TIMESTAMPING_OPT_TX_SWHW 1
756 fi
757 fi
758
759 timepps_h=""
760 if [ $feat_refclock = "1" ] && [ $feat_pps = "1" ]; then
761 if test_code '<sys/timepps.h>' 'inttypes.h time.h sys/timepps.h' '' '' ''; then
762 timepps_h="sys/timepps.h"
763 add_def HAVE_SYS_TIMEPPS_H
764 else
765 if test_code '<timepps.h>' 'inttypes.h time.h timepps.h' '' '' ''; then
766 timepps_h="timepps.h"
767 add_def HAVE_TIMEPPS_H
768 fi
769 fi
770 fi
771
772 if [ "x$timepps_h" != "x" ] && \
773 test_code 'PPSAPI' "inttypes.h string.h time.h $timepps_h" '' '' '
774 pps_handle_t h = 0;
775 pps_info_t i;
776 struct timespec ts;
777 ts.tv_sec = ts.tv_nsec = 0;
778 return time_pps_fetch(h, PPS_TSFMT_TSPEC, &i, &ts);'
779 then
780 add_def FEAT_PPS
781 fi
782
783 if [ $feat_droproot = "1" ] && [ $try_libcap = "1" ] && \
784 test_code \
785 libcap \
786 'sys/types.h pwd.h sys/prctl.h sys/capability.h grp.h' \
787 '' '-lcap' \
788 'prctl(PR_SET_KEEPCAPS, 1);cap_set_proc(cap_from_text("cap_sys_time=ep"));'
789 then
790 add_def FEAT_PRIVDROP
791 EXTRA_LIBS="$EXTRA_LIBS -lcap"
792 fi
793
794 if [ $feat_droproot = "1" ] && [ $try_clockctl = "1" ] && \
795 test_code '<sys/clockctl.h>' 'sys/clockctl.h' '' '' ''
796 then
797 add_def FEAT_PRIVDROP
798 priv_ops="BINDSOCKET"
799 fi
800
801 if [ $feat_scfilter = "1" ] && [ $try_seccomp = "1" ] && \
802 test_code seccomp 'seccomp.h' '' '-lseccomp' \
803 'seccomp_init(SCMP_ACT_KILL);'
804 then
805 add_def FEAT_SCFILTER
806 # NAME2IPADDRESS shouldn't be enabled with other operations as the helper
807 # process works on one request at the time and the async resolver could
808 # block the main thread
809 priv_ops="NAME2IPADDRESS RELOADDNS"
810 EXTRA_LIBS="$EXTRA_LIBS -lseccomp"
811 fi
812
813 if [ "x$priv_ops" != "x" ]; then
814 EXTRA_OBJECTS="$EXTRA_OBJECTS privops.o"
815 add_def PRIVOPS_HELPER
816 for o in $priv_ops; do
817 add_def PRIVOPS_$o
818 done
819 fi
820
821 if [ $feat_rtc = "1" ] && [ $try_rtc = "1" ] && \
822 test_code '<linux/rtc.h>' 'sys/ioctl.h linux/rtc.h' '' '' \
823 'ioctl(1, RTC_UIE_ON&RTC_UIE_OFF&RTC_RD_TIME&RTC_SET_TIME, 0&RTC_UF);'
824 then
825 EXTRA_OBJECTS="$EXTRA_OBJECTS rtc_linux.o"
826 add_def FEAT_RTC
827 fi
828
829 if [ $feat_refclock = "1" ] && [ $feat_phc = "1" ] && [ $try_phc = "1" ] && \
830 grep '#define HAVE_CLOCK_GETTIME' config.h > /dev/null && \
831 test_code '<linux/ptp_clock.h>' 'sys/ioctl.h linux/ptp_clock.h' '' '' \
832 'ioctl(1, PTP_CLOCK_GETCAPS + PTP_SYS_OFFSET, 0);'
833 then
834 grep 'HAVE_LINUX_TIMESTAMPING' config.h > /dev/null ||
835 EXTRA_OBJECTS="$EXTRA_OBJECTS hwclock.o"
836 add_def FEAT_PHC
837 fi
838
839 if [ $try_setsched = "1" ] && \
840 test_code \
841 'pthread_setschedparam()' \
842 'pthread.h sched.h' '-pthread' '' '
843 struct sched_param sched;
844 sched_get_priority_max(SCHED_FIFO);
845 pthread_setschedparam(pthread_self(), SCHED_FIFO, &sched);'
846 then
847 add_def HAVE_PTHREAD_SETSCHEDPARAM
848 use_pthread=1
849 fi
850
851 if [ $try_lockmem = "1" ] && \
852 test_code \
853 'mlockall()' \
854 'sys/mman.h' '' '' '
855 mlockall(MCL_CURRENT|MCL_FUTURE);'
856 then
857 add_def HAVE_MLOCKALL
858 fi
859 if [ $try_lockmem = "1" ] && \
860 test_code \
861 'setrlimit(RLIMIT_MEMLOCK, ...)' \
862 'sys/resource.h' '' '' '
863 struct rlimit rlim;
864 rlim.rlim_max = rlim.rlim_cur = RLIM_INFINITY;
865 setrlimit(RLIMIT_MEMLOCK, &rlim);'
866 then
867 add_def HAVE_SETRLIMIT_MEMLOCK
868 fi
869
870 if [ $feat_forcednsretry = "1" ]
871 then
872 add_def FORCE_DNSRETRY
873 fi
874
875 READLINE_LINK=""
876 if [ $feat_readline = "1" ]; then
877 if [ $try_editline = "1" ]; then
878 if test_code editline 'stdio.h editline/readline.h' \
879 "$readline_inc" "$readline_lib -ledit" \
880 'add_history(readline("prompt"));'
881 then
882 add_def FEAT_READLINE
883 add_def USE_EDITLINE
884 MYCPPFLAGS="$MYCPPFLAGS $readline_inc"
885 READLINE_LINK="$readline_lib -ledit"
886 fi
887 fi
888
889 if [ "x$READLINE_LINK" = "x" ] && [ $try_readline = "1" ]; then
890 if test_code readline 'stdio.h readline/readline.h readline/history.h' \
891 "$readline_inc" "$readline_lib -lreadline" \
892 'add_history(readline("prompt"));'
893 then
894 add_def FEAT_READLINE
895 MYCPPFLAGS="$MYCPPFLAGS $readline_inc"
896 READLINE_LINK="$readline_lib -lreadline"
897 fi
898 fi
899
900 if [ "x$READLINE_LINK" = "x" ] && [ $try_readline = "1" ]; then
901 if test_code 'readline with -lncurses' \
902 'stdio.h readline/readline.h readline/history.h' \
903 "$readline_inc" "$readline_lib $ncurses_lib -lreadline -lncurses" \
904 'add_history(readline("prompt"));'
905 then
906 add_def FEAT_READLINE
907 MYCPPFLAGS="$MYCPPFLAGS $readline_inc"
908 READLINE_LINK="$readline_lib $ncurses_lib -lreadline -lncurses"
909 fi
910 fi
911
912 EXTRA_CLI_LIBS="$EXTRA_CLI_LIBS $READLINE_LINK"
913 fi
914
915 HASH_OBJ="hash_intmd5.o"
916 HASH_LINK=""
917
918 if [ $feat_sechash = "1" ] && [ "x$HASH_LINK" = "x" ] && [ $try_nettle = "1" ]; then
919 test_cflags="`pkg_config --cflags nettle`"
920 test_link="`pkg_config --libs nettle`"
921 if test_code 'nettle' 'nettle/nettle-meta.h nettle/sha2.h' \
922 "$test_cflags" "$test_link" \
923 'return nettle_hashes[0]->context_size;'
924 then
925 HASH_OBJ="hash_nettle.o"
926 HASH_LINK="$test_link"
927 MYCPPFLAGS="$MYCPPFLAGS $test_cflags"
928 add_def FEAT_SECHASH
929
930 if test_code 'CMAC in nettle' 'nettle/cmac.h' "$test_cflags" "$test_link" \
931 'cmac128_update(NULL, NULL, NULL, 0, NULL);'
932 then
933 add_def HAVE_CMAC
934 EXTRA_OBJECTS="$EXTRA_OBJECTS cmac_nettle.o"
935 EXTRA_CLI_OBJECTS="$EXTRA_CLI_OBJECTS cmac_nettle.o"
936 fi
937 fi
938 fi
939
940 if [ $feat_sechash = "1" ] && [ "x$HASH_LINK" = "x" ] && [ $try_nss = "1" ]; then
941 test_cflags="`pkg_config --cflags nss`"
942 test_link="`pkg_config --libs-only-L nss` -lfreebl3"
943 if test_code 'NSS' 'nss.h hasht.h nsslowhash.h' \
944 "$test_cflags" "$test_link" \
945 'NSSLOWHASH_Begin(NSSLOWHASH_NewContext(NSSLOW_Init(), HASH_AlgSHA512));'
946 then
947 HASH_OBJ="hash_nss.o"
948 HASH_LINK="$test_link"
949 MYCPPFLAGS="$MYCPPFLAGS $test_cflags"
950 add_def FEAT_SECHASH
951 fi
952 fi
953
954 if [ $feat_sechash = "1" ] && [ "x$HASH_LINK" = "x" ] && [ $try_tomcrypt = "1" ]; then
955 if test_code 'tomcrypt' 'tomcrypt.h' '-I/usr/include/tomcrypt' '-ltomcrypt' \
956 'hash_memory_multi(find_hash("md5"), NULL, NULL, NULL, 0, NULL, 0);'
957 then
958 HASH_OBJ="hash_tomcrypt.o"
959 HASH_LINK="-ltomcrypt"
960 MYCPPFLAGS="$MYCPPFLAGS -I/usr/include/tomcrypt"
961 add_def FEAT_SECHASH
962 fi
963 fi
964
965 EXTRA_OBJECTS="$EXTRA_OBJECTS $HASH_OBJ"
966 EXTRA_CLI_OBJECTS="$EXTRA_CLI_OBJECTS $HASH_OBJ"
967 LIBS="$LIBS $HASH_LINK"
968
969 if [ $feat_ntp = "1" ] && [ $feat_nts = "1" ] && [ $try_gnutls = "1" ] && \
970 echo "$HASH_LINK" | grep 'nettle' > /dev/null; then
971 test_cflags="`pkg_config --cflags gnutls`"
972 test_link="`pkg_config --libs gnutls`"
973 if test_code 'gnutls' 'gnutls/gnutls.h' \
974 "$test_cflags" "$test_link" '
975 return gnutls_init(NULL, 0) +
976 gnutls_priority_init2(NULL, "", NULL, GNUTLS_PRIORITY_INIT_DEF_APPEND) +
977 gnutls_prf_rfc5705(NULL, 0, "", 0, "", 16, NULL);' &&
978 test_code 'AES128 in nettle' 'nettle/aes.h' '' "$LIBS" \
979 'aes128_set_encrypt_key(NULL, NULL);'
980 then
981 EXTRA_OBJECTS="$EXTRA_OBJECTS nts_ke_client.o nts_ke_server.o nts_ke_session.o"
982 EXTRA_OBJECTS="$EXTRA_OBJECTS nts_ntp_auth.o nts_ntp_client.o nts_ntp_server.o"
983 EXTRA_OBJECTS="$EXTRA_OBJECTS siv_nettle.o"
984 LIBS="$LIBS $test_link"
985 MYCPPFLAGS="$MYCPPFLAGS $test_cflags"
986 add_def FEAT_NTS
987
988 add_def HAVE_SIV
989 if test_code 'SIV in nettle' \
990 'nettle/siv-cmac.h' "" "$LIBS" \
991 'siv_cmac_aes128_set_key(NULL, NULL);'
992 then
993 add_def HAVE_NETTLE_SIV_CMAC
994 fi
995 fi
996 fi
997
998 if [ $use_pthread = "1" ]; then
999 MYCFLAGS="$MYCFLAGS -pthread"
1000 fi
1001
1002 SYSCONFDIR=/etc
1003 if [ "x$SETSYSCONFDIR" != "x" ]; then
1004 SYSCONFDIR=$SETSYSCONFDIR
1005 fi
1006
1007 PREFIX=/usr/local
1008 if [ "x$SETPREFIX" != "x" ]; then
1009 PREFIX=$SETPREFIX
1010 fi
1011
1012 EPREFIX=${PREFIX}
1013 if [ "x$SETEPREFIX" != "x" ]; then
1014 EPREFIX=$SETEPREFIX
1015 fi
1016
1017 BINDIR=${EPREFIX}/bin
1018 if [ "x$SETBINDIR" != "x" ]; then
1019 BINDIR=$SETBINDIR
1020 fi
1021
1022 SBINDIR=${EPREFIX}/sbin
1023 if [ "x$SETSBINDIR" != "x" ]; then
1024 SBINDIR=$SETSBINDIR
1025 fi
1026
1027 DATAROOTDIR=${PREFIX}/share
1028 if [ "x$SETDATAROOTDIR" != "x" ]; then
1029 DATAROOTDIR=$SETDATAROOTDIR
1030 fi
1031
1032 MANDIR=${DATAROOTDIR}/man
1033 if [ "x$SETMANDIR" != "x" ]; then
1034 MANDIR=$SETMANDIR
1035 fi
1036
1037 DOCDIR=${DATAROOTDIR}/doc/chrony
1038 if [ "x$SETDOCDIR" != "x" ]; then
1039 DOCDIR=$SETDOCDIR
1040 fi
1041
1042 LOCALSTATEDIR=/var
1043 if [ "x$SETLOCALSTATEDIR" != "x" ]; then
1044 LOCALSTATEDIR=$SETLOCALSTATEDIR
1045 fi
1046
1047 CHRONYRUNDIR=${LOCALSTATEDIR}/run/chrony
1048 if [ "x$SETCHRONYRUNDIR" != "x" ]; then
1049 CHRONYRUNDIR=$SETCHRONYRUNDIR
1050 fi
1051
1052 CHRONYVARDIR=${LOCALSTATEDIR}/lib/chrony
1053 if [ "x$SETCHRONYVARDIR" != "x" ]; then
1054 CHRONYVARDIR=$SETCHRONYVARDIR
1055 fi
1056
1057 add_def DEFAULT_CONF_FILE "\"$SYSCONFDIR/chrony.conf\""
1058 add_def DEFAULT_HWCLOCK_FILE "\"$default_hwclockfile\""
1059 add_def DEFAULT_PID_FILE "\"$default_pidfile\""
1060 add_def DEFAULT_RTC_DEVICE "\"$default_rtcdevice\""
1061 add_def DEFAULT_USER "\"$default_user\""
1062 add_def DEFAULT_COMMAND_SOCKET "\"$CHRONYRUNDIR/chronyd.sock\""
1063 add_def MAIL_PROGRAM "\"$mail_program\""
1064
1065 common_features="`get_features SECHASH IPV6 DEBUG`"
1066 chronyc_features="`get_features READLINE`"
1067 chronyd_features="`get_features CMDMON NTP REFCLOCK RTC PRIVDROP SCFILTER SIGND ASYNCDNS NTS`"
1068 add_def CHRONYC_FEATURES "\"$chronyc_features $common_features\""
1069 add_def CHRONYD_FEATURES "\"$chronyd_features $common_features\""
1070 echo "Features : $chronyd_features $chronyc_features $common_features"
1071
1072 if [ -f version.txt ]; then
1073 CHRONY_VERSION="`cat version.txt`"
1074 else
1075 CHRONY_VERSION="DEVELOPMENT"
1076 fi
1077
1078 add_def CHRONY_VERSION "\"${CHRONY_VERSION}\""
1079
1080 for f in Makefile doc/Makefile test/unit/Makefile
1081 do
1082 echo Creating $f
1083 sed -e "s%@EXTRA_OBJS@%${EXTRA_OBJECTS}%;\
1084 s%@EXTRA_CLI_OBJS@%${EXTRA_CLI_OBJECTS}%;\
1085 s%@CC@%${MYCC}%;\
1086 s%@CFLAGS@%${MYCFLAGS}%;\
1087 s%@CPPFLAGS@%${MYCPPFLAGS}%;\
1088 s%@LDFLAGS@%${MYLDFLAGS}%;\
1089 s%@LIBS@%${LIBS}%;\
1090 s%@EXTRA_LIBS@%${EXTRA_LIBS}%;\
1091 s%@EXTRA_CLI_LIBS@%${EXTRA_CLI_LIBS}%;\
1092 s%@SYSCONFDIR@%${SYSCONFDIR}%;\
1093 s%@BINDIR@%${BINDIR}%;\
1094 s%@SBINDIR@%${SBINDIR}%;\
1095 s%@DOCDIR@%${DOCDIR}%;\
1096 s%@MANDIR@%${MANDIR}%;\
1097 s%@LOCALSTATEDIR@%${LOCALSTATEDIR}%;\
1098 s%@CHRONYRUNDIR@%${CHRONYRUNDIR}%;\
1099 s%@CHRONYVARDIR@%${CHRONYVARDIR}%;\
1100 s%@DEFAULT_HWCLOCK_FILE@%${default_hwclockfile}%;\
1101 s%@DEFAULT_PID_FILE@%${default_pidfile}%;\
1102 s%@DEFAULT_RTC_DEVICE@%${default_rtcdevice}%;\
1103 s%@DEFAULT_USER@%${default_user}%;\
1104 s%@CHRONY_VERSION@%${CHRONY_VERSION}%;" \
1105 < ${f}.in > $f
1106 done
1107
1108 # =======================================================================
1109 # vim:et:sw=2:ht=2:sts=2:fdm=marker:cms=#%s
1110