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