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