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