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