]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/unbound/configure.ac
Import a new version of NetBSD's mtree.
[FreeBSD/FreeBSD.git] / contrib / unbound / configure.ac
1 #                                               -*- Autoconf -*-
2 # Process this file with autoconf to produce a configure script.
3 AC_PREREQ(2.56)
4 sinclude(acx_nlnetlabs.m4)
5 sinclude(acx_pthread.m4)
6 sinclude(acx_python.m4)
7 sinclude(ac_pkg_swig.m4)
8
9 AC_INIT(unbound, 1.4.20, unbound-bugs@nlnetlabs.nl, unbound)
10
11 LIBUNBOUND_CURRENT=3
12 LIBUNBOUND_REVISION=5
13 LIBUNBOUND_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.
68 AC_SUBST(LIBUNBOUND_CURRENT)
69 AC_SUBST(LIBUNBOUND_REVISION)
70 AC_SUBST(LIBUNBOUND_AGE)
71
72 pretty_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 }
79 pretty_cmdline $@
80 AC_DEFINE_UNQUOTED(CONFIGURE_BUILD_WITH, ["$cmdline"], [configure flags])
81 AC_CANONICAL_TARGET
82 AC_DEFINE_UNQUOTED(CONFIGURE_TARGET, ["$target"], [configure target system])
83 AC_DEFINE_UNQUOTED(CONFIGURE_DATE, ["`date`"], [configure date])
84
85 CFLAGS="$CFLAGS"
86 AC_AIX
87
88 dnl
89 dnl By default set prefix to /usr/local
90 dnl
91 case "$prefix" in
92         NONE)
93                 prefix="/usr/local"
94         ;;
95 esac
96
97 # are we on MinGW?
98 if uname -s 2>&1 | grep MINGW32 >/dev/null; then on_mingw="yes"
99 else 
100         if echo $target | grep mingw32 >/dev/null; then on_mingw="yes"
101         else on_mingw="no"; fi
102 fi
103
104 #
105 # Determine configuration file
106 # the eval is to evaluate shell expansion twice
107 if test $on_mingw = "no"; then
108   ub_conf_file=`eval echo "${sysconfdir}/unbound/unbound.conf"`
109 else
110   ub_conf_file="C:\\Program Files\\Unbound\\service.conf"
111 fi
112 AC_ARG_WITH([conf_file],
113         AC_HELP_STRING([--with-conf-file=path], 
114         [Pathname to the Unbound configuration file]),
115         [ub_conf_file="$withval"])
116 AC_SUBST(ub_conf_file)
117 ACX_ESCAPE_BACKSLASH($ub_conf_file, hdr_config)
118 AC_DEFINE_UNQUOTED(CONFIGFILE, ["$hdr_config"], [Pathname to the Unbound configuration file])
119
120 # Determine run, chroot directory and pidfile locations
121 AC_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", 
125 if test $on_mingw = no; then
126     UNBOUND_RUN_DIR=`dirname "$ub_conf_file"`
127 else
128     UNBOUND_RUN_DIR=""
129 fi
130 )
131 AC_SUBST(UNBOUND_RUN_DIR)
132 ACX_ESCAPE_BACKSLASH($UNBOUND_RUN_DIR, hdr_run)
133 AC_DEFINE_UNQUOTED(RUN_DIR, ["$hdr_run"], [Directory to chdir to])
134
135 AC_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", 
139 if test $on_mingw = no; then
140     UNBOUND_CHROOT_DIR="$UNBOUND_RUN_DIR"
141 else
142     UNBOUND_CHROOT_DIR=""
143 fi
144 )
145 AC_SUBST(UNBOUND_CHROOT_DIR)
146 ACX_ESCAPE_BACKSLASH($UNBOUND_CHROOT_DIR, hdr_chroot)
147 AC_DEFINE_UNQUOTED(CHROOT_DIR, ["$hdr_chroot"], [Directory to chroot to])
148
149 AC_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")
154 AC_SUBST(UNBOUND_SHARE_DIR)
155 AC_DEFINE_UNQUOTED(SHARE_DIR, ["$UNBOUND_SHARE_DIR"], [Shared data])
156
157 AC_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", 
161 if test $on_mingw = no; then
162     UNBOUND_PIDFILE="$UNBOUND_RUN_DIR/unbound.pid"
163 else
164     UNBOUND_PIDFILE=""
165 fi
166 )
167 AC_SUBST(UNBOUND_PIDFILE)
168 ACX_ESCAPE_BACKSLASH($UNBOUND_PIDFILE, hdr_pid)
169 AC_DEFINE_UNQUOTED(PIDFILE, ["$hdr_pid"], [default pidfile location])
170
171 AC_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", 
175 if test $on_mingw = no; then
176     UNBOUND_ROOTKEY_FILE="$UNBOUND_RUN_DIR/root.key"
177 else
178     UNBOUND_ROOTKEY_FILE="C:\\Program Files\\Unbound\\root.key"
179 fi
180 )
181 AC_SUBST(UNBOUND_ROOTKEY_FILE)
182 ACX_ESCAPE_BACKSLASH($UNBOUND_ROOTKEY_FILE, hdr_rkey)
183 AC_DEFINE_UNQUOTED(ROOT_ANCHOR_FILE, ["$hdr_rkey"], [default rootkey location])
184
185 AC_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", 
189 if test $on_mingw = no; then
190     UNBOUND_ROOTCERT_FILE="$UNBOUND_RUN_DIR/icannbundle.pem"
191 else
192     UNBOUND_ROOTCERT_FILE="C:\\Program Files\\Unbound\\icannbundle.pem"
193 fi
194 )
195 AC_SUBST(UNBOUND_ROOTCERT_FILE)
196 ACX_ESCAPE_BACKSLASH($UNBOUND_ROOTCERT_FILE, hdr_rpem)
197 AC_DEFINE_UNQUOTED(ROOT_CERT_FILE, ["$hdr_rpem"], [default rootcert location])
198
199 AC_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")
204 AC_SUBST(UNBOUND_USERNAME)
205 AC_DEFINE_UNQUOTED(UB_USERNAME, ["$UNBOUND_USERNAME"], [default username])
206
207 AC_DEFINE(WINVER, 0x0502, [the version of the windows API enabled])
208 ACX_RSRC_VERSION(wnvs)
209 AC_DEFINE_UNQUOTED(RSRC_PACKAGE_VERSION, [$wnvs], [version number for resource files])
210
211 # Checks for typedefs, structures, and compiler characteristics.
212 AC_C_CONST
213 AC_LANG_C
214 # allow user to override the -g -O2 flags.
215 if test "x$CFLAGS" = "x" ; then
216 ACX_CHECK_COMPILER_FLAG(g, [CFLAGS="$CFLAGS -g"])
217 ACX_CHECK_COMPILER_FLAG(O2, [CFLAGS="$CFLAGS -O2"])
218 fi
219 AC_PROG_CC
220 ACX_DEPFLAG
221 ACX_DETERMINE_EXT_FLAGS_UNBOUND
222
223 # debug mode flags warnings
224 AC_ARG_ENABLE(checking, AC_HELP_STRING([--enable-checking], [Enable warnings, asserts, makefile-dependencies]))
225 AC_ARG_ENABLE(debug, AC_HELP_STRING([--enable-debug], [same as enable-checking]))
226 if test "$enable_debug" = "yes"; then debug_enabled="$enable_debug"; 
227 else debug_enabled="$enable_checking"; fi
228 AC_SUBST(debug_enabled)
229 case "$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                 ;;
240 esac
241 ACX_CHECK_FLTO
242
243 AC_C_INLINE
244 ACX_CHECK_FORMAT_ATTRIBUTE
245 ACX_CHECK_UNUSED_ATTRIBUTE
246
247 if test "$srcdir" != "."; then
248         CPPFLAGS="$CPPFLAGS -I$srcdir"
249 fi
250
251 AC_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
259 AC_PROG_LEX
260 ACX_YYLEX_DESTROY
261 AC_PROG_YACC
262 AC_CHECK_PROG(doxygen, doxygen, doxygen)
263 AC_CHECK_TOOL(STRIP, strip)
264 ACX_LIBTOOL_C_ONLY
265
266 # Checks for header files.
267 AC_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.
271 AC_CHECK_TYPE(int8_t, signed char)
272 AC_CHECK_TYPE(int16_t, short)
273 AC_CHECK_TYPE(int32_t, int)
274 AC_CHECK_TYPE(int64_t, long long)
275 AC_CHECK_TYPE(uint8_t, unsigned char)
276 AC_CHECK_TYPE(uint16_t, unsigned short)
277 AC_CHECK_TYPE(uint32_t, unsigned int)
278 AC_CHECK_TYPE(uint64_t, unsigned long long)
279 AC_TYPE_SIZE_T
280 AC_CHECK_TYPE(ssize_t, int)
281 AC_TYPE_UID_T
282 AC_TYPE_PID_T
283 AC_TYPE_OFF_T
284 ACX_TYPE_U_CHAR
285 ACX_TYPE_RLIM_T
286 ACX_TYPE_SOCKLEN_T
287 ACX_TYPE_IN_ADDR_T
288 ACX_TYPE_IN_PORT_T
289 ACX_CHECK_MEMCMP_SIGNED
290
291 # add option to disable the evil rpath
292 ACX_ARG_RPATH
293 AC_SUBST(RUNTIME_PATH)
294
295 # check to see if libraries are needed for these functions.
296 AC_SEARCH_LIBS([inet_pton], [nsl])
297 AC_SEARCH_LIBS([socket], [socket])
298
299 # check wether strptime also works
300 AC_DEFUN([AC_CHECK_STRPTIME_WORKS],
301 [AC_REQUIRE([AC_PROG_CC])
302 AC_MSG_CHECKING(whether strptime works)
303 if test c${cross_compiling} = cno; then
304 AC_RUN_IFELSE([AC_LANG_SOURCE([[
305 #define _XOPEN_SOURCE
306 #include <time.h>
307 int main(void) { struct tm tm; char *res;
308 res = 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);
309 if (!res) return 2;
310 res = strptime("20070207111842", "%Y%m%d%H%M%S", &tm);
311 if (!res) return 1; return 0; }
312 ]])] , [eval "ac_cv_c_strptime_works=yes"], [eval "ac_cv_c_strptime_works=no"])
313 else
314 eval "ac_cv_c_strptime_works=maybe"
315 fi
316 AC_MSG_RESULT($ac_cv_c_strptime_works)
317 if test $ac_cv_c_strptime_works = no; then
318 AC_LIBOBJ(strptime)
319 else
320 AC_DEFINE_UNQUOTED([STRPTIME_WORKS], 1, [use default strptime.])
321 fi
322 ])dnl
323
324 # check some functions of the OS before linking libs (while still runnable).
325 AC_FUNC_CHOWN
326 AC_FUNC_FORK
327 AC_TYPE_SIGNAL
328 AC_FUNC_FSEEKO
329 ACX_SYS_LARGEFILE
330 ACX_CHECK_NONBLOCKING_BROKEN
331 ACX_MKDIR_ONE_ARG
332 AC_CHECK_FUNCS([strptime],[AC_CHECK_STRPTIME_WORKS],[AC_LIBOBJ([strptime])])
333
334 # set memory allocation checking if requested
335 AC_ARG_ENABLE(alloc-checks, AC_HELP_STRING([--enable-alloc-checks],
336         [ enable to memory allocation statistics, for debug purposes ]), 
337         , )
338 AC_ARG_ENABLE(alloc-lite, AC_HELP_STRING([--enable-alloc-lite],
339         [ enable for lightweight alloc assertions, for debug purposes ]), 
340         , )
341 AC_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         , )
344 if test x_$enable_alloc_nonregional = x_yes; then
345         AC_DEFINE(UNBOUND_ALLOC_NONREGIONAL, 1, [use malloc not regions, for debug use])
346 fi
347 if test x_$enable_alloc_checks = x_yes; then
348         AC_DEFINE(UNBOUND_ALLOC_STATS, 1, [use statistics for allocs and frees, for debug use])
349 else
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
355 fi
356
357 # check windows threads (we use them, not pthreads, on windows).
358 if 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
375 else
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.
382 AC_ARG_WITH(pthreads, AC_HELP_STRING([--with-pthreads], 
383  [use pthreads library, or --without-pthreads to disable threading support.]), 
384  [ ],[ withval="yes" ])
385 ub_have_pthreads=no
386 if 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                 ])
395 fi
396
397 # check solaris thread library 
398 AC_ARG_WITH(solaris-threads, AC_HELP_STRING([--with-solaris-threads], 
399         [use solaris native thread library.]), [ ],[ withval="no" ])
400 ub_have_sol_threads=no
401 if 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
416 fi
417
418 fi # end of non-mingw check of thread libraries
419
420 # Check for PyUnbound
421 AC_ARG_WITH(pyunbound,
422    AC_HELP_STRING([--with-pyunbound],
423    [build PyUnbound, or --without-pyunbound to skip it. (default=no)]),
424    [], [ withval="no" ])
425
426 ub_test_python=no
427 ub_with_pyunbound=no
428 if test x_$withval != x_no; then
429    ub_with_pyunbound=yes
430    ub_test_python=yes
431 fi
432
433 # Check for Python module
434 AC_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
439 ub_with_pythonmod=no
440 if test x_$withval != x_no; then
441    ub_with_pythonmod=yes
442    ub_test_python=yes
443 fi
444
445 # Check for Python & SWIG only on PyUnbound or PyModule
446 if 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
510 fi
511
512 if test "`uname`" = "NetBSD"; then
513         NETBSD_LINTFLAGS='"-D__RENAME(x)=" -D_NETINET_IN_H_'
514         AC_SUBST(NETBSD_LINTFLAGS)
515 fi
516 CONFIG_DATE=`date +%Y%m%d`
517 AC_SUBST(CONFIG_DATE)
518
519 # Checks for libraries.
520
521 # libnss
522 USE_NSS="no"
523 AC_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
542 if test $USE_NSS = "no"; then
543 ACX_WITH_SSL
544 ACX_LIB_SSL
545 AC_CHECK_HEADERS([openssl/conf.h],,, [AC_INCLUDES_DEFAULT])
546 AC_CHECK_HEADERS([openssl/engine.h],,, [AC_INCLUDES_DEFAULT])
547 AC_CHECK_FUNCS([OPENSSL_config EVP_sha1 EVP_sha256 EVP_sha512 FIPS_mode])
548 AC_CHECK_DECLS([SSL_COMP_get_compression_methods,sk_SSL_COMP_pop_free], [], [], [
549 AC_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 ])
568 fi
569
570
571 AC_ARG_ENABLE(sha2, AC_HELP_STRING([--disable-sha2], [Disable SHA256 and SHA512 RRSIG support]))
572 case "$enable_sha2" in
573         no)
574         ;;
575         yes|*)
576         AC_DEFINE([USE_SHA2], [1], [Define this to enable SHA256 and SHA512 support.])
577         ;;
578 esac
579
580 # check wether gost also works
581 AC_DEFUN([AC_CHECK_GOST_WORKS],
582 [AC_REQUIRE([AC_PROG_CC])
583 AC_MSG_CHECKING([if GOST works])
584 if test c${cross_compiling} = cno; then
585 BAKCFLAGS="$CFLAGS"
586 if test -n "$ssldir"; then
587         CFLAGS="$CFLAGS -Wl,-rpath,$ssldir/lib"
588 fi
589 AC_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 */
596 int 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 }
639 int 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"])
671 CFLAGS="$BAKCFLAGS"
672 else
673 eval "ac_cv_c_gost_works=maybe"
674 fi
675 AC_MSG_RESULT($ac_cv_c_gost_works)
676 ])dnl
677
678 AC_ARG_ENABLE(gost, AC_HELP_STRING([--disable-gost], [Disable GOST support]))
679 use_gost="no"
680 if test $USE_NSS = "no"; then
681 case "$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         ;;
693 esac
694 fi dnl !USE_NSS
695
696 AC_ARG_ENABLE(ecdsa, AC_HELP_STRING([--disable-ecdsa], [Disable ECDSA support]))
697 use_ecdsa="no"
698 case "$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       ;;
721 esac
722
723 # check for libevent
724 AC_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" ])
727 if 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
764 You can restart ./configure --with-libevent=no to use a builtin alternative.
765 Please note that this alternative is not as capable as libevent when using
766 large 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
797 else
798         AC_DEFINE(USE_MINI_EVENT, 1, [Define if you want to use internal select based events])
799 fi
800
801 # check for libexpat
802 AC_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" ])
805 AC_MSG_CHECKING(for libexpat)
806 found_libexpat="no"
807 for 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
818 done
819 if test x_$found_libexpat != x_yes; then
820         AC_ERROR([Could not find libexpat, expat.h])
821 fi
822 AC_CHECK_HEADERS([expat.h],,, [AC_INCLUDES_DEFAULT])
823
824 # set static linking if requested
825 AC_SUBST(staticexe)
826 staticexe=""
827 AC_ARG_ENABLE(static-exe, AC_HELP_STRING([--enable-static-exe],
828         [ enable to compile executables statically against event, ldns libs, for debug purposes ]), 
829         , )
830 if 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
839 fi
840
841 # set lock checking if requested
842 AC_ARG_ENABLE(lock_checks, AC_HELP_STRING([--enable-lock-checks],
843         [ enable to check lock and unlock calls, for debug purposes ]), 
844         , )
845 if 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)
849 fi
850
851 ACX_CHECK_GETADDRINFO_WITH_INCLUDES
852 if 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)
875 fi
876 if test $ac_cv_func_getaddrinfo = no; then
877         AC_LIBOBJ([fake-rfc2553])
878 fi
879 # check after getaddrinfo for its libraries
880 ACX_FUNC_IOCTLSOCKET
881
882 # see if daemon(3) exists, and if it is deprecated.
883 AC_CHECK_FUNCS([daemon])
884 if test $ac_cv_func_daemon = yes; then
885         ACX_FUNC_DEPRECATED([daemon], [(void)daemon(0, 0);], [
886 #include <stdlib.h>
887 ])
888 fi
889
890 AC_CHECK_MEMBERS([struct in_pktinfo.ipi_spec_dst],,,[
891 AC_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 ])
920 AC_SEARCH_LIBS([setusercontext], [util])
921 AC_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])
922 AC_CHECK_FUNCS([setresuid],,[AC_CHECK_FUNCS([setreuid])])
923 AC_CHECK_FUNCS([setresgid],,[AC_CHECK_FUNCS([setregid])])
924
925 # check if setreuid en setregid fail, on MacOSX10.4(darwin8).
926 if 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])
928 fi
929 AC_REPLACE_FUNCS(inet_aton)
930 AC_REPLACE_FUNCS(inet_pton)
931 AC_REPLACE_FUNCS(inet_ntop)
932 AC_REPLACE_FUNCS(snprintf)
933 AC_REPLACE_FUNCS(strlcpy)
934 AC_REPLACE_FUNCS(memmove)
935 AC_REPLACE_FUNCS(gmtime_r)
936 LIBOBJ_WITHOUT_CTIME="$LIBOBJS"
937 AC_SUBST(LIBOBJ_WITHOUT_CTIME)
938 AC_REPLACE_FUNCS(ctime_r)
939
940 AC_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]))
941 case "$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         ;;
953 esac
954 AC_SUBST(COMMON_OBJ_ALL_SYMBOLS)
955 AC_SUBST(EXTRALINK)
956 AC_SUBST(UBSYMS)
957 if 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
970 fi
971
972 AC_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.
976 cat >conftest.make <<EOF
977 all:    conftest.lo
978
979 conftest.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
986 conftest.lo:        conftest.dir/conftest.c
987 EOF
988 mkdir conftest.dir
989 touch conftest.dir/conftest.c
990 rm -f conftest.lo conftest.c
991 ${MAKE:-make} -f conftest.make >/dev/null
992 rm -f conftest.make conftest.c conftest.dir/conftest.c
993 rm -rf conftest.dir
994 if test ! -f conftest.lo; then
995         AC_MSG_RESULT(no)
996         SOURCEDETERMINE='echo "$^" | awk "-F " "{print \$$1;}" > .source'
997         SOURCEFILE='`cat .source`'
998 else
999         AC_MSG_RESULT(yes)
1000         SOURCEDETERMINE=':'
1001         SOURCEFILE='$<'
1002 fi
1003 rm -f conftest.lo
1004 AC_SUBST(SOURCEDETERMINE)
1005 AC_SUBST(SOURCEFILE)
1006
1007 # see if we want to build the library or everything
1008 ALLTARGET="alltargets"
1009 AC_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 ])
1016 AC_SUBST(ALLTARGET)
1017
1018 # check this after all other compilation checks, since the linking of the lib
1019 # may break checks after this.
1020 AC_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
1035 AC_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 ])
1038 AC_CHECK_FUNC(ldns_buffer_copy)
1039 if test $USE_NSS = "no"; then
1040     AC_CHECK_FUNC(ldns_key_buf2rsa_raw)
1041 else
1042     dnl ignore test
1043     ac_cv_func_ldns_key_buf2rsa_raw="yes"
1044 fi
1045 AC_CHECK_FUNC(ldns_get_random)
1046 AC_CHECK_FUNC(ldns_b32_ntop_extended_hex)
1047 if 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])
1050 else
1051     dnl ignore test
1052     ac_cv_func_ldns_key_EVP_load_gost_id="yes"
1053 fi
1054 if test x$use_ecdsa = xyes; then
1055     AC_CHECK_DECL([LDNS_ECDSAP384SHA384], [], [], [
1056 AC_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     ])
1065 else
1066     ac_cv_have_decl_LDNS_ECDSAP384SHA384="yes"
1067 fi
1068 AC_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 ])
1091 if 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     :
1100 else
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])
1102 fi
1103
1104 ACX_STRIP_EXT_FLAGS
1105 LDFLAGS="$LATE_LDFLAGS $LDFLAGS"
1106
1107 AC_DEFINE_UNQUOTED([MAXSYSLOGMSGLEN], [10240], [Define to the maximum message length to pass to syslog.])
1108
1109 AH_BOTTOM(
1110 dnl this must be first AH_CONFIG, to define the flags before any includes.
1111 AHX_CONFIG_EXT_FLAGS
1112
1113 dnl 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
1164 AHX_CONFIG_FORMAT_ATTRIBUTE
1165 AHX_CONFIG_UNUSED_ATTRIBUTE
1166 AHX_CONFIG_FSEEKO
1167 AHX_CONFIG_MAXHOSTNAMELEN
1168 AHX_CONFIG_SNPRINTF(unbound)
1169 AHX_CONFIG_INET_PTON(unbound)
1170 AHX_CONFIG_INET_NTOP(unbound)
1171 AHX_CONFIG_INET_ATON(unbound)
1172 AHX_CONFIG_MEMMOVE(unbound)
1173 AHX_CONFIG_STRLCPY(unbound)
1174 AHX_CONFIG_GMTIME_R(unbound)
1175 AHX_CONFIG_W32_SLEEP
1176 AHX_CONFIG_W32_USLEEP
1177 AHX_CONFIG_W32_RANDOM
1178 AHX_CONFIG_W32_SRANDOM
1179 AHX_CONFIG_W32_FD_SET_T
1180 AHX_CONFIG_IPV6_MIN_MTU
1181 AHX_MEMCMP_BROKEN(unbound)
1182
1183 [
1184 #ifndef HAVE_CTIME_R
1185 #define ctime_r unbound_ctime_r
1186 char *ctime_r(const time_t *timep, char *buf);
1187 #endif
1188
1189 #if !defined(HAVE_STRPTIME) || !defined(STRPTIME_WORKS)
1190 #define strptime unbound_strptime
1191 struct tm;
1192 char *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
1212 struct 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__)
1221 void *unbound_stat_malloc(size_t size);
1222 void *unbound_stat_calloc(size_t nmemb, size_t size);
1223 void unbound_stat_free(void *ptr);
1224 void *unbound_stat_realloc(void *ptr, size_t size);
1225 void *unbound_stat_malloc_log(size_t size, const char* file, int line,
1226         const char* func);
1227 void *unbound_stat_calloc_log(size_t nmemb, size_t size, const char* file,
1228         int line, const char* func);
1229 void unbound_stat_free_log(void *ptr, const char* file, int line,
1230         const char* func);
1231 void *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
1247 AC_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])
1248 AC_CONFIG_HEADER([config.h])
1249 AC_OUTPUT