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