xref: /freebsd/contrib/unbound/configure.ac (revision c9dbb1cc52b063bbd9ab078a7afc89a8696da659)
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)
9
10# must be numbers. ac_defun because of later processing
11m4_define([VERSION_MAJOR],[1])
12m4_define([VERSION_MINOR],[5])
13m4_define([VERSION_MICRO],[4])
14AC_INIT(unbound, m4_defn([VERSION_MAJOR]).m4_defn([VERSION_MINOR]).m4_defn([VERSION_MICRO]), unbound-bugs@nlnetlabs.nl, unbound)
15AC_SUBST(UNBOUND_VERSION_MAJOR, [VERSION_MAJOR])
16AC_SUBST(UNBOUND_VERSION_MINOR, [VERSION_MINOR])
17AC_SUBST(UNBOUND_VERSION_MICRO, [VERSION_MICRO])
18
19LIBUNBOUND_CURRENT=5
20LIBUNBOUND_REVISION=7
21LIBUNBOUND_AGE=3
22# 1.0.0 had 0:12:0
23# 1.0.1 had 0:13:0
24# 1.0.2 had 0:14:0
25# 1.1.0 had 0:15:0
26# 1.1.1 had 0:16:0
27# 1.2.0 had 0:17:0
28# 1.2.1 had 0:18:0
29# 1.3.0 had 1:0:0   # ub_cancel and -export-symbols.
30# 1.3.1 had 1:1:0
31# 1.3.2 had 1:2:0
32# 1.3.3 had 1:3:0
33# 1.3.4 had 1:4:0
34# 1.4.0-snapshots had 1:5:0
35# 1.4.0 had 1:5:0 (not 2:0:0)   # ub_result.why_bogus
36# 1.4.1 had 2:1:0
37# 1.4.2 had 2:2:0
38# 1.4.3 had 2:3:0
39# 1.4.4 had 2:4:0
40# 1.4.5 had 2:5:0
41# 1.4.6 had 2:6:0
42# 1.4.7 had 2:7:0
43# 1.4.8 had 2:8:0
44# 1.4.9 had 2:9:0
45# 1.4.10 had 2:10:0
46# 1.4.11 had 2:11:0
47# 1.4.12 had 2:12:0
48# 1.4.13 had 2:13:0
49# and 1.4.13p1 and 1.4.13.p2
50# 1.4.14 had 2:14:0
51# 1.4.15 had 3:0:1 # adds ub_version()
52# 1.4.16 had 3:1:1
53# 1.4.17 had 3:2:1
54# 1.4.18 had 3:3:1
55# 1.4.19 had 3:4:1
56# 1.4.20 had 4:0:2 # adds libunbound.ttl # but shipped 3:5:1
57# 1.4.21 had 4:1:2
58# 1.4.22 had 4:1:2
59# 1.5.0 had 5:3:3 # adds ub_ctx_add_ta_autr
60# 1.5.1 had 5:3:3
61# 1.5.2 had 5:5:3
62# 1.5.3 had 5:6:3
63# 1.5.4 had 5:7:3
64
65#   Current  -- the number of the binary API that we're implementing
66#   Revision -- which iteration of the implementation of the binary
67#               API are we supplying?
68#   Age      -- How many previous binary API versions do we also
69#               support?
70#
71# If we release a new version that does not change the binary API,
72# increment Revision.
73#
74# If we release a new version that changes the binary API, but does
75# not break programs compiled against the old binary API, increment
76# Current and Age.  Set Revision to 0, since this is the first
77# implementation of the new API.
78#
79# Otherwise, we're changing the binary API and breaking bakward
80# compatibility with old binaries.  Increment Current.  Set Age to 0,
81# since we're backward compatible with no previous APIs.  Set Revision
82# to 0 too.
83AC_SUBST(LIBUNBOUND_CURRENT)
84AC_SUBST(LIBUNBOUND_REVISION)
85AC_SUBST(LIBUNBOUND_AGE)
86
87CFLAGS="$CFLAGS"
88AC_AIX
89if test "$ac_cv_header_minix_config_h" = "yes"; then
90	AC_DEFINE(_NETBSD_SOURCE,1, [Enable for compile on Minix])
91fi
92
93dnl
94dnl By default set prefix to /usr/local
95dnl
96case "$prefix" in
97        NONE)
98		prefix="/usr/local"
99        ;;
100esac
101
102# are we on MinGW?
103if uname -s 2>&1 | grep MINGW32 >/dev/null; then on_mingw="yes"
104else
105	if echo $target | grep mingw32 >/dev/null; then on_mingw="yes"
106	else on_mingw="no"; fi
107fi
108
109#
110# Determine configuration file
111# the eval is to evaluate shell expansion twice
112if test $on_mingw = "no"; then
113  ub_conf_file=`eval echo "${sysconfdir}/unbound/unbound.conf"`
114else
115  ub_conf_file="C:\\Program Files\\Unbound\\service.conf"
116fi
117AC_ARG_WITH([conf_file],
118        AC_HELP_STRING([--with-conf-file=path],
119	[Pathname to the Unbound configuration file]),
120	[ub_conf_file="$withval"])
121AC_SUBST(ub_conf_file)
122ACX_ESCAPE_BACKSLASH($ub_conf_file, hdr_config)
123AC_DEFINE_UNQUOTED(CONFIGFILE, ["$hdr_config"], [Pathname to the Unbound configuration file])
124ub_conf_dir=`AS_DIRNAME(["$ub_conf_file"])`
125AC_SUBST(ub_conf_dir)
126
127# Determine run, chroot directory and pidfile locations
128AC_ARG_WITH(run-dir,
129    AC_HELP_STRING([--with-run-dir=path],
130    [set default directory to chdir to (by default dir part of cfg file)]),
131    UNBOUND_RUN_DIR="$withval",
132if test $on_mingw = no; then
133    UNBOUND_RUN_DIR=`dirname "$ub_conf_file"`
134else
135    UNBOUND_RUN_DIR=""
136fi
137)
138AC_SUBST(UNBOUND_RUN_DIR)
139ACX_ESCAPE_BACKSLASH($UNBOUND_RUN_DIR, hdr_run)
140AC_DEFINE_UNQUOTED(RUN_DIR, ["$hdr_run"], [Directory to chdir to])
141
142AC_ARG_WITH(chroot-dir,
143    AC_HELP_STRING([--with-chroot-dir=path],
144    [set default directory to chroot to (by default same as run-dir)]),
145    UNBOUND_CHROOT_DIR="$withval",
146if test $on_mingw = no; then
147    UNBOUND_CHROOT_DIR="$UNBOUND_RUN_DIR"
148else
149    UNBOUND_CHROOT_DIR=""
150fi
151)
152AC_SUBST(UNBOUND_CHROOT_DIR)
153ACX_ESCAPE_BACKSLASH($UNBOUND_CHROOT_DIR, hdr_chroot)
154AC_DEFINE_UNQUOTED(CHROOT_DIR, ["$hdr_chroot"], [Directory to chroot to])
155
156AC_ARG_WITH(share-dir,
157    AC_HELP_STRING([--with-share-dir=path],
158    [set default directory with shared data (by default same as share/unbound)]),
159    UNBOUND_SHARE_DIR="$withval",
160    UNBOUND_SHARE_DIR="$UNBOUND_RUN_DIR")
161AC_SUBST(UNBOUND_SHARE_DIR)
162AC_DEFINE_UNQUOTED(SHARE_DIR, ["$UNBOUND_SHARE_DIR"], [Shared data])
163
164AC_ARG_WITH(pidfile,
165    AC_HELP_STRING([--with-pidfile=filename],
166    [set default pathname to unbound pidfile (default run-dir/unbound.pid)]),
167    UNBOUND_PIDFILE="$withval",
168if test $on_mingw = no; then
169    UNBOUND_PIDFILE="$UNBOUND_RUN_DIR/unbound.pid"
170else
171    UNBOUND_PIDFILE=""
172fi
173)
174AC_SUBST(UNBOUND_PIDFILE)
175ACX_ESCAPE_BACKSLASH($UNBOUND_PIDFILE, hdr_pid)
176AC_DEFINE_UNQUOTED(PIDFILE, ["$hdr_pid"], [default pidfile location])
177
178AC_ARG_WITH(rootkey-file,
179    AC_HELP_STRING([--with-rootkey-file=filename],
180    [set default pathname to root key file (default run-dir/root.key). This file is read and written.]),
181    UNBOUND_ROOTKEY_FILE="$withval",
182if test $on_mingw = no; then
183    UNBOUND_ROOTKEY_FILE="$UNBOUND_RUN_DIR/root.key"
184else
185    UNBOUND_ROOTKEY_FILE="C:\\Program Files\\Unbound\\root.key"
186fi
187)
188AC_SUBST(UNBOUND_ROOTKEY_FILE)
189ACX_ESCAPE_BACKSLASH($UNBOUND_ROOTKEY_FILE, hdr_rkey)
190AC_DEFINE_UNQUOTED(ROOT_ANCHOR_FILE, ["$hdr_rkey"], [default rootkey location])
191
192AC_ARG_WITH(rootcert-file,
193    AC_HELP_STRING([--with-rootcert-file=filename],
194    [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.]),
195    UNBOUND_ROOTCERT_FILE="$withval",
196if test $on_mingw = no; then
197    UNBOUND_ROOTCERT_FILE="$UNBOUND_RUN_DIR/icannbundle.pem"
198else
199    UNBOUND_ROOTCERT_FILE="C:\\Program Files\\Unbound\\icannbundle.pem"
200fi
201)
202AC_SUBST(UNBOUND_ROOTCERT_FILE)
203ACX_ESCAPE_BACKSLASH($UNBOUND_ROOTCERT_FILE, hdr_rpem)
204AC_DEFINE_UNQUOTED(ROOT_CERT_FILE, ["$hdr_rpem"], [default rootcert location])
205
206AC_ARG_WITH(username,
207    AC_HELP_STRING([--with-username=user],
208    [set default user that unbound changes to (default user is unbound)]),
209    UNBOUND_USERNAME="$withval",
210    UNBOUND_USERNAME="unbound")
211AC_SUBST(UNBOUND_USERNAME)
212AC_DEFINE_UNQUOTED(UB_USERNAME, ["$UNBOUND_USERNAME"], [default username])
213
214AC_DEFINE(WINVER, 0x0502, [the version of the windows API enabled])
215ACX_RSRC_VERSION(wnvs)
216AC_DEFINE_UNQUOTED(RSRC_PACKAGE_VERSION, [$wnvs], [version number for resource files])
217
218# Checks for typedefs, structures, and compiler characteristics.
219AC_C_CONST
220AC_LANG_C
221# allow user to override the -g -O2 flags.
222if test "x$CFLAGS" = "x" ; then
223ACX_CHECK_COMPILER_FLAG(g, [CFLAGS="$CFLAGS -g"])
224ACX_CHECK_COMPILER_FLAG(O2, [CFLAGS="$CFLAGS -O2"])
225fi
226AC_PROG_CC
227ACX_DEPFLAG
228ACX_DETERMINE_EXT_FLAGS_UNBOUND
229
230# debug mode flags warnings
231AC_ARG_ENABLE(checking, AC_HELP_STRING([--enable-checking], [Enable warnings, asserts, makefile-dependencies]))
232AC_ARG_ENABLE(debug, AC_HELP_STRING([--enable-debug], [same as enable-checking]))
233if test "$enable_debug" = "yes"; then debug_enabled="$enable_debug";
234else debug_enabled="$enable_checking"; fi
235AC_SUBST(debug_enabled)
236case "$debug_enabled" in
237        yes)
238		ACX_CHECK_COMPILER_FLAG(W, [CFLAGS="$CFLAGS -W"])
239		ACX_CHECK_COMPILER_FLAG(Wall, [CFLAGS="$CFLAGS -Wall"])
240		ACX_CHECK_COMPILER_FLAG(Wextra, [CFLAGS="$CFLAGS -Wextra"])
241		ACX_CHECK_COMPILER_FLAG(Wdeclaration-after-statement, [CFLAGS="$CFLAGS -Wdeclaration-after-statement"])
242		AC_DEFINE([UNBOUND_DEBUG], [], [define this to enable debug checks.])
243		;;
244	no|*)
245		# nothing to do.
246		;;
247esac
248ACX_CHECK_FLTO
249
250AC_C_INLINE
251ACX_CHECK_FORMAT_ATTRIBUTE
252ACX_CHECK_UNUSED_ATTRIBUTE
253
254if test "$srcdir" != "."; then
255	CPPFLAGS="$CPPFLAGS -I$srcdir"
256fi
257
258AC_DEFUN([ACX_YYLEX_DESTROY], [
259	AC_MSG_CHECKING([for yylex_destroy])
260	if echo %% | $LEX -t 2>&1 | grep yylex_destroy >/dev/null 2>&1; then
261		AC_DEFINE(LEX_HAS_YYLEX_DESTROY, 1, [if lex has yylex_destroy])
262		AC_MSG_RESULT(yes)
263	else AC_MSG_RESULT(no); fi
264])
265
266AC_PROG_LEX
267ACX_YYLEX_DESTROY
268AC_PROG_YACC
269AC_CHECK_PROG(doxygen, doxygen, doxygen)
270AC_CHECK_TOOL(STRIP, strip)
271ACX_LIBTOOL_C_ONLY
272
273# Checks for header files.
274AC_CHECK_HEADERS([stdarg.h stdbool.h netinet/in.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],,, [AC_INCLUDES_DEFAULT])
275
276# check for types.
277# Using own tests for int64* because autoconf builtin only give 32bit.
278AC_CHECK_TYPE(int8_t, signed char)
279AC_CHECK_TYPE(int16_t, short)
280AC_CHECK_TYPE(int32_t, int)
281AC_CHECK_TYPE(int64_t, long long)
282AC_CHECK_TYPE(uint8_t, unsigned char)
283AC_CHECK_TYPE(uint16_t, unsigned short)
284AC_CHECK_TYPE(uint32_t, unsigned int)
285AC_CHECK_TYPE(uint64_t, unsigned long long)
286AC_TYPE_SIZE_T
287AC_CHECK_TYPE(ssize_t, int)
288AC_TYPE_UID_T
289AC_TYPE_PID_T
290AC_TYPE_OFF_T
291ACX_TYPE_U_CHAR
292ACX_TYPE_RLIM_T
293ACX_TYPE_SOCKLEN_T
294ACX_TYPE_IN_ADDR_T
295ACX_TYPE_IN_PORT_T
296ACX_CHECK_MEMCMP_SIGNED
297
298AC_CHECK_SIZEOF(time_t,,[
299AC_INCLUDES_DEFAULT
300#ifdef TIME_WITH_SYS_TIME
301# include <sys/time.h>
302# include <time.h>
303#else
304# ifdef HAVE_SYS_TIME_H
305#  include <sys/time.h>
306# else
307#  include <time.h>
308# endif
309#endif
310])
311
312# add option to disable the evil rpath
313ACX_ARG_RPATH
314AC_SUBST(RUNTIME_PATH)
315
316# check to see if libraries are needed for these functions.
317AC_SEARCH_LIBS([inet_pton], [nsl])
318AC_SEARCH_LIBS([socket], [socket])
319
320# check wether strptime also works
321AC_DEFUN([AC_CHECK_STRPTIME_WORKS],
322[AC_REQUIRE([AC_PROG_CC])
323AC_MSG_CHECKING(whether strptime works)
324if test c${cross_compiling} = cno; then
325AC_RUN_IFELSE([AC_LANG_SOURCE([[
326#define _XOPEN_SOURCE 600
327#include <time.h>
328int main(void) { struct tm tm; char *res;
329res = 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);
330if (!res) return 2;
331res = strptime("20070207111842", "%Y%m%d%H%M%S", &tm);
332if (!res) return 1; return 0; }
333]])] , [eval "ac_cv_c_strptime_works=yes"], [eval "ac_cv_c_strptime_works=no"])
334else
335eval "ac_cv_c_strptime_works=maybe"
336fi
337AC_MSG_RESULT($ac_cv_c_strptime_works)
338if test $ac_cv_c_strptime_works = no; then
339AC_LIBOBJ(strptime)
340else
341AC_DEFINE_UNQUOTED([STRPTIME_WORKS], 1, [use default strptime.])
342fi
343])dnl
344
345# check some functions of the OS before linking libs (while still runnable).
346AC_FUNC_CHOWN
347AC_FUNC_FORK
348AC_TYPE_SIGNAL
349AC_FUNC_FSEEKO
350ACX_SYS_LARGEFILE
351ACX_CHECK_NONBLOCKING_BROKEN
352ACX_MKDIR_ONE_ARG
353AC_CHECK_FUNCS([strptime],[AC_CHECK_STRPTIME_WORKS],[AC_LIBOBJ([strptime])])
354
355# set memory allocation checking if requested
356AC_ARG_ENABLE(alloc-checks, AC_HELP_STRING([--enable-alloc-checks],
357	[ enable to memory allocation statistics, for debug purposes ]),
358	, )
359AC_ARG_ENABLE(alloc-lite, AC_HELP_STRING([--enable-alloc-lite],
360	[ enable for lightweight alloc assertions, for debug purposes ]),
361	, )
362AC_ARG_ENABLE(alloc-nonregional, AC_HELP_STRING([--enable-alloc-nonregional],
363	[ enable nonregional allocs, slow but exposes regional allocations to other memory purifiers, for debug purposes ]),
364	, )
365if test x_$enable_alloc_nonregional = x_yes; then
366	AC_DEFINE(UNBOUND_ALLOC_NONREGIONAL, 1, [use malloc not regions, for debug use])
367fi
368if test x_$enable_alloc_checks = x_yes; then
369	AC_DEFINE(UNBOUND_ALLOC_STATS, 1, [use statistics for allocs and frees, for debug use])
370else
371	if test x_$enable_alloc_lite = x_yes; then
372		AC_DEFINE(UNBOUND_ALLOC_LITE, 1, [use to enable lightweight alloc assertions, for debug use])
373	else
374		ACX_FUNC_MALLOC([unbound])
375	fi
376fi
377
378# check windows threads (we use them, not pthreads, on windows).
379if test "$on_mingw" = "yes"; then
380# check windows threads
381	AC_CHECK_HEADERS([windows.h],,, [AC_INCLUDES_DEFAULT])
382	AC_MSG_CHECKING([for CreateThread])
383	AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
384#ifdef HAVE_WINDOWS_H
385#include <windows.h>
386#endif
387], [
388	HANDLE t = CreateThread(NULL, 0, NULL, NULL, 0, NULL);
389])],
390	AC_MSG_RESULT(yes)
391	AC_DEFINE(HAVE_WINDOWS_THREADS, 1, [Using Windows threads])
392,
393	AC_MSG_RESULT(no)
394)
395
396else
397# not on mingw, check thread libraries.
398
399# check for thread library.
400# check this first, so that the pthread lib does not get linked in via
401# libssl or libpython, and thus distorts the tests, and we end up using
402# the non-threadsafe C libraries.
403AC_ARG_WITH(pthreads, AC_HELP_STRING([--with-pthreads],
404 [use pthreads library, or --without-pthreads to disable threading support.]),
405 [ ],[ withval="yes" ])
406ub_have_pthreads=no
407if test x_$withval != x_no; then
408	AX_PTHREAD([
409		AC_DEFINE(HAVE_PTHREAD,1,[Define if you have POSIX threads libraries and header files.])
410		LIBS="$PTHREAD_LIBS $LIBS"
411		CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
412		CC="$PTHREAD_CC"
413		ub_have_pthreads=yes
414		AC_CHECK_TYPES([pthread_spinlock_t, pthread_rwlock_t],,,[#include <pthread.h>])
415		])
416fi
417
418# check solaris thread library
419AC_ARG_WITH(solaris-threads, AC_HELP_STRING([--with-solaris-threads],
420	[use solaris native thread library.]), [ ],[ withval="no" ])
421ub_have_sol_threads=no
422if test x_$withval != x_no; then
423	if test x_$ub_have_pthreads != x_no; then
424	    AC_WARN([Have pthreads already, ignoring --with-solaris-threads])
425	else
426	AC_SEARCH_LIBS(thr_create, [thread],
427	[
428    		AC_DEFINE(HAVE_SOLARIS_THREADS, 1, [Using Solaris threads])
429
430		ACX_CHECK_COMPILER_FLAG(mt, [CFLAGS="$CFLAGS -mt"],
431			[CFLAGS="$CFLAGS -D_REENTRANT"])
432		ub_have_sol_threads=yes
433	] , [
434		AC_ERROR([no solaris threads found.])
435	])
436	fi
437fi
438
439fi # end of non-mingw check of thread libraries
440
441# Check for PyUnbound
442AC_ARG_WITH(pyunbound,
443   AC_HELP_STRING([--with-pyunbound],
444   [build PyUnbound, or --without-pyunbound to skip it. (default=no)]),
445   [], [ withval="no" ])
446
447ub_test_python=no
448ub_with_pyunbound=no
449if test x_$withval != x_no; then
450   ub_with_pyunbound=yes
451   ub_test_python=yes
452fi
453
454# Check for Python module
455AC_ARG_WITH(pythonmodule,
456   AC_HELP_STRING([--with-pythonmodule],
457   [build Python module, or --without-pythonmodule to disable script engine. (default=no)]),
458   [], [ withval="no" ])
459
460ub_with_pythonmod=no
461if test x_$withval != x_no; then
462   ub_with_pythonmod=yes
463   ub_test_python=yes
464fi
465
466# Check for Python & SWIG only on PyUnbound or PyModule
467if test x_$ub_test_python != x_no; then
468
469   # Check for Python
470   ub_have_python=no
471   ac_save_LIBS="$LIBS" dnl otherwise AC_PYTHON_DEVEL thrashes $LIBS
472   AC_PYTHON_DEVEL
473   if test ! -z "$PYTHON_VERSION"; then
474	if test `$PYTHON -c "print('$PYTHON_VERSION' >= '2.4.0')"` = "False"; then
475		AC_ERROR([Python version >= 2.4.0 is required])
476	fi
477
478      PY_MAJOR_VERSION="`$PYTHON -c "import sys; print(sys.version_info.major)"`"
479      AC_SUBST(PY_MAJOR_VERSION)
480      # Have Python
481      AC_DEFINE(HAVE_PYTHON,1,[Define if you have Python libraries and header files.])
482      LIBS="$PYTHON_LDFLAGS $LIBS"
483      CPPFLAGS="$CPPFLAGS $PYTHON_CPPFLAGS"
484      ub_have_python=yes
485
486      # Check for SWIG
487      ub_have_swig=no
488      AC_PROG_SWIG
489      AC_MSG_CHECKING(SWIG)
490      if test ! -x "$SWIG"; then
491         AC_ERROR([failed to find swig tool, install it, or do not build Python module and PyUnbound])
492      else
493         AC_DEFINE(HAVE_SWIG, 1, [Define if you have Swig libraries and header files.])
494         AC_SUBST(swig, "$SWIG")
495         AC_MSG_RESULT(present)
496
497         # If have Python & SWIG
498         # Declare PythonMod
499         if test x_$ub_with_pythonmod != x_no; then
500            AC_DEFINE(WITH_PYTHONMODULE, 1, [Define if you want Python module.])
501            WITH_PYTHONMODULE=yes
502            AC_SUBST(WITH_PYTHONMODULE)
503	    PYTHONMOD_OBJ="pythonmod.lo pythonmod_utils.lo"
504	    AC_SUBST(PYTHONMOD_OBJ)
505	    PYTHONMOD_HEADER='$(srcdir)/pythonmod/pythonmod.h'
506	    AC_SUBST(PYTHONMOD_HEADER)
507	    PYTHONMOD_INSTALL=pythonmod-install
508	    AC_SUBST(PYTHONMOD_INSTALL)
509	    PYTHONMOD_UNINSTALL=pythonmod-uninstall
510	    AC_SUBST(PYTHONMOD_UNINSTALL)
511         fi
512
513         # Declare PyUnbound
514         if test x_$ub_with_pyunbound != x_no; then
515            AC_DEFINE(WITH_PYUNBOUND, 1, [Define if you want PyUnbound.])
516            WITH_PYUNBOUND=yes
517            AC_SUBST(WITH_PYUNBOUND)
518	    PYUNBOUND_OBJ="libunbound_wrap.lo"
519	    AC_SUBST(PYUNBOUND_OBJ)
520	    PYUNBOUND_TARGET="_unbound.la"
521	    AC_SUBST(PYUNBOUND_TARGET)
522	    PYUNBOUND_INSTALL=pyunbound-install
523	    AC_SUBST(PYUNBOUND_INSTALL)
524	    PYUNBOUND_UNINSTALL=pyunbound-uninstall
525	    AC_SUBST(PYUNBOUND_UNINSTALL)
526         fi
527      fi
528   else
529      AC_MSG_RESULT([*** Python libraries not found, won't build PythonMod or PyUnbound ***])
530      ub_with_pyunbound=no
531      ub_with_pythonmod=no
532   fi
533fi
534
535if test "`uname`" = "NetBSD"; then
536	NETBSD_LINTFLAGS='"-D__RENAME(x)=" -D_NETINET_IN_H_'
537	AC_SUBST(NETBSD_LINTFLAGS)
538fi
539CONFIG_DATE=`date +%Y%m%d`
540AC_SUBST(CONFIG_DATE)
541
542# Checks for libraries.
543
544# libnss
545USE_NSS="no"
546AC_ARG_WITH([nss], AC_HELP_STRING([--with-nss=path],
547	[use libnss instead of openssl, installed at path.]),
548	[
549	USE_NSS="yes"
550	AC_DEFINE(HAVE_NSS, 1, [Use libnss for crypto])
551	if test "$withval" != "" -a "$withval" != "yes"; then
552		CPPFLAGS="$CPPFLAGS -I$withval/include/nss3"
553		LDFLAGS="$LDFLAGS -L$withval/lib"
554		ACX_RUNTIME_PATH_ADD([$withval/lib])
555		CPPFLAGS="-I$withval/include/nspr4 $CPPFLAGS"
556	else
557		CPPFLAGS="$CPPFLAGS -I/usr/include/nss3"
558		CPPFLAGS="-I/usr/include/nspr4 $CPPFLAGS"
559	fi
560        LIBS="$LIBS -lnss3 -lnspr4"
561	]
562)
563
564# openssl
565if test $USE_NSS = "no"; then
566ACX_WITH_SSL
567ACX_LIB_SSL
568AC_MSG_CHECKING([for LibreSSL])
569if grep OPENSSL_VERSION_TEXT $ssldir/include/openssl/opensslv.h | grep "LibreSSL" >/dev/null; then
570	AC_MSG_RESULT([yes])
571	AC_DEFINE([HAVE_LIBRESSL], [1], [Define if we have LibreSSL])
572	# libressl provides these compat functions, but they may also be
573	# declared by the OS in libc.  See if they have been declared.
574	AC_CHECK_DECLS([strlcpy,strlcat,arc4random,arc4random_uniform,reallocarray])
575else
576	AC_MSG_RESULT([no])
577fi
578AC_CHECK_HEADERS([openssl/conf.h],,, [AC_INCLUDES_DEFAULT])
579AC_CHECK_HEADERS([openssl/engine.h],,, [AC_INCLUDES_DEFAULT])
580AC_CHECK_FUNCS([OPENSSL_config EVP_sha1 EVP_sha256 EVP_sha512 FIPS_mode])
581AC_CHECK_DECLS([SSL_COMP_get_compression_methods,sk_SSL_COMP_pop_free], [], [], [
582AC_INCLUDES_DEFAULT
583#ifdef HAVE_OPENSSL_ERR_H
584#include <openssl/err.h>
585#endif
586
587#ifdef HAVE_OPENSSL_RAND_H
588#include <openssl/rand.h>
589#endif
590
591#ifdef HAVE_OPENSSL_CONF_H
592#include <openssl/conf.h>
593#endif
594
595#ifdef HAVE_OPENSSL_ENGINE_H
596#include <openssl/engine.h>
597#endif
598#include <openssl/ssl.h>
599#include <openssl/evp.h>
600])
601fi
602
603
604AC_ARG_ENABLE(sha2, AC_HELP_STRING([--disable-sha2], [Disable SHA256 and SHA512 RRSIG support]))
605case "$enable_sha2" in
606	no)
607	;;
608	yes|*)
609	AC_DEFINE([USE_SHA2], [1], [Define this to enable SHA256 and SHA512 support.])
610	;;
611esac
612
613# check wether gost also works
614AC_DEFUN([AC_CHECK_GOST_WORKS],
615[AC_REQUIRE([AC_PROG_CC])
616AC_MSG_CHECKING([if GOST works])
617if test c${cross_compiling} = cno; then
618BAKCFLAGS="$CFLAGS"
619if test -n "$ssldir"; then
620	CFLAGS="$CFLAGS -Wl,-rpath,$ssldir/lib"
621fi
622AC_RUN_IFELSE([AC_LANG_SOURCE([[
623#include <string.h>
624#include <openssl/ssl.h>
625#include <openssl/evp.h>
626#include <openssl/engine.h>
627#include <openssl/conf.h>
628/* routine to load gost (from sldns) */
629int load_gost_id(void)
630{
631	static int gost_id = 0;
632	const EVP_PKEY_ASN1_METHOD* meth;
633	ENGINE* e;
634
635	if(gost_id) return gost_id;
636
637	/* see if configuration loaded gost implementation from other engine*/
638	meth = EVP_PKEY_asn1_find_str(NULL, "gost2001", -1);
639	if(meth) {
640		EVP_PKEY_asn1_get0_info(&gost_id, NULL, NULL, NULL, NULL, meth);
641		return gost_id;
642	}
643
644	/* see if engine can be loaded already */
645	e = ENGINE_by_id("gost");
646	if(!e) {
647		/* load it ourself, in case statically linked */
648		ENGINE_load_builtin_engines();
649		ENGINE_load_dynamic();
650		e = ENGINE_by_id("gost");
651	}
652	if(!e) {
653		/* no gost engine in openssl */
654		return 0;
655	}
656	if(!ENGINE_set_default(e, ENGINE_METHOD_ALL)) {
657		ENGINE_finish(e);
658		ENGINE_free(e);
659		return 0;
660	}
661
662	meth = EVP_PKEY_asn1_find_str(&e, "gost2001", -1);
663	if(!meth) {
664		/* algo not found */
665		ENGINE_finish(e);
666		ENGINE_free(e);
667		return 0;
668	}
669	EVP_PKEY_asn1_get0_info(&gost_id, NULL, NULL, NULL, NULL, meth);
670	return gost_id;
671}
672int main(void) {
673	EVP_MD_CTX* ctx;
674	const EVP_MD* md;
675	unsigned char digest[64]; /* its a 256-bit digest, so uses 32 bytes */
676	const char* str = "Hello world";
677	const unsigned char check[] = {
678		0x40 , 0xed , 0xf8 , 0x56 , 0x5a , 0xc5 , 0x36 , 0xe1 ,
679		0x33 , 0x7c , 0x7e , 0x87 , 0x62 , 0x1c , 0x42 , 0xe0 ,
680		0x17 , 0x1b , 0x5e , 0xce , 0xa8 , 0x46 , 0x65 , 0x4d ,
681		0x8d , 0x3e , 0x22 , 0x9b , 0xe1 , 0x30 , 0x19 , 0x9d
682	};
683	OPENSSL_config(NULL);
684	(void)load_gost_id();
685	md = EVP_get_digestbyname("md_gost94");
686	if(!md) return 1;
687	memset(digest, 0, sizeof(digest));
688	ctx = EVP_MD_CTX_create();
689	if(!ctx) return 2;
690	if(!EVP_DigestInit_ex(ctx, md, NULL)) return 3;
691	if(!EVP_DigestUpdate(ctx, str, 10)) return 4;
692	if(!EVP_DigestFinal_ex(ctx, digest, NULL)) return 5;
693	/* uncomment to see the hash calculated.
694		{int i;
695		for(i=0; i<32; i++)
696			printf(" %2.2x", (int)digest[i]);
697		printf("\n");}
698	*/
699	if(memcmp(digest, check, sizeof(check)) != 0)
700		return 6;
701	return 0;
702}
703]])] , [eval "ac_cv_c_gost_works=yes"], [eval "ac_cv_c_gost_works=no"])
704CFLAGS="$BAKCFLAGS"
705else
706eval "ac_cv_c_gost_works=maybe"
707fi
708AC_MSG_RESULT($ac_cv_c_gost_works)
709])dnl
710
711AC_ARG_ENABLE(gost, AC_HELP_STRING([--disable-gost], [Disable GOST support]))
712use_gost="no"
713if test $USE_NSS = "no"; then
714case "$enable_gost" in
715	no)
716	;;
717	*)
718	AC_CHECK_FUNC(EVP_PKEY_set_type_str, [:],[AC_MSG_ERROR([OpenSSL 1.0.0 is needed for GOST support])])
719	AC_CHECK_FUNC(EC_KEY_new, [], [AC_MSG_ERROR([OpenSSL does not support ECC, needed for GOST support])])
720	AC_CHECK_GOST_WORKS
721	if test "$ac_cv_c_gost_works" != no; then
722		use_gost="yes"
723		AC_DEFINE([USE_GOST], [1], [Define this to enable GOST support.])
724	fi
725	;;
726esac
727fi dnl !USE_NSS
728
729AC_ARG_ENABLE(ecdsa, AC_HELP_STRING([--disable-ecdsa], [Disable ECDSA support]))
730use_ecdsa="no"
731case "$enable_ecdsa" in
732    no)
733      ;;
734    *)
735      if test $USE_NSS = "no"; then
736	      AC_CHECK_FUNC(ECDSA_sign, [], [AC_MSG_ERROR([OpenSSL does not support ECDSA: please upgrade or rerun with --disable-ecdsa])])
737	      AC_CHECK_FUNC(SHA384_Init, [], [AC_MSG_ERROR([OpenSSL does not support SHA384: please upgrade or rerun with --disable-ecdsa])])
738	      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
739#include <openssl/evp.h>
740	      ])
741	      # see if OPENSSL 1.0.0 or later (has EVP MD and Verify independency)
742	      AC_MSG_CHECKING([if openssl supports SHA2 and ECDSA with EVP])
743	      if grep OPENSSL_VERSION_TEXT $ssldir/include/openssl/opensslv.h | grep "OpenSSL" >/dev/null; then
744		if grep OPENSSL_VERSION_NUMBER $ssldir/include/openssl/opensslv.h | grep 0x0 >/dev/null; then
745		  AC_MSG_RESULT([no])
746		  AC_DEFINE_UNQUOTED([USE_ECDSA_EVP_WORKAROUND], [1], [Define this to enable an EVP workaround for older openssl])
747		else
748		  AC_MSG_RESULT([yes])
749		fi
750	      else
751		# not OpenSSL, thus likely LibreSSL, which supports it
752		AC_MSG_RESULT([yes])
753	      fi
754      fi
755      # we now know we have ECDSA and the required curves.
756      AC_DEFINE_UNQUOTED([USE_ECDSA], [1], [Define this to enable ECDSA support.])
757      use_ecdsa="yes"
758      ;;
759esac
760
761AC_ARG_ENABLE(event-api, AC_HELP_STRING([--enable-event-api], [Enable (experimental) libevent-based libunbound API installed to unbound-event.h]))
762use_unbound_event="no"
763case "$enable_event_api" in
764    yes)
765      use_unbound_event="yes"
766      ;;
767    *)
768      ;;
769esac
770
771# check for libevent
772AC_ARG_WITH(libevent, AC_HELP_STRING([--with-libevent=pathname],
773    [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.]),
774    [ ],[ withval="no" ])
775if test x_$withval = x_yes -o x_$withval != x_no; then
776        AC_MSG_CHECKING(for libevent)
777        if test x_$withval = x_ -o x_$withval = x_yes; then
778            withval="/usr/local /opt/local /usr/lib /usr/pkg /usr/sfw /usr"
779        fi
780        for dir in $withval; do
781            thedir="$dir"
782            if test -f "$dir/include/event.h" -o -f "$dir/include/event2/event.h"; then
783                found_libevent="yes"
784		dnl assume /usr is in default path.
785		if test "$thedir" != "/usr"; then
786                    CPPFLAGS="$CPPFLAGS -I$thedir/include"
787		fi
788                break;
789            fi
790        done
791        if test x_$found_libevent != x_yes; then
792		if test -f "$dir/event.h" -a \( -f "$dir/libevent.la" -o -f "$dir/libev.la" \) ; then
793			# libevent source directory
794            		AC_MSG_RESULT(found in $thedir)
795                	CPPFLAGS="$CPPFLAGS -I$thedir -I$thedir/include"
796			BAK_LDFLAGS_SET="1"
797			BAK_LDFLAGS="$LDFLAGS"
798			# remove evdns from linking
799			mkdir build >/dev/null 2>&1
800			mkdir build/libevent >/dev/null 2>&1
801			mkdir build/libevent/.libs >/dev/null 2>&1
802			ev_files_o=`ls $thedir/*.o | grep -v evdns\.o | grep -v bufferevent_openssl\.o`
803			ev_files_lo=`ls $thedir/*.lo | grep -v evdns\.lo | grep -v bufferevent_openssl\.lo`
804			ev_files_libso=`ls $thedir/.libs/*.o | grep -v evdns\.o | grep -v bufferevent_openssl\.o`
805			cp $ev_files_o build/libevent
806			cp $ev_files_lo build/libevent
807			cp $ev_files_libso build/libevent/.libs
808            		LATE_LDFLAGS="build/libevent/*.lo -lm"
809			LDFLAGS="build/libevent/*.o $LDFLAGS -lm"
810		else
811            		AC_MSG_ERROR([Cannot find the libevent library in $withval
812You can restart ./configure --with-libevent=no to use a builtin alternative.
813Please note that this alternative is not as capable as libevent when using
814large outgoing port ranges.  ])
815		fi
816        else
817            AC_MSG_RESULT(found in $thedir)
818	    dnl if event2 exists and no event lib in dir itself, use subdir
819	    if test ! -f $thedir/lib/libevent.a -a ! -f $thedir/lib/libevent.so -a -d "$thedir/lib/event2"; then
820		    LDFLAGS="$LDFLAGS -L$thedir/lib/event2"
821		    ACX_RUNTIME_PATH_ADD([$thedir/lib/event2])
822	    else
823		    dnl assume /usr is in default path, do not add "".
824		    if test "$thedir" != "/usr" -a "$thedir" != ""; then
825			LDFLAGS="$LDFLAGS -L$thedir/lib"
826			ACX_RUNTIME_PATH_ADD([$thedir/lib])
827		    fi
828	    fi
829        fi
830	# check for library used by libevent after 1.3c
831	AC_SEARCH_LIBS([clock_gettime], [rt])
832
833	# is the event.h header libev or libevent?
834	AC_CHECK_HEADERS([event.h],,, [AC_INCLUDES_DEFAULT])
835	AC_CHECK_DECL(EV_VERSION_MAJOR, [
836		AC_SEARCH_LIBS(event_set, [ev])
837	],[
838		AC_SEARCH_LIBS(event_set, [event])
839	],[AC_INCLUDES_DEFAULT
840#include <event.h>
841	])
842	AC_CHECK_FUNCS([event_base_free]) # only in libevent 1.2 and later
843	AC_CHECK_FUNCS([event_base_once]) # only in libevent 1.4.1 and later
844	AC_CHECK_FUNCS([event_base_new]) # only in libevent 1.4.1 and later
845	AC_CHECK_FUNCS([event_base_get_method]) # only in libevent 1.4.3 and later
846	AC_CHECK_FUNCS([ev_loop]) # only in libev. (tested on 3.51)
847	AC_CHECK_FUNCS([ev_default_loop]) # only in libev. (tested on 4.00)
848	if test -n "$BAK_LDFLAGS_SET"; then
849		LDFLAGS="$BAK_LDFLAGS"
850	fi
851        if test "$use_unbound_event" = "yes"; then
852		AC_SUBST(UNBOUND_EVENT_INSTALL, [unbound-event-install])
853		AC_SUBST(UNBOUND_EVENT_UNINSTALL, [unbound-event-uninstall])
854	fi
855else
856	AC_DEFINE(USE_MINI_EVENT, 1, [Define if you want to use internal select based events])
857fi
858
859# check for libexpat
860AC_ARG_WITH(libexpat, AC_HELP_STRING([--with-libexpat=path],
861    [specify explicit path for libexpat.]),
862    [ ],[ withval="/usr/local /opt/local /usr/lib /usr/pkg /usr/sfw /usr" ])
863AC_MSG_CHECKING(for libexpat)
864found_libexpat="no"
865for dir in $withval ; do
866            if test -f "$dir/include/expat.h"; then
867		found_libexpat="yes"
868		dnl assume /usr is in default path.
869		if test "$dir" != "/usr"; then
870                    CPPFLAGS="$CPPFLAGS -I$dir/include"
871		    LDFLAGS="$LDFLAGS -L$dir/lib"
872		fi
873            	AC_MSG_RESULT(found in $dir)
874                break;
875            fi
876done
877if test x_$found_libexpat != x_yes; then
878	AC_ERROR([Could not find libexpat, expat.h])
879fi
880AC_CHECK_HEADERS([expat.h],,, [AC_INCLUDES_DEFAULT])
881
882# set static linking if requested
883AC_SUBST(staticexe)
884staticexe=""
885AC_ARG_ENABLE(static-exe, AC_HELP_STRING([--enable-static-exe],
886	[ enable to compile executables statically against (event) libs, for debug purposes ]),
887	, )
888if test x_$enable_static_exe = x_yes; then
889	staticexe="-static"
890	if test "$on_mingw" = yes; then
891		staticexe="-all-static"
892		# for static crosscompile, include gdi32 and zlib here.
893		if test "`uname`" = "Linux"; then
894			LIBS="$LIBS -lgdi32 -lz"
895		fi
896	fi
897fi
898
899# set lock checking if requested
900AC_ARG_ENABLE(lock_checks, AC_HELP_STRING([--enable-lock-checks],
901	[ enable to check lock and unlock calls, for debug purposes ]),
902	, )
903if test x_$enable_lock_checks = x_yes; then
904	AC_DEFINE(ENABLE_LOCK_CHECKS, 1, [Define if you want to use debug lock checking (slow).])
905	CHECKLOCK_OBJ="checklocks.lo"
906	AC_SUBST(CHECKLOCK_OBJ)
907fi
908
909ACX_CHECK_GETADDRINFO_WITH_INCLUDES
910if test "$USE_WINSOCK" = 1; then
911	AC_DEFINE(UB_ON_WINDOWS, 1, [Use win32 resources and API])
912	AC_CHECK_HEADERS([iphlpapi.h],,, [AC_INCLUDES_DEFAULT
913#include <windows.h>
914	])
915	AC_CHECK_TOOL(WINDRES, windres)
916	LIBS="$LIBS -liphlpapi"
917	WINAPPS="unbound-service-install.exe unbound-service-remove.exe anchor-update.exe"
918	AC_SUBST(WINAPPS)
919	WIN_DAEMON_SRC="winrc/win_svc.c winrc/w_inst.c"
920	AC_SUBST(WIN_DAEMON_SRC)
921	WIN_DAEMON_OBJ="win_svc.lo w_inst.lo"
922	AC_SUBST(WIN_DAEMON_OBJ)
923	WIN_DAEMON_OBJ_LINK="rsrc_unbound.o"
924	AC_SUBST(WIN_DAEMON_OBJ_LINK)
925	WIN_HOST_OBJ_LINK="rsrc_unbound_host.o"
926	AC_SUBST(WIN_HOST_OBJ_LINK)
927	WIN_UBANCHOR_OBJ_LINK="rsrc_unbound_anchor.o log.lo locks.lo"
928	AC_SUBST(WIN_UBANCHOR_OBJ_LINK)
929	WIN_CONTROL_OBJ_LINK="rsrc_unbound_control.o"
930	AC_SUBST(WIN_CONTROL_OBJ_LINK)
931	WIN_CHECKCONF_OBJ_LINK="rsrc_unbound_checkconf.o"
932	AC_SUBST(WIN_CHECKCONF_OBJ_LINK)
933fi
934if test $ac_cv_func_getaddrinfo = no; then
935	AC_LIBOBJ([fake-rfc2553])
936fi
937# check after getaddrinfo for its libraries
938ACX_FUNC_IOCTLSOCKET
939
940# see if daemon(3) exists, and if it is deprecated.
941AC_CHECK_FUNCS([daemon])
942if test $ac_cv_func_daemon = yes; then
943	ACX_FUNC_DEPRECATED([daemon], [(void)daemon(0, 0);], [
944#include <stdlib.h>
945])
946fi
947
948AC_CHECK_MEMBERS([struct sockaddr_un.sun_len],,,[
949AC_INCLUDES_DEFAULT
950#ifdef HAVE_SYS_UN_H
951#include <sys/un.h>
952#endif
953])
954AC_CHECK_MEMBERS([struct in_pktinfo.ipi_spec_dst],,,[
955AC_INCLUDES_DEFAULT
956#if HAVE_SYS_PARAM_H
957#include <sys/param.h>
958#endif
959
960#ifdef HAVE_SYS_SOCKET_H
961#include <sys/socket.h>
962#endif
963
964#ifdef HAVE_SYS_UIO_H
965#include <sys/uio.h>
966#endif
967
968#ifdef HAVE_NETINET_IN_H
969#include <netinet/in.h>
970#endif
971
972#ifdef HAVE_ARPA_INET_H
973#include <arpa/inet.h>
974#endif
975
976#ifdef HAVE_WINSOCK2_H
977#include <winsock2.h>
978#endif
979
980#ifdef HAVE_WS2TCPIP_H
981#include <ws2tcpip.h>
982#endif
983])
984AC_SEARCH_LIBS([setusercontext], [util])
985AC_CHECK_FUNCS([tzset sigprocmask fcntl getpwnam getrlimit setrlimit setsid sbrk chroot kill chown sleep usleep random srandom recvmsg sendmsg writev socketpair glob initgroups strftime localtime_r setusercontext _beginthreadex endservent endprotoent])
986AC_CHECK_FUNCS([setresuid],,[AC_CHECK_FUNCS([setreuid])])
987AC_CHECK_FUNCS([setresgid],,[AC_CHECK_FUNCS([setregid])])
988
989# check if setreuid en setregid fail, on MacOSX10.4(darwin8).
990if echo $build_os | grep darwin8 > /dev/null; then
991	AC_DEFINE(DARWIN_BROKEN_SETREUID, 1, [Define this if on macOSX10.4-darwin8 and setreuid and setregid do not work])
992fi
993AC_REPLACE_FUNCS(inet_aton)
994AC_REPLACE_FUNCS(inet_pton)
995AC_REPLACE_FUNCS(inet_ntop)
996AC_REPLACE_FUNCS(snprintf)
997AC_REPLACE_FUNCS(strlcat)
998AC_REPLACE_FUNCS(strlcpy)
999AC_REPLACE_FUNCS(memmove)
1000AC_REPLACE_FUNCS(gmtime_r)
1001dnl without CTIME, ARC4-functions and without reallocarray.
1002LIBOBJ_WITHOUT_CTIMEARC4="$LIBOBJS"
1003AC_SUBST(LIBOBJ_WITHOUT_CTIMEARC4)
1004AC_REPLACE_FUNCS(reallocarray)
1005if test "$USE_NSS" = "no"; then
1006	AC_REPLACE_FUNCS(arc4random)
1007	AC_REPLACE_FUNCS(arc4random_uniform)
1008	if test "$ac_cv_func_arc4random" = "no"; then
1009		AC_LIBOBJ(explicit_bzero)
1010		AC_LIBOBJ(arc4_lock)
1011		AC_CHECK_FUNCS([getentropy],,[
1012		    if test "$USE_WINSOCK" = 1; then
1013			AC_LIBOBJ(getentropy_win)
1014		    else
1015			case `uname` in
1016			Darwin)
1017				AC_LIBOBJ(getentropy_osx)
1018			;;
1019			SunOS)
1020				AC_LIBOBJ(getentropy_solaris)
1021				AC_CHECK_HEADERS([sys/sha2.h],, [
1022					AC_CHECK_FUNCS([SHA512_Update],,[
1023						AC_LIBOBJ(sha512)
1024					])
1025				], [AC_INCLUDES_DEFAULT])
1026				if test "$ac_cv_header_sys_sha2_h" = "yes"; then
1027					# this lib needed for sha2 on solaris
1028					LIBS="$LIBS -lmd"
1029				fi
1030				AC_SEARCH_LIBS([clock_gettime], [rt])
1031			;;
1032			Linux|*)
1033				AC_LIBOBJ(getentropy_linux)
1034				AC_CHECK_FUNCS([SHA512_Update],,[
1035					AC_DEFINE([COMPAT_SHA512], [1], [Do sha512 definitions in config.h])
1036					AC_LIBOBJ(sha512)
1037				])
1038				AC_CHECK_HEADERS([sys/sysctl.h],,, [AC_INCLUDES_DEFAULT])
1039				AC_CHECK_FUNCS([getauxval])
1040				AC_SEARCH_LIBS([clock_gettime], [rt])
1041			;;
1042			esac
1043		    fi
1044		])
1045	fi
1046fi
1047LIBOBJ_WITHOUT_CTIME="$LIBOBJS"
1048AC_SUBST(LIBOBJ_WITHOUT_CTIME)
1049AC_REPLACE_FUNCS(ctime_r)
1050
1051AC_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]))
1052case "$enable_allsymbols" in
1053	yes)
1054	COMMON_OBJ_ALL_SYMBOLS=""
1055	UBSYMS=""
1056	EXTRALINK="-L. -L.libs -lunbound"
1057	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])
1058	;;
1059	no|*)
1060	COMMON_OBJ_ALL_SYMBOLS='$(COMMON_OBJ)'
1061	UBSYMS='-export-symbols $(srcdir)/libunbound/ubsyms.def'
1062	EXTRALINK=""
1063	;;
1064esac
1065AC_SUBST(COMMON_OBJ_ALL_SYMBOLS)
1066AC_SUBST(EXTRALINK)
1067AC_SUBST(UBSYMS)
1068if test x_$enable_lock_checks = x_yes; then
1069	UBSYMS="-export-symbols clubsyms.def"
1070	cp ${srcdir}/libunbound/ubsyms.def clubsyms.def
1071	echo lock_protect >> clubsyms.def
1072	echo lock_unprotect >> clubsyms.def
1073	echo lock_get_mem >> clubsyms.def
1074	echo checklock_start >> clubsyms.def
1075	echo checklock_stop >> clubsyms.def
1076	echo checklock_lock >> clubsyms.def
1077	echo checklock_unlock >> clubsyms.def
1078	echo checklock_init >> clubsyms.def
1079	echo checklock_thrcreate >> clubsyms.def
1080	echo checklock_thrjoin >> clubsyms.def
1081fi
1082
1083# check for dnstap if requested
1084dt_DNSTAP([$UNBOUND_RUN_DIR/dnstap.sock],
1085    [
1086        AC_DEFINE([USE_DNSTAP], [1], [Define to 1 to enable dnstap support])
1087        AC_SUBST([ENABLE_DNSTAP], [1])
1088
1089        AC_SUBST([opt_dnstap_socket_path])
1090        ACX_ESCAPE_BACKSLASH($opt_dnstap_socket_path, hdr_dnstap_socket_path)
1091        AC_DEFINE_UNQUOTED(DNSTAP_SOCKET_PATH,
1092            ["$hdr_dnstap_socket_path"], [default dnstap socket path])
1093
1094        AC_SUBST([DNSTAP_SRC], ["dnstap/dnstap.c dnstap/dnstap.pb-c.c"])
1095        AC_SUBST([DNSTAP_OBJ], ["dnstap.lo dnstap.pb-c.lo"])
1096    ],
1097    [
1098        AC_SUBST([ENABLE_DNSTAP], [0])
1099    ]
1100)
1101
1102AC_MSG_CHECKING([if ${MAKE:-make} supports $< with implicit rule in scope])
1103# on openBSD, the implicit rule make $< work.
1104# on Solaris, it does not work ($? is changed sources, $^ lists dependencies).
1105# gmake works.
1106cat >conftest.make <<EOF
1107all:	conftest.lo
1108
1109conftest.lo foo.lo bla.lo:
1110	if test -f "\$<"; then touch \$@; fi
1111
1112.SUFFIXES: .lo
1113.c.lo:
1114	if test -f "\$<"; then touch \$@; fi
1115
1116conftest.lo:        conftest.dir/conftest.c
1117EOF
1118mkdir conftest.dir
1119touch conftest.dir/conftest.c
1120rm -f conftest.lo conftest.c
1121${MAKE:-make} -f conftest.make >/dev/null
1122rm -f conftest.make conftest.c conftest.dir/conftest.c
1123rm -rf conftest.dir
1124if test ! -f conftest.lo; then
1125	AC_MSG_RESULT(no)
1126	SOURCEDETERMINE='echo "$^" | awk "-F " "{print \$$1;}" > .source'
1127	SOURCEFILE='`cat .source`'
1128else
1129	AC_MSG_RESULT(yes)
1130	SOURCEDETERMINE=':'
1131	SOURCEFILE='$<'
1132fi
1133rm -f conftest.lo
1134AC_SUBST(SOURCEDETERMINE)
1135AC_SUBST(SOURCEFILE)
1136
1137# see if we want to build the library or everything
1138ALLTARGET="alltargets"
1139INSTALLTARGET="install-all"
1140AC_ARG_WITH(libunbound-only, AC_HELP_STRING([--with-libunbound-only],
1141	[do not build daemon and tool programs]),
1142	[
1143	if test "$withval" = "yes"; then
1144		ALLTARGET="lib"
1145		INSTALLTARGET="install-lib"
1146	fi
1147])
1148AC_SUBST(ALLTARGET)
1149AC_SUBST(INSTALLTARGET)
1150
1151ACX_STRIP_EXT_FLAGS
1152LDFLAGS="$LATE_LDFLAGS $LDFLAGS"
1153
1154AC_DEFINE_UNQUOTED([MAXSYSLOGMSGLEN], [10240], [Define to the maximum message length to pass to syslog.])
1155
1156AH_BOTTOM(
1157dnl this must be first AH_CONFIG, to define the flags before any includes.
1158AHX_CONFIG_EXT_FLAGS
1159
1160dnl includes
1161[
1162#ifndef UNBOUND_DEBUG
1163#  define NDEBUG
1164#endif
1165
1166/** Use small-ldns codebase */
1167#define USE_SLDNS 1
1168#ifdef HAVE_SSL
1169#  define LDNS_BUILD_CONFIG_HAVE_SSL 1
1170#endif
1171
1172#include <stdio.h>
1173#include <string.h>
1174#include <unistd.h>
1175#include <assert.h>
1176
1177#if STDC_HEADERS
1178#include <stdlib.h>
1179#include <stddef.h>
1180#endif
1181
1182#ifdef HAVE_STDARG_H
1183#include <stdarg.h>
1184#endif
1185
1186#ifdef HAVE_STDINT_H
1187#include <stdint.h>
1188#endif
1189
1190#include <errno.h>
1191
1192#if HAVE_SYS_PARAM_H
1193#include <sys/param.h>
1194#endif
1195
1196#ifdef HAVE_SYS_SOCKET_H
1197#include <sys/socket.h>
1198#endif
1199
1200#ifdef HAVE_SYS_UIO_H
1201#include <sys/uio.h>
1202#endif
1203
1204#ifdef HAVE_NETINET_IN_H
1205#include <netinet/in.h>
1206#endif
1207
1208#ifdef HAVE_ARPA_INET_H
1209#include <arpa/inet.h>
1210#endif
1211
1212#ifdef HAVE_WINSOCK2_H
1213#include <winsock2.h>
1214#endif
1215
1216#ifdef HAVE_WS2TCPIP_H
1217#include <ws2tcpip.h>
1218#endif
1219
1220#ifndef USE_WINSOCK
1221#define ARG_LL "%ll"
1222#else
1223#define ARG_LL "%I64"
1224#endif
1225
1226#ifndef AF_LOCAL
1227#define AF_LOCAL AF_UNIX
1228#endif
1229]
1230
1231AHX_CONFIG_FORMAT_ATTRIBUTE
1232AHX_CONFIG_UNUSED_ATTRIBUTE
1233AHX_CONFIG_FSEEKO
1234AHX_CONFIG_MAXHOSTNAMELEN
1235AHX_CONFIG_SNPRINTF(unbound)
1236AHX_CONFIG_INET_PTON(unbound)
1237AHX_CONFIG_INET_NTOP(unbound)
1238AHX_CONFIG_INET_ATON(unbound)
1239AHX_CONFIG_MEMMOVE(unbound)
1240AHX_CONFIG_STRLCAT(unbound)
1241AHX_CONFIG_STRLCPY(unbound)
1242AHX_CONFIG_GMTIME_R(unbound)
1243AHX_CONFIG_REALLOCARRAY(unbound)
1244AHX_CONFIG_W32_SLEEP
1245AHX_CONFIG_W32_USLEEP
1246AHX_CONFIG_W32_RANDOM
1247AHX_CONFIG_W32_SRANDOM
1248AHX_CONFIG_W32_FD_SET_T
1249AHX_CONFIG_IPV6_MIN_MTU
1250AHX_MEMCMP_BROKEN(unbound)
1251
1252[
1253#ifndef HAVE_CTIME_R
1254#define ctime_r unbound_ctime_r
1255char *ctime_r(const time_t *timep, char *buf);
1256#endif
1257
1258#if !defined(HAVE_STRPTIME) || !defined(STRPTIME_WORKS)
1259#define strptime unbound_strptime
1260struct tm;
1261char *strptime(const char *s, const char *format, struct tm *tm);
1262#endif
1263
1264#ifdef HAVE_LIBRESSL
1265#  if !HAVE_DECL_STRLCPY
1266size_t strlcpy(char *dst, const char *src, size_t siz);
1267#  endif
1268#  if !HAVE_DECL_STRLCAT
1269size_t strlcat(char *dst, const char *src, size_t siz);
1270#  endif
1271#  if !HAVE_DECL_ARC4RANDOM && defined(HAVE_ARC4RANDOM)
1272uint32_t arc4random(void);
1273#  endif
1274#  if !HAVE_DECL_ARC4RANDOM_UNIFORM && defined(HAVE_ARC4RANDOM_UNIFORM)
1275uint32_t arc4random_uniform(uint32_t upper_bound);
1276#  endif
1277#  if !HAVE_DECL_REALLOCARRAY
1278void *reallocarray(void *ptr, size_t nmemb, size_t size);
1279#  endif
1280#endif /* HAVE_LIBRESSL */
1281#ifndef HAVE_ARC4RANDOM
1282void explicit_bzero(void* buf, size_t len);
1283int getentropy(void* buf, size_t len);
1284uint32_t arc4random(void);
1285void arc4random_buf(void* buf, size_t n);
1286void _ARC4_LOCK(void);
1287void _ARC4_UNLOCK(void);
1288#endif
1289#ifndef HAVE_ARC4RANDOM_UNIFORM
1290uint32_t arc4random_uniform(uint32_t upper_bound);
1291#endif
1292#ifdef COMPAT_SHA512
1293#ifndef SHA512_DIGEST_LENGTH
1294#define SHA512_BLOCK_LENGTH		128
1295#define SHA512_DIGEST_LENGTH		64
1296#define SHA512_DIGEST_STRING_LENGTH	(SHA512_DIGEST_LENGTH * 2 + 1)
1297typedef struct _SHA512_CTX {
1298	uint64_t	state[8];
1299	uint64_t	bitcount[2];
1300	uint8_t	buffer[SHA512_BLOCK_LENGTH];
1301} SHA512_CTX;
1302#endif /* SHA512_DIGEST_LENGTH */
1303void SHA512_Init(SHA512_CTX*);
1304void SHA512_Update(SHA512_CTX*, void*, size_t);
1305void SHA512_Final(uint8_t[SHA512_DIGEST_LENGTH], SHA512_CTX*);
1306unsigned char *SHA512(void* data, unsigned int data_len, unsigned char *digest);
1307#endif /* COMPAT_SHA512 */
1308
1309
1310
1311#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))
1312   /* using version of libevent that is not threadsafe. */
1313#  define LIBEVENT_SIGNAL_PROBLEM 1
1314#endif
1315
1316#ifndef CHECKED_INET6
1317#  define CHECKED_INET6
1318#  ifdef AF_INET6
1319#    define INET6
1320#  else
1321#    define AF_INET6        28
1322#  endif
1323#endif /* CHECKED_INET6 */
1324
1325#ifndef HAVE_GETADDRINFO
1326struct sockaddr_storage;
1327#include "compat/fake-rfc2553.h"
1328#endif
1329
1330#ifdef UNBOUND_ALLOC_STATS
1331#  define malloc(s) unbound_stat_malloc_log(s, __FILE__, __LINE__, __func__)
1332#  define calloc(n,s) unbound_stat_calloc_log(n, s, __FILE__, __LINE__, __func__)
1333#  define free(p) unbound_stat_free_log(p, __FILE__, __LINE__, __func__)
1334#  define realloc(p,s) unbound_stat_realloc_log(p, s, __FILE__, __LINE__, __func__)
1335void *unbound_stat_malloc(size_t size);
1336void *unbound_stat_calloc(size_t nmemb, size_t size);
1337void unbound_stat_free(void *ptr);
1338void *unbound_stat_realloc(void *ptr, size_t size);
1339void *unbound_stat_malloc_log(size_t size, const char* file, int line,
1340	const char* func);
1341void *unbound_stat_calloc_log(size_t nmemb, size_t size, const char* file,
1342	int line, const char* func);
1343void unbound_stat_free_log(void *ptr, const char* file, int line,
1344	const char* func);
1345void *unbound_stat_realloc_log(void *ptr, size_t size, const char* file,
1346	int line, const char* func);
1347#elif defined(UNBOUND_ALLOC_LITE)
1348#  include "util/alloc.h"
1349#endif /* UNBOUND_ALLOC_LITE and UNBOUND_ALLOC_STATS */
1350
1351/** default port for DNS traffic. */
1352#define UNBOUND_DNS_PORT 53
1353/** default port for unbound control traffic, registered port with IANA,
1354    ub-dns-control  8953/tcp    unbound dns nameserver control */
1355#define UNBOUND_CONTROL_PORT 8953
1356/** the version of unbound-control that this software implements */
1357#define UNBOUND_CONTROL_VERSION 1
1358
1359])
1360
1361dnl if we build from source tree, the man pages need @date@ and @version@
1362dnl if this is a distro tarball, that was already done by makedist.sh
1363AC_SUBST(version, [VERSION_MAJOR.VERSION_MINOR.VERSION_MICRO])
1364AC_SUBST(date, [`date +'%b %e, %Y'`])
1365
1366AC_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])
1367AC_CONFIG_HEADER([config.h])
1368AC_OUTPUT
1369