xref: /freebsd/contrib/unbound/configure.ac (revision 50caa0ea0c16499c40e785b5aa37053b180b2830)
1#                                               -*- Autoconf -*-
2# Process this file with autoconf to produce a configure script.
3AC_PREREQ([2.56])
4sinclude(acx_nlnetlabs.m4)
5sinclude(ax_build_date_epoch.m4)
6sinclude(ax_pthread.m4)
7sinclude(acx_python.m4)
8sinclude(ax_pkg_swig.m4)
9sinclude(dnstap/dnstap.m4)
10sinclude(dnscrypt/dnscrypt.m4)
11
12# must be numbers. ac_defun because of later processing
13m4_define([VERSION_MAJOR],[1])
14m4_define([VERSION_MINOR],[25])
15m4_define([VERSION_MICRO],[1])
16AC_INIT([unbound],m4_defn([VERSION_MAJOR]).m4_defn([VERSION_MINOR]).m4_defn([VERSION_MICRO]),[unbound-bugs@nlnetlabs.nl or https://github.com/NLnetLabs/unbound/issues],[unbound])
17AC_SUBST(UNBOUND_VERSION_MAJOR, [VERSION_MAJOR])
18AC_SUBST(UNBOUND_VERSION_MINOR, [VERSION_MINOR])
19AC_SUBST(UNBOUND_VERSION_MICRO, [VERSION_MICRO])
20
21LIBUNBOUND_CURRENT=9
22LIBUNBOUND_REVISION=37
23LIBUNBOUND_AGE=1
24# 1.0.0 had 0:12:0
25# 1.0.1 had 0:13:0
26# 1.0.2 had 0:14:0
27# 1.1.0 had 0:15:0
28# 1.1.1 had 0:16:0
29# 1.2.0 had 0:17:0
30# 1.2.1 had 0:18:0
31# 1.3.0 had 1:0:0   # ub_cancel and -export-symbols.
32# 1.3.1 had 1:1:0
33# 1.3.2 had 1:2:0
34# 1.3.3 had 1:3:0
35# 1.3.4 had 1:4:0
36# 1.4.0-snapshots had 1:5:0
37# 1.4.0 had 1:5:0 (not 2:0:0)   # ub_result.why_bogus
38# 1.4.1 had 2:1:0
39# 1.4.2 had 2:2:0
40# 1.4.3 had 2:3:0
41# 1.4.4 had 2:4:0
42# 1.4.5 had 2:5:0
43# 1.4.6 had 2:6:0
44# 1.4.7 had 2:7:0
45# 1.4.8 had 2:8:0
46# 1.4.9 had 2:9:0
47# 1.4.10 had 2:10:0
48# 1.4.11 had 2:11:0
49# 1.4.12 had 2:12:0
50# 1.4.13 had 2:13:0
51# and 1.4.13p1 and 1.4.13.p2
52# 1.4.14 had 2:14:0
53# 1.4.15 had 3:0:1 # adds ub_version()
54# 1.4.16 had 3:1:1
55# 1.4.17 had 3:2:1
56# 1.4.18 had 3:3:1
57# 1.4.19 had 3:4:1
58# 1.4.20 had 4:0:2 # adds libunbound.ttl # but shipped 3:5:1
59# 1.4.21 had 4:1:2
60# 1.4.22 had 4:1:2
61# 1.5.0 had 5:3:3 # adds ub_ctx_add_ta_autr
62# 1.5.1 had 5:3:3
63# 1.5.2 had 5:5:3
64# 1.5.3 had 5:6:3
65# 1.5.4 had 5:7:3
66# 1.5.5 had 5:8:3
67# 1.5.6 had 5:9:3
68# 1.5.7 had 5:10:3
69# 1.5.8 had 6:0:4 # adds ub_ctx_set_stub
70# 1.5.9 had 6:1:4
71# 1.5.10 had 6:2:4
72# 1.6.0 had 6:3:4
73# 1.6.1 had 7:0:5 # ub_callback_t typedef renamed to ub_callback_type
74# 1.6.2 had 7:1:5
75# 1.6.3 had 7:2:5
76# 1.6.4 had 7:3:5
77# 1.6.5 had 7:4:5
78# 1.6.6 had 7:5:5
79# 1.6.7 had 7:6:5
80# 1.6.8 had 7:7:5
81# 1.7.0 had 7:8:5
82# 1.7.1 had 7:9:5
83# 1.7.2 had 7:10:5
84# 1.7.3 had 7:11:5
85# 1.8.0 had 8:0:0 # changes the event callback function signature
86# 1.8.1 had 8:1:0
87# 1.8.2 had 8:2:0
88# 1.8.3 had 8:3:0
89# 1.9.0 had 9:0:1 # add ub_ctx_set_tls
90# 1.9.1 had 9:1:1
91# 1.9.2 had 9:2:1
92# 1.9.3 had 9:3:1
93# 1.9.4 had 9:4:1
94# 1.9.5 had 9:5:1
95# 1.9.6 had 9:6:1
96# 1.10.0 had 9:7:1
97# 1.10.1 had 9:8:1
98# 1.11.0 had 9:9:1
99# 1.12.0 had 9:10:1
100# 1.13.0 had 9:11:1
101# 1.13.1 had 9:12:1
102# 1.13.2 had 9:13:1
103# 1.14.0 had 9:14:1
104# 1.15.0 had 9:15:1
105# 1.16.0 had 9:16:1
106# 1.16.1 had 9:17:1
107# 1.16.2 had 9:18:1
108# 1.16.3 had 9:19:1
109# 1.17.0 had 9:20:1
110# 1.17.1 had 9:21:1
111# 1.18.0 had 9:22:1
112# 1.19.0 had 9:23:1
113# 1.19.1 had 9:24:1
114# 1.19.2 had 9:25:1
115# 1.19.3 had 9:26:1
116# 1.20.0 had 9:27:1
117# 1.21.0 had 9:28:1
118# 1.21.1 had 9:29:1
119# 1.22.0 had 9:30:1
120# 1.23.0 had 9:31:1
121# 1.23.1 had 9:32:1
122# 1.24.0 had 9:33:1
123# 1.24.1 had 9:34:1
124# 1.24.2 had 9:35:1
125# 1.25.0 had 9:36:1
126# 1.25.1 had 9:37:1
127
128#   Current  -- the number of the binary API that we're implementing
129#   Revision -- which iteration of the implementation of the binary
130#               API are we supplying?
131#   Age      -- How many previous binary API versions do we also
132#               support?
133#
134# If we release a new version that does not change the binary API,
135# increment Revision.
136#
137# If we release a new version that changes the binary API, but does
138# not break programs compiled against the old binary API, increment
139# Current and Age.  Set Revision to 0, since this is the first
140# implementation of the new API.
141#
142# Otherwise, we're changing the binary API and breaking backward
143# compatibility with old binaries.  Increment Current.  Set Age to 0,
144# since we're backward compatible with no previous APIs.  Set Revision
145# to 0 too.
146AC_SUBST(LIBUNBOUND_CURRENT)
147AC_SUBST(LIBUNBOUND_REVISION)
148AC_SUBST(LIBUNBOUND_AGE)
149
150
151cmdln="`echo $@ | sed -e 's/\\\\/\\\\\\\\/g' | sed -e 's/"/\\\\"/'g`"
152AC_DEFINE_UNQUOTED(CONFCMDLINE, ["$cmdln"], [Command line arguments used with configure])
153
154CFLAGS="$CFLAGS"
155AC_USE_SYSTEM_EXTENSIONS
156if test "$ac_cv_header_minix_config_h" = "yes"; then
157	AC_DEFINE(_NETBSD_SOURCE,1, [Enable for compile on Minix])
158fi
159
160dnl
161dnl By default set prefix to /usr/local
162dnl
163case "$prefix" in
164        NONE)
165		prefix="/usr/local"
166        ;;
167esac
168case "$exec_prefix" in
169        NONE)
170		exec_prefix="$prefix"
171        ;;
172esac
173
174# are we on MinGW?
175if uname -s 2>&1 | grep MINGW >/dev/null; then on_mingw="yes"
176else
177	if echo $host | grep mingw >/dev/null; then on_mingw="yes"
178	else on_mingw="no"; fi
179fi
180
181#
182# Determine configuration file
183# the eval is to evaluate shell expansion twice
184UNBOUND_SBIN_DIR=`eval echo "${sbindir}"`
185AC_SUBST(UNBOUND_SBIN_DIR)
186UNBOUND_SYSCONF_DIR=`eval echo "${sysconfdir}"`
187AC_SUBST(UNBOUND_SYSCONF_DIR)
188UNBOUND_LOCALSTATE_DIR=`eval echo "${localstatedir}"`
189AC_SUBST(UNBOUND_LOCALSTATE_DIR)
190if test $on_mingw = "no"; then
191  ub_conf_file=`eval echo "${sysconfdir}/unbound/unbound.conf"`
192else
193  ub_conf_file="C:\\Program Files\\Unbound\\service.conf"
194fi
195AC_ARG_WITH([conf_file],
196        AS_HELP_STRING([--with-conf-file=path],[Pathname to the Unbound configuration file]),
197	[ub_conf_file="$withval"])
198AC_SUBST(ub_conf_file)
199ACX_ESCAPE_BACKSLASH($ub_conf_file, hdr_config)
200AC_DEFINE_UNQUOTED(CONFIGFILE, ["$hdr_config"], [Pathname to the Unbound configuration file])
201ub_conf_dir=`AS_DIRNAME(["$ub_conf_file"])`
202AC_SUBST(ub_conf_dir)
203
204# Determine run, chroot directory and pidfile locations
205AC_ARG_WITH(run-dir,
206    AS_HELP_STRING([--with-run-dir=path],[set default directory to chdir to (by default dir part of cfg file)]),
207    UNBOUND_RUN_DIR="$withval",
208if test $on_mingw = no; then
209    UNBOUND_RUN_DIR=`dirname "$ub_conf_file"`
210else
211    UNBOUND_RUN_DIR=""
212fi
213)
214AC_SUBST(UNBOUND_RUN_DIR)
215ACX_ESCAPE_BACKSLASH($UNBOUND_RUN_DIR, hdr_run)
216AC_DEFINE_UNQUOTED(RUN_DIR, ["$hdr_run"], [Directory to chdir to])
217
218AC_ARG_WITH(chroot-dir,
219    AS_HELP_STRING([--with-chroot-dir=path],[set default directory to chroot to (by default same as run-dir)]),
220    UNBOUND_CHROOT_DIR="$withval",
221if test $on_mingw = no; then
222    UNBOUND_CHROOT_DIR="$UNBOUND_RUN_DIR"
223else
224    UNBOUND_CHROOT_DIR=""
225fi
226)
227AC_SUBST(UNBOUND_CHROOT_DIR)
228ACX_ESCAPE_BACKSLASH($UNBOUND_CHROOT_DIR, hdr_chroot)
229AC_DEFINE_UNQUOTED(CHROOT_DIR, ["$hdr_chroot"], [Directory to chroot to])
230
231AC_ARG_WITH(share-dir,
232    AS_HELP_STRING([--with-share-dir=path],[set default directory with shared data (by default same as share/unbound)]),
233    UNBOUND_SHARE_DIR="$withval",
234    UNBOUND_SHARE_DIR="$UNBOUND_RUN_DIR")
235AC_SUBST(UNBOUND_SHARE_DIR)
236AC_DEFINE_UNQUOTED(SHARE_DIR, ["$UNBOUND_SHARE_DIR"], [Shared data])
237
238AC_ARG_WITH(pidfile,
239    AS_HELP_STRING([--with-pidfile=filename],[set default pathname to unbound pidfile (default run-dir/unbound.pid)]),
240    UNBOUND_PIDFILE="$withval",
241if test $on_mingw = no; then
242    UNBOUND_PIDFILE="$UNBOUND_RUN_DIR/unbound.pid"
243else
244    UNBOUND_PIDFILE=""
245fi
246)
247AC_SUBST(UNBOUND_PIDFILE)
248ACX_ESCAPE_BACKSLASH($UNBOUND_PIDFILE, hdr_pid)
249AC_DEFINE_UNQUOTED(PIDFILE, ["$hdr_pid"], [default pidfile location])
250
251AC_ARG_WITH(rootkey-file,
252    AS_HELP_STRING([--with-rootkey-file=filename],[set default pathname to root key file (default run-dir/root.key). This file is read and written.]),
253    UNBOUND_ROOTKEY_FILE="$withval",
254if test $on_mingw = no; then
255    UNBOUND_ROOTKEY_FILE="$UNBOUND_RUN_DIR/root.key"
256else
257    UNBOUND_ROOTKEY_FILE="C:\\Program Files\\Unbound\\root.key"
258fi
259)
260AC_SUBST(UNBOUND_ROOTKEY_FILE)
261ACX_ESCAPE_BACKSLASH($UNBOUND_ROOTKEY_FILE, hdr_rkey)
262AC_DEFINE_UNQUOTED(ROOT_ANCHOR_FILE, ["$hdr_rkey"], [default rootkey location])
263
264AC_ARG_WITH(rootcert-file,
265    AS_HELP_STRING([--with-rootcert-file=filename],[set default pathname to root update certificate file (default run-dir/icannbundle.pem).  This file need not exist if you are content with the builtin.]),
266    UNBOUND_ROOTCERT_FILE="$withval",
267if test $on_mingw = no; then
268    UNBOUND_ROOTCERT_FILE="$UNBOUND_RUN_DIR/icannbundle.pem"
269else
270    UNBOUND_ROOTCERT_FILE="C:\\Program Files\\Unbound\\icannbundle.pem"
271fi
272)
273AC_SUBST(UNBOUND_ROOTCERT_FILE)
274ACX_ESCAPE_BACKSLASH($UNBOUND_ROOTCERT_FILE, hdr_rpem)
275AC_DEFINE_UNQUOTED(ROOT_CERT_FILE, ["$hdr_rpem"], [default rootcert location])
276
277AC_ARG_WITH(username,
278    AS_HELP_STRING([--with-username=user],[set default user that unbound changes to (default user is unbound)]),
279    UNBOUND_USERNAME="$withval",
280    UNBOUND_USERNAME="unbound")
281AC_SUBST(UNBOUND_USERNAME)
282AC_DEFINE_UNQUOTED(UB_USERNAME, ["$UNBOUND_USERNAME"], [default username])
283
284AC_DEFINE(WINVER, 0x0502, [the version of the windows API enabled])
285ACX_RSRC_VERSION(wnvs)
286AC_DEFINE_UNQUOTED(RSRC_PACKAGE_VERSION, [$wnvs], [version number for resource files])
287
288# Check for 'grep -e' program, here, since ACX_CHECK_FLTO needs that.
289AC_PROG_GREP
290
291# Checks for typedefs, structures, and compiler characteristics.
292AC_C_CONST
293AC_LANG([C])
294# allow user to override the -g -O2 flags.
295default_cflags=no
296if test "x$CFLAGS" = "x" ; then
297ACX_CHECK_COMPILER_FLAG(g, [CFLAGS="$CFLAGS -g"])
298ACX_CHECK_COMPILER_FLAG(O2, [CFLAGS="$CFLAGS -O2"])
299default_cflags=yes
300fi
301m4_version_prereq([2.70], [AC_PROG_CC], [AC_PROG_CC_STDC])
302ACX_DEPFLAG
303ACX_DETERMINE_EXT_FLAGS_UNBOUND
304
305# debug mode flags warnings
306AC_ARG_ENABLE(checking, AS_HELP_STRING([--enable-checking],[Enable warnings, asserts, makefile-dependencies]))
307AC_ARG_ENABLE(debug, AS_HELP_STRING([--enable-debug],[same as enable-checking]))
308if test "$enable_debug" = "yes"; then debug_enabled="$enable_debug";
309else debug_enabled="$enable_checking"; fi
310AC_SUBST(debug_enabled)
311case "$debug_enabled" in
312        yes)
313		ACX_CHECK_COMPILER_FLAG(W, [CFLAGS="$CFLAGS -W"])
314		ACX_CHECK_COMPILER_FLAG(Wall, [CFLAGS="$CFLAGS -Wall"])
315		ACX_CHECK_COMPILER_FLAG(Wextra, [CFLAGS="$CFLAGS -Wextra"])
316		ACX_CHECK_COMPILER_FLAG(Wdeclaration-after-statement, [CFLAGS="$CFLAGS -Wdeclaration-after-statement"])
317		AC_DEFINE([UNBOUND_DEBUG], [], [define this to enable debug checks.])
318		;;
319	no|*)
320		# nothing to do.
321		;;
322esac
323if test "$default_cflags" = "yes"; then
324	# only when CFLAGS was "" at the start, if the users wants to
325	# override we shouldn't add default cflags, because they wouldn't
326	# be able to turn off these options and set the CFLAGS wanted.
327	ACX_CHECK_FLTO
328	ACX_CHECK_PIE
329	ACX_CHECK_RELRO_NOW
330fi
331
332AC_C_INLINE
333ACX_CHECK_FORMAT_ATTRIBUTE
334ACX_CHECK_UNUSED_ATTRIBUTE
335ACX_CHECK_NONSTRING_ATTRIBUTE
336
337AC_DEFUN([CHECK_WEAK_ATTRIBUTE],
338[AC_REQUIRE([AC_PROG_CC])
339AC_MSG_CHECKING(whether the C compiler (${CC-cc}) accepts the "weak" attribute)
340AC_CACHE_VAL(ac_cv_c_weak_attribute,
341[ac_cv_c_weak_attribute=no
342AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ #include <stdio.h>
343__attribute__((weak)) void f(int x) { printf("%d", x); }
344]], [[
345   f(1);
346]])],[ac_cv_c_weak_attribute="yes"],[ac_cv_c_weak_attribute="no"])
347])
348
349AC_MSG_RESULT($ac_cv_c_weak_attribute)
350if test $ac_cv_c_weak_attribute = yes; then
351  AC_DEFINE(HAVE_ATTR_WEAK, 1, [Whether the C compiler accepts the "weak" attribute])
352  AC_DEFINE(ATTR_WEAK, [__attribute__((weak))], [apply the weak attribute to a symbol])
353else
354  AC_DEFINE(ATTR_WEAK,[], [apply the weak attribute to a symbol])
355fi
356])dnl End of CHECK_WEAK_ATTRIBUTE
357
358CHECK_WEAK_ATTRIBUTE
359
360AC_DEFUN([CHECK_NORETURN_ATTRIBUTE],
361[AC_REQUIRE([AC_PROG_CC])
362AC_MSG_CHECKING(whether the C compiler (${CC-cc}) accepts the "noreturn" attribute)
363AC_CACHE_VAL(ac_cv_c_noreturn_attribute,
364[ac_cv_c_noreturn_attribute=no
365AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ #include <stdio.h>
366#ifdef STDC_HEADERS
367# include <stdlib.h>
368#else
369# ifdef HAVE_STDLIB_H
370#  include <stdlib.h>
371# endif
372#endif
373__attribute__((noreturn)) void f(int x) { printf("%d", x); exit(1); }
374]], [[
375   f(1);
376]])],[ac_cv_c_noreturn_attribute="yes"],[ac_cv_c_noreturn_attribute="no"])
377])
378
379AC_MSG_RESULT($ac_cv_c_noreturn_attribute)
380if test $ac_cv_c_noreturn_attribute = yes; then
381  AC_DEFINE(HAVE_ATTR_NORETURN, 1, [Whether the C compiler accepts the "noreturn" attribute])
382  AC_DEFINE(ATTR_NORETURN, [__attribute__((__noreturn__))], [apply the noreturn attribute to a function that exits the program])
383else
384  AC_DEFINE(ATTR_NORETURN,[], [apply the noreturn attribute to a function that exits the program])
385fi
386])dnl End of CHECK_NORETURN_ATTRIBUTE
387
388CHECK_NORETURN_ATTRIBUTE
389
390AC_DEFUN([CHECK_FALLTHROUGH_ATTRIBUTE],
391[AC_REQUIRE([AC_PROG_CC])
392AC_MSG_CHECKING(whether the C compiler (${CC-cc}) accepts the "fallthrough" attribute)
393BAKCFLAGS="$CFLAGS"
394CFLAGS="$CFLAGS -Werror"
395AC_CACHE_VAL(ac_cv_c_fallthrough_attribute,
396[ac_cv_c_fallthrough_attribute=no
397AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ #include <stdio.h>
398void f(int x) {
399	int y = 0;
400	switch(x) {
401	case 1:
402		y = 1;
403		__attribute__((fallthrough));
404		/* fallthrough */
405	case 2:
406		y++;
407		break;
408	case 3:
409		y = 3;
410		break;
411	}
412	printf("%d", y);
413}
414]], [[
415   f(1);
416]])],[ac_cv_c_fallthrough_attribute="yes"],[ac_cv_c_fallthrough_attribute="no"])
417])
418CFLAGS="$BAKCFLAGS"
419
420AC_MSG_RESULT($ac_cv_c_fallthrough_attribute)
421if test $ac_cv_c_fallthrough_attribute = yes; then
422  AC_DEFINE(HAVE_ATTR_FALLTHROUGH, 1, [Whether the C compiler accepts the "fallthrough" attribute])
423  AC_DEFINE(ATTR_FALLTHROUGH, [__attribute__((fallthrough));], [apply the fallthrough attribute.])
424else
425  AC_DEFINE(ATTR_FALLTHROUGH,[], [apply the fallthrough attribute.])
426fi
427])dnl End of CHECK_FALLTHROUGH_ATTRIBUTE
428
429CHECK_FALLTHROUGH_ATTRIBUTE
430
431if test "$srcdir" != "."; then
432	CPPFLAGS="$CPPFLAGS -I$srcdir"
433fi
434
435AC_DEFUN([ACX_YYLEX_DESTROY], [
436	AC_MSG_CHECKING([for yylex_destroy])
437	if echo %% | $LEX -t 2>&1 | grep yylex_destroy >/dev/null 2>&1; then
438		AC_DEFINE(LEX_HAS_YYLEX_DESTROY, 1, [if lex has yylex_destroy])
439		AC_MSG_RESULT(yes)
440	else AC_MSG_RESULT(no);
441		LEX=":"
442	fi
443])
444
445AC_DEFUN([ACX_YYLEX_OPTION], [
446	AC_MSG_CHECKING([for lex %option])
447	if cat <<EOF | $LEX -t 2>&1 | grep yy_delete_buffer >/dev/null 2>&1; then
448%option nounput
449%%
450EOF
451		AC_MSG_RESULT(yes)
452	else AC_MSG_RESULT(no);
453		LEX=":"
454	fi
455])
456
457AC_PROG_LEX([noyywrap])
458if test "$LEX" != "" -a "$LEX" != ":"; then
459ACX_YYLEX_DESTROY
460fi
461if test "$LEX" != "" -a "$LEX" != ":"; then
462ACX_YYLEX_OPTION
463fi
464if test "$LEX" = "" -o "$LEX" = ":"; then
465	if test ! -f util/configlexer.c; then
466		AC_MSG_ERROR([no lex and no util/configlexer.c: need flex and bison to compile from source repository.])
467	fi
468fi
469AC_PROG_YACC
470if test "$YACC" = "" -o "$YACC" = ":"; then
471	if test ! -f util/configparser.c; then
472		AC_MSG_ERROR([no yacc and no util/configparser.c: need flex and bison to compile from source repository.])
473	fi
474fi
475AC_CHECK_PROG(doxygen, doxygen, doxygen)
476AC_CHECK_TOOL(STRIP, strip)
477ACX_LIBTOOL_C_ONLY
478
479# pkg-config is only needed for these options, do not require it otherwise
480if test "$enable_systemd" = "yes" -o "$enable_dnstap" = "yes" -o "$with_pyunbound" = "yes" -o "$with_pythonmod" = "yes"; then
481PKG_PROG_PKG_CONFIG
482fi
483
484# Checks for header files.
485AC_CHECK_HEADERS([stdarg.h stdbool.h netinet/in.h netinet/tcp.h sys/param.h sys/select.h sys/socket.h sys/un.h sys/uio.h sys/resource.h arpa/inet.h syslog.h netdb.h sys/wait.h pwd.h glob.h grp.h login_cap.h winsock2.h ws2tcpip.h endian.h sys/endian.h libkern/OSByteOrder.h sys/ipc.h sys/shm.h ifaddrs.h poll.h],,, [AC_INCLUDES_DEFAULT])
486# net/if.h portability for Darwin see:
487# https://www.gnu.org/software/autoconf/manual/autoconf-2.69/html_node/Header-Portability.html
488AC_CHECK_HEADERS([net/if.h],,, [
489#include <stdio.h>
490#ifdef STDC_HEADERS
491# include <stdlib.h>
492# include <stddef.h>
493#else
494# ifdef HAVE_STDLIB_H
495#  include <stdlib.h>
496# endif
497#endif
498#ifdef HAVE_SYS_SOCKET_H
499# include <sys/socket.h>
500#endif
501])
502
503# Check for Apple header. This uncovers TARGET_OS_IPHONE, TARGET_OS_TV or TARGET_OS_WATCH
504AC_CHECK_HEADERS([TargetConditionals.h],,, [AC_INCLUDES_DEFAULT])
505AC_CHECK_HEADERS([netioapi.h],,, [AC_INCLUDES_DEFAULT
506#if HAVE_SYS_PARAM_H
507#include <sys/param.h>
508#endif
509
510#ifdef HAVE_SYS_SOCKET_H
511#include <sys/socket.h>
512#endif
513
514#ifdef HAVE_SYS_UIO_H
515#include <sys/uio.h>
516#endif
517
518#ifdef HAVE_NETINET_IN_H
519#include <netinet/in.h>
520#endif
521
522#ifdef HAVE_NETINET_TCP_H
523#include <netinet/tcp.h>
524#endif
525
526#ifdef HAVE_ARPA_INET_H
527#include <arpa/inet.h>
528#endif
529
530#ifdef HAVE_WINSOCK2_H
531#include <winsock2.h>
532#endif
533
534#ifdef HAVE_WS2TCPIP_H
535#include <ws2tcpip.h>
536#endif
537])
538
539# Check for Linux timestamping headers
540AC_CHECK_HEADERS([linux/net_tstamp.h],,, [AC_INCLUDES_DEFAULT])
541AC_CHECK_HEADERS([stdatomic.h],,, [AC_INCLUDES_DEFAULT])
542
543# check for types.
544# Using own tests for int64* because autoconf builtin only give 32bit.
545AC_CHECK_TYPE(int8_t, signed char)
546AC_CHECK_TYPE(int16_t, short)
547AC_CHECK_TYPE(int32_t, int)
548AC_CHECK_TYPE(int64_t, long long)
549AC_CHECK_TYPE(uint8_t, unsigned char)
550AC_CHECK_TYPE(uint16_t, unsigned short)
551AC_CHECK_TYPE(uint32_t, unsigned int)
552AC_CHECK_TYPE(uint64_t, unsigned long long)
553AC_TYPE_SIZE_T
554AC_CHECK_TYPE(ssize_t, int)
555AC_TYPE_UID_T
556AC_TYPE_PID_T
557AC_TYPE_OFF_T
558ACX_TYPE_U_CHAR
559ACX_TYPE_RLIM_T
560ACX_TYPE_SOCKLEN_T
561ACX_TYPE_IN_ADDR_T
562ACX_TYPE_IN_PORT_T
563ACX_CHECK_MEMCMP_SIGNED
564
565AC_CHECK_SIZEOF(time_t,,[
566AC_INCLUDES_DEFAULT
567#ifdef TIME_WITH_SYS_TIME
568# include <sys/time.h>
569# include <time.h>
570#else
571# ifdef HAVE_SYS_TIME_H
572#  include <sys/time.h>
573# else
574#  include <time.h>
575# endif
576#endif
577])
578AC_CHECK_SIZEOF(size_t)
579
580# add option to disable the evil rpath
581ACX_ARG_RPATH
582AC_SUBST(RUNTIME_PATH)
583
584# check to see if libraries are needed for these functions.
585AC_SEARCH_LIBS([inet_pton], [nsl])
586AC_SEARCH_LIBS([socket], [socket])
587
588# check whether strptime also works
589AC_DEFUN([AC_CHECK_STRPTIME_WORKS],
590[AC_REQUIRE([AC_PROG_CC])
591AC_MSG_CHECKING(whether strptime works)
592if test c${cross_compiling} = cno; then
593AC_RUN_IFELSE([AC_LANG_SOURCE([[
594#define _XOPEN_SOURCE 600
595#include <time.h>
596int main(void) { struct tm tm; char *res;
597res = strptime("2010-07-15T00:00:00+00:00", "%t%Y%t-%t%m%t-%t%d%tT%t%H%t:%t%M%t:%t%S%t", &tm);
598if (!res) return 2;
599res = strptime("20070207111842", "%Y%m%d%H%M%S", &tm);
600if (!res) return 1; return 0; }
601]])] , [eval "ac_cv_c_strptime_works=yes"], [eval "ac_cv_c_strptime_works=no"],
602[eval "ac_cv_c_strptime_works=maybe"])
603else
604eval "ac_cv_c_strptime_works=maybe"
605fi
606AC_MSG_RESULT($ac_cv_c_strptime_works)
607if test $ac_cv_c_strptime_works = no; then
608AC_LIBOBJ(strptime)
609else
610AC_DEFINE_UNQUOTED([STRPTIME_WORKS], 1, [use default strptime.])
611fi
612])dnl
613
614# check some functions of the OS before linking libs (while still runnable).
615AC_FUNC_CHOWN
616AC_FUNC_FORK
617AC_DEFINE(RETSIGTYPE,void,[Return type of signal handlers, but autoconf 2.70 says 'your code may safely assume C89 semantics that RETSIGTYPE is void.'])
618AC_FUNC_FSEEKO
619ACX_SYS_LARGEFILE
620ACX_CHECK_NONBLOCKING_BROKEN
621ACX_MKDIR_ONE_ARG
622AC_CHECK_FUNCS([strptime],[AC_CHECK_STRPTIME_WORKS],[AC_LIBOBJ([strptime])])
623
624# check if we can use SO_REUSEPORT
625reuseport_default=0
626if echo "$host" | $GREP -i -e linux >/dev/null; then reuseport_default=1; fi
627if echo "$host" | $GREP -i -e dragonfly >/dev/null; then reuseport_default=1; fi
628if test "$reuseport_default" = 1; then
629	AC_DEFINE(REUSEPORT_DEFAULT, 1, [if REUSEPORT is enabled by default])
630else
631	AC_DEFINE(REUSEPORT_DEFAULT, 0, [if REUSEPORT is enabled by default])
632fi
633
634# Include systemd.m4 - begin
635sinclude(systemd.m4)
636# Include systemd.m4 - end
637
638# set memory allocation checking if requested
639AC_ARG_ENABLE(alloc-checks, AS_HELP_STRING([--enable-alloc-checks],[ enable to memory allocation statistics, for debug purposes ]),
640	, )
641AC_ARG_ENABLE(alloc-lite, AS_HELP_STRING([--enable-alloc-lite],[ enable for lightweight alloc assertions, for debug purposes ]),
642	, )
643AC_ARG_ENABLE(alloc-nonregional, AS_HELP_STRING([--enable-alloc-nonregional],[ enable nonregional allocs, slow but exposes regional allocations to other memory purifiers, for debug purposes ]),
644	, )
645if test x_$enable_alloc_nonregional = x_yes; then
646	AC_DEFINE(UNBOUND_ALLOC_NONREGIONAL, 1, [use malloc not regions, for debug use])
647fi
648AS_IF([test x_$enable_alloc_checks = x_yes],[
649	AC_DEFINE(UNBOUND_ALLOC_STATS, 1, [use statistics for allocs and frees, for debug use])
650	SLDNS_ALLOCCHECK_EXTRA_OBJ="alloc.lo log.lo"
651	AC_SUBST(SLDNS_ALLOCCHECK_EXTRA_OBJ)
652	ASYNCLOOK_ALLOCCHECK_EXTRA_OBJ="alloc.lo"
653	AC_SUBST(ASYNCLOOK_ALLOCCHECK_EXTRA_OBJ)
654],[
655	AS_IF([test x_$enable_alloc_lite = x_yes],[
656		AC_DEFINE(UNBOUND_ALLOC_LITE, 1, [use to enable lightweight alloc assertions, for debug use])
657	],[
658		ACX_FUNC_MALLOC([unbound])
659	])
660])
661
662# check windows threads (we use them, not pthreads, on windows).
663if test "$on_mingw" = "yes"; then
664# check windows threads
665	AC_CHECK_HEADERS([windows.h],,, [AC_INCLUDES_DEFAULT])
666	AC_MSG_CHECKING([for CreateThread])
667	AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
668#ifdef HAVE_WINDOWS_H
669#include <windows.h>
670#endif
671], [
672	HANDLE t = CreateThread(NULL, 0, NULL, NULL, 0, NULL);
673])],
674	AC_MSG_RESULT(yes)
675	AC_DEFINE(HAVE_WINDOWS_THREADS, 1, [Using Windows threads])
676,
677	AC_MSG_RESULT(no)
678)
679
680else
681# not on mingw, check thread libraries.
682
683# check for thread library.
684# check this first, so that the pthread lib does not get linked in via
685# libssl or libpython, and thus distorts the tests, and we end up using
686# the non-threadsafe C libraries.
687AC_ARG_WITH(pthreads, AS_HELP_STRING([--with-pthreads],[use pthreads library, or --without-pthreads to disable threading support.]),
688 [ ],[ withval="yes" ])
689ub_have_pthreads=no
690if test x_$withval != x_no; then
691	AX_PTHREAD([
692		AC_DEFINE(HAVE_PTHREAD,1,[Define if you have POSIX threads libraries and header files.])
693		if test -n "$PTHREAD_LIBS"; then
694		  LIBS="$PTHREAD_LIBS $LIBS"
695		fi
696		CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
697		CC="$PTHREAD_CC"
698		ub_have_pthreads=yes
699		AC_CHECK_TYPES([pthread_spinlock_t, pthread_rwlock_t],,,[#include <pthread.h>])
700		AC_CHECK_SIZEOF([unsigned long])
701		AC_CHECK_SIZEOF(pthread_t)
702
703		if echo "$CFLAGS" | $GREP -e "-pthread" >/dev/null; then
704		AC_MSG_CHECKING([if -pthread unused during linking])
705		# catch clang warning 'argument unused during compilation'
706		AC_LANG_CONFTEST([AC_LANG_SOURCE(AC_INCLUDES_DEFAULT
707[[
708int main(void) {return 0;}
709]])])
710		pthread_unused="yes"
711		# first compile
712		echo "$CC $CFLAGS -c conftest.c -o conftest.o" >&AS_MESSAGE_LOG_FD
713		$CC $CFLAGS -c conftest.c -o conftest.o 2>&AS_MESSAGE_LOG_FD >&AS_MESSAGE_LOG_FD
714		if test $? = 0; then
715			# then link
716			echo "$CC $CFLAGS -Werror $LDFLAGS $LIBS -o conftest contest.o" >&AS_MESSAGE_LOG_FD
717			$CC $CFLAGS -Werror $LDFLAGS $LIBS -o conftest conftest.o 2>&AS_MESSAGE_LOG_FD >&AS_MESSAGE_LOG_FD
718			if test $? -ne 0; then
719				AC_MSG_RESULT(yes)
720				CFLAGS=`echo "$CFLAGS" | sed -e 's/-pthread//'`
721				PTHREAD_CFLAGS_ONLY="-pthread"
722				AC_SUBST(PTHREAD_CFLAGS_ONLY)
723			else
724				AC_MSG_RESULT(no)
725			fi
726		else
727			AC_MSG_RESULT(no)
728		fi # endif cc successful
729		rm -f conftest conftest.c conftest.o
730		fi # endif -pthread in CFLAGS
731
732		])
733fi
734
735if test x_$ub_have_pthreads != x_no; then
736	# Long checks to support pthread_setname_np().
737	# Some OSes have the extra non-portable functions in a specific
738	# header file.
739	AC_CHECK_HEADERS([pthread_np.h],,, [AC_INCLUDES_DEFAULT])
740	BAKCFLAGS="$CFLAGS"
741	CFLAGS="$CFLAGS -Werror"
742	# MacOS only has 1 argument, the name.
743	AC_MSG_CHECKING([whether pthread_setname_np has only 1 argument])
744	AC_COMPILE_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT
745#include <pthread.h>
746#ifdef HAVE_PTHREAD_NP_H
747#include <pthread_np.h>
748#endif
749	],[
750	    (void)pthread_setname_np("");
751	])],[
752	    AC_MSG_RESULT(yes)
753	    AC_DEFINE(HAVE_PTHREAD_SETNAME_NP1, 1, [Define if pthread_setname_np has only 1 argument.])
754	],[
755	    AC_MSG_RESULT(no)
756	])
757	# NetBSD has 3 arguments to allow for formatting of the name.
758	AC_MSG_CHECKING([whether pthread_setname_np has 3 arguments])
759	AC_COMPILE_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT
760#include <pthread.h>
761#ifdef HAVE_PTHREAD_NP_H
762#include <pthread_np.h>
763#endif
764	],[
765	    (void)pthread_setname_np(0, "", NULL);
766	])],[
767	    AC_MSG_RESULT(yes)
768	    AC_DEFINE(HAVE_PTHREAD_SETNAME_NP3, 1, [Define if pthread_setname_np has 3 arguments.])
769	],[
770	    AC_MSG_RESULT(no)
771	])
772	# Most OSes have the common 2 arguments, thread and name.
773	AC_MSG_CHECKING([whether pthread_setname_np has the common 2 arguments])
774	AC_COMPILE_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT
775#include <pthread.h>
776#ifdef HAVE_PTHREAD_NP_H
777#include <pthread_np.h>
778#endif
779	],[
780	    (void)pthread_setname_np(0, "");
781	])],[
782	    AC_MSG_RESULT(yes)
783	    AC_DEFINE(HAVE_PTHREAD_SETNAME_NP, 1, [Define if pthread_setname_np has the common 2 arguments.])
784	],[
785	    AC_MSG_RESULT(no)
786	])
787	# FreeBSD/OpenBSD use a slightly different function name.
788	AC_MSG_CHECKING([whether pthread_setname_np exists as pthread_set_name_np instead])
789	AC_COMPILE_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT
790#include <pthread.h>
791#ifdef HAVE_PTHREAD_NP_H
792#include <pthread_np.h>
793#endif
794	],[
795	    (void)pthread_set_name_np(0, "");
796	])],[
797	    AC_MSG_RESULT(yes)
798	    AC_DEFINE(HAVE_PTHREAD_SET_NAME_NP, 1, [Define if pthread_setname_np exists as pthread_set_name_np instead.])
799	],[
800	    AC_MSG_RESULT(no)
801	])
802	CFLAGS="$BAKCFLAGS"
803fi
804
805# check solaris thread library
806AC_ARG_WITH(solaris-threads, AS_HELP_STRING([--with-solaris-threads],[use solaris native thread library.]), [ ],[ withval="no" ])
807ub_have_sol_threads=no
808if test x_$withval != x_no; then
809	if test x_$ub_have_pthreads != x_no; then
810	    AC_MSG_WARN([Have pthreads already, ignoring --with-solaris-threads])
811	else
812	AC_SEARCH_LIBS(thr_create, [thread],
813	[
814    		AC_DEFINE(HAVE_SOLARIS_THREADS, 1, [Using Solaris threads])
815
816		ACX_CHECK_COMPILER_FLAG(mt, [CFLAGS="$CFLAGS -mt"],
817			[CFLAGS="$CFLAGS -D_REENTRANT"])
818		ub_have_sol_threads=yes
819	] , [
820		AC_MSG_ERROR([no solaris threads found.])
821	])
822	fi
823fi
824
825fi # end of non-mingw check of thread libraries
826
827# Check for SYSLOG_FACILITY
828AC_ARG_WITH(syslog-facility, AS_HELP_STRING([--with-syslog-facility=LOCAL0 - LOCAL7],[ set SYSLOG_FACILITY, default DAEMON ]),
829	[ UNBOUND_SYSLOG_FACILITY="$withval" ], [])
830case "${UNBOUND_SYSLOG_FACILITY}" in
831
832  LOCAL[[0-7]]) UNBOUND_SYSLOG_FACILITY="LOG_${UNBOUND_SYSLOG_FACILITY}" ;;
833
834           *) UNBOUND_SYSLOG_FACILITY="LOG_DAEMON" ;;
835
836esac
837AC_DEFINE_UNQUOTED(UB_SYSLOG_FACILITY,${UNBOUND_SYSLOG_FACILITY},[the SYSLOG_FACILITY to use, default LOG_DAEMON])
838
839# Check for dynamic library module
840AC_ARG_WITH(dynlibmodule,
841   AS_HELP_STRING([--with-dynlibmodule],[build dynamic library module, or --without-dynlibmodule to disable it. (default=no)]),
842   [], [ withval="no" ])
843
844if test x_$withval != x_no; then
845  AC_DEFINE(WITH_DYNLIBMODULE, 1, [Define if you want dynlib module.])
846  WITH_DYNLIBMODULE=yes
847  AC_SUBST(WITH_DYNLIBMODULE)
848  DYNLIBMOD_OBJ="dynlibmod.lo"
849  AC_SUBST(DYNLIBMOD_OBJ)
850  DYNLIBMOD_HEADER='$(srcdir)/dynlibmod/dynlibmod.h'
851  AC_SUBST(DYNLIBMOD_HEADER)
852  if test $on_mingw = "no"; then
853    # link with -ldl if not already there, for all executables because
854    # dlopen call is in the dynlib module.  For unbound executable, also
855    # export symbols.
856    AC_SEARCH_LIBS([dlopen], [dl])
857    DYNLIBMOD_EXTRALIBS="-export-dynamic"
858  else
859    DYNLIBMOD_EXTRALIBS="-Wl,--export-all-symbols,--out-implib,libunbound.dll.a"
860  fi
861  AC_SUBST(DYNLIBMOD_EXTRALIBS)
862fi
863
864# Check for PyUnbound
865AC_ARG_WITH(pyunbound,
866   AS_HELP_STRING([--with-pyunbound],[build PyUnbound, or --without-pyunbound to skip it. (default=no)]),
867   [], [ withval="no" ])
868
869ub_test_python=no
870ub_with_pyunbound=no
871if test x_$withval != x_no; then
872   ub_with_pyunbound=yes
873   ub_test_python=yes
874fi
875
876# Check for Python module
877AC_ARG_WITH(pythonmodule,
878   AS_HELP_STRING([--with-pythonmodule],[build Python module, or --without-pythonmodule to disable script engine. (default=no)]),
879   [], [ withval="no" ])
880
881ub_with_pythonmod=no
882if test x_$withval != x_no; then
883   ub_with_pythonmod=yes
884   ub_test_python=yes
885fi
886
887# Check for Python & SWIG only on PyUnbound or PyModule
888if test x_$ub_test_python != x_no; then
889
890   # Check for Python
891   ub_have_python=no
892   ac_save_LIBS="$LIBS" dnl otherwise AC_PYTHON_DEVEL thrashes $LIBS
893   AC_PYTHON_DEVEL
894   if test ! -z "$PYTHON_VERSION"; then
895	badversion="no"
896	if test "$PYTHON_VERSION_MAJOR" -lt 2; then
897		badversion="yes"
898	fi
899	if test "$PYTHON_VERSION_MAJOR" -eq 2 -a "$PYTHON_VERSION_MINOR" -lt 4; then
900		badversion="yes"
901	fi
902	if test "$badversion" = "yes"; then
903		AC_MSG_ERROR([Python version >= 2.4.0 is required])
904	fi
905
906      [PY_MAJOR_VERSION="`$PYTHON -c \"import sys; print(sys.version_info[0])\"`"]
907      AC_SUBST(PY_MAJOR_VERSION)
908      # Have Python
909      AC_DEFINE(HAVE_PYTHON,1,[Define if you have Python libraries and header files.])
910      if test x_$ub_with_pythonmod != x_no; then
911        if test -n "$LIBS"; then
912          LIBS="$PYTHON_LDFLAGS $LIBS"
913        else
914          LIBS="$PYTHON_LDFLAGS"
915        fi
916      fi
917      PYTHON_LIBS="$PYTHON_LDFLAGS"
918      AC_SUBST(PYTHON_LIBS)
919      if test -n "$CPPFLAGS"; then
920        CPPFLAGS="$CPPFLAGS $PYTHON_CPPFLAGS"
921      else
922        CPPFLAGS="$PYTHON_CPPFLAGS"
923      fi
924      if test "$PYTHON_LIBDIR" != "/usr/lib" -a "$PYTHON_LIBDIR" != "" -a "$PYTHON_LIBDIR" != "/usr/lib64"; then
925        ACX_RUNTIME_PATH_ADD([$PYTHON_LIBDIR])
926      fi
927      ub_have_python=yes
928      PKG_CHECK_EXISTS(["python${PY_MAJOR_VERSION}"],
929                       [PC_PY_DEPENDENCY="python${PY_MAJOR_VERSION}"],
930                       [PC_PY_DEPENDENCY="python"])
931      AC_SUBST(PC_PY_DEPENDENCY)
932
933      # Check for SWIG
934      ub_have_swig=no
935      AC_ARG_ENABLE(swig-version-check, AS_HELP_STRING([--disable-swig-version-check],[Disable swig version check to build python modules with older swig even though that is unreliable]))
936      if test "$enable_swig_version_check" = "yes"; then
937      	AX_PKG_SWIG(2.0.1)
938      else
939      	AX_PKG_SWIG
940      fi
941      AC_MSG_CHECKING(SWIG)
942      if test ! -x "$SWIG"; then
943         AC_MSG_ERROR([failed to find swig tool, install it, or do not build Python module and PyUnbound])
944      else
945         AC_DEFINE(HAVE_SWIG, 1, [Define if you have Swig libraries and header files.])
946         AC_SUBST(swig, "$SWIG")
947         AC_MSG_RESULT(present)
948
949         # If have Python & SWIG
950         # Declare PythonMod
951         if test x_$ub_with_pythonmod != x_no; then
952            AC_DEFINE(WITH_PYTHONMODULE, 1, [Define if you want Python module.])
953            WITH_PYTHONMODULE=yes
954            AC_SUBST(WITH_PYTHONMODULE)
955	    PYTHONMOD_OBJ="pythonmod.lo pythonmod_utils.lo"
956	    AC_SUBST(PYTHONMOD_OBJ)
957	    PYTHONMOD_HEADER='$(srcdir)/pythonmod/pythonmod.h'
958	    AC_SUBST(PYTHONMOD_HEADER)
959	    PYTHONMOD_INSTALL=pythonmod-install
960	    AC_SUBST(PYTHONMOD_INSTALL)
961	    PYTHONMOD_UNINSTALL=pythonmod-uninstall
962	    AC_SUBST(PYTHONMOD_UNINSTALL)
963         fi
964
965         # Declare PyUnbound
966         if test x_$ub_with_pyunbound != x_no; then
967            AC_DEFINE(WITH_PYUNBOUND, 1, [Define if you want PyUnbound.])
968            WITH_PYUNBOUND=yes
969            AC_SUBST(WITH_PYUNBOUND)
970	    PYUNBOUND_OBJ="libunbound_wrap.lo"
971	    AC_SUBST(PYUNBOUND_OBJ)
972	    PYUNBOUND_TARGET="_unbound.la"
973	    AC_SUBST(PYUNBOUND_TARGET)
974	    PYUNBOUND_INSTALL=pyunbound-install
975	    AC_SUBST(PYUNBOUND_INSTALL)
976	    PYUNBOUND_UNINSTALL=pyunbound-uninstall
977	    AC_SUBST(PYUNBOUND_UNINSTALL)
978         fi
979      fi
980   else
981      AC_MSG_RESULT([*** Python libraries not found, won't build PythonMod or PyUnbound ***])
982      ub_with_pyunbound=no
983      ub_with_pythonmod=no
984   fi
985fi
986
987if test "`uname`" = "NetBSD"; then
988	NETBSD_LINTFLAGS='"-D__RENAME(x)=" -D_NETINET_IN_H_'
989	AC_SUBST(NETBSD_LINTFLAGS)
990fi
991
992if test "`uname`" = "Linux"; then
993	# splint cannot parse modern c99 header files
994	GCC_DOCKER_LINTFLAGS='-syntax'
995	AC_SUBST(GCC_DOCKER_LINTFLAGS)
996fi
997AX_BUILD_DATE_EPOCH(CONFIG_DATE, [%Y%m%d])
998AC_ARG_VAR(SOURCE_DATE_EPOCH, [If it is set, it uses the value of that variable instead of the current time as the build timestamp. The format is a unix timestamp. This enables reproducible build output.])
999AC_SUBST(CONFIG_DATE)
1000
1001# Checks for libraries.
1002
1003# libnss
1004USE_NSS="no"
1005AC_ARG_WITH([nss], AS_HELP_STRING([--with-nss=path],[use libnss instead of openssl, installed at path.]),
1006	[
1007	USE_NSS="yes"
1008	AC_DEFINE(HAVE_NSS, 1, [Use libnss for crypto])
1009	if test "$withval" != "" -a "$withval" != "yes"; then
1010		CPPFLAGS="$CPPFLAGS -I$withval/include/nss3"
1011		LDFLAGS="$LDFLAGS -L$withval/lib"
1012		ACX_RUNTIME_PATH_ADD([$withval/lib])
1013		CPPFLAGS="-I$withval/include/nspr4 $CPPFLAGS"
1014	else
1015		CPPFLAGS="$CPPFLAGS -I/usr/include/nss3"
1016		CPPFLAGS="-I/usr/include/nspr4 $CPPFLAGS"
1017	fi
1018        LIBS="$LIBS -lnss3 -lnspr4"
1019	SSLLIB=""
1020	PC_CRYPTO_DEPENDENCY="nss nspr"
1021	AC_SUBST(PC_CRYPTO_DEPENDENCY)
1022	]
1023)
1024
1025# libnettle
1026USE_NETTLE="no"
1027AC_ARG_WITH([nettle], AS_HELP_STRING([--with-nettle=path],[use libnettle as crypto library, installed at path.]),
1028	[
1029	USE_NETTLE="yes"
1030	AC_DEFINE(HAVE_NETTLE, 1, [Use libnettle for crypto])
1031	AC_CHECK_HEADERS([nettle/dsa-compat.h],,, [AC_INCLUDES_DEFAULT])
1032	if test "$withval" != "" -a "$withval" != "yes"; then
1033		CPPFLAGS="$CPPFLAGS -I$withval/include/nettle"
1034		LDFLAGS="$LDFLAGS -L$withval/lib"
1035		ACX_RUNTIME_PATH_ADD([$withval/lib])
1036	else
1037		CPPFLAGS="$CPPFLAGS -I/usr/include/nettle"
1038	fi
1039        LIBS="$LIBS -lhogweed -lnettle -lgmp"
1040	SSLLIB=""
1041	PC_CRYPTO_DEPENDENCY="hogweed nettle"
1042	AC_SUBST(PC_CRYPTO_DEPENDENCY)
1043	]
1044)
1045
1046# openssl
1047if test $USE_NSS = "no" -a $USE_NETTLE = "no"; then
1048ACX_WITH_SSL
1049ACX_LIB_SSL
1050SSLLIB="-lssl"
1051
1052PC_CRYPTO_DEPENDENCY=""
1053AC_SUBST(PC_CRYPTO_DEPENDENCY)
1054
1055# check if -lcrypt32 is needed because CAPIENG needs that. (on windows)
1056BAKLIBS="$LIBS"
1057LIBS="-lssl $LIBS"
1058AC_MSG_CHECKING([if libssl needs -lcrypt32])
1059AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[
1060	int EVP_sha256(void);
1061	(void)EVP_sha256();
1062]])], [
1063	AC_MSG_RESULT([no])
1064	LIBS="$BAKLIBS"
1065], [
1066	AC_MSG_RESULT([yes])
1067	LIBS="$BAKLIBS"
1068	LIBS="$LIBS -lcrypt32"
1069])
1070
1071AC_MSG_CHECKING([for LibreSSL])
1072if grep VERSION_TEXT $ssldir_include/openssl/opensslv.h | grep "LibreSSL" >/dev/null; then
1073	AC_MSG_RESULT([yes])
1074	AC_DEFINE([HAVE_LIBRESSL], [1], [Define if we have LibreSSL])
1075	# libressl provides these compat functions, but they may also be
1076	# declared by the OS in libc.  See if they have been declared.
1077	AC_CHECK_DECLS([strlcpy,strlcat,arc4random,arc4random_uniform])
1078else
1079	AC_MSG_RESULT([no])
1080fi
1081AC_CHECK_HEADERS([openssl/conf.h openssl/engine.h openssl/bn.h openssl/dh.h openssl/dsa.h openssl/rsa.h openssl/core_names.h openssl/param_build.h],,, [AC_INCLUDES_DEFAULT])
1082AC_CHECK_FUNCS([OPENSSL_config EVP_sha1 EVP_sha256 EVP_sha512 FIPS_mode EVP_default_properties_is_fips_enabled EVP_MD_CTX_new OpenSSL_add_all_digests OPENSSL_init_crypto EVP_cleanup ENGINE_cleanup ERR_load_crypto_strings CRYPTO_cleanup_all_ex_data ERR_free_strings RAND_cleanup DSA_SIG_set0 EVP_dss1 EVP_DigestVerify EVP_aes_256_cbc EVP_EncryptInit_ex HMAC_Init_ex CRYPTO_THREADID_set_callback EVP_MAC_CTX_set_params OSSL_PARAM_BLD_new BIO_set_callback_ex])
1083
1084# these check_funcs need -lssl
1085BAKLIBS="$LIBS"
1086LIBS="-lssl $LIBS"
1087AC_CHECK_FUNCS([OPENSSL_init_ssl SSL_CTX_set_security_level SSL_set1_host SSL_get0_peername X509_VERIFY_PARAM_set1_host SSL_CTX_set_ciphersuites SSL_CTX_set_tlsext_ticket_key_evp_cb SSL_CTX_set_alpn_select_cb SSL_get0_alpn_selected SSL_CTX_set_alpn_protos SSL_get1_peer_certificate])
1088LIBS="$BAKLIBS"
1089
1090AC_CHECK_DECLS([SSL_COMP_get_compression_methods,sk_SSL_COMP_pop_free,SSL_CTX_set_ecdh_auto,SSL_CTX_set_tmp_ecdh], [], [], [
1091AC_INCLUDES_DEFAULT
1092#ifdef HAVE_OPENSSL_ERR_H
1093#include <openssl/err.h>
1094#endif
1095
1096#ifdef HAVE_OPENSSL_RAND_H
1097#include <openssl/rand.h>
1098#endif
1099
1100#ifdef HAVE_OPENSSL_CONF_H
1101#include <openssl/conf.h>
1102#endif
1103
1104#ifdef HAVE_OPENSSL_ENGINE_H
1105#include <openssl/engine.h>
1106#endif
1107#include <openssl/ssl.h>
1108#include <openssl/evp.h>
1109])
1110
1111if test "$ac_cv_func_HMAC_Init_ex" = "yes"; then
1112# check function return type.
1113AC_MSG_CHECKING(the return type of HMAC_Init_ex)
1114AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
1115#ifdef HAVE_OPENSSL_ERR_H
1116#include <openssl/err.h>
1117#endif
1118
1119#ifdef HAVE_OPENSSL_RAND_H
1120#include <openssl/rand.h>
1121#endif
1122
1123#ifdef HAVE_OPENSSL_CONF_H
1124#include <openssl/conf.h>
1125#endif
1126
1127#ifdef HAVE_OPENSSL_ENGINE_H
1128#include <openssl/engine.h>
1129#endif
1130#include <openssl/ssl.h>
1131#include <openssl/evp.h>
1132], [
1133	HMAC_CTX* hmac_ctx = NULL;
1134	void* hmac_key = NULL;
1135	const EVP_MD* digest = NULL;
1136	int x = HMAC_Init_ex(hmac_ctx, hmac_key, 32, digest, NULL);
1137	(void)x;
1138])], [
1139	AC_MSG_RESULT(int)
1140], [
1141	AC_MSG_RESULT(void)
1142	AC_DEFINE([HMAC_INIT_EX_RETURNS_VOID], 1, [If HMAC_Init_ex() returns void])
1143])
1144fi
1145
1146fi
1147AC_SUBST(SSLLIB)
1148
1149# libbsd
1150AC_ARG_WITH([libbsd], AS_HELP_STRING([--with-libbsd],[Use portable libbsd functions]), [
1151	AC_CHECK_HEADERS([bsd/string.h bsd/stdlib.h],,, [AC_INCLUDES_DEFAULT])
1152	if test "x$ac_cv_header_bsd_string_h" = xyes -a "x$ac_cv_header_bsd_stdlib_h" = xyes; then
1153		for func in strlcpy strlcat arc4random arc4random_uniform reallocarray; do
1154			AC_SEARCH_LIBS([$func], [bsd], [
1155				AC_DEFINE(HAVE_LIBBSD, 1, [Use portable libbsd functions])
1156				PC_LIBBSD_DEPENDENCY=libbsd
1157				AC_SUBST(PC_LIBBSD_DEPENDENCY)
1158			])
1159		done
1160	fi
1161])
1162
1163AC_ARG_ENABLE(sha1, AS_HELP_STRING([--disable-sha1],[Disable SHA1 RRSIG support, does not disable nsec3 support]))
1164case "$enable_sha1" in
1165	no)
1166	;;
1167	yes|*)
1168	AC_DEFINE([USE_SHA1], [1], [Define this to enable SHA1 support.])
1169	;;
1170esac
1171
1172
1173AC_ARG_ENABLE(sha2, AS_HELP_STRING([--disable-sha2],[Disable SHA256 and SHA512 RRSIG support]))
1174case "$enable_sha2" in
1175	no)
1176	;;
1177	yes|*)
1178	AC_DEFINE([USE_SHA2], [1], [Define this to enable SHA256 and SHA512 support.])
1179	;;
1180esac
1181
1182AC_ARG_ENABLE(subnet, AS_HELP_STRING([--enable-subnet],[Enable client subnet]))
1183case "$enable_subnet" in
1184	yes)
1185	AC_DEFINE([CLIENT_SUBNET], [1], [Define this to enable client subnet option.])
1186	SUBNET_OBJ="edns-subnet.lo subnetmod.lo addrtree.lo subnet-whitelist.lo"
1187	AC_SUBST(SUBNET_OBJ)
1188	SUBNET_HEADER='$(srcdir)/edns-subnet/subnetmod.h $(srcdir)/edns-subnet/edns-subnet.h $(srcdir)/edns-subnet/subnet-whitelist.h $(srcdir)/edns-subnet/addrtree.h'
1189	AC_SUBST(SUBNET_HEADER)
1190	;;
1191	no|*)
1192	;;
1193esac
1194
1195# check whether gost also works
1196AC_DEFUN([AC_CHECK_GOST_WORKS],
1197[AC_REQUIRE([AC_PROG_CC])
1198AC_MSG_CHECKING([if GOST works])
1199if test c${cross_compiling} = cno; then
1200BAKCFLAGS="$CFLAGS"
1201if test -n "$ssldir"; then
1202	CFLAGS="$CFLAGS -Wl,-rpath,$ssldir_lib"
1203fi
1204AC_RUN_IFELSE([AC_LANG_SOURCE([[
1205#include <string.h>
1206#include <openssl/ssl.h>
1207#include <openssl/evp.h>
1208#include <openssl/engine.h>
1209#include <openssl/conf.h>
1210/* routine to load gost (from sldns) */
1211int load_gost_id(void)
1212{
1213	static int gost_id = 0;
1214	const EVP_PKEY_ASN1_METHOD* meth;
1215	ENGINE* e;
1216
1217	if(gost_id) return gost_id;
1218
1219	/* see if configuration loaded gost implementation from other engine*/
1220	meth = EVP_PKEY_asn1_find_str(NULL, "gost2001", -1);
1221	if(meth) {
1222		EVP_PKEY_asn1_get0_info(&gost_id, NULL, NULL, NULL, NULL, meth);
1223		return gost_id;
1224	}
1225
1226	/* see if engine can be loaded already */
1227	e = ENGINE_by_id("gost");
1228	if(!e) {
1229		/* load it ourself, in case statically linked */
1230		ENGINE_load_builtin_engines();
1231		ENGINE_load_dynamic();
1232		e = ENGINE_by_id("gost");
1233	}
1234	if(!e) {
1235		/* no gost engine in openssl */
1236		return 0;
1237	}
1238	if(!ENGINE_set_default(e, ENGINE_METHOD_ALL)) {
1239		ENGINE_finish(e);
1240		ENGINE_free(e);
1241		return 0;
1242	}
1243
1244	meth = EVP_PKEY_asn1_find_str(&e, "gost2001", -1);
1245	if(!meth) {
1246		/* algo not found */
1247		ENGINE_finish(e);
1248		ENGINE_free(e);
1249		return 0;
1250	}
1251	EVP_PKEY_asn1_get0_info(&gost_id, NULL, NULL, NULL, NULL, meth);
1252	return gost_id;
1253}
1254int main(void) {
1255	EVP_MD_CTX* ctx;
1256	const EVP_MD* md;
1257	unsigned char digest[64]; /* its a 256-bit digest, so uses 32 bytes */
1258	const char* str = "Hello world";
1259	const unsigned char check[] = {
1260		0x40 , 0xed , 0xf8 , 0x56 , 0x5a , 0xc5 , 0x36 , 0xe1 ,
1261		0x33 , 0x7c , 0x7e , 0x87 , 0x62 , 0x1c , 0x42 , 0xe0 ,
1262		0x17 , 0x1b , 0x5e , 0xce , 0xa8 , 0x46 , 0x65 , 0x4d ,
1263		0x8d , 0x3e , 0x22 , 0x9b , 0xe1 , 0x30 , 0x19 , 0x9d
1264	};
1265	OPENSSL_config(NULL);
1266	(void)load_gost_id();
1267	md = EVP_get_digestbyname("md_gost94");
1268	if(!md) return 1;
1269	memset(digest, 0, sizeof(digest));
1270	ctx = EVP_MD_CTX_create();
1271	if(!ctx) return 2;
1272	if(!EVP_DigestInit_ex(ctx, md, NULL)) return 3;
1273	if(!EVP_DigestUpdate(ctx, str, 10)) return 4;
1274	if(!EVP_DigestFinal_ex(ctx, digest, NULL)) return 5;
1275	/* uncomment to see the hash calculated.
1276		{int i;
1277		for(i=0; i<32; i++)
1278			printf(" %2.2x", (int)digest[i]);
1279		printf("\n");}
1280	*/
1281	if(memcmp(digest, check, sizeof(check)) != 0)
1282		return 6;
1283	return 0;
1284}
1285]])] , [eval "ac_cv_c_gost_works=yes"], [eval "ac_cv_c_gost_works=no"],
1286[eval "ac_cv_c_gost_works=maybe"])
1287CFLAGS="$BAKCFLAGS"
1288else
1289eval "ac_cv_c_gost_works=maybe"
1290fi
1291AC_MSG_RESULT($ac_cv_c_gost_works)
1292])dnl
1293
1294AC_ARG_ENABLE(gost, AS_HELP_STRING([--disable-gost],[Disable GOST support]))
1295use_gost="no"
1296if test $USE_NSS = "no" -a $USE_NETTLE = "no"; then
1297case "$enable_gost" in
1298	no)
1299	;;
1300	*)
1301	AC_CHECK_FUNC(EVP_PKEY_set_type_str, [:],[AC_MSG_ERROR([OpenSSL 1.0.0 is needed for GOST support])])
1302	AC_CHECK_FUNC(EC_KEY_new, [], [AC_MSG_ERROR([OpenSSL does not support ECC, needed for GOST support])])
1303	AC_CHECK_GOST_WORKS
1304	if test "$ac_cv_c_gost_works" != no; then
1305		use_gost="yes"
1306		AC_DEFINE([USE_GOST], [1], [Define this to enable GOST support.])
1307	fi
1308	;;
1309esac
1310fi dnl !USE_NSS && !USE_NETTLE
1311
1312AC_ARG_ENABLE(ecdsa, AS_HELP_STRING([--disable-ecdsa],[Disable ECDSA support]))
1313use_ecdsa="no"
1314case "$enable_ecdsa" in
1315    no)
1316      ;;
1317    *)
1318      if test $USE_NSS = "no" -a $USE_NETTLE = "no"; then
1319	      AC_CHECK_FUNC(EVP_PKEY_fromdata, [
1320	          # with EVP_PKEY_fromdata, check if EC is not disabled
1321	          AC_CHECK_DECL([OPENSSL_NO_EC], [AC_MSG_ERROR([OpenSSL does not support ECDSA: please upgrade or rerun with --disable-ecdsa])
1322		  ], [], [AC_INCLUDES_DEFAULT
1323#include <openssl/evp.h>
1324		  ])
1325		], [
1326		  # without EVP_PKEY_fromdata, older openssl, check for support
1327		  AC_CHECK_FUNC(ECDSA_sign, [], [AC_MSG_ERROR([OpenSSL does not support ECDSA: please upgrade or rerun with --disable-ecdsa])])
1328		  AC_CHECK_FUNC(SHA384_Init, [], [AC_MSG_ERROR([OpenSSL does not support SHA384: please upgrade or rerun with --disable-ecdsa])])
1329		])
1330	      AC_CHECK_DECLS([NID_X9_62_prime256v1, NID_secp384r1], [], [AC_MSG_ERROR([OpenSSL does not support the ECDSA curves: please upgrade or rerun with --disable-ecdsa])], [AC_INCLUDES_DEFAULT
1331#include <openssl/evp.h>
1332	      ])
1333	      # see if OPENSSL 1.0.0 or later (has EVP MD and Verify independency)
1334	      AC_MSG_CHECKING([if openssl supports SHA2 and ECDSA with EVP])
1335	      if grep OPENSSL_VERSION_TEXT $ssldir_include/openssl/opensslv.h | grep "OpenSSL" >/dev/null; then
1336		if grep OPENSSL_VERSION_TEXT $ssldir_include/openssl/opensslv.h | grep "OpenSSL 0\." >/dev/null; then
1337		  AC_MSG_RESULT([no])
1338		  AC_DEFINE_UNQUOTED([USE_ECDSA_EVP_WORKAROUND], [1], [Define this to enable an EVP workaround for older openssl])
1339		else
1340		  AC_MSG_RESULT([yes])
1341		fi
1342	      else
1343		# not OpenSSL, thus likely LibreSSL, which supports it
1344		AC_MSG_RESULT([yes])
1345	      fi
1346      fi
1347      # we now know we have ECDSA and the required curves.
1348      AC_DEFINE_UNQUOTED([USE_ECDSA], [1], [Define this to enable ECDSA support.])
1349      use_ecdsa="yes"
1350      ;;
1351esac
1352
1353AC_ARG_ENABLE(dsa, AS_HELP_STRING([--disable-dsa],[Disable DSA support]))
1354use_dsa="no"
1355case "$enable_dsa" in
1356    yes)
1357      # detect if DSA is supported, and turn it off if not.
1358      if test $USE_NSS = "no" -a $USE_NETTLE = "no"; then
1359      AC_CHECK_FUNC(DSA_SIG_new, [
1360      AC_CHECK_TYPE(DSA_SIG*, [
1361      AC_DEFINE_UNQUOTED([USE_DSA], [1], [Define this to enable DSA support.])
1362      ], [if test "x$enable_dsa" = "xyes"; then AC_MSG_ERROR([OpenSSL does not support DSA and you used --enable-dsa.])
1363               fi ], [
1364AC_INCLUDES_DEFAULT
1365#ifdef HAVE_OPENSSL_ERR_H
1366#include <openssl/err.h>
1367#endif
1368
1369#ifdef HAVE_OPENSSL_RAND_H
1370#include <openssl/rand.h>
1371#endif
1372
1373#ifdef HAVE_OPENSSL_CONF_H
1374#include <openssl/conf.h>
1375#endif
1376
1377#ifdef HAVE_OPENSSL_ENGINE_H
1378#include <openssl/engine.h>
1379#endif
1380      ])
1381      ], [if test "x$enable_dsa" = "xyes"; then AC_MSG_ERROR([OpenSSL does not support DSA and you used --enable-dsa.])
1382               fi ])
1383      else
1384      AC_DEFINE_UNQUOTED([USE_DSA], [1], [Define this to enable DSA support.])
1385      fi
1386      ;;
1387    *)
1388      # disable dsa by default, RFC 8624 section 3.1, validators MUST NOT
1389      # support DSA for DNSSEC Validation.
1390      ;;
1391esac
1392
1393AC_ARG_WITH(deprecate-rsa-1024, AS_HELP_STRING([--with-deprecate-rsa-1024],[Deprecate RSA 1024 bit length, makes that an unsupported key, for use when OpenSSL FIPS refuses 1024 bit verification]))
1394if test "$with_deprecate_rsa_1024" = "yes"; then
1395	AC_DEFINE([DEPRECATE_RSA_1024], [1], [Deprecate RSA 1024 bit length, makes that an unsupported key])
1396fi
1397
1398AC_ARG_ENABLE(ed25519, AS_HELP_STRING([--disable-ed25519],[Disable ED25519 support]))
1399use_ed25519="no"
1400case "$enable_ed25519" in
1401    no)
1402      ;;
1403    *)
1404      if test $USE_NSS = "no" -a $USE_NETTLE = "no"; then
1405	      AC_CHECK_DECLS([NID_ED25519], [
1406      		use_ed25519="yes"
1407	      ], [ if test "x$enable_ed25519" = "xyes"; then AC_MSG_ERROR([OpenSSL does not support ED25519 and you used --enable-ed25519.])
1408	      	fi ], [AC_INCLUDES_DEFAULT
1409#include <openssl/evp.h>
1410	      ])
1411      fi
1412      if test $USE_NETTLE = "yes"; then
1413		AC_CHECK_HEADERS([nettle/eddsa.h], use_ed25519="yes",, [AC_INCLUDES_DEFAULT])
1414      fi
1415      if test $use_ed25519 = "yes"; then
1416      		AC_DEFINE_UNQUOTED([USE_ED25519], [1], [Define this to enable ED25519 support.])
1417      fi
1418      ;;
1419esac
1420
1421AC_ARG_ENABLE(ed448, AS_HELP_STRING([--disable-ed448],[Disable ED448 support]))
1422use_ed448="no"
1423case "$enable_ed448" in
1424    no)
1425      ;;
1426    *)
1427      if test $USE_NSS = "no" -a $USE_NETTLE = "no"; then
1428	      AC_CHECK_DECLS([NID_ED448], [
1429      		use_ed448="yes"
1430	      ], [ if test "x$enable_ed448" = "xyes"; then AC_MSG_ERROR([OpenSSL does not support ED448 and you used --enable-ed448.])
1431	      	fi ], [AC_INCLUDES_DEFAULT
1432#include <openssl/evp.h>
1433	      ])
1434      fi
1435      if test $use_ed448 = "yes"; then
1436      		AC_DEFINE_UNQUOTED([USE_ED448], [1], [Define this to enable ED448 support.])
1437      fi
1438      ;;
1439esac
1440
1441AC_ARG_ENABLE(event-api, AS_HELP_STRING([--enable-event-api],[Enable (experimental) pluggable event base libunbound API installed to unbound-event.h]))
1442case "$enable_event_api" in
1443    yes)
1444      AC_SUBST(UNBOUND_EVENT_INSTALL, [unbound-event-install])
1445      AC_SUBST(UNBOUND_EVENT_UNINSTALL, [unbound-event-uninstall])
1446      ;;
1447    *)
1448      ;;
1449esac
1450
1451AC_ARG_ENABLE(tfo-client, AS_HELP_STRING([--enable-tfo-client],[Enable TCP Fast Open for client mode]))
1452case "$enable_tfo_client" in
1453	yes)
1454		case "$host_os" in
1455			linux*) AC_CHECK_DECL([MSG_FASTOPEN], [AC_MSG_WARN([Check the platform specific TFO kernel parameters are correctly configured to support client mode TFO])],
1456				[AC_MSG_ERROR([TCP Fast Open is not available for client mode: please rerun without --enable-tfo-client])],
1457				[AC_INCLUDES_DEFAULT
1458#include <netinet/tcp.h>
1459])
1460				AC_DEFINE_UNQUOTED([USE_MSG_FASTOPEN], [1], [Define this to enable client TCP Fast Open.])
1461				;;
1462			darwin*) AC_CHECK_DECL([CONNECT_RESUME_ON_READ_WRITE], [AC_MSG_WARN([Check the platform specific TFO kernel parameters are correctly configured to support client mode TFO])],
1463				[AC_MSG_ERROR([TCP Fast Open is not available for client mode: please rerun without --enable-tfo-client])],
1464				[AC_INCLUDES_DEFAULT
1465#include <sys/socket.h>
1466])
1467				AC_DEFINE_UNQUOTED([USE_OSX_MSG_FASTOPEN], [1], [Define this to enable client TCP Fast Open.])
1468				;;
1469		esac
1470		;;
1471	no|*)
1472		;;
1473esac
1474
1475AC_ARG_ENABLE(tfo-server, AS_HELP_STRING([--enable-tfo-server],[Enable TCP Fast Open for server mode]))
1476case "$enable_tfo_server" in
1477	yes)
1478	      AC_CHECK_DECL([TCP_FASTOPEN], [AC_MSG_WARN([Check the platform specific TFO kernel parameters are correctly configured to support server mode TFO])], [AC_MSG_ERROR([TCP Fast Open is not available for server mode: please rerun without --enable-tfo-server])], [AC_INCLUDES_DEFAULT
1479#include <netinet/tcp.h>
1480	      ])
1481		AC_DEFINE_UNQUOTED([USE_TCP_FASTOPEN], [1], [Define this to enable server TCP Fast Open.])
1482		;;
1483	no|*)
1484		;;
1485esac
1486
1487# check for libevent
1488AC_ARG_WITH(libevent, AS_HELP_STRING([--with-libevent=pathname],[use libevent (will check /usr/local /opt/local /usr/lib /usr/pkg /usr/sfw /usr  or you can specify an explicit path). Slower, but allows use of large outgoing port ranges.]),
1489    [ ],[ with_libevent="no" ])
1490if test "x_$with_libevent" != x_no; then
1491        AC_DEFINE([USE_LIBEVENT], [1], [Define if you enable libevent])
1492        AC_MSG_CHECKING(for libevent)
1493        if test "x_$with_libevent" = x_ -o "x_$with_libevent" = x_yes; then
1494            with_libevent="/usr/local /opt/local /usr/lib /usr/pkg /usr/sfw /usr"
1495        fi
1496        for dir in $with_libevent; do
1497            thedir="$dir"
1498            if test -f "$dir/include/event.h" -o -f "$dir/include/event2/event.h"; then
1499                found_libevent="yes"
1500				dnl assume /usr is in default path.
1501				if test "$thedir" != "/usr"; then
1502				    CPPFLAGS="$CPPFLAGS -I$thedir/include"
1503				fi
1504				break;
1505		    fi
1506        done
1507        if test x_$found_libevent != x_yes; then
1508		if test -f "$dir/event.h" -a \( -f "$dir/libevent.la" -o -f "$dir/libev.la" \) ; then
1509			# libevent source directory
1510			AC_MSG_RESULT(found in $thedir)
1511			CPPFLAGS="$CPPFLAGS -I$thedir -I$thedir/include"
1512			BAK_LDFLAGS_SET="1"
1513			BAK_LDFLAGS="$LDFLAGS"
1514			# remove evdns from linking
1515			mkdir build >/dev/null 2>&1
1516			mkdir build/libevent >/dev/null 2>&1
1517			mkdir build/libevent/.libs >/dev/null 2>&1
1518			ev_files_o=`ls $thedir/*.o | grep -v evdns\.o | grep -v bufferevent_openssl\.o`
1519			ev_files_lo=`ls $thedir/*.lo | grep -v evdns\.lo | grep -v bufferevent_openssl\.lo`
1520			ev_files_libso=`ls $thedir/.libs/*.o | grep -v evdns\.o | grep -v bufferevent_openssl\.o`
1521			cp $ev_files_o build/libevent
1522			cp $ev_files_lo build/libevent
1523			cp $ev_files_libso build/libevent/.libs
1524			LATE_LDFLAGS="build/libevent/*.lo -lm"
1525			LDFLAGS="build/libevent/*.o $LDFLAGS -lm"
1526		else
1527            AC_MSG_ERROR([Cannot find the libevent library in $with_libevent
1528You can restart ./configure --with-libevent=no to use a builtin alternative.
1529Please note that this alternative is not as capable as libevent when using
1530large outgoing port ranges.  ])
1531		fi
1532        else
1533            AC_MSG_RESULT(found in $thedir)
1534	    dnl if event2 exists and no event lib in dir itself, use subdir
1535	    if test ! -f $thedir/lib/libevent.a -a ! -f $thedir/lib/libevent.so -a -d "$thedir/lib/event2"; then
1536		    LDFLAGS="$LDFLAGS -L$thedir/lib/event2"
1537		    ACX_RUNTIME_PATH_ADD([$thedir/lib/event2])
1538	    else
1539		    dnl assume /usr is in default path, do not add "".
1540		    if test "$thedir" != "/usr" -a "$thedir" != ""; then
1541			LDFLAGS="$LDFLAGS -L$thedir/lib"
1542			ACX_RUNTIME_PATH_ADD([$thedir/lib])
1543		    fi
1544	    fi
1545        fi
1546	# check for library used by libevent after 1.3c
1547	AC_SEARCH_LIBS([clock_gettime], [rt])
1548
1549	# is the event.h header libev or libevent?
1550	AC_CHECK_HEADERS([event.h],,, [AC_INCLUDES_DEFAULT])
1551	AC_CHECK_DECL(EV_VERSION_MAJOR, [
1552		AC_SEARCH_LIBS(event_set, [ev])
1553	],[
1554		AC_SEARCH_LIBS(event_set, [event])
1555	],[AC_INCLUDES_DEFAULT
1556#include <event.h>
1557	])
1558	AC_CHECK_FUNCS([event_base_free]) # only in libevent 1.2 and later
1559	AC_CHECK_FUNCS([event_base_once]) # only in libevent 1.4.1 and later
1560	AC_CHECK_FUNCS([event_base_new]) # only in libevent 1.4.1 and later
1561	AC_CHECK_FUNCS([event_base_get_method]) # only in libevent 1.4.3 and later
1562	AC_CHECK_FUNCS([ev_loop]) # only in libev. (tested on 3.51)
1563	AC_CHECK_FUNCS([ev_default_loop]) # only in libev. (tested on 4.00)
1564	AC_CHECK_FUNCS([event_assign]) # in libevent, for thread-safety
1565	AC_CHECK_DECLS([evsignal_assign], [], [], [AC_INCLUDES_DEFAULT
1566#ifdef HAVE_EVENT_H
1567#  include <event.h>
1568#else
1569#  include "event2/event.h"
1570#endif
1571	])
1572        PC_LIBEVENT_DEPENDENCY="libevent"
1573        AC_SUBST(PC_LIBEVENT_DEPENDENCY)
1574	if test -n "$BAK_LDFLAGS_SET"; then
1575		LDFLAGS="$BAK_LDFLAGS"
1576	fi
1577else
1578	AC_DEFINE(USE_MINI_EVENT, 1, [Define if you want to use internal select based events])
1579fi
1580
1581# check for libexpat
1582AC_ARG_WITH(libexpat, AS_HELP_STRING([--with-libexpat=path],[specify explicit path for libexpat.]),
1583    [ ],[ withval="/usr/local /opt/local /usr/lib /usr/pkg /usr/sfw /usr" ])
1584AC_MSG_CHECKING(for libexpat)
1585found_libexpat="no"
1586for dir in $withval ; do
1587            if test -f "$dir/include/expat.h"; then
1588		found_libexpat="yes"
1589		dnl assume /usr is in default path.
1590		if test "$dir" != "/usr"; then
1591                    CPPFLAGS="$CPPFLAGS -I$dir/include"
1592		    LDFLAGS="$LDFLAGS -L$dir/lib"
1593		fi
1594            	AC_MSG_RESULT(found in $dir)
1595                break;
1596            fi
1597done
1598if test x_$found_libexpat != x_yes; then
1599	AC_MSG_ERROR([Could not find libexpat, expat.h])
1600fi
1601AC_CHECK_HEADERS([expat.h],,, [AC_INCLUDES_DEFAULT])
1602AC_CHECK_DECLS([XML_StopParser], [], [], [AC_INCLUDES_DEFAULT
1603#include <expat.h>
1604])
1605
1606# hiredis (redis C client for cachedb)
1607AC_ARG_WITH(libhiredis, AS_HELP_STRING([--with-libhiredis=path],[specify explicit path for libhiredis.]),
1608    [ ],[ withval="no" ])
1609found_libhiredis="no"
1610if test x_$withval = x_yes -o x_$withval != x_no; then
1611   AC_MSG_CHECKING(for libhiredis)
1612   if test x_$withval = x_ -o x_$withval = x_yes; then
1613            withval="/usr/local /opt/local /usr/lib /usr/pkg /usr/sfw /usr"
1614   fi
1615   for dir in $withval ; do
1616            if test -f "$dir/include/hiredis/hiredis.h"; then
1617		found_libhiredis="yes"
1618		dnl assume /usr is in default path.
1619		if test "$dir" != "/usr"; then
1620                    CPPFLAGS="$CPPFLAGS -I$dir/include"
1621		    LDFLAGS="$LDFLAGS -L$dir/lib"
1622		fi
1623		AC_MSG_RESULT(found in $dir)
1624		AC_DEFINE([USE_REDIS], [1], [Define this to use hiredis client.])
1625		LIBS="$LIBS -lhiredis"
1626                break;
1627            fi
1628    done
1629    if test x_$found_libhiredis != x_yes; then
1630	AC_MSG_ERROR([Could not find libhiredis, hiredis.h])
1631    fi
1632    AC_CHECK_HEADERS([hiredis/hiredis.h],,, [AC_INCLUDES_DEFAULT])
1633    AC_CHECK_DECLS([redisConnect], [], [], [AC_INCLUDES_DEFAULT
1634    #include <hiredis/hiredis.h>
1635    ])
1636fi
1637
1638# nghttp2
1639AC_ARG_WITH(libnghttp2, AS_HELP_STRING([--with-libnghttp2=path],[specify explicit path for libnghttp2.]),
1640    [ ],[ withval="no" ])
1641found_libnghttp2="no"
1642if test x_$withval = x_yes -o x_$withval != x_no; then
1643   AC_MSG_CHECKING(for libnghttp2)
1644   if test x_$withval = x_ -o x_$withval = x_yes; then
1645            withval="/usr/local /opt/local /usr/lib /usr/pkg /usr/sfw /usr"
1646   fi
1647   for dir in $withval ; do
1648            if test -f "$dir/include/nghttp2/nghttp2.h"; then
1649		found_libnghttp2="yes"
1650		dnl assume /usr is in default path.
1651		if test "$dir" != "/usr"; then
1652                    CPPFLAGS="$CPPFLAGS -I$dir/include"
1653		    LDFLAGS="$LDFLAGS -L$dir/lib"
1654		fi
1655		AC_MSG_RESULT(found in $dir)
1656		AC_DEFINE([HAVE_NGHTTP2], [1], [Define this to use nghttp2 client.])
1657		LIBS="$LIBS -lnghttp2"
1658                break;
1659            fi
1660    done
1661    if test x_$found_libnghttp2 != x_yes; then
1662	AC_MSG_ERROR([Could not find libnghttp2, nghttp2.h])
1663    fi
1664    AC_CHECK_HEADERS([nghttp2/nghttp2.h],,, [AC_INCLUDES_DEFAULT])
1665    AC_CHECK_DECLS([nghttp2_session_server_new], [], [], [AC_INCLUDES_DEFAULT
1666    #include <nghttp2/nghttp2.h>
1667    ])
1668fi
1669
1670# ngtcp2
1671AC_ARG_WITH(libngtcp2, AS_HELP_STRING([--with-libngtcp2=path],[specify explicit path for libngtcp2, for QUIC.]),
1672    [ ],[ withval="no" ])
1673found_libngtcp2="no"
1674if test x_$withval = x_yes -o x_$withval != x_no; then
1675   AC_MSG_CHECKING(for libngtcp2)
1676   if test x_$withval = x_ -o x_$withval = x_yes; then
1677            withval="/usr/local /opt/local /usr/lib /usr/pkg /usr/sfw /usr"
1678   fi
1679   for dir in $withval ; do
1680            if test -f "$dir/include/ngtcp2/ngtcp2.h"; then
1681		found_libngtcp2="yes"
1682		dnl assume /usr is in default path.
1683		if test "$dir" != "/usr"; then
1684                    CPPFLAGS="$CPPFLAGS -I$dir/include"
1685		    LDFLAGS="$LDFLAGS -L$dir/lib"
1686		fi
1687		AC_MSG_RESULT(found in $dir)
1688		AC_DEFINE([HAVE_NGTCP2], [1], [Define this to use ngtcp2.])
1689		LIBS="$LIBS -lngtcp2"
1690                break;
1691            fi
1692    done
1693    if test x_$found_libngtcp2 != x_yes; then
1694	AC_MSG_ERROR([Could not find libngtcp2, ngtcp2.h])
1695    fi
1696    AC_CHECK_HEADERS([ngtcp2/ngtcp2.h ngtcp2/ngtcp2_crypto_ossl.h ngtcp2/ngtcp2_crypto_openssl.h ngtcp2/ngtcp2_crypto_quictls.h],,, [AC_INCLUDES_DEFAULT])
1697    AC_CHECK_DECLS([ngtcp2_conn_server_new], [], [], [AC_INCLUDES_DEFAULT
1698    #include <ngtcp2/ngtcp2.h>
1699    ])
1700    AC_CHECK_DECLS([ngtcp2_crypto_encrypt_cb], [], [], [AC_INCLUDES_DEFAULT
1701    #include <ngtcp2/ngtcp2_crypto.h>
1702    ])
1703    AC_CHECK_LIB([ngtcp2_crypto_ossl], [ngtcp2_crypto_encrypt_cb], [
1704	LIBS="$LIBS -lngtcp2_crypto_ossl"
1705	AC_DEFINE(USE_NGTCP2_CRYPTO_OSSL, 1, [Define this to use ngtcp2_crypto_ossl.])
1706    ], [
1707        AC_CHECK_LIB([ngtcp2_crypto_openssl], [ngtcp2_crypto_encrypt_cb], [ LIBS="$LIBS -lngtcp2_crypto_openssl" ], [
1708            AC_CHECK_LIB([ngtcp2_crypto_quictls], [ngtcp2_crypto_encrypt_cb], [ LIBS="$LIBS -lngtcp2_crypto_quictls" ])
1709	])
1710    ])
1711    AC_CHECK_FUNCS([ngtcp2_crypto_encrypt_cb ngtcp2_ccerr_default ngtcp2_conn_in_closing_period ngtcp2_conn_in_draining_period ngtcp2_conn_get_max_local_streams_uni ngtcp2_crypto_quictls_from_ossl_encryption_level ngtcp2_crypto_quictls_configure_server_context ngtcp2_crypto_quictls_configure_client_context ngtcp2_crypto_quictls_init ngtcp2_conn_get_num_scid ngtcp2_conn_tls_early_data_rejected ngtcp2_conn_encode_0rtt_transport_params])
1712
1713    # these check_funcs need -lssl
1714    BAKLIBS="$LIBS"
1715    LIBS="-lssl $LIBS"
1716    AC_CHECK_FUNCS([SSL_is_quic], [], [AC_MSG_ERROR([No QUIC support detected in OpenSSL. Need OpenSSL version with QUIC support to enable DNS over QUIC with libngtcp2.])])
1717    LIBS="$BAKLIBS"
1718
1719    AC_CHECK_TYPES([struct ngtcp2_version_cid, ngtcp2_encryption_level],,,[AC_INCLUDES_DEFAULT
1720    #include <ngtcp2/ngtcp2.h>
1721    ])
1722    AC_CHECK_MEMBERS([struct ngtcp2_pkt_hd.tokenlen, struct ngtcp2_settings.tokenlen, struct ngtcp2_settings.max_tx_udp_payload_size, struct ngtcp2_transport_params.original_dcid_present],,,[AC_INCLUDES_DEFAULT
1723    #include <ngtcp2/ngtcp2.h>
1724    ])
1725
1726    AC_MSG_CHECKING([whether ngtcp2_conn_shutdown_stream has 4 arguments])
1727    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT
1728#include <ngtcp2/ngtcp2.h>
1729    ],[
1730	(void)ngtcp2_conn_shutdown_stream(NULL, 0, 0, 0);
1731    ])],[
1732	AC_MSG_RESULT(yes)
1733	AC_DEFINE(HAVE_NGTCP2_CONN_SHUTDOWN_STREAM4, 1, [Define if ngtcp2_conn_shutdown_stream has 4 arguments.])
1734    ],[
1735	AC_MSG_RESULT(no)
1736    ])
1737
1738fi
1739
1740# set static linking for uninstalled libraries if requested
1741AC_SUBST(staticexe)
1742staticexe=""
1743AC_ARG_ENABLE(static-exe, AS_HELP_STRING([--enable-static-exe],[ enable to compile executables statically against (event) uninstalled libs, for debug purposes ]),
1744	, )
1745if test x_$enable_static_exe = x_yes; then
1746	staticexe="-static"
1747	if test "$on_mingw" = yes; then
1748		staticexe="-all-static"
1749		# for static compile, include gdi32 and zlib here.
1750		if echo "$LIBS" | grep 'lgdi32' >/dev/null; then
1751			:
1752		else
1753			LIBS="$LIBS -lgdi32"
1754		fi
1755		AC_CHECK_LIB([z], [compress], [ LIBS="$LIBS -lz" ])
1756		if echo "$host" | $GREP -i -e linux >/dev/null; then
1757			if echo "$LIBS" | grep -e "libssp.a" -e "lssp" >/dev/null; then
1758				:
1759			else
1760				LIBS="$LIBS -l:libssp.a"
1761			fi
1762		fi
1763	fi
1764fi
1765
1766# set full static linking if requested
1767AC_ARG_ENABLE(fully-static, AS_HELP_STRING([--enable-fully-static],[ enable to compile fully static ]),
1768	, )
1769if test x_$enable_fully_static = x_yes; then
1770	staticexe="-all-static"
1771	if test "$on_mingw" = yes; then
1772		# for static compile, include gdi32 and zlib here.
1773		if echo $LIBS | grep 'lgdi32' >/dev/null; then
1774			:
1775		else
1776			LIBS="$LIBS -lgdi32"
1777		fi
1778		AC_CHECK_LIB([z], [compress], [ LIBS="$LIBS -lz" ])
1779		if echo "$host" | $GREP -i -e linux >/dev/null; then
1780			if echo "$LIBS" | grep -e "libssp.a" -e "lssp" >/dev/null; then
1781				:
1782			else
1783				LIBS="$LIBS -l:libssp.a"
1784			fi
1785		fi
1786	fi
1787fi
1788
1789# set lock checking if requested
1790AC_ARG_ENABLE(lock_checks, AS_HELP_STRING([--enable-lock-checks],[ enable to check lock and unlock calls, for debug purposes ]),
1791	, )
1792if test x_$enable_lock_checks = x_yes; then
1793	AC_DEFINE(ENABLE_LOCK_CHECKS, 1, [Define if you want to use debug lock checking (slow).])
1794	CHECKLOCK_OBJ="checklocks.lo"
1795	AC_SUBST(CHECKLOCK_OBJ)
1796fi
1797
1798ACX_CHECK_GETADDRINFO_WITH_INCLUDES
1799if test "$USE_WINSOCK" = 1; then
1800	AC_DEFINE(UB_ON_WINDOWS, 1, [Use win32 resources and API])
1801	AC_CHECK_HEADERS([iphlpapi.h],,, [AC_INCLUDES_DEFAULT
1802#include <windows.h>
1803	])
1804	AC_CHECK_TOOL(WINDRES, windres)
1805	if echo "$LIBS" | grep crypt32 >/dev/null; then
1806		LIBS="$LIBS -liphlpapi"
1807	else
1808		LIBS="$LIBS -liphlpapi -lcrypt32"
1809	fi
1810	WINAPPS="unbound-service-install.exe unbound-service-remove.exe anchor-update.exe"
1811	AC_SUBST(WINAPPS)
1812	WIN_DAEMON_SRC="winrc/win_svc.c winrc/w_inst.c"
1813	AC_SUBST(WIN_DAEMON_SRC)
1814	WIN_DAEMON_OBJ="win_svc.lo w_inst.lo"
1815	AC_SUBST(WIN_DAEMON_OBJ)
1816	WIN_DAEMON_OBJ_LINK="rsrc_unbound.o"
1817	AC_SUBST(WIN_DAEMON_OBJ_LINK)
1818	WIN_HOST_OBJ_LINK="rsrc_unbound_host.o"
1819	AC_SUBST(WIN_HOST_OBJ_LINK)
1820	WIN_UBANCHOR_OBJ_LINK="rsrc_unbound_anchor.o log.lo locks.lo"
1821	AC_SUBST(WIN_UBANCHOR_OBJ_LINK)
1822	WIN_CONTROL_OBJ_LINK="rsrc_unbound_control.o"
1823	AC_SUBST(WIN_CONTROL_OBJ_LINK)
1824	WIN_CHECKCONF_OBJ_LINK="rsrc_unbound_checkconf.o"
1825	AC_SUBST(WIN_CHECKCONF_OBJ_LINK)
1826	AC_DEFINE(__USE_MINGW_ANSI_STDIO, 1, [defined to use gcc ansi snprintf and sscanf that understands %lld when compiled for windows.])
1827fi
1828if test $ac_cv_func_getaddrinfo = no; then
1829	AC_LIBOBJ([fake-rfc2553])
1830fi
1831# check after getaddrinfo for its libraries
1832ACX_FUNC_IOCTLSOCKET
1833
1834# see if daemon(3) exists, and if it is deprecated.
1835AC_CHECK_FUNCS([daemon])
1836if test $ac_cv_func_daemon = yes; then
1837	ACX_FUNC_DEPRECATED([daemon], [(void)daemon(0, 0);], [
1838#include <stdlib.h>
1839#include <unistd.h>
1840])
1841fi
1842
1843AC_CHECK_MEMBERS([struct stat.st_mtimensec, struct stat.st_mtim.tv_nsec])
1844AC_CHECK_MEMBERS([struct sockaddr_un.sun_len],,,[
1845AC_INCLUDES_DEFAULT
1846#ifdef HAVE_SYS_UN_H
1847#include <sys/un.h>
1848#endif
1849])
1850AC_CHECK_MEMBERS([struct in_pktinfo.ipi_spec_dst],,,[
1851AC_INCLUDES_DEFAULT
1852#if HAVE_SYS_PARAM_H
1853#include <sys/param.h>
1854#endif
1855
1856#ifdef HAVE_SYS_SOCKET_H
1857#include <sys/socket.h>
1858#endif
1859
1860#ifdef HAVE_SYS_UIO_H
1861#include <sys/uio.h>
1862#endif
1863
1864#ifdef HAVE_NETINET_IN_H
1865#include <netinet/in.h>
1866#endif
1867
1868#ifdef HAVE_NETINET_TCP_H
1869#include <netinet/tcp.h>
1870#endif
1871
1872#ifdef HAVE_ARPA_INET_H
1873#include <arpa/inet.h>
1874#endif
1875
1876#ifdef HAVE_WINSOCK2_H
1877#include <winsock2.h>
1878#endif
1879
1880#ifdef HAVE_WS2TCPIP_H
1881#include <ws2tcpip.h>
1882#endif
1883])
1884
1885AC_MSG_CHECKING([for htobe64])
1886AC_LINK_IFELSE([AC_LANG_PROGRAM([
1887#include <stdio.h>
1888#ifdef HAVE_ENDIAN_H
1889#  include <endian.h>
1890#endif
1891#ifdef HAVE_SYS_ENDIAN_H
1892#  include <sys/endian.h>
1893#endif
1894], [unsigned long long x = htobe64(0); printf("%u", (unsigned)x);])],
1895  AC_MSG_RESULT(yes)
1896  AC_DEFINE(HAVE_HTOBE64, 1, [If we have htobe64]),
1897  AC_MSG_RESULT(no))
1898
1899AC_MSG_CHECKING([for be64toh])
1900AC_LINK_IFELSE([AC_LANG_PROGRAM([
1901#include <stdio.h>
1902#ifdef HAVE_ENDIAN_H
1903#  include <endian.h>
1904#endif
1905#ifdef HAVE_SYS_ENDIAN_H
1906#  include <sys/endian.h>
1907#endif
1908], [unsigned long long x = be64toh(0); printf("%u", (unsigned)x);])],
1909  AC_MSG_RESULT(yes)
1910  AC_DEFINE(HAVE_BE64TOH, 1, [If we have be64toh]),
1911  AC_MSG_RESULT(no))
1912
1913AC_SEARCH_LIBS([setusercontext], [util])
1914AC_CHECK_FUNCS([tzset sigprocmask fcntl getpwnam endpwent getrlimit setrlimit setsid chroot kill chown sleep usleep random srandom recvmsg sendmsg writev socketpair glob initgroups strftime localtime_r setusercontext _beginthreadex endservent endprotoent fsync shmget accept4 getifaddrs if_nametoindex poll gettid])
1915AC_CHECK_FUNCS([setresuid],,[AC_CHECK_FUNCS([setreuid])])
1916AC_CHECK_FUNCS([setresgid],,[AC_CHECK_FUNCS([setregid])])
1917
1918# check if setreuid en setregid fail, on MacOSX10.4(darwin8).
1919if echo $host_os | grep darwin8 > /dev/null; then
1920	AC_DEFINE(DARWIN_BROKEN_SETREUID, 1, [Define this if on macOSX10.4-darwin8 and setreuid and setregid do not work])
1921fi
1922
1923AC_MSG_CHECKING([for atomic_store])
1924AC_LINK_IFELSE([AC_LANG_PROGRAM(AC_INCLUDES_DEFAULT [[
1925#ifdef HAVE_STDATOMIC_H
1926#include <stdatomic.h>
1927#endif
1928]], [[
1929	int newvar = 5, var = 0;
1930	atomic_store((_Atomic int*)&var, newvar);
1931	newvar = 0;
1932	/* condition to use the variables. */
1933	if(var == newvar) return 1;
1934]])], [
1935	AC_MSG_RESULT(yes)
1936	AC_DEFINE(HAVE_LINK_ATOMIC_STORE, 1, [If we have atomic_store])
1937], [
1938	AC_MSG_RESULT([no])
1939])
1940
1941AC_CHECK_DECLS([inet_pton,inet_ntop], [], [], [
1942AC_INCLUDES_DEFAULT
1943#ifdef HAVE_NETINET_IN_H
1944#include <netinet/in.h>
1945#endif
1946
1947#ifdef HAVE_NETINET_TCP_H
1948#include <netinet/tcp.h>
1949#endif
1950
1951#ifdef HAVE_ARPA_INET_H
1952#include <arpa/inet.h>
1953#endif
1954
1955#ifdef HAVE_WINSOCK2_H
1956#include <winsock2.h>
1957#endif
1958
1959#ifdef HAVE_WS2TCPIP_H
1960#include <ws2tcpip.h>
1961#endif
1962])
1963AC_REPLACE_FUNCS(inet_aton)
1964AC_REPLACE_FUNCS(inet_pton)
1965AC_REPLACE_FUNCS(inet_ntop)
1966AC_REPLACE_FUNCS(snprintf)
1967# test if snprintf return the proper length
1968if test "x$ac_cv_func_snprintf" = xyes; then
1969    if test c${cross_compiling} = cno; then
1970	AC_MSG_CHECKING([for correct snprintf return value])
1971	AC_RUN_IFELSE([AC_LANG_SOURCE(AC_INCLUDES_DEFAULT
1972[[
1973int main(void) { return !(snprintf(NULL, 0, "test") == 4); }
1974]])], [AC_MSG_RESULT(yes)], [
1975		AC_MSG_RESULT(no)
1976		AC_DEFINE([SNPRINTF_RET_BROKEN], [], [define if (v)snprintf does not return length needed, (but length used)])
1977		AC_LIBOBJ(snprintf)
1978	  ], [AC_MSG_RESULT(maybe)])
1979    fi
1980fi
1981AC_REPLACE_FUNCS(strlcat)
1982AC_REPLACE_FUNCS(strlcpy)
1983AC_REPLACE_FUNCS(memmove)
1984AC_REPLACE_FUNCS(gmtime_r)
1985AC_REPLACE_FUNCS(isblank)
1986AC_REPLACE_FUNCS(explicit_bzero)
1987dnl without CTIME, ARC4-functions and without reallocarray.
1988LIBOBJ_WITHOUT_CTIMEARC4="$LIBOBJS"
1989AC_SUBST(LIBOBJ_WITHOUT_CTIMEARC4)
1990AC_MSG_CHECKING([for reallocarray])
1991AC_LINK_IFELSE([AC_LANG_SOURCE(AC_INCLUDES_DEFAULT
1992[[
1993#ifndef _OPENBSD_SOURCE
1994#define _OPENBSD_SOURCE 1
1995#endif
1996#include <stdlib.h>
1997int main(void) {
1998	void* p = reallocarray(NULL, 10, 100);
1999	free(p);
2000	return 0;
2001}
2002]])], [AC_MSG_RESULT(yes)
2003	AC_DEFINE(HAVE_REALLOCARRAY, 1, [If we have reallocarray(3)])
2004], [
2005	AC_MSG_RESULT(no)
2006	AC_LIBOBJ(reallocarray)
2007])
2008AC_CHECK_DECLS([reallocarray])
2009if test "$USE_NSS" = "no"; then
2010	AC_REPLACE_FUNCS(arc4random)
2011	AC_REPLACE_FUNCS(arc4random_uniform)
2012	if test "$ac_cv_func_arc4random" = "no"; then
2013		AC_LIBOBJ(arc4_lock)
2014		AC_CHECK_FUNCS([getentropy],,[
2015		    if test "$USE_WINSOCK" = 1; then
2016			AC_LIBOBJ(getentropy_win)
2017		    else
2018			case "$host" in
2019			Darwin|*darwin*)
2020				AC_LIBOBJ(getentropy_osx)
2021			;;
2022			*solaris*|*sunos*|SunOS)
2023				AC_LIBOBJ(getentropy_solaris)
2024				AC_CHECK_HEADERS([sys/sha2.h],, [
2025					AC_CHECK_FUNCS([SHA512_Update],,[
2026						AC_LIBOBJ(sha512)
2027					])
2028				], [AC_INCLUDES_DEFAULT])
2029				if test "$ac_cv_header_sys_sha2_h" = "yes"; then
2030					# this lib needed for sha2 on solaris
2031					LIBS="$LIBS -lmd"
2032				fi
2033				AC_SEARCH_LIBS([clock_gettime], [rt])
2034			;;
2035			*freebsd*|*FreeBSD)
2036				AC_LIBOBJ(getentropy_freebsd)
2037			;;
2038			*linux*|Linux|*)
2039				AC_LIBOBJ(getentropy_linux)
2040				AC_CHECK_FUNCS([SHA512_Update],,[
2041					AC_DEFINE([COMPAT_SHA512], [1], [Do sha512 definitions in config.h])
2042					AC_LIBOBJ(sha512)
2043				])
2044				AC_CHECK_HEADERS([sys/sysctl.h],,, [AC_INCLUDES_DEFAULT])
2045				AC_CHECK_FUNCS([getauxval])
2046				AC_SEARCH_LIBS([clock_gettime], [rt])
2047			;;
2048			esac
2049		    fi
2050		])
2051	fi
2052fi
2053LIBOBJ_WITHOUT_CTIME="$LIBOBJS"
2054AC_SUBST(LIBOBJ_WITHOUT_CTIME)
2055AC_REPLACE_FUNCS(ctime_r)
2056AC_REPLACE_FUNCS(strsep)
2057
2058AC_ARG_ENABLE(allsymbols, AS_HELP_STRING([--enable-allsymbols],[export all symbols from libunbound and link binaries to it, smaller install size but libunbound export table is polluted by internal symbols]))
2059case "$enable_allsymbols" in
2060	yes)
2061	COMMON_OBJ_ALL_SYMBOLS=""
2062	UBSYMS=""
2063	EXTRALINK="libunbound.la"
2064	AC_DEFINE(EXPORT_ALL_SYMBOLS, 1, [Define this if you enabled-allsymbols from libunbound to link binaries to it for smaller install size, but the libunbound export table is polluted by internal symbols])
2065	;;
2066	no|*)
2067	COMMON_OBJ_ALL_SYMBOLS='$(COMMON_OBJ)'
2068	UBSYMS='-export-symbols $(srcdir)/libunbound/ubsyms.def'
2069	EXTRALINK=""
2070	;;
2071esac
2072AC_SUBST(COMMON_OBJ_ALL_SYMBOLS)
2073AC_SUBST(EXTRALINK)
2074AC_SUBST(UBSYMS)
2075if test x_$enable_lock_checks = x_yes; then
2076	UBSYMS="-export-symbols clubsyms.def"
2077	cp ${srcdir}/libunbound/ubsyms.def clubsyms.def
2078	echo lock_protect >> clubsyms.def
2079	echo lock_protect_place >> clubsyms.def
2080	echo lock_unprotect >> clubsyms.def
2081	echo lock_get_mem >> clubsyms.def
2082	echo checklock_start >> clubsyms.def
2083	echo checklock_stop >> clubsyms.def
2084	echo checklock_set_output_name >> clubsyms.def
2085	echo checklock_lock >> clubsyms.def
2086	echo checklock_unlock >> clubsyms.def
2087	echo checklock_init >> clubsyms.def
2088	echo checklock_thrcreate >> clubsyms.def
2089	echo checklock_thrjoin >> clubsyms.def
2090fi
2091
2092# check for dnstap if requested
2093dt_DNSTAP([$UNBOUND_RUN_DIR/dnstap.sock],
2094    [
2095        AC_DEFINE([USE_DNSTAP], [1], [Define to 1 to enable dnstap support])
2096        AC_SUBST([ENABLE_DNSTAP], [1])
2097
2098        AC_SUBST([opt_dnstap_socket_path])
2099        ACX_ESCAPE_BACKSLASH($opt_dnstap_socket_path, hdr_dnstap_socket_path)
2100        AC_DEFINE_UNQUOTED(DNSTAP_SOCKET_PATH,
2101            ["$hdr_dnstap_socket_path"], [default dnstap socket path])
2102	AC_SUBST(DNSTAP_SOCKET_PATH,["$hdr_dnstap_socket_path"])
2103	AC_SUBST(DNSTAP_SOCKET_TESTBIN,['unbound-dnstap-socket$(EXEEXT)'])
2104        AC_SUBST([DNSTAP_SRC], ["dnstap/dnstap.c dnstap/dnstap.pb-c.c dnstap/dnstap_fstrm.c dnstap/dtstream.c"])
2105        AC_SUBST([DNSTAP_OBJ], ["dnstap.lo dnstap.pb-c.lo dnstap_fstrm.lo dtstream.lo"])
2106    ],
2107    [
2108        AC_SUBST([ENABLE_DNSTAP], [0])
2109    ]
2110)
2111
2112# check for dnscrypt if requested
2113dnsc_DNSCRYPT([
2114        AC_DEFINE([USE_DNSCRYPT], [1], [Define to 1 to enable dnscrypt support])
2115        AC_SUBST([ENABLE_DNSCRYPT], [1])
2116
2117        AC_SUBST([DNSCRYPT_SRC], ["dnscrypt/dnscrypt.c"])
2118        AC_SUBST([DNSCRYPT_OBJ], ["dnscrypt.lo"])
2119    ],
2120    [
2121        AC_SUBST([ENABLE_DNSCRYPT], [0])
2122    ]
2123)
2124
2125# check for cachedb if requested
2126AC_ARG_ENABLE(cachedb, AS_HELP_STRING([--enable-cachedb],[enable cachedb module that can use external cache storage]))
2127# turn on cachedb when hiredis support is enabled.
2128if test "$found_libhiredis" = "yes"; then enable_cachedb="yes"; fi
2129case "$enable_cachedb" in
2130    yes)
2131    	AC_DEFINE([USE_CACHEDB], [1], [Define to 1 to use cachedb support])
2132	AC_SUBST([CACHEDB_SRC], ["cachedb/cachedb.c cachedb/redis.c"])
2133	AC_SUBST([CACHEDB_OBJ], ["cachedb.lo redis.lo"])
2134    	;;
2135    no|*)
2136    	# nothing
2137    	;;
2138esac
2139
2140# check for ipsecmod if requested
2141AC_ARG_ENABLE(ipsecmod, AS_HELP_STRING([--enable-ipsecmod],[Enable ipsecmod module that facilitates opportunistic IPsec]))
2142case "$enable_ipsecmod" in
2143	yes)
2144		AC_DEFINE([USE_IPSECMOD], [1], [Define to 1 to use ipsecmod support.])
2145		IPSECMOD_OBJ="ipsecmod.lo ipsecmod-whitelist.lo"
2146		AC_SUBST(IPSECMOD_OBJ)
2147		IPSECMOD_HEADER='$(srcdir)/ipsecmod/ipsecmod.h $(srcdir)/ipsecmod/ipsecmod-whitelist.h'
2148		AC_SUBST(IPSECMOD_HEADER)
2149		;;
2150	no|*)
2151		# nothing
2152		;;
2153esac
2154
2155# check for ipset if requested
2156AC_ARG_ENABLE(ipset, AS_HELP_STRING([--enable-ipset],[enable ipset module]))
2157case "$enable_ipset" in
2158    yes)
2159		AC_DEFINE([USE_IPSET], [1], [Define to 1 to use ipset support])
2160		IPSET_SRC="ipset/ipset.c"
2161		AC_SUBST(IPSET_SRC)
2162		IPSET_OBJ="ipset.lo"
2163		AC_SUBST(IPSET_OBJ)
2164
2165		# BSD's pf
2166		AC_CHECK_HEADERS([net/pfvar.h], [], [
2167		    # mnl
2168		    AC_ARG_WITH(libmnl, AS_HELP_STRING([--with-libmnl=path],[specify explicit path for libmnl.]),
2169			[ ],[ withval="yes" ])
2170		    found_libmnl="no"
2171		    AC_MSG_CHECKING(for libmnl)
2172		    if test x_$withval = x_ -o x_$withval = x_yes; then
2173			withval="/usr/local /opt/local /usr/lib /usr/pkg /usr/sfw /usr"
2174		    fi
2175		    for dir in $withval ; do
2176			if test -f "$dir/include/libmnl/libmnl.h" -o -f "$dir/include/libmnl/libmnl/libmnl.h"; then
2177				found_libmnl="yes"
2178				dnl assume /usr is in default path.
2179				extralibmnl=""
2180				if test -f "$dir/include/libmnl/libmnl/libmnl.h"; then
2181					extralibmnl="/libmnl"
2182				fi
2183				if test "$dir" != "/usr" -o -n "$extralibmnl"; then
2184					CPPFLAGS="$CPPFLAGS -I$dir/include$extralibmnl"
2185				fi
2186				if test "$dir" != "/usr"; then
2187					LDFLAGS="$LDFLAGS -L$dir/lib"
2188				fi
2189				AC_MSG_RESULT(found in $dir)
2190				LIBS="$LIBS -lmnl"
2191				break;
2192			fi
2193		    done
2194		    if test x_$found_libmnl != x_yes; then
2195			  AC_MSG_ERROR([Could not find libmnl, libmnl.h])
2196		    fi
2197		], [
2198		  #include <netinet/in.h>
2199		  #include <net/if.h>
2200		])
2201		;;
2202    no|*)
2203    	# nothing
2204		;;
2205esac
2206AC_ARG_ENABLE(explicit-port-randomisation, AS_HELP_STRING([--disable-explicit-port-randomisation],[disable explicit source port randomisation and rely on the kernel to provide random source ports]))
2207case "$enable_explicit_port_randomisation" in
2208	no)
2209		AC_DEFINE([DISABLE_EXPLICIT_PORT_RANDOMISATION], [1], [Define this to enable kernel based UDP source port randomization.])
2210		;;
2211	yes|*)
2212		;;
2213esac
2214
2215if echo "$host" | $GREP -i -e linux >/dev/null; then
2216	AC_ARG_ENABLE(linux-ip-local-port-range, AS_HELP_STRING([--enable-linux-ip-local-port-range], [Define this to enable use of /proc/sys/net/ipv4/ip_local_port_range as a default outgoing port range. This is only for the libunbound on Linux and does not affect unbound resolving daemon itself. This may severely limit the number of available outgoing ports and thus decrease randomness. Define this only when the target system restricts (e.g. some of SELinux enabled distributions) the use of non-ephemeral ports.]))
2217	case "$enable_linux_ip_local_port_range" in
2218		yes)
2219			AC_DEFINE([USE_LINUX_IP_LOCAL_PORT_RANGE], [1], [Define this to enable use of /proc/sys/net/ipv4/ip_local_port_range as a default outgoing port range. This is only for the libunbound on Linux and does not affect unbound resolving daemon itself. This may severely limit the number of available outgoing ports and thus decrease randomness. Define this only when the target system restricts (e.g. some of SELinux enabled distributions) the use of non-ephemeral ports.])
2220			;;
2221		no|*)
2222			;;
2223	esac
2224fi
2225
2226
2227AC_MSG_CHECKING([if ${MAKE:-make} supports $< with implicit rule in scope])
2228# on openBSD, the implicit rule make $< work.
2229# on Solaris, it does not work ($? is changed sources, $^ lists dependencies).
2230# gmake works.
2231cat >conftest.make <<EOF
2232all:	conftest.lo
2233
2234conftest.lo foo.lo bla.lo:
2235	if test -f "\$<"; then touch \$@; fi
2236
2237.SUFFIXES: .lo
2238.c.lo:
2239	if test -f "\$<"; then touch \$@; fi
2240
2241conftest.lo:        conftest.dir/conftest.c
2242EOF
2243mkdir conftest.dir
2244touch conftest.dir/conftest.c
2245rm -f conftest.lo conftest.c
2246${MAKE:-make} -f conftest.make >/dev/null
2247rm -f conftest.make conftest.c conftest.dir/conftest.c
2248rm -rf conftest.dir
2249if test ! -f conftest.lo; then
2250	AC_MSG_RESULT(no)
2251	SOURCEDETERMINE='echo "$^" | awk "-F " "{print \$$1;}" > .source'
2252	SOURCEFILE='`cat .source`'
2253else
2254	AC_MSG_RESULT(yes)
2255	SOURCEDETERMINE=':'
2256	SOURCEFILE='$<'
2257fi
2258rm -f conftest.lo
2259AC_SUBST(SOURCEDETERMINE)
2260AC_SUBST(SOURCEFILE)
2261
2262# see if we want to build the library or everything
2263ALLTARGET="alltargets"
2264INSTALLTARGET="install-all"
2265AC_ARG_WITH(libunbound-only, AS_HELP_STRING([--with-libunbound-only],[do not build daemon and tool programs]),
2266	[
2267	if test "$withval" = "yes"; then
2268		ALLTARGET="lib"
2269		INSTALLTARGET="install-lib"
2270	fi
2271])
2272if test $ALLTARGET = "alltargets"; then
2273	if test $USE_NSS = "yes"; then
2274		AC_MSG_ERROR([--with-nss can only be used in combination with --with-libunbound-only.])
2275	fi
2276	if test $USE_NETTLE = "yes"; then
2277		AC_MSG_ERROR([--with-nettle can only be used in combination with --with-libunbound-only.])
2278	fi
2279fi
2280
2281AC_SUBST(ALLTARGET)
2282AC_SUBST(INSTALLTARGET)
2283
2284ACX_STRIP_EXT_FLAGS
2285if test -n "$LATE_LDFLAGS"; then
2286  LDFLAGS="$LATE_LDFLAGS $LDFLAGS"
2287fi
2288# remove start spaces
2289LDFLAGS=`echo "$LDFLAGS"|sed -e 's/^ *//'`
2290LIBS=`echo "$LIBS"|sed -e 's/^ *//'`
2291
2292AC_DEFINE_UNQUOTED([MAXSYSLOGMSGLEN], [10240], [Define to the maximum message length to pass to syslog.])
2293
2294AH_BOTTOM(
2295dnl this must be first AH_CONFIG, to define the flags before any includes.
2296AHX_CONFIG_EXT_FLAGS
2297
2298dnl includes
2299[
2300#ifndef _OPENBSD_SOURCE
2301#define _OPENBSD_SOURCE 1
2302#endif
2303
2304#ifndef UNBOUND_DEBUG
2305# ifndef NDEBUG
2306#  define NDEBUG
2307# endif
2308#endif
2309
2310/** Use small-ldns codebase */
2311#define USE_SLDNS 1
2312#ifdef HAVE_SSL
2313#  define LDNS_BUILD_CONFIG_HAVE_SSL 1
2314#endif
2315
2316#include <stdio.h>
2317#include <string.h>
2318#include <unistd.h>
2319#include <assert.h>
2320
2321#if STDC_HEADERS
2322#include <stdlib.h>
2323#include <stddef.h>
2324#endif
2325
2326#ifdef HAVE_STDARG_H
2327#include <stdarg.h>
2328#endif
2329
2330#ifdef HAVE_STDINT_H
2331#include <stdint.h>
2332#endif
2333
2334#include <errno.h>
2335
2336#if HAVE_SYS_PARAM_H
2337#include <sys/param.h>
2338#endif
2339
2340#ifdef HAVE_SYS_SOCKET_H
2341#include <sys/socket.h>
2342#endif
2343
2344#ifdef HAVE_SYS_UIO_H
2345#include <sys/uio.h>
2346#endif
2347
2348#ifdef HAVE_NETINET_IN_H
2349#include <netinet/in.h>
2350#endif
2351
2352#ifdef HAVE_NETINET_TCP_H
2353#include <netinet/tcp.h>
2354#endif
2355
2356#ifdef HAVE_ARPA_INET_H
2357#include <arpa/inet.h>
2358#endif
2359
2360#ifdef HAVE_WINSOCK2_H
2361#include <winsock2.h>
2362#endif
2363
2364#ifdef HAVE_WS2TCPIP_H
2365#include <ws2tcpip.h>
2366#endif
2367
2368#if !defined(USE_WINSOCK) || !defined(HAVE_SNPRINTF) || defined(SNPRINTF_RET_BROKEN) || defined(__USE_MINGW_ANSI_STDIO)
2369#define ARG_LL "%ll"
2370#else
2371#define ARG_LL "%I64"
2372#endif
2373
2374#ifndef AF_LOCAL
2375#define AF_LOCAL AF_UNIX
2376#endif
2377]
2378
2379AHX_CONFIG_FORMAT_ATTRIBUTE
2380AHX_CONFIG_UNUSED_ATTRIBUTE
2381AHX_CONFIG_NONSTRING_ATTRIBUTE
2382AHX_CONFIG_FSEEKO
2383AHX_CONFIG_MAXHOSTNAMELEN
2384#if !defined(HAVE_SNPRINTF) || defined(SNPRINTF_RET_BROKEN)
2385#define snprintf snprintf_unbound
2386#define vsnprintf vsnprintf_unbound
2387#include <stdarg.h>
2388int snprintf (char *str, size_t count, const char *fmt, ...);
2389int vsnprintf (char *str, size_t count, const char *fmt, va_list arg);
2390#endif /* HAVE_SNPRINTF or SNPRINTF_RET_BROKEN */
2391AHX_CONFIG_INET_PTON(unbound)
2392AHX_CONFIG_INET_NTOP(unbound)
2393AHX_CONFIG_INET_ATON(unbound)
2394AHX_CONFIG_MEMMOVE(unbound)
2395AHX_CONFIG_STRLCAT(unbound)
2396AHX_CONFIG_STRLCPY(unbound)
2397AHX_CONFIG_GMTIME_R(unbound)
2398AHX_CONFIG_REALLOCARRAY(unbound)
2399AHX_CONFIG_W32_SLEEP
2400AHX_CONFIG_W32_USLEEP
2401AHX_CONFIG_W32_RANDOM
2402AHX_CONFIG_W32_SRANDOM
2403AHX_CONFIG_W32_FD_SET_T
2404AHX_CONFIG_IPV6_MIN_MTU
2405AHX_MEMCMP_BROKEN(unbound)
2406
2407[
2408#ifndef HAVE_CTIME_R
2409#define ctime_r unbound_ctime_r
2410char *ctime_r(const time_t *timep, char *buf);
2411#endif
2412
2413#ifndef HAVE_STRSEP
2414#define strsep unbound_strsep
2415char *strsep(char **stringp, const char *delim);
2416#endif
2417
2418#ifndef HAVE_ISBLANK
2419#define isblank unbound_isblank
2420int isblank(int c);
2421#endif
2422
2423#ifndef HAVE_EXPLICIT_BZERO
2424#define explicit_bzero unbound_explicit_bzero
2425void explicit_bzero(void* buf, size_t len);
2426#endif
2427
2428#if defined(HAVE_INET_NTOP) && !HAVE_DECL_INET_NTOP
2429const char *inet_ntop(int af, const void *src, char *dst, size_t size);
2430#endif
2431
2432#if defined(HAVE_INET_PTON) && !HAVE_DECL_INET_PTON
2433int inet_pton(int af, const char* src, void* dst);
2434#endif
2435
2436#if !defined(HAVE_STRPTIME) || !defined(STRPTIME_WORKS)
2437#define strptime unbound_strptime
2438struct tm;
2439char *strptime(const char *s, const char *format, struct tm *tm);
2440#endif
2441
2442#if !HAVE_DECL_REALLOCARRAY
2443void *reallocarray(void *ptr, size_t nmemb, size_t size);
2444#endif
2445
2446#ifdef HAVE_LIBBSD
2447#include <bsd/string.h>
2448#include <bsd/stdlib.h>
2449#endif
2450
2451#ifdef HAVE_LIBRESSL
2452#  if !HAVE_DECL_STRLCPY
2453size_t strlcpy(char *dst, const char *src, size_t siz);
2454#  endif
2455#  if !HAVE_DECL_STRLCAT
2456size_t strlcat(char *dst, const char *src, size_t siz);
2457#  endif
2458#  if !HAVE_DECL_ARC4RANDOM && defined(HAVE_ARC4RANDOM)
2459uint32_t arc4random(void);
2460#  endif
2461#  if !HAVE_DECL_ARC4RANDOM_UNIFORM && defined(HAVE_ARC4RANDOM_UNIFORM)
2462uint32_t arc4random_uniform(uint32_t upper_bound);
2463#  endif
2464#endif /* HAVE_LIBRESSL */
2465#ifndef HAVE_ARC4RANDOM
2466int getentropy(void* buf, size_t len);
2467uint32_t arc4random(void);
2468void arc4random_buf(void* buf, size_t n);
2469void _ARC4_LOCK(void);
2470void _ARC4_UNLOCK(void);
2471void _ARC4_LOCK_DESTROY(void);
2472#endif
2473#ifndef HAVE_ARC4RANDOM_UNIFORM
2474uint32_t arc4random_uniform(uint32_t upper_bound);
2475#endif
2476#ifdef COMPAT_SHA512
2477#ifndef SHA512_DIGEST_LENGTH
2478#define SHA512_BLOCK_LENGTH		128
2479#define SHA512_DIGEST_LENGTH		64
2480#define SHA512_DIGEST_STRING_LENGTH	(SHA512_DIGEST_LENGTH * 2 + 1)
2481typedef struct _SHA512_CTX {
2482	uint64_t	state[8];
2483	uint64_t	bitcount[2];
2484	uint8_t	buffer[SHA512_BLOCK_LENGTH];
2485} SHA512_CTX;
2486#endif /* SHA512_DIGEST_LENGTH */
2487void SHA512_Init(SHA512_CTX*);
2488void SHA512_Update(SHA512_CTX*, void*, size_t);
2489void SHA512_Final(uint8_t[SHA512_DIGEST_LENGTH], SHA512_CTX*);
2490unsigned char *SHA512(void* data, unsigned int data_len, unsigned char *digest);
2491#endif /* COMPAT_SHA512 */
2492
2493
2494
2495#if defined(HAVE_EVENT_H) && !defined(HAVE_EVENT_BASE_ONCE) && !(defined(HAVE_EV_LOOP) || defined(HAVE_EV_DEFAULT_LOOP)) && (defined(HAVE_PTHREAD) || defined(HAVE_SOLARIS_THREADS))
2496   /* using version of libevent that is not threadsafe. */
2497#  define LIBEVENT_SIGNAL_PROBLEM 1
2498#endif
2499
2500#ifndef CHECKED_INET6
2501#  define CHECKED_INET6
2502#  ifdef AF_INET6
2503#    define INET6
2504#  else
2505#    define AF_INET6        28
2506#  endif
2507#endif /* CHECKED_INET6 */
2508
2509#ifndef HAVE_GETADDRINFO
2510struct sockaddr_storage;
2511#include "compat/fake-rfc2553.h"
2512#endif
2513
2514#ifdef UNBOUND_ALLOC_STATS
2515#  define malloc(s) unbound_stat_malloc_log(s, __FILE__, __LINE__, __func__)
2516#  define calloc(n,s) unbound_stat_calloc_log(n, s, __FILE__, __LINE__, __func__)
2517#  define free(p) unbound_stat_free_log(p, __FILE__, __LINE__, __func__)
2518#  define realloc(p,s) unbound_stat_realloc_log(p, s, __FILE__, __LINE__, __func__)
2519#  define strdup(s) unbound_stat_strdup_log(s, __FILE__, __LINE__, __func__)
2520#ifdef HAVE_REALLOCARRAY
2521#  define reallocarray(p,n,s) unbound_stat_reallocarray_log(p, n, s, __FILE__, __LINE__, __func__)
2522#endif
2523void *unbound_stat_malloc(size_t size);
2524void *unbound_stat_calloc(size_t nmemb, size_t size);
2525void unbound_stat_free(void *ptr);
2526void *unbound_stat_realloc(void *ptr, size_t size);
2527void *unbound_stat_malloc_log(size_t size, const char* file, int line,
2528	const char* func);
2529void *unbound_stat_calloc_log(size_t nmemb, size_t size, const char* file,
2530	int line, const char* func);
2531void unbound_stat_free_log(void *ptr, const char* file, int line,
2532	const char* func);
2533void *unbound_stat_realloc_log(void *ptr, size_t size, const char* file,
2534	int line, const char* func);
2535void *unbound_stat_reallocarray_log(void *ptr, size_t nmemb, size_t size,
2536	const char* file, int line, const char* func);
2537char *unbound_stat_strdup_log(const char *s, const char* file, int line,
2538	const char* func);
2539#elif defined(UNBOUND_ALLOC_LITE)
2540#  include "util/alloc.h"
2541#endif /* UNBOUND_ALLOC_LITE and UNBOUND_ALLOC_STATS */
2542
2543/** default port for DNS traffic. */
2544#define UNBOUND_DNS_PORT 53
2545/** default port for DNS over TLS traffic. */
2546#define UNBOUND_DNS_OVER_TLS_PORT 853
2547/** default port for DNS over HTTPS traffic. */
2548#define UNBOUND_DNS_OVER_HTTPS_PORT 443
2549/** default port for DNS over QUIC traffic. */
2550#define UNBOUND_DNS_OVER_QUIC_PORT 853
2551/** default port for unbound control traffic, registered port with IANA,
2552    ub-dns-control  8953/tcp    unbound dns nameserver control */
2553#define UNBOUND_CONTROL_PORT 8953
2554/** the version of unbound-control that this software implements */
2555#define UNBOUND_CONTROL_VERSION 1
2556
2557])
2558
2559dnl if we build from source tree, the man pages need @date@ and @version@
2560dnl if this is a distro tarball, that was already done by makedist.sh
2561AC_SUBST(version, [VERSION_MAJOR.VERSION_MINOR.VERSION_MICRO])
2562AX_BUILD_DATE_EPOCH(date, [[%b %e, %Y]])
2563AC_SUBST(date)
2564
2565AC_CONFIG_FILES([Makefile doc/example.conf doc/libunbound.3 doc/unbound.8 doc/unbound-anchor.8 doc/unbound-checkconf.8 doc/unbound.conf.5 doc/unbound-control.8 doc/unbound-host.1 smallapp/unbound-control-setup.sh dnstap/dnstap_config.h dnscrypt/dnscrypt_config.h contrib/libunbound.pc contrib/unbound.socket contrib/unbound.service contrib/unbound_portable.service])
2566AC_CONFIG_HEADERS([config.h])
2567AC_OUTPUT
2568