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