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