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