]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - configure.ac
Vendor import of Unbound 1.6.7.
[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 sinclude(dnscrypt/dnscrypt.m4)
10
11 # must be numbers. ac_defun because of later processing
12 m4_define([VERSION_MAJOR],[1])
13 m4_define([VERSION_MINOR],[6])
14 m4_define([VERSION_MICRO],[7])
15 AC_INIT(unbound, m4_defn([VERSION_MAJOR]).m4_defn([VERSION_MINOR]).m4_defn([VERSION_MICRO]), unbound-bugs@nlnetlabs.nl, unbound)
16 AC_SUBST(UNBOUND_VERSION_MAJOR, [VERSION_MAJOR])
17 AC_SUBST(UNBOUND_VERSION_MINOR, [VERSION_MINOR])
18 AC_SUBST(UNBOUND_VERSION_MICRO, [VERSION_MICRO])
19
20 LIBUNBOUND_CURRENT=7
21 LIBUNBOUND_REVISION=6
22 LIBUNBOUND_AGE=5
23 # 1.0.0 had 0:12:0
24 # 1.0.1 had 0:13:0
25 # 1.0.2 had 0:14:0
26 # 1.1.0 had 0:15:0
27 # 1.1.1 had 0:16:0
28 # 1.2.0 had 0:17:0
29 # 1.2.1 had 0:18:0
30 # 1.3.0 had 1:0:0   # ub_cancel and -export-symbols.
31 # 1.3.1 had 1:1:0
32 # 1.3.2 had 1:2:0
33 # 1.3.3 had 1:3:0
34 # 1.3.4 had 1:4:0
35 # 1.4.0-snapshots had 1:5:0
36 # 1.4.0 had 1:5:0 (not 2:0:0)   # ub_result.why_bogus
37 # 1.4.1 had 2:1:0
38 # 1.4.2 had 2:2:0
39 # 1.4.3 had 2:3:0
40 # 1.4.4 had 2:4:0
41 # 1.4.5 had 2:5:0
42 # 1.4.6 had 2:6:0
43 # 1.4.7 had 2:7:0
44 # 1.4.8 had 2:8:0
45 # 1.4.9 had 2:9:0
46 # 1.4.10 had 2:10:0
47 # 1.4.11 had 2:11:0
48 # 1.4.12 had 2:12:0
49 # 1.4.13 had 2:13:0
50 # and 1.4.13p1 and 1.4.13.p2
51 # 1.4.14 had 2:14:0
52 # 1.4.15 had 3:0:1 # adds ub_version()
53 # 1.4.16 had 3:1:1
54 # 1.4.17 had 3:2:1
55 # 1.4.18 had 3:3:1
56 # 1.4.19 had 3:4:1
57 # 1.4.20 had 4:0:2 # adds libunbound.ttl # but shipped 3:5:1
58 # 1.4.21 had 4:1:2
59 # 1.4.22 had 4:1:2
60 # 1.5.0 had 5:3:3 # adds ub_ctx_add_ta_autr
61 # 1.5.1 had 5:3:3
62 # 1.5.2 had 5:5:3
63 # 1.5.3 had 5:6:3
64 # 1.5.4 had 5:7:3
65 # 1.5.5 had 5:8:3
66 # 1.5.6 had 5:9:3
67 # 1.5.7 had 5:10:3
68 # 1.5.8 had 6:0:4 # adds ub_ctx_set_stub
69 # 1.5.9 had 6:1:4
70 # 1.5.10 had 6:2:4
71 # 1.6.0 had 6:3:4
72 # 1.6.1 had 7:0:5 # ub_callback_t typedef renamed to ub_callback_type
73 # 1.6.2 had 7:1:5
74 # 1.6.3 had 7:2:5
75 # 1.6.4 had 7:3:5
76 # 1.6.5 had 7:4:5
77 # 1.6.6 had 7:5:5
78 # 1.6.7 had 7:6:5
79
80 #   Current  -- the number of the binary API that we're implementing
81 #   Revision -- which iteration of the implementation of the binary
82 #               API are we supplying?
83 #   Age      -- How many previous binary API versions do we also
84 #               support?
85 #
86 # If we release a new version that does not change the binary API,
87 # increment Revision.
88 #
89 # If we release a new version that changes the binary API, but does
90 # not break programs compiled against the old binary API, increment
91 # Current and Age.  Set Revision to 0, since this is the first
92 # implementation of the new API.
93 #
94 # Otherwise, we're changing the binary API and breaking backward
95 # compatibility with old binaries.  Increment Current.  Set Age to 0,
96 # since we're backward compatible with no previous APIs.  Set Revision
97 # to 0 too.
98 AC_SUBST(LIBUNBOUND_CURRENT)
99 AC_SUBST(LIBUNBOUND_REVISION)
100 AC_SUBST(LIBUNBOUND_AGE)
101
102 CFLAGS="$CFLAGS"
103 AC_AIX
104 if test "$ac_cv_header_minix_config_h" = "yes"; then
105         AC_DEFINE(_NETBSD_SOURCE,1, [Enable for compile on Minix])
106 fi
107
108 dnl
109 dnl By default set prefix to /usr/local
110 dnl
111 case "$prefix" in
112         NONE)
113                 prefix="/usr/local"
114         ;;
115 esac
116 case "$exec_prefix" in
117         NONE)
118                 exec_prefix="$prefix"
119         ;;
120 esac
121
122 # are we on MinGW?
123 if uname -s 2>&1 | grep MINGW32 >/dev/null; then on_mingw="yes"
124 else 
125         if echo $host $target | grep mingw32 >/dev/null; then on_mingw="yes"
126         else on_mingw="no"; fi
127 fi
128
129 #
130 # Determine configuration file
131 # the eval is to evaluate shell expansion twice
132 UNBOUND_SBIN_DIR=`eval echo "${sbindir}"`
133 AC_SUBST(UNBOUND_SBIN_DIR)
134 UNBOUND_SYSCONF_DIR=`eval echo "${sysconfdir}"`
135 AC_SUBST(UNBOUND_SYSCONF_DIR)
136 UNBOUND_LOCALSTATE_DIR=`eval echo "${localstatedir}"`
137 AC_SUBST(UNBOUND_LOCALSTATE_DIR)
138 if test $on_mingw = "no"; then
139   ub_conf_file=`eval echo "${sysconfdir}/unbound/unbound.conf"`
140 else
141   ub_conf_file="C:\\Program Files\\Unbound\\service.conf"
142 fi
143 AC_ARG_WITH([conf_file],
144         AC_HELP_STRING([--with-conf-file=path], 
145         [Pathname to the Unbound configuration file]),
146         [ub_conf_file="$withval"])
147 AC_SUBST(ub_conf_file)
148 ACX_ESCAPE_BACKSLASH($ub_conf_file, hdr_config)
149 AC_DEFINE_UNQUOTED(CONFIGFILE, ["$hdr_config"], [Pathname to the Unbound configuration file])
150 ub_conf_dir=`AS_DIRNAME(["$ub_conf_file"])`
151 AC_SUBST(ub_conf_dir)
152
153 # Determine run, chroot directory and pidfile locations
154 AC_ARG_WITH(run-dir, 
155     AC_HELP_STRING([--with-run-dir=path], 
156     [set default directory to chdir to (by default dir part of cfg file)]), 
157     UNBOUND_RUN_DIR="$withval", 
158 if test $on_mingw = no; then
159     UNBOUND_RUN_DIR=`dirname "$ub_conf_file"`
160 else
161     UNBOUND_RUN_DIR=""
162 fi
163 )
164 AC_SUBST(UNBOUND_RUN_DIR)
165 ACX_ESCAPE_BACKSLASH($UNBOUND_RUN_DIR, hdr_run)
166 AC_DEFINE_UNQUOTED(RUN_DIR, ["$hdr_run"], [Directory to chdir to])
167
168 AC_ARG_WITH(chroot-dir, 
169     AC_HELP_STRING([--with-chroot-dir=path], 
170     [set default directory to chroot to (by default same as run-dir)]), 
171     UNBOUND_CHROOT_DIR="$withval", 
172 if test $on_mingw = no; then
173     UNBOUND_CHROOT_DIR="$UNBOUND_RUN_DIR"
174 else
175     UNBOUND_CHROOT_DIR=""
176 fi
177 )
178 AC_SUBST(UNBOUND_CHROOT_DIR)
179 ACX_ESCAPE_BACKSLASH($UNBOUND_CHROOT_DIR, hdr_chroot)
180 AC_DEFINE_UNQUOTED(CHROOT_DIR, ["$hdr_chroot"], [Directory to chroot to])
181
182 AC_ARG_WITH(share-dir,
183     AC_HELP_STRING([--with-share-dir=path],
184     [set default directory with shared data (by default same as share/unbound)]),
185     UNBOUND_SHARE_DIR="$withval",
186     UNBOUND_SHARE_DIR="$UNBOUND_RUN_DIR")
187 AC_SUBST(UNBOUND_SHARE_DIR)
188 AC_DEFINE_UNQUOTED(SHARE_DIR, ["$UNBOUND_SHARE_DIR"], [Shared data])
189
190 AC_ARG_WITH(pidfile, 
191     AC_HELP_STRING([--with-pidfile=filename], 
192     [set default pathname to unbound pidfile (default run-dir/unbound.pid)]), 
193     UNBOUND_PIDFILE="$withval", 
194 if test $on_mingw = no; then
195     UNBOUND_PIDFILE="$UNBOUND_RUN_DIR/unbound.pid"
196 else
197     UNBOUND_PIDFILE=""
198 fi
199 )
200 AC_SUBST(UNBOUND_PIDFILE)
201 ACX_ESCAPE_BACKSLASH($UNBOUND_PIDFILE, hdr_pid)
202 AC_DEFINE_UNQUOTED(PIDFILE, ["$hdr_pid"], [default pidfile location])
203
204 AC_ARG_WITH(rootkey-file, 
205     AC_HELP_STRING([--with-rootkey-file=filename], 
206     [set default pathname to root key file (default run-dir/root.key). This file is read and written.]), 
207     UNBOUND_ROOTKEY_FILE="$withval", 
208 if test $on_mingw = no; then
209     UNBOUND_ROOTKEY_FILE="$UNBOUND_RUN_DIR/root.key"
210 else
211     UNBOUND_ROOTKEY_FILE="C:\\Program Files\\Unbound\\root.key"
212 fi
213 )
214 AC_SUBST(UNBOUND_ROOTKEY_FILE)
215 ACX_ESCAPE_BACKSLASH($UNBOUND_ROOTKEY_FILE, hdr_rkey)
216 AC_DEFINE_UNQUOTED(ROOT_ANCHOR_FILE, ["$hdr_rkey"], [default rootkey location])
217
218 AC_ARG_WITH(rootcert-file, 
219     AC_HELP_STRING([--with-rootcert-file=filename], 
220     [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.]), 
221     UNBOUND_ROOTCERT_FILE="$withval", 
222 if test $on_mingw = no; then
223     UNBOUND_ROOTCERT_FILE="$UNBOUND_RUN_DIR/icannbundle.pem"
224 else
225     UNBOUND_ROOTCERT_FILE="C:\\Program Files\\Unbound\\icannbundle.pem"
226 fi
227 )
228 AC_SUBST(UNBOUND_ROOTCERT_FILE)
229 ACX_ESCAPE_BACKSLASH($UNBOUND_ROOTCERT_FILE, hdr_rpem)
230 AC_DEFINE_UNQUOTED(ROOT_CERT_FILE, ["$hdr_rpem"], [default rootcert location])
231
232 AC_ARG_WITH(username, 
233     AC_HELP_STRING([--with-username=user], 
234     [set default user that unbound changes to (default user is unbound)]), 
235     UNBOUND_USERNAME="$withval", 
236     UNBOUND_USERNAME="unbound")
237 AC_SUBST(UNBOUND_USERNAME)
238 AC_DEFINE_UNQUOTED(UB_USERNAME, ["$UNBOUND_USERNAME"], [default username])
239
240 AC_DEFINE(WINVER, 0x0502, [the version of the windows API enabled])
241 ACX_RSRC_VERSION(wnvs)
242 AC_DEFINE_UNQUOTED(RSRC_PACKAGE_VERSION, [$wnvs], [version number for resource files])
243
244 # Checks for typedefs, structures, and compiler characteristics.
245 AC_C_CONST
246 AC_LANG_C
247 # allow user to override the -g -O2 flags.
248 if test "x$CFLAGS" = "x" ; then
249 ACX_CHECK_COMPILER_FLAG(g, [CFLAGS="$CFLAGS -g"])
250 ACX_CHECK_COMPILER_FLAG(O2, [CFLAGS="$CFLAGS -O2"])
251 fi
252 AC_PROG_CC
253 ACX_DEPFLAG
254 ACX_DETERMINE_EXT_FLAGS_UNBOUND
255
256 # debug mode flags warnings
257 AC_ARG_ENABLE(checking, AC_HELP_STRING([--enable-checking], [Enable warnings, asserts, makefile-dependencies]))
258 AC_ARG_ENABLE(debug, AC_HELP_STRING([--enable-debug], [same as enable-checking]))
259 if test "$enable_debug" = "yes"; then debug_enabled="$enable_debug"; 
260 else debug_enabled="$enable_checking"; fi
261 AC_SUBST(debug_enabled)
262 case "$debug_enabled" in
263         yes)
264                 ACX_CHECK_COMPILER_FLAG(W, [CFLAGS="$CFLAGS -W"])
265                 ACX_CHECK_COMPILER_FLAG(Wall, [CFLAGS="$CFLAGS -Wall"])
266                 ACX_CHECK_COMPILER_FLAG(Wextra, [CFLAGS="$CFLAGS -Wextra"])
267                 ACX_CHECK_COMPILER_FLAG(Wdeclaration-after-statement, [CFLAGS="$CFLAGS -Wdeclaration-after-statement"])
268                 AC_DEFINE([UNBOUND_DEBUG], [], [define this to enable debug checks.])
269                 ;;
270         no|*)
271                 # nothing to do.
272                 ;;
273 esac
274 ACX_CHECK_FLTO
275 ACX_CHECK_PIE
276 ACX_CHECK_RELRO_NOW
277
278 AC_C_INLINE
279 ACX_CHECK_FORMAT_ATTRIBUTE
280 ACX_CHECK_UNUSED_ATTRIBUTE
281
282 AC_DEFUN([CHECK_WEAK_ATTRIBUTE],
283 [AC_REQUIRE([AC_PROG_CC])
284 AC_MSG_CHECKING(whether the C compiler (${CC-cc}) accepts the "weak" attribute)
285 AC_CACHE_VAL(ac_cv_c_weak_attribute,
286 [ac_cv_c_weak_attribute=no
287 AC_TRY_COMPILE(
288 [ #include <stdio.h>
289 __attribute__((weak)) void f(int x) { printf("%d", x); }
290 ], [
291    f(1);
292 ],
293 [ac_cv_c_weak_attribute="yes"],
294 [ac_cv_c_weak_attribute="no"])
295 ])
296
297 AC_MSG_RESULT($ac_cv_c_weak_attribute)
298 if test $ac_cv_c_weak_attribute = yes; then
299   AC_DEFINE(HAVE_ATTR_WEAK, 1, [Whether the C compiler accepts the "weak" attribute])
300 fi
301 ])dnl End of CHECK_WEAK_ATTRIBUTE
302
303 CHECK_WEAK_ATTRIBUTE
304
305 if test "$srcdir" != "."; then
306         CPPFLAGS="$CPPFLAGS -I$srcdir"
307 fi
308
309 AC_DEFUN([ACX_YYLEX_DESTROY], [
310         AC_MSG_CHECKING([for yylex_destroy])
311         if echo %% | $LEX -t 2>&1 | grep yylex_destroy >/dev/null 2>&1; then
312                 AC_DEFINE(LEX_HAS_YYLEX_DESTROY, 1, [if lex has yylex_destroy])
313                 AC_MSG_RESULT(yes)
314         else AC_MSG_RESULT(no); fi
315 ])
316
317 AC_PROG_LEX
318 ACX_YYLEX_DESTROY
319 AC_PROG_YACC
320 AC_CHECK_PROG(doxygen, doxygen, doxygen)
321 AC_CHECK_TOOL(STRIP, strip)
322 ACX_LIBTOOL_C_ONLY
323
324 # Checks for header files.
325 AC_CHECK_HEADERS([stdarg.h stdbool.h netinet/in.h netinet/tcp.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 sys/ipc.h sys/shm.h],,, [AC_INCLUDES_DEFAULT])
326
327 # check for types.  
328 # Using own tests for int64* because autoconf builtin only give 32bit.
329 AC_CHECK_TYPE(int8_t, signed char)
330 AC_CHECK_TYPE(int16_t, short)
331 AC_CHECK_TYPE(int32_t, int)
332 AC_CHECK_TYPE(int64_t, long long)
333 AC_CHECK_TYPE(uint8_t, unsigned char)
334 AC_CHECK_TYPE(uint16_t, unsigned short)
335 AC_CHECK_TYPE(uint32_t, unsigned int)
336 AC_CHECK_TYPE(uint64_t, unsigned long long)
337 AC_TYPE_SIZE_T
338 AC_CHECK_TYPE(ssize_t, int)
339 AC_TYPE_UID_T
340 AC_TYPE_PID_T
341 AC_TYPE_OFF_T
342 ACX_TYPE_U_CHAR
343 ACX_TYPE_RLIM_T
344 ACX_TYPE_SOCKLEN_T
345 ACX_TYPE_IN_ADDR_T
346 ACX_TYPE_IN_PORT_T
347 ACX_CHECK_MEMCMP_SIGNED
348
349 AC_CHECK_SIZEOF(time_t,,[
350 AC_INCLUDES_DEFAULT
351 #ifdef TIME_WITH_SYS_TIME
352 # include <sys/time.h>
353 # include <time.h>
354 #else
355 # ifdef HAVE_SYS_TIME_H
356 #  include <sys/time.h>
357 # else
358 #  include <time.h>
359 # endif
360 #endif
361 ])
362
363 # add option to disable the evil rpath
364 ACX_ARG_RPATH
365 AC_SUBST(RUNTIME_PATH)
366
367 # check to see if libraries are needed for these functions.
368 AC_SEARCH_LIBS([inet_pton], [nsl])
369 AC_SEARCH_LIBS([socket], [socket])
370
371 # check wether strptime also works
372 AC_DEFUN([AC_CHECK_STRPTIME_WORKS],
373 [AC_REQUIRE([AC_PROG_CC])
374 AC_MSG_CHECKING(whether strptime works)
375 if test c${cross_compiling} = cno; then
376 AC_RUN_IFELSE([AC_LANG_SOURCE([[
377 #define _XOPEN_SOURCE 600
378 #include <time.h>
379 int main(void) { struct tm tm; char *res;
380 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);
381 if (!res) return 2;
382 res = strptime("20070207111842", "%Y%m%d%H%M%S", &tm);
383 if (!res) return 1; return 0; }
384 ]])] , [eval "ac_cv_c_strptime_works=yes"], [eval "ac_cv_c_strptime_works=no"])
385 else
386 eval "ac_cv_c_strptime_works=maybe"
387 fi
388 AC_MSG_RESULT($ac_cv_c_strptime_works)
389 if test $ac_cv_c_strptime_works = no; then
390 AC_LIBOBJ(strptime)
391 else
392 AC_DEFINE_UNQUOTED([STRPTIME_WORKS], 1, [use default strptime.])
393 fi
394 ])dnl
395
396 # check some functions of the OS before linking libs (while still runnable).
397 AC_FUNC_CHOWN
398 AC_FUNC_FORK
399 AC_TYPE_SIGNAL
400 AC_FUNC_FSEEKO
401 ACX_SYS_LARGEFILE
402 ACX_CHECK_NONBLOCKING_BROKEN
403 ACX_MKDIR_ONE_ARG
404 AC_CHECK_FUNCS([strptime],[AC_CHECK_STRPTIME_WORKS],[AC_LIBOBJ([strptime])])
405
406 # set memory allocation checking if requested
407 AC_ARG_ENABLE(alloc-checks, AC_HELP_STRING([--enable-alloc-checks],
408         [ enable to memory allocation statistics, for debug purposes ]), 
409         , )
410 AC_ARG_ENABLE(alloc-lite, AC_HELP_STRING([--enable-alloc-lite],
411         [ enable for lightweight alloc assertions, for debug purposes ]), 
412         , )
413 AC_ARG_ENABLE(alloc-nonregional, AC_HELP_STRING([--enable-alloc-nonregional],
414         [ enable nonregional allocs, slow but exposes regional allocations to other memory purifiers, for debug purposes ]), 
415         , )
416 if test x_$enable_alloc_nonregional = x_yes; then
417         AC_DEFINE(UNBOUND_ALLOC_NONREGIONAL, 1, [use malloc not regions, for debug use])
418 fi
419 if test x_$enable_alloc_checks = x_yes; then
420         AC_DEFINE(UNBOUND_ALLOC_STATS, 1, [use statistics for allocs and frees, for debug use])
421 else
422         if test x_$enable_alloc_lite = x_yes; then
423                 AC_DEFINE(UNBOUND_ALLOC_LITE, 1, [use to enable lightweight alloc assertions, for debug use])
424         else
425                 ACX_FUNC_MALLOC([unbound])
426         fi
427 fi
428
429 # check windows threads (we use them, not pthreads, on windows).
430 if test "$on_mingw" = "yes"; then
431 # check windows threads
432         AC_CHECK_HEADERS([windows.h],,, [AC_INCLUDES_DEFAULT])
433         AC_MSG_CHECKING([for CreateThread])
434         AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
435 #ifdef HAVE_WINDOWS_H
436 #include <windows.h>
437 #endif
438 ], [
439         HANDLE t = CreateThread(NULL, 0, NULL, NULL, 0, NULL);
440 ])],
441         AC_MSG_RESULT(yes)
442         AC_DEFINE(HAVE_WINDOWS_THREADS, 1, [Using Windows threads])
443 ,       
444         AC_MSG_RESULT(no)
445 )
446
447 else
448 # not on mingw, check thread libraries.
449
450 # check for thread library.
451 # check this first, so that the pthread lib does not get linked in via
452 # libssl or libpython, and thus distorts the tests, and we end up using
453 # the non-threadsafe C libraries.
454 AC_ARG_WITH(pthreads, AC_HELP_STRING([--with-pthreads], 
455  [use pthreads library, or --without-pthreads to disable threading support.]), 
456  [ ],[ withval="yes" ])
457 ub_have_pthreads=no
458 if test x_$withval != x_no; then
459         AX_PTHREAD([
460                 AC_DEFINE(HAVE_PTHREAD,1,[Define if you have POSIX threads libraries and header files.])
461                 if test -n "$PTHREAD_LIBS"; then
462                   LIBS="$PTHREAD_LIBS $LIBS"
463                 fi
464                 CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
465                 CC="$PTHREAD_CC"
466                 ub_have_pthreads=yes
467                 AC_CHECK_TYPES([pthread_spinlock_t, pthread_rwlock_t],,,[#include <pthread.h>])
468
469                 if echo "$CFLAGS" | $GREP -e "-pthread" >/dev/null; then
470                 AC_MSG_CHECKING([if -pthread unused during linking])
471                 # catch clang warning 'argument unused during compilation'
472                 AC_LANG_CONFTEST([AC_LANG_SOURCE(AC_INCLUDES_DEFAULT
473 [[
474 int main(void) {return 0;}
475 ]])])
476                 pthread_unused="yes"
477                 # first compile
478                 echo "$CC $CFLAGS -c conftest.c -o conftest.o" >&AS_MESSAGE_LOG_FD
479                 $CC $CFLAGS -c conftest.c -o conftest.o 2>&AS_MESSAGE_LOG_FD >&AS_MESSAGE_LOG_FD
480                 if test $? = 0; then 
481                         # then link
482                         echo "$CC $CFLAGS -Werror $LDFLAGS $LIBS -o conftest contest.o" >&AS_MESSAGE_LOG_FD
483                         $CC $CFLAGS -Werror $LDFLAGS $LIBS -o conftest conftest.o 2>&AS_MESSAGE_LOG_FD >&AS_MESSAGE_LOG_FD
484                         if test $? -ne 0; then
485                                 AC_MSG_RESULT(yes)
486                                 CFLAGS=`echo "$CFLAGS" | sed -e 's/-pthread//'`
487                                 PTHREAD_CFLAGS_ONLY="-pthread"
488                                 AC_SUBST(PTHREAD_CFLAGS_ONLY)
489                         else
490                                 AC_MSG_RESULT(no)
491                         fi
492                 else
493                         AC_MSG_RESULT(no)
494                 fi # endif cc successful
495                 rm -f conftest conftest.c conftest.o
496                 fi # endif -pthread in CFLAGS
497
498                 ])
499 fi
500
501 # check solaris thread library 
502 AC_ARG_WITH(solaris-threads, AC_HELP_STRING([--with-solaris-threads], 
503         [use solaris native thread library.]), [ ],[ withval="no" ])
504 ub_have_sol_threads=no
505 if test x_$withval != x_no; then
506         if test x_$ub_have_pthreads != x_no; then
507             AC_WARN([Have pthreads already, ignoring --with-solaris-threads])
508         else
509         AC_SEARCH_LIBS(thr_create, [thread],
510         [
511                 AC_DEFINE(HAVE_SOLARIS_THREADS, 1, [Using Solaris threads])
512
513                 ACX_CHECK_COMPILER_FLAG(mt, [CFLAGS="$CFLAGS -mt"],
514                         [CFLAGS="$CFLAGS -D_REENTRANT"])
515                 ub_have_sol_threads=yes
516         ] , [ 
517                 AC_ERROR([no solaris threads found.]) 
518         ])
519         fi
520 fi
521
522 fi # end of non-mingw check of thread libraries
523
524 # Check for PyUnbound
525 AC_ARG_WITH(pyunbound,
526    AC_HELP_STRING([--with-pyunbound],
527    [build PyUnbound, or --without-pyunbound to skip it. (default=no)]),
528    [], [ withval="no" ])
529
530 ub_test_python=no
531 ub_with_pyunbound=no
532 if test x_$withval != x_no; then
533    ub_with_pyunbound=yes
534    ub_test_python=yes
535 fi
536
537 # Check for Python module
538 AC_ARG_WITH(pythonmodule,
539    AC_HELP_STRING([--with-pythonmodule],
540    [build Python module, or --without-pythonmodule to disable script engine. (default=no)]),
541    [], [ withval="no" ])
542
543 ub_with_pythonmod=no
544 if test x_$withval != x_no; then
545    ub_with_pythonmod=yes
546    ub_test_python=yes
547 fi
548
549 # Check for Python & SWIG only on PyUnbound or PyModule
550 if test x_$ub_test_python != x_no; then
551
552    # Check for Python
553    ub_have_python=no
554    ac_save_LIBS="$LIBS" dnl otherwise AC_PYTHON_DEVEL thrashes $LIBS
555    AC_PYTHON_DEVEL
556    if test ! -z "$PYTHON_VERSION"; then
557         if test `$PYTHON -c "print('$PYTHON_VERSION' >= '2.4.0')"` = "False"; then
558                 AC_ERROR([Python version >= 2.4.0 is required])
559         fi
560
561       [PY_MAJOR_VERSION="`$PYTHON -c \"import sys; print(sys.version_info[0])\"`"]
562       AC_SUBST(PY_MAJOR_VERSION)
563       # Have Python
564       AC_DEFINE(HAVE_PYTHON,1,[Define if you have Python libraries and header files.])
565       if test -n "$LIBS"; then
566         LIBS="$PYTHON_LDFLAGS $LIBS"
567       else
568         LIBS="$PYTHON_LDFLAGS"
569       fi
570       if test -n "$CPPFLAGS"; then
571         CPPFLAGS="$CPPFLAGS $PYTHON_CPPFLAGS"
572       else
573         CPPFLAGS="$PYTHON_CPPFLAGS"
574       fi
575       ub_have_python=yes
576       PC_PY_DEPENDENCY="python"
577       AC_SUBST(PC_PY_DEPENDENCY)
578
579       # Check for SWIG
580       ub_have_swig=no
581       AC_PROG_SWIG(2.0.1)
582       AC_MSG_CHECKING(SWIG)
583       if test ! -x "$SWIG"; then
584          AC_ERROR([failed to find swig tool, install it, or do not build Python module and PyUnbound])
585       else
586          AC_DEFINE(HAVE_SWIG, 1, [Define if you have Swig libraries and header files.])
587          AC_SUBST(swig, "$SWIG")
588          AC_MSG_RESULT(present)
589
590          # If have Python & SWIG
591          # Declare PythonMod
592          if test x_$ub_with_pythonmod != x_no; then
593             AC_DEFINE(WITH_PYTHONMODULE, 1, [Define if you want Python module.])
594             WITH_PYTHONMODULE=yes
595             AC_SUBST(WITH_PYTHONMODULE)
596             PYTHONMOD_OBJ="pythonmod.lo pythonmod_utils.lo"
597             AC_SUBST(PYTHONMOD_OBJ)
598             PYTHONMOD_HEADER='$(srcdir)/pythonmod/pythonmod.h'
599             AC_SUBST(PYTHONMOD_HEADER)
600             PYTHONMOD_INSTALL=pythonmod-install
601             AC_SUBST(PYTHONMOD_INSTALL)
602             PYTHONMOD_UNINSTALL=pythonmod-uninstall
603             AC_SUBST(PYTHONMOD_UNINSTALL)
604          fi
605
606          # Declare PyUnbound
607          if test x_$ub_with_pyunbound != x_no; then
608             AC_DEFINE(WITH_PYUNBOUND, 1, [Define if you want PyUnbound.])
609             WITH_PYUNBOUND=yes
610             AC_SUBST(WITH_PYUNBOUND)
611             PYUNBOUND_OBJ="libunbound_wrap.lo"
612             AC_SUBST(PYUNBOUND_OBJ)
613             PYUNBOUND_TARGET="_unbound.la"
614             AC_SUBST(PYUNBOUND_TARGET)
615             PYUNBOUND_INSTALL=pyunbound-install
616             AC_SUBST(PYUNBOUND_INSTALL)
617             PYUNBOUND_UNINSTALL=pyunbound-uninstall
618             AC_SUBST(PYUNBOUND_UNINSTALL)
619          fi
620       fi
621    else
622       AC_MSG_RESULT([*** Python libraries not found, won't build PythonMod or PyUnbound ***])
623       ub_with_pyunbound=no
624       ub_with_pythonmod=no
625    fi
626 fi
627
628 if test "`uname`" = "NetBSD"; then
629         NETBSD_LINTFLAGS='"-D__RENAME(x)=" -D_NETINET_IN_H_'
630         AC_SUBST(NETBSD_LINTFLAGS)
631 fi
632 CONFIG_DATE=`date +%Y%m%d`
633 AC_SUBST(CONFIG_DATE)
634
635 # Checks for libraries.
636
637 # libnss
638 USE_NSS="no"
639 AC_ARG_WITH([nss], AC_HELP_STRING([--with-nss=path],
640         [use libnss instead of openssl, installed at path.]),
641         [
642         USE_NSS="yes"
643         AC_DEFINE(HAVE_NSS, 1, [Use libnss for crypto])
644         if test "$withval" != "" -a "$withval" != "yes"; then
645                 CPPFLAGS="$CPPFLAGS -I$withval/include/nss3"
646                 LDFLAGS="$LDFLAGS -L$withval/lib"
647                 ACX_RUNTIME_PATH_ADD([$withval/lib])
648                 CPPFLAGS="-I$withval/include/nspr4 $CPPFLAGS"
649         else
650                 CPPFLAGS="$CPPFLAGS -I/usr/include/nss3"
651                 CPPFLAGS="-I/usr/include/nspr4 $CPPFLAGS"
652         fi
653         LIBS="$LIBS -lnss3 -lnspr4"
654         SSLLIB=""
655         ]
656 )
657
658 # libnettle
659 USE_NETTLE="no"
660 AC_ARG_WITH([nettle], AC_HELP_STRING([--with-nettle=path],
661         [use libnettle as crypto library, installed at path.]),
662         [
663         USE_NETTLE="yes"
664         AC_DEFINE(HAVE_NETTLE, 1, [Use libnettle for crypto])
665         AC_CHECK_HEADERS([nettle/dsa-compat.h],,, [AC_INCLUDES_DEFAULT])
666         if test "$withval" != "" -a "$withval" != "yes"; then
667                 CPPFLAGS="$CPPFLAGS -I$withval/include/nettle"
668                 LDFLAGS="$LDFLAGS -L$withval/lib"
669                 ACX_RUNTIME_PATH_ADD([$withval/lib])
670         else
671                 CPPFLAGS="$CPPFLAGS -I/usr/include/nettle"
672         fi
673         LIBS="$LIBS -lhogweed -lnettle -lgmp"
674         SSLLIB=""
675         ]
676 )
677
678 # openssl
679 if test $USE_NSS = "no" -a $USE_NETTLE = "no"; then
680 ACX_WITH_SSL
681 ACX_LIB_SSL
682 SSLLIB="-lssl"
683
684 # check if -lcrypt32 is needed because CAPIENG needs that. (on windows)
685 BAKLIBS="$LIBS"
686 LIBS="-lssl $LIBS"
687 AC_MSG_CHECKING([if libssl needs -lcrypt32])
688 AC_TRY_LINK_FUNC([HMAC_Update], [
689         AC_MSG_RESULT([no])
690         LIBS="$BAKLIBS"
691 ], [
692         AC_MSG_RESULT([yes])
693         LIBS="$BAKLIBS"
694         LIBS="$LIBS -lcrypt32"
695 ])
696
697 AC_MSG_CHECKING([for LibreSSL])
698 if grep VERSION_TEXT $ssldir/include/openssl/opensslv.h | grep "LibreSSL" >/dev/null; then
699         AC_MSG_RESULT([yes])
700         AC_DEFINE([HAVE_LIBRESSL], [1], [Define if we have LibreSSL])
701         # libressl provides these compat functions, but they may also be
702         # declared by the OS in libc.  See if they have been declared.
703         AC_CHECK_DECLS([strlcpy,strlcat,arc4random,arc4random_uniform,reallocarray])
704 else
705         AC_MSG_RESULT([no])
706 fi
707 AC_CHECK_HEADERS([openssl/conf.h openssl/engine.h openssl/bn.h openssl/dh.h openssl/dsa.h openssl/rsa.h],,, [AC_INCLUDES_DEFAULT])
708 AC_CHECK_FUNCS([OPENSSL_config EVP_sha1 EVP_sha256 EVP_sha512 FIPS_mode EVP_MD_CTX_new OpenSSL_add_all_digests OPENSSL_init_crypto EVP_cleanup ERR_load_crypto_strings CRYPTO_cleanup_all_ex_data ERR_free_strings RAND_cleanup DSA_SIG_set0 EVP_dss1 EVP_DigestVerify])
709
710 # these check_funcs need -lssl
711 BAKLIBS="$LIBS"
712 LIBS="-lssl $LIBS"
713 AC_CHECK_FUNCS([OPENSSL_init_ssl SSL_CTX_set_security_level])
714 LIBS="$BAKLIBS"
715
716 AC_CHECK_DECLS([SSL_COMP_get_compression_methods,sk_SSL_COMP_pop_free,SSL_CTX_set_ecdh_auto], [], [], [
717 AC_INCLUDES_DEFAULT
718 #ifdef HAVE_OPENSSL_ERR_H
719 #include <openssl/err.h>
720 #endif
721
722 #ifdef HAVE_OPENSSL_RAND_H
723 #include <openssl/rand.h>
724 #endif
725
726 #ifdef HAVE_OPENSSL_CONF_H
727 #include <openssl/conf.h>
728 #endif
729
730 #ifdef HAVE_OPENSSL_ENGINE_H
731 #include <openssl/engine.h>
732 #endif
733 #include <openssl/ssl.h>
734 #include <openssl/evp.h>
735 ])
736 fi
737 AC_SUBST(SSLLIB)
738
739
740 AC_ARG_ENABLE(sha1, AC_HELP_STRING([--disable-sha1], [Disable SHA1 RRSIG support, does not disable nsec3 support]))
741 case "$enable_sha1" in
742         no)
743         ;;
744         yes|*)
745         AC_DEFINE([USE_SHA1], [1], [Define this to enable SHA1 support.])
746         ;;
747 esac
748
749
750 AC_ARG_ENABLE(sha2, AC_HELP_STRING([--disable-sha2], [Disable SHA256 and SHA512 RRSIG support]))
751 case "$enable_sha2" in
752         no)
753         ;;
754         yes|*)
755         AC_DEFINE([USE_SHA2], [1], [Define this to enable SHA256 and SHA512 support.])
756         ;;
757 esac
758
759 AC_ARG_ENABLE(subnet, AC_HELP_STRING([--enable-subnet], [Enable client subnet]))
760 case "$enable_subnet" in
761         yes)
762         AC_DEFINE([CLIENT_SUBNET], [1], [Define this to enable client subnet option.])
763         SUBNET_OBJ="edns-subnet.lo subnetmod.lo addrtree.lo subnet-whitelist.lo"
764         AC_SUBST(SUBNET_OBJ)
765         SUBNET_HEADER='$(srcdir)/edns-subnet/subnetmod.h $(srcdir)/edns-subnet/edns-subnet.h $(srcdir)/edns-subnet/subnet-whitelist.h $(srcdir)/edns-subnet/addrtree.h'
766         AC_SUBST(SUBNET_HEADER)
767         ;;
768         no|*)
769         ;;
770 esac
771
772 # check wether gost also works
773 AC_DEFUN([AC_CHECK_GOST_WORKS],
774 [AC_REQUIRE([AC_PROG_CC])
775 AC_MSG_CHECKING([if GOST works])
776 if test c${cross_compiling} = cno; then
777 BAKCFLAGS="$CFLAGS"
778 if test -n "$ssldir"; then
779         CFLAGS="$CFLAGS -Wl,-rpath,$ssldir/lib"
780 fi
781 AC_RUN_IFELSE([AC_LANG_SOURCE([[
782 #include <string.h>
783 #include <openssl/ssl.h>
784 #include <openssl/evp.h>
785 #include <openssl/engine.h>
786 #include <openssl/conf.h>
787 /* routine to load gost (from sldns) */
788 int load_gost_id(void)
789 {
790         static int gost_id = 0;
791         const EVP_PKEY_ASN1_METHOD* meth;
792         ENGINE* e;
793
794         if(gost_id) return gost_id;
795
796         /* see if configuration loaded gost implementation from other engine*/
797         meth = EVP_PKEY_asn1_find_str(NULL, "gost2001", -1);
798         if(meth) {
799                 EVP_PKEY_asn1_get0_info(&gost_id, NULL, NULL, NULL, NULL, meth);
800                 return gost_id;
801         }
802
803         /* see if engine can be loaded already */
804         e = ENGINE_by_id("gost");
805         if(!e) {
806                 /* load it ourself, in case statically linked */
807                 ENGINE_load_builtin_engines();
808                 ENGINE_load_dynamic();
809                 e = ENGINE_by_id("gost");
810         }
811         if(!e) {
812                 /* no gost engine in openssl */
813                 return 0;
814         }
815         if(!ENGINE_set_default(e, ENGINE_METHOD_ALL)) {
816                 ENGINE_finish(e);
817                 ENGINE_free(e);
818                 return 0;
819         }
820
821         meth = EVP_PKEY_asn1_find_str(&e, "gost2001", -1);
822         if(!meth) {
823                 /* algo not found */
824                 ENGINE_finish(e);
825                 ENGINE_free(e);
826                 return 0;
827         }
828         EVP_PKEY_asn1_get0_info(&gost_id, NULL, NULL, NULL, NULL, meth);
829         return gost_id;
830 }
831 int main(void) { 
832         EVP_MD_CTX* ctx;
833         const EVP_MD* md;
834         unsigned char digest[64]; /* its a 256-bit digest, so uses 32 bytes */
835         const char* str = "Hello world";
836         const unsigned char check[] = {
837                 0x40 , 0xed , 0xf8 , 0x56 , 0x5a , 0xc5 , 0x36 , 0xe1 ,
838                 0x33 , 0x7c , 0x7e , 0x87 , 0x62 , 0x1c , 0x42 , 0xe0 ,
839                 0x17 , 0x1b , 0x5e , 0xce , 0xa8 , 0x46 , 0x65 , 0x4d ,
840                 0x8d , 0x3e , 0x22 , 0x9b , 0xe1 , 0x30 , 0x19 , 0x9d
841         };
842         OPENSSL_config(NULL);
843         (void)load_gost_id();
844         md = EVP_get_digestbyname("md_gost94");
845         if(!md) return 1;
846         memset(digest, 0, sizeof(digest));
847         ctx = EVP_MD_CTX_create();
848         if(!ctx) return 2;
849         if(!EVP_DigestInit_ex(ctx, md, NULL)) return 3;
850         if(!EVP_DigestUpdate(ctx, str, 10)) return 4;
851         if(!EVP_DigestFinal_ex(ctx, digest, NULL)) return 5;
852         /* uncomment to see the hash calculated.
853                 {int i;
854                 for(i=0; i<32; i++)
855                         printf(" %2.2x", (int)digest[i]);
856                 printf("\n");}
857         */
858         if(memcmp(digest, check, sizeof(check)) != 0)
859                 return 6;
860         return 0;
861 }
862 ]])] , [eval "ac_cv_c_gost_works=yes"], [eval "ac_cv_c_gost_works=no"])
863 CFLAGS="$BAKCFLAGS"
864 else
865 eval "ac_cv_c_gost_works=maybe"
866 fi
867 AC_MSG_RESULT($ac_cv_c_gost_works)
868 ])dnl
869
870 AC_ARG_ENABLE(gost, AC_HELP_STRING([--disable-gost], [Disable GOST support]))
871 use_gost="no"
872 if test $USE_NSS = "no" -a $USE_NETTLE = "no"; then
873 case "$enable_gost" in
874         no)
875         ;;
876         *)
877         AC_CHECK_FUNC(EVP_PKEY_set_type_str, [:],[AC_MSG_ERROR([OpenSSL 1.0.0 is needed for GOST support])])
878         AC_CHECK_FUNC(EC_KEY_new, [], [AC_MSG_ERROR([OpenSSL does not support ECC, needed for GOST support])])
879         AC_CHECK_GOST_WORKS
880         if test "$ac_cv_c_gost_works" != no; then
881                 use_gost="yes"
882                 AC_DEFINE([USE_GOST], [1], [Define this to enable GOST support.])
883         fi
884         ;;
885 esac
886 fi dnl !USE_NSS && !USE_NETTLE
887
888 AC_ARG_ENABLE(ecdsa, AC_HELP_STRING([--disable-ecdsa], [Disable ECDSA support]))
889 use_ecdsa="no"
890 case "$enable_ecdsa" in
891     no)
892       ;;
893     *)
894       if test $USE_NSS = "no" -a $USE_NETTLE = "no"; then
895               AC_CHECK_FUNC(ECDSA_sign, [], [AC_MSG_ERROR([OpenSSL does not support ECDSA: please upgrade or rerun with --disable-ecdsa])])
896               AC_CHECK_FUNC(SHA384_Init, [], [AC_MSG_ERROR([OpenSSL does not support SHA384: please upgrade or rerun with --disable-ecdsa])])
897               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
898 #include <openssl/evp.h>
899               ])
900               # see if OPENSSL 1.0.0 or later (has EVP MD and Verify independency)
901               AC_MSG_CHECKING([if openssl supports SHA2 and ECDSA with EVP])
902               if grep OPENSSL_VERSION_TEXT $ssldir/include/openssl/opensslv.h | grep "OpenSSL" >/dev/null; then
903                 if grep OPENSSL_VERSION_NUMBER $ssldir/include/openssl/opensslv.h | grep 0x0 >/dev/null; then
904                   AC_MSG_RESULT([no])
905                   AC_DEFINE_UNQUOTED([USE_ECDSA_EVP_WORKAROUND], [1], [Define this to enable an EVP workaround for older openssl])
906                 else
907                   AC_MSG_RESULT([yes])
908                 fi
909               else
910                 # not OpenSSL, thus likely LibreSSL, which supports it
911                 AC_MSG_RESULT([yes])
912               fi
913       fi
914       # we now know we have ECDSA and the required curves.
915       AC_DEFINE_UNQUOTED([USE_ECDSA], [1], [Define this to enable ECDSA support.])
916       use_ecdsa="yes"
917       ;;
918 esac
919
920 AC_ARG_ENABLE(dsa, AC_HELP_STRING([--disable-dsa], [Disable DSA support]))
921 use_dsa="no"
922 case "$enable_dsa" in
923     no)
924       ;;
925     *)
926       # detect if DSA is supported, and turn it off if not.
927       if test $USE_NSS = "no" -a $USE_NETTLE = "no"; then
928       AC_CHECK_FUNC(DSA_SIG_new, [
929       AC_DEFINE_UNQUOTED([USE_DSA], [1], [Define this to enable DSA support.])
930       ], [if test "x$enable_dsa" = "xyes"; then AC_MSG_ERROR([OpenSSL does not support DSA and you used --enable-dsa.])
931                fi ])
932       else
933       AC_DEFINE_UNQUOTED([USE_DSA], [1], [Define this to enable DSA support.])
934       fi
935       ;;
936 esac
937
938 AC_ARG_ENABLE(ed25519, AC_HELP_STRING([--disable-ed25519], [Disable ED25519 support]))
939 use_ed25519="no"
940 case "$enable_ed25519" in
941     no)
942       ;;
943     *)
944       if test $USE_NSS = "no" -a $USE_NETTLE = "no"; then
945               AC_CHECK_DECLS([NID_ED25519], [
946                 use_ed25519="yes"
947               ], [ if test "x$enable_ed25519" = "xyes"; then AC_MSG_ERROR([OpenSSL does not support ED25519 and you used --enable-ed25519.])
948                 fi ], [AC_INCLUDES_DEFAULT
949 #include <openssl/evp.h>
950               ])
951       fi
952       if test $USE_NETTLE = "yes"; then
953                 AC_CHECK_HEADERS([nettle/eddsa.h], use_ed25519="yes",, [AC_INCLUDES_DEFAULT])
954       fi
955       if test $use_ed25519 = "yes"; then
956                 AC_DEFINE_UNQUOTED([USE_ED25519], [1], [Define this to enable ED25519 support.])
957       fi
958       ;;
959 esac
960
961 AC_ARG_ENABLE(event-api, AC_HELP_STRING([--enable-event-api], [Enable (experimental) pluggable event base libunbound API installed to unbound-event.h]))
962 case "$enable_event_api" in
963     yes)
964       AC_SUBST(UNBOUND_EVENT_INSTALL, [unbound-event-install])
965       AC_SUBST(UNBOUND_EVENT_UNINSTALL, [unbound-event-uninstall])
966       ;;
967     *)
968       ;;
969 esac
970
971 AC_ARG_ENABLE(tfo-client, AC_HELP_STRING([--enable-tfo-client], [Enable TCP Fast Open for client mode]))
972 case "$enable_tfo_client" in
973         yes)
974                 case `uname` in
975                         Linux) AC_CHECK_DECL([MSG_FASTOPEN], [AC_MSG_WARN([Check the platform specific TFO kernel parameters are correctly configured to support client mode TFO])],
976                                              [AC_MSG_ERROR([TCP Fast Open is not available for client mode: please rerun without --enable-tfo-client])], 
977                                              [AC_INCLUDES_DEFAULT 
978 #include <netinet/tcp.h>
979 ])
980                                         AC_DEFINE_UNQUOTED([USE_MSG_FASTOPEN], [1], [Define this to enable client TCP Fast Open.])
981                           ;;
982                         Darwin) AC_CHECK_DECL([CONNECT_RESUME_ON_READ_WRITE], [AC_MSG_WARN([Check the platform specific TFO kernel parameters are correctly configured to support client mode TFO])], 
983                                               [AC_MSG_ERROR([TCP Fast Open is not available for client mode: please rerun without --enable-tfo-client])], 
984                                               [AC_INCLUDES_DEFAULT
985 #include <sys/socket.h>
986 ])
987                                         AC_DEFINE_UNQUOTED([USE_OSX_MSG_FASTOPEN], [1], [Define this to enable client TCP Fast Open.])
988                           ;;
989                 esac
990         ;;
991         no|*)
992                 ;;
993 esac
994
995 AC_ARG_ENABLE(tfo-server, AC_HELP_STRING([--enable-tfo-server], [Enable TCP Fast Open for server mode]))
996 case "$enable_tfo_server" in
997         yes)
998               AC_CHECK_DECL([TCP_FASTOPEN], [AC_MSG_WARN([Check the platform specific TFO kernel parameters are correctly configured to support server mode TFO])], [AC_MSG_ERROR([TCP Fast Open is not available for server mode: please rerun without --enable-tfo-server])], [AC_INCLUDES_DEFAULT
999 #include <netinet/tcp.h>
1000               ])
1001                 AC_DEFINE_UNQUOTED([USE_TCP_FASTOPEN], [1], [Define this to enable server TCP Fast Open.])
1002                 ;;
1003         no|*)
1004                 ;;
1005 esac
1006
1007 # check for libevent
1008 AC_ARG_WITH(libevent, AC_HELP_STRING([--with-libevent=pathname],
1009     [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.]),
1010     [ ],[ withval="no" ])
1011 if test x_$withval = x_yes -o x_$withval != x_no; then
1012         AC_MSG_CHECKING(for libevent)
1013         if test x_$withval = x_ -o x_$withval = x_yes; then
1014             withval="/usr/local /opt/local /usr/lib /usr/pkg /usr/sfw /usr"
1015         fi
1016         for dir in $withval; do
1017             thedir="$dir"
1018             if test -f "$dir/include/event.h" -o -f "$dir/include/event2/event.h"; then
1019                 found_libevent="yes"
1020                 dnl assume /usr is in default path.
1021                 if test "$thedir" != "/usr"; then
1022                     CPPFLAGS="$CPPFLAGS -I$thedir/include"
1023                 fi
1024                 break;
1025             fi
1026         done
1027         if test x_$found_libevent != x_yes; then
1028                 if test -f "$dir/event.h" -a \( -f "$dir/libevent.la" -o -f "$dir/libev.la" \) ; then
1029                         # libevent source directory
1030                         AC_MSG_RESULT(found in $thedir)
1031                         CPPFLAGS="$CPPFLAGS -I$thedir -I$thedir/include"
1032                         BAK_LDFLAGS_SET="1"
1033                         BAK_LDFLAGS="$LDFLAGS"
1034                         # remove evdns from linking
1035                         mkdir build >/dev/null 2>&1
1036                         mkdir build/libevent >/dev/null 2>&1
1037                         mkdir build/libevent/.libs >/dev/null 2>&1
1038                         ev_files_o=`ls $thedir/*.o | grep -v evdns\.o | grep -v bufferevent_openssl\.o`
1039                         ev_files_lo=`ls $thedir/*.lo | grep -v evdns\.lo | grep -v bufferevent_openssl\.lo`
1040                         ev_files_libso=`ls $thedir/.libs/*.o | grep -v evdns\.o | grep -v bufferevent_openssl\.o`
1041                         cp $ev_files_o build/libevent
1042                         cp $ev_files_lo build/libevent
1043                         cp $ev_files_libso build/libevent/.libs
1044                         LATE_LDFLAGS="build/libevent/*.lo -lm"
1045                         LDFLAGS="build/libevent/*.o $LDFLAGS -lm"
1046                 else
1047                         AC_MSG_ERROR([Cannot find the libevent library in $withval
1048 You can restart ./configure --with-libevent=no to use a builtin alternative.
1049 Please note that this alternative is not as capable as libevent when using
1050 large outgoing port ranges.  ])
1051                 fi
1052         else
1053             AC_MSG_RESULT(found in $thedir)
1054             dnl if event2 exists and no event lib in dir itself, use subdir
1055             if test ! -f $thedir/lib/libevent.a -a ! -f $thedir/lib/libevent.so -a -d "$thedir/lib/event2"; then
1056                     LDFLAGS="$LDFLAGS -L$thedir/lib/event2"
1057                     ACX_RUNTIME_PATH_ADD([$thedir/lib/event2])
1058             else
1059                     dnl assume /usr is in default path, do not add "".
1060                     if test "$thedir" != "/usr" -a "$thedir" != ""; then
1061                         LDFLAGS="$LDFLAGS -L$thedir/lib"
1062                         ACX_RUNTIME_PATH_ADD([$thedir/lib])
1063                     fi
1064             fi
1065         fi
1066         # check for library used by libevent after 1.3c
1067         AC_SEARCH_LIBS([clock_gettime], [rt])
1068
1069         # is the event.h header libev or libevent?
1070         AC_CHECK_HEADERS([event.h],,, [AC_INCLUDES_DEFAULT])
1071         AC_CHECK_DECL(EV_VERSION_MAJOR, [
1072                 AC_SEARCH_LIBS(event_set, [ev])
1073         ],[
1074                 AC_SEARCH_LIBS(event_set, [event])
1075         ],[AC_INCLUDES_DEFAULT
1076 #include <event.h>
1077         ])
1078         AC_CHECK_FUNCS([event_base_free]) # only in libevent 1.2 and later
1079         AC_CHECK_FUNCS([event_base_once]) # only in libevent 1.4.1 and later
1080         AC_CHECK_FUNCS([event_base_new]) # only in libevent 1.4.1 and later
1081         AC_CHECK_FUNCS([event_base_get_method]) # only in libevent 1.4.3 and later
1082         AC_CHECK_FUNCS([ev_loop]) # only in libev. (tested on 3.51)
1083         AC_CHECK_FUNCS([ev_default_loop]) # only in libev. (tested on 4.00)
1084         PC_LIBEVENT_DEPENDENCY="libevent"
1085         AC_SUBST(PC_LIBEVENT_DEPENDENCY)
1086         if test -n "$BAK_LDFLAGS_SET"; then
1087                 LDFLAGS="$BAK_LDFLAGS"
1088         fi
1089 else
1090         AC_DEFINE(USE_MINI_EVENT, 1, [Define if you want to use internal select based events])
1091 fi
1092
1093 # check for libexpat
1094 AC_ARG_WITH(libexpat, AC_HELP_STRING([--with-libexpat=path],
1095     [specify explicit path for libexpat.]),
1096     [ ],[ withval="/usr/local /opt/local /usr/lib /usr/pkg /usr/sfw /usr" ])
1097 AC_MSG_CHECKING(for libexpat)
1098 found_libexpat="no"
1099 for dir in $withval ; do
1100             if test -f "$dir/include/expat.h"; then
1101                 found_libexpat="yes"
1102                 dnl assume /usr is in default path.
1103                 if test "$dir" != "/usr"; then
1104                     CPPFLAGS="$CPPFLAGS -I$dir/include"
1105                     LDFLAGS="$LDFLAGS -L$dir/lib"
1106                 fi
1107                 AC_MSG_RESULT(found in $dir)
1108                 break;
1109             fi
1110 done
1111 if test x_$found_libexpat != x_yes; then
1112         AC_ERROR([Could not find libexpat, expat.h])
1113 fi
1114 AC_CHECK_HEADERS([expat.h],,, [AC_INCLUDES_DEFAULT])
1115 AC_CHECK_DECLS([XML_StopParser], [], [], [AC_INCLUDES_DEFAULT
1116 #include <expat.h>
1117 ])
1118
1119 # set static linking if requested
1120 AC_SUBST(staticexe)
1121 staticexe=""
1122 AC_ARG_ENABLE(static-exe, AC_HELP_STRING([--enable-static-exe],
1123         [ enable to compile executables statically against (event) libs, for debug purposes ]), 
1124         , )
1125 if test x_$enable_static_exe = x_yes; then
1126         staticexe="-static"
1127         if test "$on_mingw" = yes; then
1128                 staticexe="-all-static"
1129                 # for static compile, include gdi32 and zlib here.
1130                 if echo $LIBS | grep 'lgdi32' >/dev/null; then
1131                         :
1132                 else
1133                         LIBS="$LIBS -lgdi32"
1134                 fi
1135                 LIBS="$LIBS -lz"
1136         fi
1137 fi
1138
1139 # Include systemd.m4 - begin
1140 sinclude(systemd.m4)
1141 # Include systemd.m4 - end
1142
1143 # set lock checking if requested
1144 AC_ARG_ENABLE(lock_checks, AC_HELP_STRING([--enable-lock-checks],
1145         [ enable to check lock and unlock calls, for debug purposes ]), 
1146         , )
1147 if test x_$enable_lock_checks = x_yes; then
1148         AC_DEFINE(ENABLE_LOCK_CHECKS, 1, [Define if you want to use debug lock checking (slow).])
1149         CHECKLOCK_OBJ="checklocks.lo"
1150         AC_SUBST(CHECKLOCK_OBJ)
1151 fi
1152
1153 ACX_CHECK_GETADDRINFO_WITH_INCLUDES
1154 if test "$USE_WINSOCK" = 1; then
1155         AC_DEFINE(UB_ON_WINDOWS, 1, [Use win32 resources and API])
1156         AC_CHECK_HEADERS([iphlpapi.h],,, [AC_INCLUDES_DEFAULT
1157 #include <windows.h>
1158         ])
1159         AC_CHECK_TOOL(WINDRES, windres)
1160         LIBS="$LIBS -liphlpapi"
1161         WINAPPS="unbound-service-install.exe unbound-service-remove.exe anchor-update.exe"
1162         AC_SUBST(WINAPPS)
1163         WIN_DAEMON_SRC="winrc/win_svc.c winrc/w_inst.c"
1164         AC_SUBST(WIN_DAEMON_SRC)
1165         WIN_DAEMON_OBJ="win_svc.lo w_inst.lo"
1166         AC_SUBST(WIN_DAEMON_OBJ)
1167         WIN_DAEMON_OBJ_LINK="rsrc_unbound.o"
1168         AC_SUBST(WIN_DAEMON_OBJ_LINK)
1169         WIN_HOST_OBJ_LINK="rsrc_unbound_host.o"
1170         AC_SUBST(WIN_HOST_OBJ_LINK)
1171         WIN_UBANCHOR_OBJ_LINK="rsrc_unbound_anchor.o log.lo locks.lo"
1172         AC_SUBST(WIN_UBANCHOR_OBJ_LINK)
1173         WIN_CONTROL_OBJ_LINK="rsrc_unbound_control.o"
1174         AC_SUBST(WIN_CONTROL_OBJ_LINK)
1175         WIN_CHECKCONF_OBJ_LINK="rsrc_unbound_checkconf.o"
1176         AC_SUBST(WIN_CHECKCONF_OBJ_LINK)
1177 fi
1178 if test $ac_cv_func_getaddrinfo = no; then
1179         AC_LIBOBJ([fake-rfc2553])
1180 fi
1181 # check after getaddrinfo for its libraries
1182 ACX_FUNC_IOCTLSOCKET
1183
1184 # see if daemon(3) exists, and if it is deprecated.
1185 AC_CHECK_FUNCS([daemon])
1186 if test $ac_cv_func_daemon = yes; then
1187         ACX_FUNC_DEPRECATED([daemon], [(void)daemon(0, 0);], [
1188 #include <stdlib.h>
1189 ])
1190 fi
1191
1192 AC_CHECK_MEMBERS([struct sockaddr_un.sun_len],,,[
1193 AC_INCLUDES_DEFAULT
1194 #ifdef HAVE_SYS_UN_H
1195 #include <sys/un.h>
1196 #endif
1197 ])
1198 AC_CHECK_MEMBERS([struct in_pktinfo.ipi_spec_dst],,,[
1199 AC_INCLUDES_DEFAULT
1200 #if HAVE_SYS_PARAM_H
1201 #include <sys/param.h>
1202 #endif
1203
1204 #ifdef HAVE_SYS_SOCKET_H
1205 #include <sys/socket.h>
1206 #endif
1207
1208 #ifdef HAVE_SYS_UIO_H
1209 #include <sys/uio.h>
1210 #endif
1211
1212 #ifdef HAVE_NETINET_IN_H
1213 #include <netinet/in.h>
1214 #endif
1215
1216 #ifdef HAVE_NETINET_TCP_H
1217 #include <netinet/tcp.h>
1218 #endif
1219
1220 #ifdef HAVE_ARPA_INET_H
1221 #include <arpa/inet.h>
1222 #endif
1223
1224 #ifdef HAVE_WINSOCK2_H
1225 #include <winsock2.h>
1226 #endif
1227
1228 #ifdef HAVE_WS2TCPIP_H
1229 #include <ws2tcpip.h>
1230 #endif
1231 ])
1232 AC_SEARCH_LIBS([setusercontext], [util])
1233 AC_CHECK_FUNCS([tzset sigprocmask fcntl getpwnam endpwent getrlimit setrlimit setsid chroot kill chown sleep usleep random srandom recvmsg sendmsg writev socketpair glob initgroups strftime localtime_r setusercontext _beginthreadex endservent endprotoent fsync shmget])
1234 AC_CHECK_FUNCS([setresuid],,[AC_CHECK_FUNCS([setreuid])])
1235 AC_CHECK_FUNCS([setresgid],,[AC_CHECK_FUNCS([setregid])])
1236
1237 # check if setreuid en setregid fail, on MacOSX10.4(darwin8).
1238 if echo $build_os | grep darwin8 > /dev/null; then
1239         AC_DEFINE(DARWIN_BROKEN_SETREUID, 1, [Define this if on macOSX10.4-darwin8 and setreuid and setregid do not work])
1240 fi
1241 AC_CHECK_DECLS([inet_pton,inet_ntop], [], [], [
1242 AC_INCLUDES_DEFAULT
1243 #ifdef HAVE_NETINET_IN_H
1244 #include <netinet/in.h>
1245 #endif
1246
1247 #ifdef HAVE_NETINET_TCP_H
1248 #include <netinet/tcp.h>
1249 #endif
1250
1251 #ifdef HAVE_ARPA_INET_H
1252 #include <arpa/inet.h>
1253 #endif
1254
1255 #ifdef HAVE_WINSOCK2_H
1256 #include <winsock2.h>
1257 #endif
1258
1259 #ifdef HAVE_WS2TCPIP_H
1260 #include <ws2tcpip.h>
1261 #endif
1262 ])
1263 AC_REPLACE_FUNCS(inet_aton)
1264 AC_REPLACE_FUNCS(inet_pton)
1265 AC_REPLACE_FUNCS(inet_ntop)
1266 AC_REPLACE_FUNCS(snprintf)
1267 # test if snprintf return the proper length
1268 if test "x$ac_cv_func_snprintf" = xyes; then
1269     if test c${cross_compiling} = cno; then
1270         AC_MSG_CHECKING([for correct snprintf return value])
1271         AC_RUN_IFELSE([AC_LANG_SOURCE(AC_INCLUDES_DEFAULT
1272 [[
1273 int main(void) { return !(snprintf(NULL, 0, "test") == 4); }
1274 ]])], [AC_MSG_RESULT(yes)], [
1275                 AC_MSG_RESULT(no)
1276                 AC_DEFINE([SNPRINTF_RET_BROKEN], [], [define if (v)snprintf does not return length needed, (but length used)])
1277                 AC_LIBOBJ(snprintf)
1278           ])
1279     fi
1280 fi
1281 AC_REPLACE_FUNCS(strlcat)
1282 AC_REPLACE_FUNCS(strlcpy)
1283 AC_REPLACE_FUNCS(memmove)
1284 AC_REPLACE_FUNCS(gmtime_r)
1285 AC_REPLACE_FUNCS(isblank)
1286 dnl without CTIME, ARC4-functions and without reallocarray.
1287 LIBOBJ_WITHOUT_CTIMEARC4="$LIBOBJS"
1288 AC_SUBST(LIBOBJ_WITHOUT_CTIMEARC4)
1289 AC_REPLACE_FUNCS(reallocarray)
1290 if test "$USE_NSS" = "no"; then
1291         AC_REPLACE_FUNCS(arc4random)
1292         AC_REPLACE_FUNCS(arc4random_uniform)
1293         if test "$ac_cv_func_arc4random" = "no"; then
1294                 AC_LIBOBJ(explicit_bzero)
1295                 AC_LIBOBJ(arc4_lock)
1296                 AC_CHECK_FUNCS([getentropy],,[
1297                     if test "$USE_WINSOCK" = 1; then
1298                         AC_LIBOBJ(getentropy_win)
1299                     else
1300                         case "$host" in
1301                         Darwin|*darwin*)
1302                                 AC_LIBOBJ(getentropy_osx)
1303                         ;;
1304                         *solaris*|*sunos*|SunOS)
1305                                 AC_LIBOBJ(getentropy_solaris)
1306                                 AC_CHECK_HEADERS([sys/sha2.h],, [
1307                                         AC_CHECK_FUNCS([SHA512_Update],,[
1308                                                 AC_LIBOBJ(sha512)
1309                                         ])
1310                                 ], [AC_INCLUDES_DEFAULT])
1311                                 if test "$ac_cv_header_sys_sha2_h" = "yes"; then
1312                                         # this lib needed for sha2 on solaris
1313                                         LIBS="$LIBS -lmd"
1314                                 fi
1315                                 AC_SEARCH_LIBS([clock_gettime], [rt])
1316                         ;;
1317                         *linux*|Linux|*)
1318                                 AC_LIBOBJ(getentropy_linux)
1319                                 AC_CHECK_FUNCS([SHA512_Update],,[
1320                                         AC_DEFINE([COMPAT_SHA512], [1], [Do sha512 definitions in config.h])
1321                                         AC_LIBOBJ(sha512)
1322                                 ])
1323                                 AC_CHECK_HEADERS([sys/sysctl.h],,, [AC_INCLUDES_DEFAULT])
1324                                 AC_CHECK_FUNCS([getauxval])
1325                                 AC_SEARCH_LIBS([clock_gettime], [rt])
1326                         ;;
1327                         esac
1328                     fi
1329                 ])
1330         fi
1331 fi
1332 LIBOBJ_WITHOUT_CTIME="$LIBOBJS"
1333 AC_SUBST(LIBOBJ_WITHOUT_CTIME)
1334 AC_REPLACE_FUNCS(ctime_r)
1335 AC_REPLACE_FUNCS(strsep)
1336
1337 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]))
1338 case "$enable_allsymbols" in
1339         yes)
1340         COMMON_OBJ_ALL_SYMBOLS=""
1341         UBSYMS=""
1342         EXTRALINK="-L. -L.libs -lunbound"
1343         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])
1344         ;;
1345         no|*)
1346         COMMON_OBJ_ALL_SYMBOLS='$(COMMON_OBJ)'
1347         UBSYMS='-export-symbols $(srcdir)/libunbound/ubsyms.def'
1348         EXTRALINK=""
1349         ;;
1350 esac
1351 AC_SUBST(COMMON_OBJ_ALL_SYMBOLS)
1352 AC_SUBST(EXTRALINK)
1353 AC_SUBST(UBSYMS)
1354 if test x_$enable_lock_checks = x_yes; then
1355         UBSYMS="-export-symbols clubsyms.def"
1356         cp ${srcdir}/libunbound/ubsyms.def clubsyms.def
1357         echo lock_protect >> clubsyms.def
1358         echo lock_unprotect >> clubsyms.def
1359         echo lock_get_mem >> clubsyms.def
1360         echo checklock_start >> clubsyms.def
1361         echo checklock_stop >> clubsyms.def
1362         echo checklock_lock >> clubsyms.def
1363         echo checklock_unlock >> clubsyms.def
1364         echo checklock_init >> clubsyms.def
1365         echo checklock_thrcreate >> clubsyms.def
1366         echo checklock_thrjoin >> clubsyms.def
1367 fi
1368
1369 # check for dnstap if requested
1370 dt_DNSTAP([$UNBOUND_RUN_DIR/dnstap.sock],
1371     [
1372         AC_DEFINE([USE_DNSTAP], [1], [Define to 1 to enable dnstap support])
1373         AC_SUBST([ENABLE_DNSTAP], [1])
1374
1375         AC_SUBST([opt_dnstap_socket_path])
1376         ACX_ESCAPE_BACKSLASH($opt_dnstap_socket_path, hdr_dnstap_socket_path)
1377         AC_DEFINE_UNQUOTED(DNSTAP_SOCKET_PATH,
1378             ["$hdr_dnstap_socket_path"], [default dnstap socket path])
1379
1380         AC_SUBST([DNSTAP_SRC], ["dnstap/dnstap.c dnstap/dnstap.pb-c.c"])
1381         AC_SUBST([DNSTAP_OBJ], ["dnstap.lo dnstap.pb-c.lo"])
1382     ],
1383     [
1384         AC_SUBST([ENABLE_DNSTAP], [0])
1385     ]
1386 )
1387
1388 # check for dnscrypt if requested
1389 dnsc_DNSCRYPT([
1390         AC_DEFINE([USE_DNSCRYPT], [1], [Define to 1 to enable dnscrypt support])
1391         AC_SUBST([ENABLE_DNSCRYPT], [1])
1392
1393         AC_SUBST([DNSCRYPT_SRC], ["dnscrypt/dnscrypt.c"])
1394         AC_SUBST([DNSCRYPT_OBJ], ["dnscrypt.lo"])
1395     ],
1396     [
1397         AC_SUBST([ENABLE_DNSCRYPT], [0])
1398     ]
1399 )
1400
1401 # check for cachedb if requested
1402 AC_ARG_ENABLE(cachedb, AC_HELP_STRING([--enable-cachedb], [enable cachedb module that can use external cache storage]))
1403 case "$enable_cachedb" in
1404     yes)
1405         AC_DEFINE([USE_CACHEDB], [1], [Define to 1 to use cachedb support])
1406         ;;
1407     no|*)
1408         # nothing
1409         ;;
1410 esac
1411
1412 # check for ipsecmod if requested
1413 AC_ARG_ENABLE(ipsecmod, AC_HELP_STRING([--enable-ipsecmod], [Enable ipsecmod module that facilitates opportunistic IPsec]))
1414 case "$enable_ipsecmod" in
1415         yes)
1416                 AC_DEFINE([USE_IPSECMOD], [1], [Define to 1 to use ipsecmod support.])
1417                 IPSECMOD_OBJ="ipsecmod.lo ipsecmod-whitelist.lo"
1418                 AC_SUBST(IPSECMOD_OBJ)
1419                 IPSECMOD_HEADER='$(srcdir)/ipsecmod/ipsecmod.h $(srcdir)/ipsecmod/ipsecmod-whitelist.h'
1420                 AC_SUBST(IPSECMOD_HEADER)
1421                 ;;
1422         no|*)
1423                 # nothing
1424                 ;;
1425 esac
1426
1427 AC_MSG_CHECKING([if ${MAKE:-make} supports $< with implicit rule in scope])
1428 # on openBSD, the implicit rule make $< work.
1429 # on Solaris, it does not work ($? is changed sources, $^ lists dependencies).
1430 # gmake works.
1431 cat >conftest.make <<EOF
1432 all:    conftest.lo
1433
1434 conftest.lo foo.lo bla.lo:
1435         if test -f "\$<"; then touch \$@; fi
1436
1437 .SUFFIXES: .lo
1438 .c.lo:
1439         if test -f "\$<"; then touch \$@; fi
1440
1441 conftest.lo:        conftest.dir/conftest.c
1442 EOF
1443 mkdir conftest.dir
1444 touch conftest.dir/conftest.c
1445 rm -f conftest.lo conftest.c
1446 ${MAKE:-make} -f conftest.make >/dev/null
1447 rm -f conftest.make conftest.c conftest.dir/conftest.c
1448 rm -rf conftest.dir
1449 if test ! -f conftest.lo; then
1450         AC_MSG_RESULT(no)
1451         SOURCEDETERMINE='echo "$^" | awk "-F " "{print \$$1;}" > .source'
1452         SOURCEFILE='`cat .source`'
1453 else
1454         AC_MSG_RESULT(yes)
1455         SOURCEDETERMINE=':'
1456         SOURCEFILE='$<'
1457 fi
1458 rm -f conftest.lo
1459 AC_SUBST(SOURCEDETERMINE)
1460 AC_SUBST(SOURCEFILE)
1461
1462 # see if we want to build the library or everything
1463 ALLTARGET="alltargets"
1464 INSTALLTARGET="install-all"
1465 AC_ARG_WITH(libunbound-only, AC_HELP_STRING([--with-libunbound-only],
1466         [do not build daemon and tool programs]),
1467         [
1468         if test "$withval" = "yes"; then
1469                 ALLTARGET="lib"
1470                 INSTALLTARGET="install-lib"
1471         fi
1472 ])
1473 AC_SUBST(ALLTARGET)
1474 AC_SUBST(INSTALLTARGET)
1475
1476 ACX_STRIP_EXT_FLAGS
1477 if test -n "$LATE_LDFLAGS"; then
1478   LDFLAGS="$LATE_LDFLAGS $LDFLAGS"
1479 fi
1480 # remove start spaces 
1481 LDFLAGS=`echo "$LDFLAGS"|sed -e 's/^ *//'`
1482 LIBS=`echo "$LIBS"|sed -e 's/^ *//'`
1483
1484 AC_DEFINE_UNQUOTED([MAXSYSLOGMSGLEN], [10240], [Define to the maximum message length to pass to syslog.])
1485
1486 AH_BOTTOM(
1487 dnl this must be first AH_CONFIG, to define the flags before any includes.
1488 AHX_CONFIG_EXT_FLAGS
1489
1490 dnl includes
1491 [
1492 #ifndef UNBOUND_DEBUG
1493 #  define NDEBUG
1494 #endif
1495
1496 /** Use small-ldns codebase */
1497 #define USE_SLDNS 1
1498 #ifdef HAVE_SSL
1499 #  define LDNS_BUILD_CONFIG_HAVE_SSL 1
1500 #endif
1501
1502 #include <stdio.h>
1503 #include <string.h>
1504 #include <unistd.h>
1505 #include <assert.h>
1506
1507 #if STDC_HEADERS
1508 #include <stdlib.h>
1509 #include <stddef.h>
1510 #endif
1511
1512 #ifdef HAVE_STDARG_H
1513 #include <stdarg.h>
1514 #endif
1515
1516 #ifdef HAVE_STDINT_H
1517 #include <stdint.h>
1518 #endif
1519
1520 #include <errno.h>
1521
1522 #if HAVE_SYS_PARAM_H
1523 #include <sys/param.h>
1524 #endif
1525
1526 #ifdef HAVE_SYS_SOCKET_H
1527 #include <sys/socket.h>
1528 #endif
1529
1530 #ifdef HAVE_SYS_UIO_H
1531 #include <sys/uio.h>
1532 #endif
1533
1534 #ifdef HAVE_NETINET_IN_H
1535 #include <netinet/in.h>
1536 #endif
1537
1538 #ifdef HAVE_NETINET_TCP_H
1539 #include <netinet/tcp.h>
1540 #endif
1541
1542 #ifdef HAVE_ARPA_INET_H
1543 #include <arpa/inet.h>
1544 #endif
1545
1546 #ifdef HAVE_WINSOCK2_H
1547 #include <winsock2.h>
1548 #endif
1549
1550 #ifdef HAVE_WS2TCPIP_H
1551 #include <ws2tcpip.h>
1552 #endif
1553
1554 #ifndef USE_WINSOCK
1555 #define ARG_LL "%ll"
1556 #else
1557 #define ARG_LL "%I64"
1558 #endif
1559
1560 #ifndef AF_LOCAL
1561 #define AF_LOCAL AF_UNIX
1562 #endif
1563 ]
1564
1565 AHX_CONFIG_FORMAT_ATTRIBUTE
1566 AHX_CONFIG_UNUSED_ATTRIBUTE
1567 AHX_CONFIG_FSEEKO
1568 AHX_CONFIG_MAXHOSTNAMELEN
1569 #if !defined(HAVE_SNPRINTF) || defined(SNPRINTF_RET_BROKEN)
1570 #define snprintf snprintf_unbound
1571 #define vsnprintf vsnprintf_unbound
1572 #include <stdarg.h>
1573 int snprintf (char *str, size_t count, const char *fmt, ...);
1574 int vsnprintf (char *str, size_t count, const char *fmt, va_list arg);
1575 #endif /* HAVE_SNPRINTF or SNPRINTF_RET_BROKEN */
1576 AHX_CONFIG_INET_PTON(unbound)
1577 AHX_CONFIG_INET_NTOP(unbound)
1578 AHX_CONFIG_INET_ATON(unbound)
1579 AHX_CONFIG_MEMMOVE(unbound)
1580 AHX_CONFIG_STRLCAT(unbound)
1581 AHX_CONFIG_STRLCPY(unbound)
1582 AHX_CONFIG_GMTIME_R(unbound)
1583 AHX_CONFIG_REALLOCARRAY(unbound)
1584 AHX_CONFIG_W32_SLEEP
1585 AHX_CONFIG_W32_USLEEP
1586 AHX_CONFIG_W32_RANDOM
1587 AHX_CONFIG_W32_SRANDOM
1588 AHX_CONFIG_W32_FD_SET_T
1589 AHX_CONFIG_IPV6_MIN_MTU
1590 AHX_MEMCMP_BROKEN(unbound)
1591
1592 [
1593 #ifndef HAVE_CTIME_R
1594 #define ctime_r unbound_ctime_r
1595 char *ctime_r(const time_t *timep, char *buf);
1596 #endif
1597
1598 #ifndef HAVE_STRSEP
1599 #define strsep unbound_strsep
1600 char *strsep(char **stringp, const char *delim);
1601 #endif
1602
1603 #ifndef HAVE_ISBLANK
1604 #define isblank unbound_isblank
1605 int isblank(int c);
1606 #endif
1607
1608 #if defined(HAVE_INET_NTOP) && !HAVE_DECL_INET_NTOP
1609 const char *inet_ntop(int af, const void *src, char *dst, size_t size);
1610 #endif
1611
1612 #if defined(HAVE_INET_PTON) && !HAVE_DECL_INET_PTON
1613 int inet_pton(int af, const char* src, void* dst);
1614 #endif
1615
1616 #if !defined(HAVE_STRPTIME) || !defined(STRPTIME_WORKS)
1617 #define strptime unbound_strptime
1618 struct tm;
1619 char *strptime(const char *s, const char *format, struct tm *tm);
1620 #endif
1621
1622 #ifdef HAVE_LIBRESSL
1623 #  if !HAVE_DECL_STRLCPY
1624 size_t strlcpy(char *dst, const char *src, size_t siz);
1625 #  endif
1626 #  if !HAVE_DECL_STRLCAT
1627 size_t strlcat(char *dst, const char *src, size_t siz);
1628 #  endif
1629 #  if !HAVE_DECL_ARC4RANDOM && defined(HAVE_ARC4RANDOM)
1630 uint32_t arc4random(void);
1631 #  endif
1632 #  if !HAVE_DECL_ARC4RANDOM_UNIFORM && defined(HAVE_ARC4RANDOM_UNIFORM)
1633 uint32_t arc4random_uniform(uint32_t upper_bound);
1634 #  endif
1635 #  if !HAVE_DECL_REALLOCARRAY
1636 void *reallocarray(void *ptr, size_t nmemb, size_t size);
1637 #  endif
1638 #endif /* HAVE_LIBRESSL */
1639 #ifndef HAVE_ARC4RANDOM
1640 void explicit_bzero(void* buf, size_t len);
1641 int getentropy(void* buf, size_t len);
1642 uint32_t arc4random(void);
1643 void arc4random_buf(void* buf, size_t n);
1644 void _ARC4_LOCK(void);
1645 void _ARC4_UNLOCK(void);
1646 #endif
1647 #ifndef HAVE_ARC4RANDOM_UNIFORM
1648 uint32_t arc4random_uniform(uint32_t upper_bound);
1649 #endif
1650 #ifdef COMPAT_SHA512
1651 #ifndef SHA512_DIGEST_LENGTH
1652 #define SHA512_BLOCK_LENGTH             128
1653 #define SHA512_DIGEST_LENGTH            64
1654 #define SHA512_DIGEST_STRING_LENGTH     (SHA512_DIGEST_LENGTH * 2 + 1)
1655 typedef struct _SHA512_CTX {
1656         uint64_t        state[8];
1657         uint64_t        bitcount[2];
1658         uint8_t buffer[SHA512_BLOCK_LENGTH];
1659 } SHA512_CTX;
1660 #endif /* SHA512_DIGEST_LENGTH */
1661 void SHA512_Init(SHA512_CTX*);
1662 void SHA512_Update(SHA512_CTX*, void*, size_t);
1663 void SHA512_Final(uint8_t[SHA512_DIGEST_LENGTH], SHA512_CTX*);
1664 unsigned char *SHA512(void* data, unsigned int data_len, unsigned char *digest);
1665 #endif /* COMPAT_SHA512 */
1666
1667
1668
1669 #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))
1670    /* using version of libevent that is not threadsafe. */
1671 #  define LIBEVENT_SIGNAL_PROBLEM 1
1672 #endif
1673
1674 #ifndef CHECKED_INET6
1675 #  define CHECKED_INET6
1676 #  ifdef AF_INET6
1677 #    define INET6
1678 #  else
1679 #    define AF_INET6        28
1680 #  endif
1681 #endif /* CHECKED_INET6 */
1682
1683 #ifndef HAVE_GETADDRINFO
1684 struct sockaddr_storage;
1685 #include "compat/fake-rfc2553.h"
1686 #endif
1687
1688 #ifdef UNBOUND_ALLOC_STATS
1689 #  define malloc(s) unbound_stat_malloc_log(s, __FILE__, __LINE__, __func__)
1690 #  define calloc(n,s) unbound_stat_calloc_log(n, s, __FILE__, __LINE__, __func__)
1691 #  define free(p) unbound_stat_free_log(p, __FILE__, __LINE__, __func__)
1692 #  define realloc(p,s) unbound_stat_realloc_log(p, s, __FILE__, __LINE__, __func__)
1693 void *unbound_stat_malloc(size_t size);
1694 void *unbound_stat_calloc(size_t nmemb, size_t size);
1695 void unbound_stat_free(void *ptr);
1696 void *unbound_stat_realloc(void *ptr, size_t size);
1697 void *unbound_stat_malloc_log(size_t size, const char* file, int line,
1698         const char* func);
1699 void *unbound_stat_calloc_log(size_t nmemb, size_t size, const char* file,
1700         int line, const char* func);
1701 void unbound_stat_free_log(void *ptr, const char* file, int line,
1702         const char* func);
1703 void *unbound_stat_realloc_log(void *ptr, size_t size, const char* file,
1704         int line, const char* func);
1705 #elif defined(UNBOUND_ALLOC_LITE)
1706 #  include "util/alloc.h"
1707 #endif /* UNBOUND_ALLOC_LITE and UNBOUND_ALLOC_STATS */
1708
1709 /** default port for DNS traffic. */
1710 #define UNBOUND_DNS_PORT 53
1711 /** default port for unbound control traffic, registered port with IANA,
1712     ub-dns-control  8953/tcp    unbound dns nameserver control */
1713 #define UNBOUND_CONTROL_PORT 8953
1714 /** the version of unbound-control that this software implements */
1715 #define UNBOUND_CONTROL_VERSION 1
1716
1717 ])
1718
1719 dnl if we build from source tree, the man pages need @date@ and @version@
1720 dnl if this is a distro tarball, that was already done by makedist.sh
1721 AC_SUBST(version, [VERSION_MAJOR.VERSION_MINOR.VERSION_MICRO])
1722 AC_SUBST(date, [`date +'%b %e, %Y'`])
1723
1724 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 dnscrypt/dnscrypt_config.h contrib/libunbound.pc contrib/unbound.socket contrib/unbound.service])
1725 AC_CONFIG_HEADER([config.h])
1726 AC_OUTPUT