]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - contrib/unbound/configure.ac
- Copy stable/10@285827 to releng/10.2 in preparation for 10.2-RC1
[FreeBSD/releng/10.2.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(ax_pthread.m4)
6 sinclude(acx_python.m4)
7 sinclude(ac_pkg_swig.m4)
8 sinclude(dnstap/dnstap.m4)
9
10 # must be numbers. ac_defun because of later processing
11 m4_define([VERSION_MAJOR],[1])
12 m4_define([VERSION_MINOR],[5])
13 m4_define([VERSION_MICRO],[3])
14 AC_INIT(unbound, m4_defn([VERSION_MAJOR]).m4_defn([VERSION_MINOR]).m4_defn([VERSION_MICRO]), unbound-bugs@nlnetlabs.nl, unbound)
15 AC_SUBST(UNBOUND_VERSION_MAJOR, [VERSION_MAJOR])
16 AC_SUBST(UNBOUND_VERSION_MINOR, [VERSION_MINOR])
17 AC_SUBST(UNBOUND_VERSION_MICRO, [VERSION_MICRO])
18
19 LIBUNBOUND_CURRENT=5
20 LIBUNBOUND_REVISION=6
21 LIBUNBOUND_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.
82 AC_SUBST(LIBUNBOUND_CURRENT)
83 AC_SUBST(LIBUNBOUND_REVISION)
84 AC_SUBST(LIBUNBOUND_AGE)
85
86 CFLAGS="$CFLAGS"
87 AC_AIX
88 if test "$ac_cv_header_minix_config_h" = "yes"; then
89         AC_DEFINE(_NETBSD_SOURCE,1, [Enable for compile on Minix])
90 fi
91
92 dnl
93 dnl By default set prefix to /usr/local
94 dnl
95 case "$prefix" in
96         NONE)
97                 prefix="/usr/local"
98         ;;
99 esac
100
101 # are we on MinGW?
102 if uname -s 2>&1 | grep MINGW32 >/dev/null; then on_mingw="yes"
103 else 
104         if echo $target | grep mingw32 >/dev/null; then on_mingw="yes"
105         else on_mingw="no"; fi
106 fi
107
108 #
109 # Determine configuration file
110 # the eval is to evaluate shell expansion twice
111 if test $on_mingw = "no"; then
112   ub_conf_file=`eval echo "${sysconfdir}/unbound/unbound.conf"`
113 else
114   ub_conf_file="C:\\Program Files\\Unbound\\service.conf"
115 fi
116 AC_ARG_WITH([conf_file],
117         AC_HELP_STRING([--with-conf-file=path], 
118         [Pathname to the Unbound configuration file]),
119         [ub_conf_file="$withval"])
120 AC_SUBST(ub_conf_file)
121 ACX_ESCAPE_BACKSLASH($ub_conf_file, hdr_config)
122 AC_DEFINE_UNQUOTED(CONFIGFILE, ["$hdr_config"], [Pathname to the Unbound configuration file])
123 ub_conf_dir=`AS_DIRNAME(["$ub_conf_file"])`
124 AC_SUBST(ub_conf_dir)
125
126 # Determine run, chroot directory and pidfile locations
127 AC_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", 
131 if test $on_mingw = no; then
132     UNBOUND_RUN_DIR=`dirname "$ub_conf_file"`
133 else
134     UNBOUND_RUN_DIR=""
135 fi
136 )
137 AC_SUBST(UNBOUND_RUN_DIR)
138 ACX_ESCAPE_BACKSLASH($UNBOUND_RUN_DIR, hdr_run)
139 AC_DEFINE_UNQUOTED(RUN_DIR, ["$hdr_run"], [Directory to chdir to])
140
141 AC_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", 
145 if test $on_mingw = no; then
146     UNBOUND_CHROOT_DIR="$UNBOUND_RUN_DIR"
147 else
148     UNBOUND_CHROOT_DIR=""
149 fi
150 )
151 AC_SUBST(UNBOUND_CHROOT_DIR)
152 ACX_ESCAPE_BACKSLASH($UNBOUND_CHROOT_DIR, hdr_chroot)
153 AC_DEFINE_UNQUOTED(CHROOT_DIR, ["$hdr_chroot"], [Directory to chroot to])
154
155 AC_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")
160 AC_SUBST(UNBOUND_SHARE_DIR)
161 AC_DEFINE_UNQUOTED(SHARE_DIR, ["$UNBOUND_SHARE_DIR"], [Shared data])
162
163 AC_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", 
167 if test $on_mingw = no; then
168     UNBOUND_PIDFILE="$UNBOUND_RUN_DIR/unbound.pid"
169 else
170     UNBOUND_PIDFILE=""
171 fi
172 )
173 AC_SUBST(UNBOUND_PIDFILE)
174 ACX_ESCAPE_BACKSLASH($UNBOUND_PIDFILE, hdr_pid)
175 AC_DEFINE_UNQUOTED(PIDFILE, ["$hdr_pid"], [default pidfile location])
176
177 AC_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", 
181 if test $on_mingw = no; then
182     UNBOUND_ROOTKEY_FILE="$UNBOUND_RUN_DIR/root.key"
183 else
184     UNBOUND_ROOTKEY_FILE="C:\\Program Files\\Unbound\\root.key"
185 fi
186 )
187 AC_SUBST(UNBOUND_ROOTKEY_FILE)
188 ACX_ESCAPE_BACKSLASH($UNBOUND_ROOTKEY_FILE, hdr_rkey)
189 AC_DEFINE_UNQUOTED(ROOT_ANCHOR_FILE, ["$hdr_rkey"], [default rootkey location])
190
191 AC_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", 
195 if test $on_mingw = no; then
196     UNBOUND_ROOTCERT_FILE="$UNBOUND_RUN_DIR/icannbundle.pem"
197 else
198     UNBOUND_ROOTCERT_FILE="C:\\Program Files\\Unbound\\icannbundle.pem"
199 fi
200 )
201 AC_SUBST(UNBOUND_ROOTCERT_FILE)
202 ACX_ESCAPE_BACKSLASH($UNBOUND_ROOTCERT_FILE, hdr_rpem)
203 AC_DEFINE_UNQUOTED(ROOT_CERT_FILE, ["$hdr_rpem"], [default rootcert location])
204
205 AC_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")
210 AC_SUBST(UNBOUND_USERNAME)
211 AC_DEFINE_UNQUOTED(UB_USERNAME, ["$UNBOUND_USERNAME"], [default username])
212
213 AC_DEFINE(WINVER, 0x0502, [the version of the windows API enabled])
214 ACX_RSRC_VERSION(wnvs)
215 AC_DEFINE_UNQUOTED(RSRC_PACKAGE_VERSION, [$wnvs], [version number for resource files])
216
217 # Checks for typedefs, structures, and compiler characteristics.
218 AC_C_CONST
219 AC_LANG_C
220 # allow user to override the -g -O2 flags.
221 if test "x$CFLAGS" = "x" ; then
222 ACX_CHECK_COMPILER_FLAG(g, [CFLAGS="$CFLAGS -g"])
223 ACX_CHECK_COMPILER_FLAG(O2, [CFLAGS="$CFLAGS -O2"])
224 fi
225 AC_PROG_CC
226 ACX_DEPFLAG
227 ACX_DETERMINE_EXT_FLAGS_UNBOUND
228
229 # debug mode flags warnings
230 AC_ARG_ENABLE(checking, AC_HELP_STRING([--enable-checking], [Enable warnings, asserts, makefile-dependencies]))
231 AC_ARG_ENABLE(debug, AC_HELP_STRING([--enable-debug], [same as enable-checking]))
232 if test "$enable_debug" = "yes"; then debug_enabled="$enable_debug"; 
233 else debug_enabled="$enable_checking"; fi
234 AC_SUBST(debug_enabled)
235 case "$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                 ;;
246 esac
247 ACX_CHECK_FLTO
248
249 AC_C_INLINE
250 ACX_CHECK_FORMAT_ATTRIBUTE
251 ACX_CHECK_UNUSED_ATTRIBUTE
252
253 if test "$srcdir" != "."; then
254         CPPFLAGS="$CPPFLAGS -I$srcdir"
255 fi
256
257 AC_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
265 AC_PROG_LEX
266 ACX_YYLEX_DESTROY
267 AC_PROG_YACC
268 AC_CHECK_PROG(doxygen, doxygen, doxygen)
269 AC_CHECK_TOOL(STRIP, strip)
270 ACX_LIBTOOL_C_ONLY
271
272 # Checks for header files.
273 AC_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.
277 AC_CHECK_TYPE(int8_t, signed char)
278 AC_CHECK_TYPE(int16_t, short)
279 AC_CHECK_TYPE(int32_t, int)
280 AC_CHECK_TYPE(int64_t, long long)
281 AC_CHECK_TYPE(uint8_t, unsigned char)
282 AC_CHECK_TYPE(uint16_t, unsigned short)
283 AC_CHECK_TYPE(uint32_t, unsigned int)
284 AC_CHECK_TYPE(uint64_t, unsigned long long)
285 AC_TYPE_SIZE_T
286 AC_CHECK_TYPE(ssize_t, int)
287 AC_TYPE_UID_T
288 AC_TYPE_PID_T
289 AC_TYPE_OFF_T
290 ACX_TYPE_U_CHAR
291 ACX_TYPE_RLIM_T
292 ACX_TYPE_SOCKLEN_T
293 ACX_TYPE_IN_ADDR_T
294 ACX_TYPE_IN_PORT_T
295 ACX_CHECK_MEMCMP_SIGNED
296
297 AC_CHECK_SIZEOF(time_t,,[
298 AC_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
312 ACX_ARG_RPATH
313 AC_SUBST(RUNTIME_PATH)
314
315 # check to see if libraries are needed for these functions.
316 AC_SEARCH_LIBS([inet_pton], [nsl])
317 AC_SEARCH_LIBS([socket], [socket])
318
319 # check wether strptime also works
320 AC_DEFUN([AC_CHECK_STRPTIME_WORKS],
321 [AC_REQUIRE([AC_PROG_CC])
322 AC_MSG_CHECKING(whether strptime works)
323 if test c${cross_compiling} = cno; then
324 AC_RUN_IFELSE([AC_LANG_SOURCE([[
325 #define _XOPEN_SOURCE 600
326 #include <time.h>
327 int main(void) { struct tm tm; char *res;
328 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);
329 if (!res) return 2;
330 res = strptime("20070207111842", "%Y%m%d%H%M%S", &tm);
331 if (!res) return 1; return 0; }
332 ]])] , [eval "ac_cv_c_strptime_works=yes"], [eval "ac_cv_c_strptime_works=no"])
333 else
334 eval "ac_cv_c_strptime_works=maybe"
335 fi
336 AC_MSG_RESULT($ac_cv_c_strptime_works)
337 if test $ac_cv_c_strptime_works = no; then
338 AC_LIBOBJ(strptime)
339 else
340 AC_DEFINE_UNQUOTED([STRPTIME_WORKS], 1, [use default strptime.])
341 fi
342 ])dnl
343
344 # check some functions of the OS before linking libs (while still runnable).
345 AC_FUNC_CHOWN
346 AC_FUNC_FORK
347 AC_TYPE_SIGNAL
348 AC_FUNC_FSEEKO
349 ACX_SYS_LARGEFILE
350 ACX_CHECK_NONBLOCKING_BROKEN
351 ACX_MKDIR_ONE_ARG
352 AC_CHECK_FUNCS([strptime],[AC_CHECK_STRPTIME_WORKS],[AC_LIBOBJ([strptime])])
353
354 # set memory allocation checking if requested
355 AC_ARG_ENABLE(alloc-checks, AC_HELP_STRING([--enable-alloc-checks],
356         [ enable to memory allocation statistics, for debug purposes ]), 
357         , )
358 AC_ARG_ENABLE(alloc-lite, AC_HELP_STRING([--enable-alloc-lite],
359         [ enable for lightweight alloc assertions, for debug purposes ]), 
360         , )
361 AC_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         , )
364 if test x_$enable_alloc_nonregional = x_yes; then
365         AC_DEFINE(UNBOUND_ALLOC_NONREGIONAL, 1, [use malloc not regions, for debug use])
366 fi
367 if test x_$enable_alloc_checks = x_yes; then
368         AC_DEFINE(UNBOUND_ALLOC_STATS, 1, [use statistics for allocs and frees, for debug use])
369 else
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
375 fi
376
377 # check windows threads (we use them, not pthreads, on windows).
378 if 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
395 else
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.
402 AC_ARG_WITH(pthreads, AC_HELP_STRING([--with-pthreads], 
403  [use pthreads library, or --without-pthreads to disable threading support.]), 
404  [ ],[ withval="yes" ])
405 ub_have_pthreads=no
406 if 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                 ])
415 fi
416
417 # check solaris thread library 
418 AC_ARG_WITH(solaris-threads, AC_HELP_STRING([--with-solaris-threads], 
419         [use solaris native thread library.]), [ ],[ withval="no" ])
420 ub_have_sol_threads=no
421 if 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
436 fi
437
438 fi # end of non-mingw check of thread libraries
439
440 # Check for PyUnbound
441 AC_ARG_WITH(pyunbound,
442    AC_HELP_STRING([--with-pyunbound],
443    [build PyUnbound, or --without-pyunbound to skip it. (default=no)]),
444    [], [ withval="no" ])
445
446 ub_test_python=no
447 ub_with_pyunbound=no
448 if test x_$withval != x_no; then
449    ub_with_pyunbound=yes
450    ub_test_python=yes
451 fi
452
453 # Check for Python module
454 AC_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
459 ub_with_pythonmod=no
460 if test x_$withval != x_no; then
461    ub_with_pythonmod=yes
462    ub_test_python=yes
463 fi
464
465 # Check for Python & SWIG only on PyUnbound or PyModule
466 if 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
530 fi
531
532 if test "`uname`" = "NetBSD"; then
533         NETBSD_LINTFLAGS='"-D__RENAME(x)=" -D_NETINET_IN_H_'
534         AC_SUBST(NETBSD_LINTFLAGS)
535 fi
536 CONFIG_DATE=`date +%Y%m%d`
537 AC_SUBST(CONFIG_DATE)
538
539 # Checks for libraries.
540
541 # libnss
542 USE_NSS="no"
543 AC_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
562 if test $USE_NSS = "no"; then
563 ACX_WITH_SSL
564 ACX_LIB_SSL
565 AC_MSG_CHECKING([for LibreSSL])
566 if 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])
572 else
573         AC_MSG_RESULT([no])
574 fi
575 AC_CHECK_HEADERS([openssl/conf.h],,, [AC_INCLUDES_DEFAULT])
576 AC_CHECK_HEADERS([openssl/engine.h],,, [AC_INCLUDES_DEFAULT])
577 AC_CHECK_FUNCS([OPENSSL_config EVP_sha1 EVP_sha256 EVP_sha512 FIPS_mode])
578 AC_CHECK_DECLS([SSL_COMP_get_compression_methods,sk_SSL_COMP_pop_free], [], [], [
579 AC_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 ])
598 fi
599
600
601 AC_ARG_ENABLE(sha2, AC_HELP_STRING([--disable-sha2], [Disable SHA256 and SHA512 RRSIG support]))
602 case "$enable_sha2" in
603         no)
604         ;;
605         yes|*)
606         AC_DEFINE([USE_SHA2], [1], [Define this to enable SHA256 and SHA512 support.])
607         ;;
608 esac
609
610 # check wether gost also works
611 AC_DEFUN([AC_CHECK_GOST_WORKS],
612 [AC_REQUIRE([AC_PROG_CC])
613 AC_MSG_CHECKING([if GOST works])
614 if test c${cross_compiling} = cno; then
615 BAKCFLAGS="$CFLAGS"
616 if test -n "$ssldir"; then
617         CFLAGS="$CFLAGS -Wl,-rpath,$ssldir/lib"
618 fi
619 AC_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) */
626 int 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 }
669 int 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"])
701 CFLAGS="$BAKCFLAGS"
702 else
703 eval "ac_cv_c_gost_works=maybe"
704 fi
705 AC_MSG_RESULT($ac_cv_c_gost_works)
706 ])dnl
707
708 AC_ARG_ENABLE(gost, AC_HELP_STRING([--disable-gost], [Disable GOST support]))
709 use_gost="no"
710 if test $USE_NSS = "no"; then
711 case "$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         ;;
723 esac
724 fi dnl !USE_NSS
725
726 AC_ARG_ENABLE(ecdsa, AC_HELP_STRING([--disable-ecdsa], [Disable ECDSA support]))
727 use_ecdsa="no"
728 case "$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       ;;
756 esac
757
758 AC_ARG_ENABLE(event-api, AC_HELP_STRING([--enable-event-api], [Enable (experimental) libevent-based libunbound API installed to unbound-event.h]))
759 use_unbound_event="no"
760 case "$enable_event_api" in
761     yes)
762       use_unbound_event="yes"
763       ;;
764     *)
765       ;;
766 esac
767
768 # check for libevent
769 AC_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" ])
772 if 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
809 You can restart ./configure --with-libevent=no to use a builtin alternative.
810 Please note that this alternative is not as capable as libevent when using
811 large 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
852 else
853         AC_DEFINE(USE_MINI_EVENT, 1, [Define if you want to use internal select based events])
854 fi
855
856 # check for libexpat
857 AC_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" ])
860 AC_MSG_CHECKING(for libexpat)
861 found_libexpat="no"
862 for 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
873 done
874 if test x_$found_libexpat != x_yes; then
875         AC_ERROR([Could not find libexpat, expat.h])
876 fi
877 AC_CHECK_HEADERS([expat.h],,, [AC_INCLUDES_DEFAULT])
878
879 # set static linking if requested
880 AC_SUBST(staticexe)
881 staticexe=""
882 AC_ARG_ENABLE(static-exe, AC_HELP_STRING([--enable-static-exe],
883         [ enable to compile executables statically against (event) libs, for debug purposes ]), 
884         , )
885 if 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
894 fi
895
896 # set lock checking if requested
897 AC_ARG_ENABLE(lock_checks, AC_HELP_STRING([--enable-lock-checks],
898         [ enable to check lock and unlock calls, for debug purposes ]), 
899         , )
900 if 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)
904 fi
905
906 ACX_CHECK_GETADDRINFO_WITH_INCLUDES
907 if 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)
930 fi
931 if test $ac_cv_func_getaddrinfo = no; then
932         AC_LIBOBJ([fake-rfc2553])
933 fi
934 # check after getaddrinfo for its libraries
935 ACX_FUNC_IOCTLSOCKET
936
937 # see if daemon(3) exists, and if it is deprecated.
938 AC_CHECK_FUNCS([daemon])
939 if test $ac_cv_func_daemon = yes; then
940         ACX_FUNC_DEPRECATED([daemon], [(void)daemon(0, 0);], [
941 #include <stdlib.h>
942 ])
943 fi
944
945 AC_CHECK_MEMBERS([struct sockaddr_un.sun_len],,,[
946 AC_INCLUDES_DEFAULT
947 #ifdef HAVE_SYS_UN_H
948 #include <sys/un.h>
949 #endif
950 ])
951 AC_CHECK_MEMBERS([struct in_pktinfo.ipi_spec_dst],,,[
952 AC_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 ])
981 AC_SEARCH_LIBS([setusercontext], [util])
982 AC_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])
983 AC_CHECK_FUNCS([setresuid],,[AC_CHECK_FUNCS([setreuid])])
984 AC_CHECK_FUNCS([setresgid],,[AC_CHECK_FUNCS([setregid])])
985
986 # check if setreuid en setregid fail, on MacOSX10.4(darwin8).
987 if 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])
989 fi
990 AC_REPLACE_FUNCS(inet_aton)
991 AC_REPLACE_FUNCS(inet_pton)
992 AC_REPLACE_FUNCS(inet_ntop)
993 AC_REPLACE_FUNCS(snprintf)
994 AC_REPLACE_FUNCS(strlcat)
995 AC_REPLACE_FUNCS(strlcpy)
996 AC_REPLACE_FUNCS(memmove)
997 AC_REPLACE_FUNCS(gmtime_r)
998 LIBOBJ_WITHOUT_CTIMEARC4="$LIBOBJS"
999 AC_SUBST(LIBOBJ_WITHOUT_CTIMEARC4)
1000 if 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
1041 fi
1042 LIBOBJ_WITHOUT_CTIME="$LIBOBJS"
1043 AC_SUBST(LIBOBJ_WITHOUT_CTIME)
1044 AC_REPLACE_FUNCS(ctime_r)
1045
1046 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]))
1047 case "$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         ;;
1059 esac
1060 AC_SUBST(COMMON_OBJ_ALL_SYMBOLS)
1061 AC_SUBST(EXTRALINK)
1062 AC_SUBST(UBSYMS)
1063 if 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
1076 fi
1077
1078 # check for dnstap if requested
1079 dt_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
1097 AC_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.
1101 cat >conftest.make <<EOF
1102 all:    conftest.lo
1103
1104 conftest.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
1111 conftest.lo:        conftest.dir/conftest.c
1112 EOF
1113 mkdir conftest.dir
1114 touch conftest.dir/conftest.c
1115 rm -f conftest.lo conftest.c
1116 ${MAKE:-make} -f conftest.make >/dev/null
1117 rm -f conftest.make conftest.c conftest.dir/conftest.c
1118 rm -rf conftest.dir
1119 if test ! -f conftest.lo; then
1120         AC_MSG_RESULT(no)
1121         SOURCEDETERMINE='echo "$^" | awk "-F " "{print \$$1;}" > .source'
1122         SOURCEFILE='`cat .source`'
1123 else
1124         AC_MSG_RESULT(yes)
1125         SOURCEDETERMINE=':'
1126         SOURCEFILE='$<'
1127 fi
1128 rm -f conftest.lo
1129 AC_SUBST(SOURCEDETERMINE)
1130 AC_SUBST(SOURCEFILE)
1131
1132 # see if we want to build the library or everything
1133 ALLTARGET="alltargets"
1134 INSTALLTARGET="install-all"
1135 AC_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 ])
1143 AC_SUBST(ALLTARGET)
1144 AC_SUBST(INSTALLTARGET)
1145
1146 ACX_STRIP_EXT_FLAGS
1147 LDFLAGS="$LATE_LDFLAGS $LDFLAGS"
1148
1149 AC_DEFINE_UNQUOTED([MAXSYSLOGMSGLEN], [10240], [Define to the maximum message length to pass to syslog.])
1150
1151 AH_BOTTOM(
1152 dnl this must be first AH_CONFIG, to define the flags before any includes.
1153 AHX_CONFIG_EXT_FLAGS
1154
1155 dnl 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
1226 AHX_CONFIG_FORMAT_ATTRIBUTE
1227 AHX_CONFIG_UNUSED_ATTRIBUTE
1228 AHX_CONFIG_FSEEKO
1229 AHX_CONFIG_MAXHOSTNAMELEN
1230 AHX_CONFIG_SNPRINTF(unbound)
1231 AHX_CONFIG_INET_PTON(unbound)
1232 AHX_CONFIG_INET_NTOP(unbound)
1233 AHX_CONFIG_INET_ATON(unbound)
1234 AHX_CONFIG_MEMMOVE(unbound)
1235 AHX_CONFIG_STRLCAT(unbound)
1236 AHX_CONFIG_STRLCPY(unbound)
1237 AHX_CONFIG_GMTIME_R(unbound)
1238 AHX_CONFIG_W32_SLEEP
1239 AHX_CONFIG_W32_USLEEP
1240 AHX_CONFIG_W32_RANDOM
1241 AHX_CONFIG_W32_SRANDOM
1242 AHX_CONFIG_W32_FD_SET_T
1243 AHX_CONFIG_IPV6_MIN_MTU
1244 AHX_MEMCMP_BROKEN(unbound)
1245
1246 [
1247 #ifndef HAVE_CTIME_R
1248 #define ctime_r unbound_ctime_r
1249 char *ctime_r(const time_t *timep, char *buf);
1250 #endif
1251
1252 #if !defined(HAVE_STRPTIME) || !defined(STRPTIME_WORKS)
1253 #define strptime unbound_strptime
1254 struct tm;
1255 char *strptime(const char *s, const char *format, struct tm *tm);
1256 #endif
1257
1258 #ifdef HAVE_LIBRESSL
1259 #  if !HAVE_DECL_STRLCPY
1260 size_t strlcpy(char *dst, const char *src, size_t siz);
1261 #  endif
1262 #  if !HAVE_DECL_STRLCAT
1263 size_t strlcat(char *dst, const char *src, size_t siz);
1264 #  endif
1265 #  if !HAVE_DECL_ARC4RANDOM && defined(HAVE_ARC4RANDOM)
1266 uint32_t arc4random(void);
1267 #  endif
1268 #  if !HAVE_DECL_ARC4RANDOM_UNIFORM && defined(HAVE_ARC4RANDOM_UNIFORM)
1269 uint32_t arc4random_uniform(uint32_t upper_bound);
1270 #  endif
1271 #endif /* HAVE_LIBRESSL */
1272 #ifndef HAVE_ARC4RANDOM
1273 void explicit_bzero(void* buf, size_t len);
1274 int getentropy(void* buf, size_t len);
1275 uint32_t arc4random(void);
1276 void arc4random_buf(void* buf, size_t n);
1277 void _ARC4_LOCK(void);
1278 void _ARC4_UNLOCK(void);
1279 #endif
1280 #ifndef HAVE_ARC4RANDOM_UNIFORM
1281 uint32_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)
1288 typedef 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 */
1294 void SHA512_Init(SHA512_CTX*);
1295 void SHA512_Update(SHA512_CTX*, void*, size_t);
1296 void SHA512_Final(uint8_t[SHA512_DIGEST_LENGTH], SHA512_CTX*);
1297 unsigned 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
1317 struct 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__)
1326 void *unbound_stat_malloc(size_t size);
1327 void *unbound_stat_calloc(size_t nmemb, size_t size);
1328 void unbound_stat_free(void *ptr);
1329 void *unbound_stat_realloc(void *ptr, size_t size);
1330 void *unbound_stat_malloc_log(size_t size, const char* file, int line,
1331         const char* func);
1332 void *unbound_stat_calloc_log(size_t nmemb, size_t size, const char* file,
1333         int line, const char* func);
1334 void unbound_stat_free_log(void *ptr, const char* file, int line,
1335         const char* func);
1336 void *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
1352 dnl if we build from source tree, the man pages need @date@ and @version@
1353 dnl if this is a distro tarball, that was already done by makedist.sh
1354 AC_SUBST(version, [VERSION_MAJOR.VERSION_MINOR.VERSION_MICRO])
1355 AC_SUBST(date, [`date +'%b %e, %Y'`])
1356
1357 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 doc/unbound-host.1 smallapp/unbound-control-setup.sh dnstap/dnstap_config.h])
1358 AC_CONFIG_HEADER([config.h])
1359 AC_OUTPUT