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