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