xref: /freebsd/contrib/unbound/configure.ac (revision 38a52bd3b5cac3da6f7f6eef3dd050e6aa08ebb3)
1#                                               -*- Autoconf -*-
2# Process this file with autoconf to produce a configure script.
3AC_PREREQ([2.56])
4sinclude(acx_nlnetlabs.m4)
5sinclude(ax_pthread.m4)
6sinclude(acx_python.m4)
7sinclude(ac_pkg_swig.m4)
8sinclude(dnstap/dnstap.m4)
9sinclude(dnscrypt/dnscrypt.m4)
10
11# must be numbers. ac_defun because of later processing
12m4_define([VERSION_MAJOR],[1])
13m4_define([VERSION_MINOR],[17])
14m4_define([VERSION_MICRO],[0])
15AC_INIT([unbound],m4_defn([VERSION_MAJOR]).m4_defn([VERSION_MINOR]).m4_defn([VERSION_MICRO]),[unbound-bugs@nlnetlabs.nl or https://github.com/NLnetLabs/unbound/issues],[unbound])
16AC_SUBST(UNBOUND_VERSION_MAJOR, [VERSION_MAJOR])
17AC_SUBST(UNBOUND_VERSION_MINOR, [VERSION_MINOR])
18AC_SUBST(UNBOUND_VERSION_MICRO, [VERSION_MICRO])
19
20LIBUNBOUND_CURRENT=9
21LIBUNBOUND_REVISION=20
22LIBUNBOUND_AGE=1
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# 1.6.8 had 7:7:5
80# 1.7.0 had 7:8:5
81# 1.7.1 had 7:9:5
82# 1.7.2 had 7:10:5
83# 1.7.3 had 7:11:5
84# 1.8.0 had 8:0:0 # changes the event callback function signature
85# 1.8.1 had 8:1:0
86# 1.8.2 had 8:2:0
87# 1.8.3 had 8:3:0
88# 1.9.0 had 9:0:1 # add ub_ctx_set_tls
89# 1.9.1 had 9:1:1
90# 1.9.2 had 9:2:1
91# 1.9.3 had 9:3:1
92# 1.9.4 had 9:4:1
93# 1.9.5 had 9:5:1
94# 1.9.6 had 9:6:1
95# 1.10.0 had 9:7:1
96# 1.10.1 had 9:8:1
97# 1.11.0 had 9:9:1
98# 1.12.0 had 9:10:1
99# 1.13.0 had 9:11:1
100# 1.13.1 had 9:12:1
101# 1.13.2 had 9:13:1
102# 1.14.0 had 9:14:1
103# 1.15.0 had 9:15:1
104# 1.16.0 had 9:16:1
105# 1.16.1 had 9:17:1
106# 1.16.2 had 9:18:1
107# 1.16.3 had 9:19:1
108# 1.17.0 had 9:20:1
109
110#   Current  -- the number of the binary API that we're implementing
111#   Revision -- which iteration of the implementation of the binary
112#               API are we supplying?
113#   Age      -- How many previous binary API versions do we also
114#               support?
115#
116# If we release a new version that does not change the binary API,
117# increment Revision.
118#
119# If we release a new version that changes the binary API, but does
120# not break programs compiled against the old binary API, increment
121# Current and Age.  Set Revision to 0, since this is the first
122# implementation of the new API.
123#
124# Otherwise, we're changing the binary API and breaking backward
125# compatibility with old binaries.  Increment Current.  Set Age to 0,
126# since we're backward compatible with no previous APIs.  Set Revision
127# to 0 too.
128AC_SUBST(LIBUNBOUND_CURRENT)
129AC_SUBST(LIBUNBOUND_REVISION)
130AC_SUBST(LIBUNBOUND_AGE)
131
132
133cmdln="`echo $@ | sed -e 's/\\\\/\\\\\\\\/g' | sed -e 's/"/\\\\"/'g`"
134AC_DEFINE_UNQUOTED(CONFCMDLINE, ["$cmdln"], [Command line arguments used with configure])
135
136CFLAGS="$CFLAGS"
137AC_USE_SYSTEM_EXTENSIONS
138if test "$ac_cv_header_minix_config_h" = "yes"; then
139	AC_DEFINE(_NETBSD_SOURCE,1, [Enable for compile on Minix])
140fi
141
142dnl
143dnl By default set prefix to /usr/local
144dnl
145case "$prefix" in
146        NONE)
147		prefix="/usr/local"
148        ;;
149esac
150case "$exec_prefix" in
151        NONE)
152		exec_prefix="$prefix"
153        ;;
154esac
155
156# are we on MinGW?
157if uname -s 2>&1 | grep MINGW >/dev/null; then on_mingw="yes"
158else
159	if echo $host | grep mingw >/dev/null; then on_mingw="yes"
160	else on_mingw="no"; fi
161fi
162
163#
164# Determine configuration file
165# the eval is to evaluate shell expansion twice
166UNBOUND_SBIN_DIR=`eval echo "${sbindir}"`
167AC_SUBST(UNBOUND_SBIN_DIR)
168UNBOUND_SYSCONF_DIR=`eval echo "${sysconfdir}"`
169AC_SUBST(UNBOUND_SYSCONF_DIR)
170UNBOUND_LOCALSTATE_DIR=`eval echo "${localstatedir}"`
171AC_SUBST(UNBOUND_LOCALSTATE_DIR)
172if test $on_mingw = "no"; then
173  ub_conf_file=`eval echo "${sysconfdir}/unbound/unbound.conf"`
174else
175  ub_conf_file="C:\\Program Files\\Unbound\\service.conf"
176fi
177AC_ARG_WITH([conf_file],
178        AS_HELP_STRING([--with-conf-file=path],[Pathname to the Unbound configuration file]),
179	[ub_conf_file="$withval"])
180AC_SUBST(ub_conf_file)
181ACX_ESCAPE_BACKSLASH($ub_conf_file, hdr_config)
182AC_DEFINE_UNQUOTED(CONFIGFILE, ["$hdr_config"], [Pathname to the Unbound configuration file])
183ub_conf_dir=`AS_DIRNAME(["$ub_conf_file"])`
184AC_SUBST(ub_conf_dir)
185
186# Determine run, chroot directory and pidfile locations
187AC_ARG_WITH(run-dir,
188    AS_HELP_STRING([--with-run-dir=path],[set default directory to chdir to (by default dir part of cfg file)]),
189    UNBOUND_RUN_DIR="$withval",
190if test $on_mingw = no; then
191    UNBOUND_RUN_DIR=`dirname "$ub_conf_file"`
192else
193    UNBOUND_RUN_DIR=""
194fi
195)
196AC_SUBST(UNBOUND_RUN_DIR)
197ACX_ESCAPE_BACKSLASH($UNBOUND_RUN_DIR, hdr_run)
198AC_DEFINE_UNQUOTED(RUN_DIR, ["$hdr_run"], [Directory to chdir to])
199
200AC_ARG_WITH(chroot-dir,
201    AS_HELP_STRING([--with-chroot-dir=path],[set default directory to chroot to (by default same as run-dir)]),
202    UNBOUND_CHROOT_DIR="$withval",
203if test $on_mingw = no; then
204    UNBOUND_CHROOT_DIR="$UNBOUND_RUN_DIR"
205else
206    UNBOUND_CHROOT_DIR=""
207fi
208)
209AC_SUBST(UNBOUND_CHROOT_DIR)
210ACX_ESCAPE_BACKSLASH($UNBOUND_CHROOT_DIR, hdr_chroot)
211AC_DEFINE_UNQUOTED(CHROOT_DIR, ["$hdr_chroot"], [Directory to chroot to])
212
213AC_ARG_WITH(share-dir,
214    AS_HELP_STRING([--with-share-dir=path],[set default directory with shared data (by default same as share/unbound)]),
215    UNBOUND_SHARE_DIR="$withval",
216    UNBOUND_SHARE_DIR="$UNBOUND_RUN_DIR")
217AC_SUBST(UNBOUND_SHARE_DIR)
218AC_DEFINE_UNQUOTED(SHARE_DIR, ["$UNBOUND_SHARE_DIR"], [Shared data])
219
220AC_ARG_WITH(pidfile,
221    AS_HELP_STRING([--with-pidfile=filename],[set default pathname to unbound pidfile (default run-dir/unbound.pid)]),
222    UNBOUND_PIDFILE="$withval",
223if test $on_mingw = no; then
224    UNBOUND_PIDFILE="$UNBOUND_RUN_DIR/unbound.pid"
225else
226    UNBOUND_PIDFILE=""
227fi
228)
229AC_SUBST(UNBOUND_PIDFILE)
230ACX_ESCAPE_BACKSLASH($UNBOUND_PIDFILE, hdr_pid)
231AC_DEFINE_UNQUOTED(PIDFILE, ["$hdr_pid"], [default pidfile location])
232
233AC_ARG_WITH(rootkey-file,
234    AS_HELP_STRING([--with-rootkey-file=filename],[set default pathname to root key file (default run-dir/root.key). This file is read and written.]),
235    UNBOUND_ROOTKEY_FILE="$withval",
236if test $on_mingw = no; then
237    UNBOUND_ROOTKEY_FILE="$UNBOUND_RUN_DIR/root.key"
238else
239    UNBOUND_ROOTKEY_FILE="C:\\Program Files\\Unbound\\root.key"
240fi
241)
242AC_SUBST(UNBOUND_ROOTKEY_FILE)
243ACX_ESCAPE_BACKSLASH($UNBOUND_ROOTKEY_FILE, hdr_rkey)
244AC_DEFINE_UNQUOTED(ROOT_ANCHOR_FILE, ["$hdr_rkey"], [default rootkey location])
245
246AC_ARG_WITH(rootcert-file,
247    AS_HELP_STRING([--with-rootcert-file=filename],[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.]),
248    UNBOUND_ROOTCERT_FILE="$withval",
249if test $on_mingw = no; then
250    UNBOUND_ROOTCERT_FILE="$UNBOUND_RUN_DIR/icannbundle.pem"
251else
252    UNBOUND_ROOTCERT_FILE="C:\\Program Files\\Unbound\\icannbundle.pem"
253fi
254)
255AC_SUBST(UNBOUND_ROOTCERT_FILE)
256ACX_ESCAPE_BACKSLASH($UNBOUND_ROOTCERT_FILE, hdr_rpem)
257AC_DEFINE_UNQUOTED(ROOT_CERT_FILE, ["$hdr_rpem"], [default rootcert location])
258
259AC_ARG_WITH(username,
260    AS_HELP_STRING([--with-username=user],[set default user that unbound changes to (default user is unbound)]),
261    UNBOUND_USERNAME="$withval",
262    UNBOUND_USERNAME="unbound")
263AC_SUBST(UNBOUND_USERNAME)
264AC_DEFINE_UNQUOTED(UB_USERNAME, ["$UNBOUND_USERNAME"], [default username])
265
266AC_DEFINE(WINVER, 0x0502, [the version of the windows API enabled])
267ACX_RSRC_VERSION(wnvs)
268AC_DEFINE_UNQUOTED(RSRC_PACKAGE_VERSION, [$wnvs], [version number for resource files])
269
270# Checks for typedefs, structures, and compiler characteristics.
271AC_C_CONST
272AC_LANG([C])
273# allow user to override the -g -O2 flags.
274default_cflags=no
275if test "x$CFLAGS" = "x" ; then
276ACX_CHECK_COMPILER_FLAG(g, [CFLAGS="$CFLAGS -g"])
277ACX_CHECK_COMPILER_FLAG(O2, [CFLAGS="$CFLAGS -O2"])
278default_cflags=yes
279fi
280AC_PROG_CC
281ACX_DEPFLAG
282ACX_DETERMINE_EXT_FLAGS_UNBOUND
283
284# debug mode flags warnings
285AC_ARG_ENABLE(checking, AS_HELP_STRING([--enable-checking],[Enable warnings, asserts, makefile-dependencies]))
286AC_ARG_ENABLE(debug, AS_HELP_STRING([--enable-debug],[same as enable-checking]))
287if test "$enable_debug" = "yes"; then debug_enabled="$enable_debug";
288else debug_enabled="$enable_checking"; fi
289AC_SUBST(debug_enabled)
290case "$debug_enabled" in
291        yes)
292		ACX_CHECK_COMPILER_FLAG(W, [CFLAGS="$CFLAGS -W"])
293		ACX_CHECK_COMPILER_FLAG(Wall, [CFLAGS="$CFLAGS -Wall"])
294		ACX_CHECK_COMPILER_FLAG(Wextra, [CFLAGS="$CFLAGS -Wextra"])
295		ACX_CHECK_COMPILER_FLAG(Wdeclaration-after-statement, [CFLAGS="$CFLAGS -Wdeclaration-after-statement"])
296		AC_DEFINE([UNBOUND_DEBUG], [], [define this to enable debug checks.])
297		;;
298	no|*)
299		# nothing to do.
300		;;
301esac
302if test "$default_cflags" = "yes"; then
303	# only when CFLAGS was "" at the start, if the users wants to
304	# override we shouldn't add default cflags, because they wouldn't
305	# be able to turn off these options and set the CFLAGS wanted.
306	ACX_CHECK_FLTO
307	ACX_CHECK_PIE
308	ACX_CHECK_RELRO_NOW
309fi
310
311AC_C_INLINE
312ACX_CHECK_FORMAT_ATTRIBUTE
313ACX_CHECK_UNUSED_ATTRIBUTE
314
315AC_DEFUN([CHECK_WEAK_ATTRIBUTE],
316[AC_REQUIRE([AC_PROG_CC])
317AC_MSG_CHECKING(whether the C compiler (${CC-cc}) accepts the "weak" attribute)
318AC_CACHE_VAL(ac_cv_c_weak_attribute,
319[ac_cv_c_weak_attribute=no
320AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ #include <stdio.h>
321__attribute__((weak)) void f(int x) { printf("%d", x); }
322]], [[
323   f(1);
324]])],[ac_cv_c_weak_attribute="yes"],[ac_cv_c_weak_attribute="no"])
325])
326
327AC_MSG_RESULT($ac_cv_c_weak_attribute)
328if test $ac_cv_c_weak_attribute = yes; then
329  AC_DEFINE(HAVE_ATTR_WEAK, 1, [Whether the C compiler accepts the "weak" attribute])
330  AC_DEFINE(ATTR_WEAK, [__attribute__((weak))], [apply the weak attribute to a symbol])
331fi
332])dnl End of CHECK_WEAK_ATTRIBUTE
333
334CHECK_WEAK_ATTRIBUTE
335
336AC_DEFUN([CHECK_NORETURN_ATTRIBUTE],
337[AC_REQUIRE([AC_PROG_CC])
338AC_MSG_CHECKING(whether the C compiler (${CC-cc}) accepts the "noreturn" attribute)
339AC_CACHE_VAL(ac_cv_c_noreturn_attribute,
340[ac_cv_c_noreturn_attribute=no
341AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ #include <stdio.h>
342__attribute__((noreturn)) void f(int x) { printf("%d", x); }
343]], [[
344   f(1);
345]])],[ac_cv_c_noreturn_attribute="yes"],[ac_cv_c_noreturn_attribute="no"])
346])
347
348AC_MSG_RESULT($ac_cv_c_noreturn_attribute)
349if test $ac_cv_c_noreturn_attribute = yes; then
350  AC_DEFINE(HAVE_ATTR_NORETURN, 1, [Whether the C compiler accepts the "noreturn" attribute])
351  AC_DEFINE(ATTR_NORETURN, [__attribute__((__noreturn__))], [apply the noreturn attribute to a function that exits the program])
352fi
353])dnl End of CHECK_NORETURN_ATTRIBUTE
354
355CHECK_NORETURN_ATTRIBUTE
356
357if test "$srcdir" != "."; then
358	CPPFLAGS="$CPPFLAGS -I$srcdir"
359fi
360
361AC_DEFUN([ACX_YYLEX_DESTROY], [
362	AC_MSG_CHECKING([for yylex_destroy])
363	if echo %% | $LEX -t 2>&1 | grep yylex_destroy >/dev/null 2>&1; then
364		AC_DEFINE(LEX_HAS_YYLEX_DESTROY, 1, [if lex has yylex_destroy])
365		AC_MSG_RESULT(yes)
366	else AC_MSG_RESULT(no);
367		LEX=":"
368	fi
369])
370
371AC_DEFUN([ACX_YYLEX_OPTION], [
372	AC_MSG_CHECKING([for lex %option])
373	if cat <<EOF | $LEX -t 2>&1 | grep yy_delete_buffer >/dev/null 2>&1; then
374%option nounput
375%%
376EOF
377		AC_MSG_RESULT(yes)
378	else AC_MSG_RESULT(no);
379		LEX=":"
380	fi
381])
382
383AC_PROG_LEX([noyywrap])
384if test "$LEX" != "" -a "$LEX" != ":"; then
385ACX_YYLEX_DESTROY
386fi
387if test "$LEX" != "" -a "$LEX" != ":"; then
388ACX_YYLEX_OPTION
389fi
390AC_PROG_YACC
391AC_CHECK_PROG(doxygen, doxygen, doxygen)
392AC_CHECK_TOOL(STRIP, strip)
393ACX_LIBTOOL_C_ONLY
394
395# pkg-config is only needed for these options, do not require it otherwise
396if test "$enable_systemd" = "yes" -o "$with_pyunbound" = "yes" -o "$with_pythonmod" = "yes"; then
397PKG_PROG_PKG_CONFIG
398fi
399
400# Checks for header files.
401AC_CHECK_HEADERS([stdarg.h stdbool.h netinet/in.h netinet/tcp.h sys/param.h sys/select.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/endian.h libkern/OSByteOrder.h sys/ipc.h sys/shm.h ifaddrs.h poll.h],,, [AC_INCLUDES_DEFAULT])
402# net/if.h portability for Darwin see:
403# https://www.gnu.org/software/autoconf/manual/autoconf-2.69/html_node/Header-Portability.html
404AC_CHECK_HEADERS([net/if.h],,, [
405#include <stdio.h>
406#ifdef STDC_HEADERS
407# include <stdlib.h>
408# include <stddef.h>
409#else
410# ifdef HAVE_STDLIB_H
411#  include <stdlib.h>
412# endif
413#endif
414#ifdef HAVE_SYS_SOCKET_H
415# include <sys/socket.h>
416#endif
417])
418
419# Check for Apple header. This uncovers TARGET_OS_IPHONE, TARGET_OS_TV or TARGET_OS_WATCH
420AC_CHECK_HEADERS([TargetConditionals.h],,, [AC_INCLUDES_DEFAULT])
421AC_CHECK_HEADERS([netioapi.h],,, [AC_INCLUDES_DEFAULT
422#if HAVE_SYS_PARAM_H
423#include <sys/param.h>
424#endif
425
426#ifdef HAVE_SYS_SOCKET_H
427#include <sys/socket.h>
428#endif
429
430#ifdef HAVE_SYS_UIO_H
431#include <sys/uio.h>
432#endif
433
434#ifdef HAVE_NETINET_IN_H
435#include <netinet/in.h>
436#endif
437
438#ifdef HAVE_NETINET_TCP_H
439#include <netinet/tcp.h>
440#endif
441
442#ifdef HAVE_ARPA_INET_H
443#include <arpa/inet.h>
444#endif
445
446#ifdef HAVE_WINSOCK2_H
447#include <winsock2.h>
448#endif
449
450#ifdef HAVE_WS2TCPIP_H
451#include <ws2tcpip.h>
452#endif
453])
454
455# check for types.
456# Using own tests for int64* because autoconf builtin only give 32bit.
457AC_CHECK_TYPE(int8_t, signed char)
458AC_CHECK_TYPE(int16_t, short)
459AC_CHECK_TYPE(int32_t, int)
460AC_CHECK_TYPE(int64_t, long long)
461AC_CHECK_TYPE(uint8_t, unsigned char)
462AC_CHECK_TYPE(uint16_t, unsigned short)
463AC_CHECK_TYPE(uint32_t, unsigned int)
464AC_CHECK_TYPE(uint64_t, unsigned long long)
465AC_TYPE_SIZE_T
466AC_CHECK_TYPE(ssize_t, int)
467AC_TYPE_UID_T
468AC_TYPE_PID_T
469AC_TYPE_OFF_T
470ACX_TYPE_U_CHAR
471ACX_TYPE_RLIM_T
472ACX_TYPE_SOCKLEN_T
473ACX_TYPE_IN_ADDR_T
474ACX_TYPE_IN_PORT_T
475ACX_CHECK_MEMCMP_SIGNED
476
477AC_CHECK_SIZEOF(time_t,,[
478AC_INCLUDES_DEFAULT
479#ifdef TIME_WITH_SYS_TIME
480# include <sys/time.h>
481# include <time.h>
482#else
483# ifdef HAVE_SYS_TIME_H
484#  include <sys/time.h>
485# else
486#  include <time.h>
487# endif
488#endif
489])
490AC_CHECK_SIZEOF(size_t)
491
492# add option to disable the evil rpath
493ACX_ARG_RPATH
494AC_SUBST(RUNTIME_PATH)
495
496# check to see if libraries are needed for these functions.
497AC_SEARCH_LIBS([inet_pton], [nsl])
498AC_SEARCH_LIBS([socket], [socket])
499
500# check whether strptime also works
501AC_DEFUN([AC_CHECK_STRPTIME_WORKS],
502[AC_REQUIRE([AC_PROG_CC])
503AC_MSG_CHECKING(whether strptime works)
504if test c${cross_compiling} = cno; then
505AC_RUN_IFELSE([AC_LANG_SOURCE([[
506#define _XOPEN_SOURCE 600
507#include <time.h>
508int main(void) { struct tm tm; char *res;
509res = 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);
510if (!res) return 2;
511res = strptime("20070207111842", "%Y%m%d%H%M%S", &tm);
512if (!res) return 1; return 0; }
513]])] , [eval "ac_cv_c_strptime_works=yes"], [eval "ac_cv_c_strptime_works=no"])
514else
515eval "ac_cv_c_strptime_works=maybe"
516fi
517AC_MSG_RESULT($ac_cv_c_strptime_works)
518if test $ac_cv_c_strptime_works = no; then
519AC_LIBOBJ(strptime)
520else
521AC_DEFINE_UNQUOTED([STRPTIME_WORKS], 1, [use default strptime.])
522fi
523])dnl
524
525# check some functions of the OS before linking libs (while still runnable).
526AC_FUNC_CHOWN
527AC_FUNC_FORK
528AC_DEFINE(RETSIGTYPE,void,[Return type of signal handlers, but autoconf 2.70 says 'your code may safely assume C89 semantics that RETSIGTYPE is void.'])
529AC_FUNC_FSEEKO
530ACX_SYS_LARGEFILE
531ACX_CHECK_NONBLOCKING_BROKEN
532ACX_MKDIR_ONE_ARG
533AC_CHECK_FUNCS([strptime],[AC_CHECK_STRPTIME_WORKS],[AC_LIBOBJ([strptime])])
534
535# check if we can use SO_REUSEPORT
536reuseport_default=0
537if echo "$host" | $GREP -i -e linux >/dev/null; then reuseport_default=1; fi
538if echo "$host" | $GREP -i -e dragonfly >/dev/null; then reuseport_default=1; fi
539if test "$reuseport_default" = 1; then
540	AC_DEFINE(REUSEPORT_DEFAULT, 1, [if REUSEPORT is enabled by default])
541else
542	AC_DEFINE(REUSEPORT_DEFAULT, 0, [if REUSEPORT is enabled by default])
543fi
544
545# Include systemd.m4 - begin
546sinclude(systemd.m4)
547# Include systemd.m4 - end
548
549# set memory allocation checking if requested
550AC_ARG_ENABLE(alloc-checks, AS_HELP_STRING([--enable-alloc-checks],[ enable to memory allocation statistics, for debug purposes ]),
551	, )
552AC_ARG_ENABLE(alloc-lite, AS_HELP_STRING([--enable-alloc-lite],[ enable for lightweight alloc assertions, for debug purposes ]),
553	, )
554AC_ARG_ENABLE(alloc-nonregional, AS_HELP_STRING([--enable-alloc-nonregional],[ enable nonregional allocs, slow but exposes regional allocations to other memory purifiers, for debug purposes ]),
555	, )
556if test x_$enable_alloc_nonregional = x_yes; then
557	AC_DEFINE(UNBOUND_ALLOC_NONREGIONAL, 1, [use malloc not regions, for debug use])
558fi
559if test x_$enable_alloc_checks = x_yes; then
560	AC_DEFINE(UNBOUND_ALLOC_STATS, 1, [use statistics for allocs and frees, for debug use])
561	SLDNS_ALLOCCHECK_EXTRA_OBJ="alloc.lo log.lo"
562	AC_SUBST(SLDNS_ALLOCCHECK_EXTRA_OBJ)
563	ASYNCLOOK_ALLOCCHECK_EXTRA_OBJ="alloc.lo"
564	AC_SUBST(ASYNCLOOK_ALLOCCHECK_EXTRA_OBJ)
565else
566	if test x_$enable_alloc_lite = x_yes; then
567		AC_DEFINE(UNBOUND_ALLOC_LITE, 1, [use to enable lightweight alloc assertions, for debug use])
568	else
569		ACX_FUNC_MALLOC([unbound])
570	fi
571fi
572
573# check windows threads (we use them, not pthreads, on windows).
574if test "$on_mingw" = "yes"; then
575# check windows threads
576	AC_CHECK_HEADERS([windows.h],,, [AC_INCLUDES_DEFAULT])
577	AC_MSG_CHECKING([for CreateThread])
578	AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
579#ifdef HAVE_WINDOWS_H
580#include <windows.h>
581#endif
582], [
583	HANDLE t = CreateThread(NULL, 0, NULL, NULL, 0, NULL);
584])],
585	AC_MSG_RESULT(yes)
586	AC_DEFINE(HAVE_WINDOWS_THREADS, 1, [Using Windows threads])
587,
588	AC_MSG_RESULT(no)
589)
590
591else
592# not on mingw, check thread libraries.
593
594# check for thread library.
595# check this first, so that the pthread lib does not get linked in via
596# libssl or libpython, and thus distorts the tests, and we end up using
597# the non-threadsafe C libraries.
598AC_ARG_WITH(pthreads, AS_HELP_STRING([--with-pthreads],[use pthreads library, or --without-pthreads to disable threading support.]),
599 [ ],[ withval="yes" ])
600ub_have_pthreads=no
601if test x_$withval != x_no; then
602	AX_PTHREAD([
603		AC_DEFINE(HAVE_PTHREAD,1,[Define if you have POSIX threads libraries and header files.])
604		if test -n "$PTHREAD_LIBS"; then
605		  LIBS="$PTHREAD_LIBS $LIBS"
606		fi
607		CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
608		CC="$PTHREAD_CC"
609		ub_have_pthreads=yes
610		AC_CHECK_TYPES([pthread_spinlock_t, pthread_rwlock_t],,,[#include <pthread.h>])
611		AC_CHECK_SIZEOF([unsigned long])
612		AC_CHECK_SIZEOF(pthread_t)
613
614		if echo "$CFLAGS" | $GREP -e "-pthread" >/dev/null; then
615		AC_MSG_CHECKING([if -pthread unused during linking])
616		# catch clang warning 'argument unused during compilation'
617		AC_LANG_CONFTEST([AC_LANG_SOURCE(AC_INCLUDES_DEFAULT
618[[
619int main(void) {return 0;}
620]])])
621		pthread_unused="yes"
622		# first compile
623		echo "$CC $CFLAGS -c conftest.c -o conftest.o" >&AS_MESSAGE_LOG_FD
624		$CC $CFLAGS -c conftest.c -o conftest.o 2>&AS_MESSAGE_LOG_FD >&AS_MESSAGE_LOG_FD
625		if test $? = 0; then
626			# then link
627			echo "$CC $CFLAGS -Werror $LDFLAGS $LIBS -o conftest contest.o" >&AS_MESSAGE_LOG_FD
628			$CC $CFLAGS -Werror $LDFLAGS $LIBS -o conftest conftest.o 2>&AS_MESSAGE_LOG_FD >&AS_MESSAGE_LOG_FD
629			if test $? -ne 0; then
630				AC_MSG_RESULT(yes)
631				CFLAGS=`echo "$CFLAGS" | sed -e 's/-pthread//'`
632				PTHREAD_CFLAGS_ONLY="-pthread"
633				AC_SUBST(PTHREAD_CFLAGS_ONLY)
634			else
635				AC_MSG_RESULT(no)
636			fi
637		else
638			AC_MSG_RESULT(no)
639		fi # endif cc successful
640		rm -f conftest conftest.c conftest.o
641		fi # endif -pthread in CFLAGS
642
643		])
644fi
645
646# check solaris thread library
647AC_ARG_WITH(solaris-threads, AS_HELP_STRING([--with-solaris-threads],[use solaris native thread library.]), [ ],[ withval="no" ])
648ub_have_sol_threads=no
649if test x_$withval != x_no; then
650	if test x_$ub_have_pthreads != x_no; then
651	    AC_MSG_WARN([Have pthreads already, ignoring --with-solaris-threads])
652	else
653	AC_SEARCH_LIBS(thr_create, [thread],
654	[
655    		AC_DEFINE(HAVE_SOLARIS_THREADS, 1, [Using Solaris threads])
656
657		ACX_CHECK_COMPILER_FLAG(mt, [CFLAGS="$CFLAGS -mt"],
658			[CFLAGS="$CFLAGS -D_REENTRANT"])
659		ub_have_sol_threads=yes
660	] , [
661		AC_MSG_ERROR([no solaris threads found.])
662	])
663	fi
664fi
665
666fi # end of non-mingw check of thread libraries
667
668# Check for SYSLOG_FACILITY
669AC_ARG_WITH(syslog-facility, AS_HELP_STRING([--with-syslog-facility=LOCAL0 - LOCAL7],[ set SYSLOG_FACILITY, default DAEMON ]),
670	[ UNBOUND_SYSLOG_FACILITY="$withval" ], [])
671case "${UNBOUND_SYSLOG_FACILITY}" in
672
673  LOCAL[[0-7]]) UNBOUND_SYSLOG_FACILITY="LOG_${UNBOUND_SYSLOG_FACILITY}" ;;
674
675           *) UNBOUND_SYSLOG_FACILITY="LOG_DAEMON" ;;
676
677esac
678AC_DEFINE_UNQUOTED(UB_SYSLOG_FACILITY,${UNBOUND_SYSLOG_FACILITY},[the SYSLOG_FACILITY to use, default LOG_DAEMON])
679
680# Check for dynamic library module
681AC_ARG_WITH(dynlibmodule,
682   AS_HELP_STRING([--with-dynlibmodule],[build dynamic library module, or --without-dynlibmodule to disable it. (default=no)]),
683   [], [ withval="no" ])
684
685if test x_$withval != x_no; then
686  AC_DEFINE(WITH_DYNLIBMODULE, 1, [Define if you want dynlib module.])
687  WITH_DYNLIBMODULE=yes
688  AC_SUBST(WITH_DYNLIBMODULE)
689  DYNLIBMOD_OBJ="dynlibmod.lo"
690  AC_SUBST(DYNLIBMOD_OBJ)
691  DYNLIBMOD_HEADER='$(srcdir)/dynlibmod/dynlibmod.h'
692  AC_SUBST(DYNLIBMOD_HEADER)
693  if test $on_mingw = "no"; then
694    # link with -ldl if not already there, for all executables because
695    # dlopen call is in the dynlib module.  For unbound executable, also
696    # export symbols.
697    AC_SEARCH_LIBS([dlopen], [dl])
698    DYNLIBMOD_EXTRALIBS="-export-dynamic"
699  else
700    DYNLIBMOD_EXTRALIBS="-Wl,--export-all-symbols,--out-implib,libunbound.dll.a"
701  fi
702  AC_SUBST(DYNLIBMOD_EXTRALIBS)
703fi
704
705# Check for PyUnbound
706AC_ARG_WITH(pyunbound,
707   AS_HELP_STRING([--with-pyunbound],[build PyUnbound, or --without-pyunbound to skip it. (default=no)]),
708   [], [ withval="no" ])
709
710ub_test_python=no
711ub_with_pyunbound=no
712if test x_$withval != x_no; then
713   ub_with_pyunbound=yes
714   ub_test_python=yes
715fi
716
717# Check for Python module
718AC_ARG_WITH(pythonmodule,
719   AS_HELP_STRING([--with-pythonmodule],[build Python module, or --without-pythonmodule to disable script engine. (default=no)]),
720   [], [ withval="no" ])
721
722ub_with_pythonmod=no
723if test x_$withval != x_no; then
724   ub_with_pythonmod=yes
725   ub_test_python=yes
726fi
727
728# Check for Python & SWIG only on PyUnbound or PyModule
729if test x_$ub_test_python != x_no; then
730
731   # Check for Python
732   ub_have_python=no
733   ac_save_LIBS="$LIBS" dnl otherwise AC_PYTHON_DEVEL thrashes $LIBS
734   AC_PYTHON_DEVEL
735   if test ! -z "$PYTHON_VERSION"; then
736	if test `$PYTHON -c "print('$PYTHON_VERSION' >= '2.4.0')"` = "False"; then
737		AC_MSG_ERROR([Python version >= 2.4.0 is required])
738	fi
739
740      [PY_MAJOR_VERSION="`$PYTHON -c \"import sys; print(sys.version_info[0])\"`"]
741      AC_SUBST(PY_MAJOR_VERSION)
742      # Have Python
743      AC_DEFINE(HAVE_PYTHON,1,[Define if you have Python libraries and header files.])
744      if test x_$ub_with_pythonmod != x_no; then
745        if test -n "$LIBS"; then
746          LIBS="$PYTHON_LDFLAGS $LIBS"
747        else
748          LIBS="$PYTHON_LDFLAGS"
749        fi
750      fi
751      PYTHON_LIBS="$PYTHON_LDFLAGS"
752      AC_SUBST(PYTHON_LIBS)
753      if test -n "$CPPFLAGS"; then
754        CPPFLAGS="$CPPFLAGS $PYTHON_CPPFLAGS"
755      else
756        CPPFLAGS="$PYTHON_CPPFLAGS"
757      fi
758      if test "$PYTHON_LIBDIR" != "/usr/lib" -a "$PYTHON_LIBDIR" != "" -a "$PYTHON_LIBDIR" != "/usr/lib64"; then
759        ACX_RUNTIME_PATH_ADD([$PYTHON_LIBDIR])
760      fi
761      ub_have_python=yes
762      PKG_CHECK_EXISTS(["python${PY_MAJOR_VERSION}"],
763                       [PC_PY_DEPENDENCY="python${PY_MAJOR_VERSION}"],
764                       [PC_PY_DEPENDENCY="python"])
765      AC_SUBST(PC_PY_DEPENDENCY)
766
767      # Check for SWIG
768      ub_have_swig=no
769      AC_ARG_ENABLE(swig-version-check, AS_HELP_STRING([--disable-swig-version-check],[Disable swig version check to build python modules with older swig even though that is unreliable]))
770      if test "$enable_swig_version_check" = "yes"; then
771      	AC_PROG_SWIG(2.0.1)
772      else
773      	AC_PROG_SWIG
774      fi
775      AC_MSG_CHECKING(SWIG)
776      if test ! -x "$SWIG"; then
777         AC_MSG_ERROR([failed to find swig tool, install it, or do not build Python module and PyUnbound])
778      else
779         AC_DEFINE(HAVE_SWIG, 1, [Define if you have Swig libraries and header files.])
780         AC_SUBST(swig, "$SWIG")
781         AC_MSG_RESULT(present)
782
783         # If have Python & SWIG
784         # Declare PythonMod
785         if test x_$ub_with_pythonmod != x_no; then
786            AC_DEFINE(WITH_PYTHONMODULE, 1, [Define if you want Python module.])
787            WITH_PYTHONMODULE=yes
788            AC_SUBST(WITH_PYTHONMODULE)
789	    PYTHONMOD_OBJ="pythonmod.lo pythonmod_utils.lo"
790	    AC_SUBST(PYTHONMOD_OBJ)
791	    PYTHONMOD_HEADER='$(srcdir)/pythonmod/pythonmod.h'
792	    AC_SUBST(PYTHONMOD_HEADER)
793	    PYTHONMOD_INSTALL=pythonmod-install
794	    AC_SUBST(PYTHONMOD_INSTALL)
795	    PYTHONMOD_UNINSTALL=pythonmod-uninstall
796	    AC_SUBST(PYTHONMOD_UNINSTALL)
797         fi
798
799         # Declare PyUnbound
800         if test x_$ub_with_pyunbound != x_no; then
801            AC_DEFINE(WITH_PYUNBOUND, 1, [Define if you want PyUnbound.])
802            WITH_PYUNBOUND=yes
803            AC_SUBST(WITH_PYUNBOUND)
804	    PYUNBOUND_OBJ="libunbound_wrap.lo"
805	    AC_SUBST(PYUNBOUND_OBJ)
806	    PYUNBOUND_TARGET="_unbound.la"
807	    AC_SUBST(PYUNBOUND_TARGET)
808	    PYUNBOUND_INSTALL=pyunbound-install
809	    AC_SUBST(PYUNBOUND_INSTALL)
810	    PYUNBOUND_UNINSTALL=pyunbound-uninstall
811	    AC_SUBST(PYUNBOUND_UNINSTALL)
812         fi
813      fi
814   else
815      AC_MSG_RESULT([*** Python libraries not found, won't build PythonMod or PyUnbound ***])
816      ub_with_pyunbound=no
817      ub_with_pythonmod=no
818   fi
819fi
820
821if test "`uname`" = "NetBSD"; then
822	NETBSD_LINTFLAGS='"-D__RENAME(x)=" -D_NETINET_IN_H_'
823	AC_SUBST(NETBSD_LINTFLAGS)
824fi
825
826if test "`uname`" = "Linux"; then
827	# splint cannot parse modern c99 header files
828	GCC_DOCKER_LINTFLAGS='-syntax'
829	AC_SUBST(GCC_DOCKER_LINTFLAGS)
830fi
831CONFIG_DATE=`date +%Y%m%d`
832AC_SUBST(CONFIG_DATE)
833
834# Checks for libraries.
835
836# libnss
837USE_NSS="no"
838AC_ARG_WITH([nss], AS_HELP_STRING([--with-nss=path],[use libnss instead of openssl, installed at path.]),
839	[
840	USE_NSS="yes"
841	AC_DEFINE(HAVE_NSS, 1, [Use libnss for crypto])
842	if test "$withval" != "" -a "$withval" != "yes"; then
843		CPPFLAGS="$CPPFLAGS -I$withval/include/nss3"
844		LDFLAGS="$LDFLAGS -L$withval/lib"
845		ACX_RUNTIME_PATH_ADD([$withval/lib])
846		CPPFLAGS="-I$withval/include/nspr4 $CPPFLAGS"
847	else
848		CPPFLAGS="$CPPFLAGS -I/usr/include/nss3"
849		CPPFLAGS="-I/usr/include/nspr4 $CPPFLAGS"
850	fi
851        LIBS="$LIBS -lnss3 -lnspr4"
852	SSLLIB=""
853	PC_CRYPTO_DEPENDENCY="nss nspr"
854	AC_SUBST(PC_CRYPTO_DEPENDENCY)
855	]
856)
857
858# libnettle
859USE_NETTLE="no"
860AC_ARG_WITH([nettle], AS_HELP_STRING([--with-nettle=path],[use libnettle as crypto library, installed at path.]),
861	[
862	USE_NETTLE="yes"
863	AC_DEFINE(HAVE_NETTLE, 1, [Use libnettle for crypto])
864	AC_CHECK_HEADERS([nettle/dsa-compat.h],,, [AC_INCLUDES_DEFAULT])
865	if test "$withval" != "" -a "$withval" != "yes"; then
866		CPPFLAGS="$CPPFLAGS -I$withval/include/nettle"
867		LDFLAGS="$LDFLAGS -L$withval/lib"
868		ACX_RUNTIME_PATH_ADD([$withval/lib])
869	else
870		CPPFLAGS="$CPPFLAGS -I/usr/include/nettle"
871	fi
872        LIBS="$LIBS -lhogweed -lnettle -lgmp"
873	SSLLIB=""
874	PC_CRYPTO_DEPENDENCY="hogweed nettle"
875	AC_SUBST(PC_CRYPTO_DEPENDENCY)
876	]
877)
878
879# openssl
880if test $USE_NSS = "no" -a $USE_NETTLE = "no"; then
881ACX_WITH_SSL
882ACX_LIB_SSL
883SSLLIB="-lssl"
884
885PC_CRYPTO_DEPENDENCY=""
886AC_SUBST(PC_CRYPTO_DEPENDENCY)
887
888# check if -lcrypt32 is needed because CAPIENG needs that. (on windows)
889BAKLIBS="$LIBS"
890LIBS="-lssl $LIBS"
891AC_MSG_CHECKING([if libssl needs -lcrypt32])
892AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[
893	int EVP_sha256(void);
894	(void)EVP_sha256();
895]])], [
896	AC_MSG_RESULT([no])
897	LIBS="$BAKLIBS"
898], [
899	AC_MSG_RESULT([yes])
900	LIBS="$BAKLIBS"
901	LIBS="$LIBS -lcrypt32"
902])
903
904AC_MSG_CHECKING([for LibreSSL])
905if grep VERSION_TEXT $ssldir_include/openssl/opensslv.h | grep "LibreSSL" >/dev/null; then
906	AC_MSG_RESULT([yes])
907	AC_DEFINE([HAVE_LIBRESSL], [1], [Define if we have LibreSSL])
908	# libressl provides these compat functions, but they may also be
909	# declared by the OS in libc.  See if they have been declared.
910	AC_CHECK_DECLS([strlcpy,strlcat,arc4random,arc4random_uniform])
911else
912	AC_MSG_RESULT([no])
913fi
914AC_CHECK_HEADERS([openssl/conf.h openssl/engine.h openssl/bn.h openssl/dh.h openssl/dsa.h openssl/rsa.h openssl/core_names.h openssl/param_build.h],,, [AC_INCLUDES_DEFAULT])
915AC_CHECK_FUNCS([OPENSSL_config EVP_sha1 EVP_sha256 EVP_sha512 FIPS_mode EVP_default_properties_is_fips_enabled EVP_MD_CTX_new OpenSSL_add_all_digests OPENSSL_init_crypto EVP_cleanup ENGINE_cleanup ERR_load_crypto_strings CRYPTO_cleanup_all_ex_data ERR_free_strings RAND_cleanup DSA_SIG_set0 EVP_dss1 EVP_DigestVerify EVP_aes_256_cbc EVP_EncryptInit_ex HMAC_Init_ex CRYPTO_THREADID_set_callback EVP_MAC_CTX_set_params OSSL_PARAM_BLD_new BIO_set_callback_ex])
916
917# these check_funcs need -lssl
918BAKLIBS="$LIBS"
919LIBS="-lssl $LIBS"
920AC_CHECK_FUNCS([OPENSSL_init_ssl SSL_CTX_set_security_level SSL_set1_host SSL_get0_peername X509_VERIFY_PARAM_set1_host SSL_CTX_set_ciphersuites SSL_CTX_set_tlsext_ticket_key_evp_cb SSL_CTX_set_alpn_select_cb SSL_get0_alpn_selected SSL_CTX_set_alpn_protos SSL_get1_peer_certificate])
921LIBS="$BAKLIBS"
922
923AC_CHECK_DECLS([SSL_COMP_get_compression_methods,sk_SSL_COMP_pop_free,SSL_CTX_set_ecdh_auto], [], [], [
924AC_INCLUDES_DEFAULT
925#ifdef HAVE_OPENSSL_ERR_H
926#include <openssl/err.h>
927#endif
928
929#ifdef HAVE_OPENSSL_RAND_H
930#include <openssl/rand.h>
931#endif
932
933#ifdef HAVE_OPENSSL_CONF_H
934#include <openssl/conf.h>
935#endif
936
937#ifdef HAVE_OPENSSL_ENGINE_H
938#include <openssl/engine.h>
939#endif
940#include <openssl/ssl.h>
941#include <openssl/evp.h>
942])
943
944if test "$ac_cv_func_HMAC_Init_ex" = "yes"; then
945# check function return type.
946AC_MSG_CHECKING(the return type of HMAC_Init_ex)
947AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
948#ifdef HAVE_OPENSSL_ERR_H
949#include <openssl/err.h>
950#endif
951
952#ifdef HAVE_OPENSSL_RAND_H
953#include <openssl/rand.h>
954#endif
955
956#ifdef HAVE_OPENSSL_CONF_H
957#include <openssl/conf.h>
958#endif
959
960#ifdef HAVE_OPENSSL_ENGINE_H
961#include <openssl/engine.h>
962#endif
963#include <openssl/ssl.h>
964#include <openssl/evp.h>
965], [
966	HMAC_CTX* hmac_ctx = NULL;
967	void* hmac_key = NULL;
968	const EVP_MD* digest = NULL;
969	int x = HMAC_Init_ex(hmac_ctx, hmac_key, 32, digest, NULL);
970	(void)x;
971])], [
972	AC_MSG_RESULT(int)
973], [
974	AC_MSG_RESULT(void)
975	AC_DEFINE([HMAC_INIT_EX_RETURNS_VOID], 1, [If HMAC_Init_ex() returns void])
976])
977fi
978
979fi
980AC_SUBST(SSLLIB)
981
982# libbsd
983AC_ARG_WITH([libbsd], AS_HELP_STRING([--with-libbsd],[Use portable libbsd functions]), [
984	AC_CHECK_HEADERS([bsd/string.h bsd/stdlib.h],,, [AC_INCLUDES_DEFAULT])
985	if test "x$ac_cv_header_bsd_string_h" = xyes -a "x$ac_cv_header_bsd_stdlib_h" = xyes; then
986		for func in strlcpy strlcat arc4random arc4random_uniform reallocarray; do
987			AC_SEARCH_LIBS([$func], [bsd], [
988				AC_DEFINE(HAVE_LIBBSD, 1, [Use portable libbsd functions])
989				PC_LIBBSD_DEPENDENCY=libbsd
990				AC_SUBST(PC_LIBBSD_DEPENDENCY)
991			])
992		done
993	fi
994])
995
996AC_ARG_ENABLE(sha1, AS_HELP_STRING([--disable-sha1],[Disable SHA1 RRSIG support, does not disable nsec3 support]))
997case "$enable_sha1" in
998	no)
999	;;
1000	yes|*)
1001	AC_DEFINE([USE_SHA1], [1], [Define this to enable SHA1 support.])
1002	;;
1003esac
1004
1005
1006AC_ARG_ENABLE(sha2, AS_HELP_STRING([--disable-sha2],[Disable SHA256 and SHA512 RRSIG support]))
1007case "$enable_sha2" in
1008	no)
1009	;;
1010	yes|*)
1011	AC_DEFINE([USE_SHA2], [1], [Define this to enable SHA256 and SHA512 support.])
1012	;;
1013esac
1014
1015AC_ARG_ENABLE(subnet, AS_HELP_STRING([--enable-subnet],[Enable client subnet]))
1016case "$enable_subnet" in
1017	yes)
1018	AC_DEFINE([CLIENT_SUBNET], [1], [Define this to enable client subnet option.])
1019	SUBNET_OBJ="edns-subnet.lo subnetmod.lo addrtree.lo subnet-whitelist.lo"
1020	AC_SUBST(SUBNET_OBJ)
1021	SUBNET_HEADER='$(srcdir)/edns-subnet/subnetmod.h $(srcdir)/edns-subnet/edns-subnet.h $(srcdir)/edns-subnet/subnet-whitelist.h $(srcdir)/edns-subnet/addrtree.h'
1022	AC_SUBST(SUBNET_HEADER)
1023	;;
1024	no|*)
1025	;;
1026esac
1027
1028# check whether gost also works
1029AC_DEFUN([AC_CHECK_GOST_WORKS],
1030[AC_REQUIRE([AC_PROG_CC])
1031AC_MSG_CHECKING([if GOST works])
1032if test c${cross_compiling} = cno; then
1033BAKCFLAGS="$CFLAGS"
1034if test -n "$ssldir"; then
1035	CFLAGS="$CFLAGS -Wl,-rpath,$ssldir_lib"
1036fi
1037AC_RUN_IFELSE([AC_LANG_SOURCE([[
1038#include <string.h>
1039#include <openssl/ssl.h>
1040#include <openssl/evp.h>
1041#include <openssl/engine.h>
1042#include <openssl/conf.h>
1043/* routine to load gost (from sldns) */
1044int load_gost_id(void)
1045{
1046	static int gost_id = 0;
1047	const EVP_PKEY_ASN1_METHOD* meth;
1048	ENGINE* e;
1049
1050	if(gost_id) return gost_id;
1051
1052	/* see if configuration loaded gost implementation from other engine*/
1053	meth = EVP_PKEY_asn1_find_str(NULL, "gost2001", -1);
1054	if(meth) {
1055		EVP_PKEY_asn1_get0_info(&gost_id, NULL, NULL, NULL, NULL, meth);
1056		return gost_id;
1057	}
1058
1059	/* see if engine can be loaded already */
1060	e = ENGINE_by_id("gost");
1061	if(!e) {
1062		/* load it ourself, in case statically linked */
1063		ENGINE_load_builtin_engines();
1064		ENGINE_load_dynamic();
1065		e = ENGINE_by_id("gost");
1066	}
1067	if(!e) {
1068		/* no gost engine in openssl */
1069		return 0;
1070	}
1071	if(!ENGINE_set_default(e, ENGINE_METHOD_ALL)) {
1072		ENGINE_finish(e);
1073		ENGINE_free(e);
1074		return 0;
1075	}
1076
1077	meth = EVP_PKEY_asn1_find_str(&e, "gost2001", -1);
1078	if(!meth) {
1079		/* algo not found */
1080		ENGINE_finish(e);
1081		ENGINE_free(e);
1082		return 0;
1083	}
1084	EVP_PKEY_asn1_get0_info(&gost_id, NULL, NULL, NULL, NULL, meth);
1085	return gost_id;
1086}
1087int main(void) {
1088	EVP_MD_CTX* ctx;
1089	const EVP_MD* md;
1090	unsigned char digest[64]; /* its a 256-bit digest, so uses 32 bytes */
1091	const char* str = "Hello world";
1092	const unsigned char check[] = {
1093		0x40 , 0xed , 0xf8 , 0x56 , 0x5a , 0xc5 , 0x36 , 0xe1 ,
1094		0x33 , 0x7c , 0x7e , 0x87 , 0x62 , 0x1c , 0x42 , 0xe0 ,
1095		0x17 , 0x1b , 0x5e , 0xce , 0xa8 , 0x46 , 0x65 , 0x4d ,
1096		0x8d , 0x3e , 0x22 , 0x9b , 0xe1 , 0x30 , 0x19 , 0x9d
1097	};
1098	OPENSSL_config(NULL);
1099	(void)load_gost_id();
1100	md = EVP_get_digestbyname("md_gost94");
1101	if(!md) return 1;
1102	memset(digest, 0, sizeof(digest));
1103	ctx = EVP_MD_CTX_create();
1104	if(!ctx) return 2;
1105	if(!EVP_DigestInit_ex(ctx, md, NULL)) return 3;
1106	if(!EVP_DigestUpdate(ctx, str, 10)) return 4;
1107	if(!EVP_DigestFinal_ex(ctx, digest, NULL)) return 5;
1108	/* uncomment to see the hash calculated.
1109		{int i;
1110		for(i=0; i<32; i++)
1111			printf(" %2.2x", (int)digest[i]);
1112		printf("\n");}
1113	*/
1114	if(memcmp(digest, check, sizeof(check)) != 0)
1115		return 6;
1116	return 0;
1117}
1118]])] , [eval "ac_cv_c_gost_works=yes"], [eval "ac_cv_c_gost_works=no"])
1119CFLAGS="$BAKCFLAGS"
1120else
1121eval "ac_cv_c_gost_works=maybe"
1122fi
1123AC_MSG_RESULT($ac_cv_c_gost_works)
1124])dnl
1125
1126AC_ARG_ENABLE(gost, AS_HELP_STRING([--disable-gost],[Disable GOST support]))
1127use_gost="no"
1128if test $USE_NSS = "no" -a $USE_NETTLE = "no"; then
1129case "$enable_gost" in
1130	no)
1131	;;
1132	*)
1133	AC_CHECK_FUNC(EVP_PKEY_set_type_str, [:],[AC_MSG_ERROR([OpenSSL 1.0.0 is needed for GOST support])])
1134	AC_CHECK_FUNC(EC_KEY_new, [], [AC_MSG_ERROR([OpenSSL does not support ECC, needed for GOST support])])
1135	AC_CHECK_GOST_WORKS
1136	if test "$ac_cv_c_gost_works" != no; then
1137		use_gost="yes"
1138		AC_DEFINE([USE_GOST], [1], [Define this to enable GOST support.])
1139	fi
1140	;;
1141esac
1142fi dnl !USE_NSS && !USE_NETTLE
1143
1144AC_ARG_ENABLE(ecdsa, AS_HELP_STRING([--disable-ecdsa],[Disable ECDSA support]))
1145use_ecdsa="no"
1146case "$enable_ecdsa" in
1147    no)
1148      ;;
1149    *)
1150      if test $USE_NSS = "no" -a $USE_NETTLE = "no"; then
1151	      AC_CHECK_FUNC(ECDSA_sign, [], [AC_MSG_ERROR([OpenSSL does not support ECDSA: please upgrade or rerun with --disable-ecdsa])])
1152	      AC_CHECK_FUNC(SHA384_Init, [], [AC_MSG_ERROR([OpenSSL does not support SHA384: please upgrade or rerun with --disable-ecdsa])])
1153	      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
1154#include <openssl/evp.h>
1155	      ])
1156	      # see if OPENSSL 1.0.0 or later (has EVP MD and Verify independency)
1157	      AC_MSG_CHECKING([if openssl supports SHA2 and ECDSA with EVP])
1158	      if grep OPENSSL_VERSION_TEXT $ssldir_include/openssl/opensslv.h | grep "OpenSSL" >/dev/null; then
1159		if grep OPENSSL_VERSION_NUMBER $ssldir_include/openssl/opensslv.h | grep 0x0 >/dev/null; then
1160		  AC_MSG_RESULT([no])
1161		  AC_DEFINE_UNQUOTED([USE_ECDSA_EVP_WORKAROUND], [1], [Define this to enable an EVP workaround for older openssl])
1162		else
1163		  AC_MSG_RESULT([yes])
1164		fi
1165	      else
1166		# not OpenSSL, thus likely LibreSSL, which supports it
1167		AC_MSG_RESULT([yes])
1168	      fi
1169      fi
1170      # we now know we have ECDSA and the required curves.
1171      AC_DEFINE_UNQUOTED([USE_ECDSA], [1], [Define this to enable ECDSA support.])
1172      use_ecdsa="yes"
1173      ;;
1174esac
1175
1176AC_ARG_ENABLE(dsa, AS_HELP_STRING([--disable-dsa],[Disable DSA support]))
1177use_dsa="no"
1178case "$enable_dsa" in
1179    yes)
1180      # detect if DSA is supported, and turn it off if not.
1181      if test $USE_NSS = "no" -a $USE_NETTLE = "no"; then
1182      AC_CHECK_FUNC(DSA_SIG_new, [
1183      AC_CHECK_TYPE(DSA_SIG*, [
1184      AC_DEFINE_UNQUOTED([USE_DSA], [1], [Define this to enable DSA support.])
1185      ], [if test "x$enable_dsa" = "xyes"; then AC_MSG_ERROR([OpenSSL does not support DSA and you used --enable-dsa.])
1186               fi ], [
1187AC_INCLUDES_DEFAULT
1188#ifdef HAVE_OPENSSL_ERR_H
1189#include <openssl/err.h>
1190#endif
1191
1192#ifdef HAVE_OPENSSL_RAND_H
1193#include <openssl/rand.h>
1194#endif
1195
1196#ifdef HAVE_OPENSSL_CONF_H
1197#include <openssl/conf.h>
1198#endif
1199
1200#ifdef HAVE_OPENSSL_ENGINE_H
1201#include <openssl/engine.h>
1202#endif
1203      ])
1204      ], [if test "x$enable_dsa" = "xyes"; then AC_MSG_ERROR([OpenSSL does not support DSA and you used --enable-dsa.])
1205               fi ])
1206      else
1207      AC_DEFINE_UNQUOTED([USE_DSA], [1], [Define this to enable DSA support.])
1208      fi
1209      ;;
1210    *)
1211      # disable dsa by default, RFC 8624 section 3.1, validators MUST NOT
1212      # support DSA for DNSSEC Validation.
1213      ;;
1214esac
1215
1216AC_ARG_WITH(deprecate-rsa-1024, AS_HELP_STRING([--with-deprecate-rsa-1024],[Deprecate RSA 1024 bit length, makes that an unsupported key, for use when OpenSSL FIPS refuses 1024 bit verification]))
1217if test "$with_deprecate_rsa_1024" = "yes"; then
1218	AC_DEFINE([DEPRECATE_RSA_1024], [1], [Deprecate RSA 1024 bit length, makes that an unsupported key])
1219fi
1220
1221AC_ARG_ENABLE(ed25519, AS_HELP_STRING([--disable-ed25519],[Disable ED25519 support]))
1222use_ed25519="no"
1223case "$enable_ed25519" in
1224    no)
1225      ;;
1226    *)
1227      if test $USE_NSS = "no" -a $USE_NETTLE = "no"; then
1228	      AC_CHECK_DECLS([NID_ED25519], [
1229      		use_ed25519="yes"
1230	      ], [ if test "x$enable_ed25519" = "xyes"; then AC_MSG_ERROR([OpenSSL does not support ED25519 and you used --enable-ed25519.])
1231	      	fi ], [AC_INCLUDES_DEFAULT
1232#include <openssl/evp.h>
1233	      ])
1234      fi
1235      if test $USE_NETTLE = "yes"; then
1236		AC_CHECK_HEADERS([nettle/eddsa.h], use_ed25519="yes",, [AC_INCLUDES_DEFAULT])
1237      fi
1238      if test $use_ed25519 = "yes"; then
1239      		AC_DEFINE_UNQUOTED([USE_ED25519], [1], [Define this to enable ED25519 support.])
1240      fi
1241      ;;
1242esac
1243
1244AC_ARG_ENABLE(ed448, AS_HELP_STRING([--disable-ed448],[Disable ED448 support]))
1245use_ed448="no"
1246case "$enable_ed448" in
1247    no)
1248      ;;
1249    *)
1250      if test $USE_NSS = "no" -a $USE_NETTLE = "no"; then
1251	      AC_CHECK_DECLS([NID_ED448], [
1252      		use_ed448="yes"
1253	      ], [ if test "x$enable_ed448" = "xyes"; then AC_MSG_ERROR([OpenSSL does not support ED448 and you used --enable-ed448.])
1254	      	fi ], [AC_INCLUDES_DEFAULT
1255#include <openssl/evp.h>
1256	      ])
1257      fi
1258      if test $use_ed448 = "yes"; then
1259      		AC_DEFINE_UNQUOTED([USE_ED448], [1], [Define this to enable ED448 support.])
1260      fi
1261      ;;
1262esac
1263
1264AC_ARG_ENABLE(event-api, AS_HELP_STRING([--enable-event-api],[Enable (experimental) pluggable event base libunbound API installed to unbound-event.h]))
1265case "$enable_event_api" in
1266    yes)
1267      AC_SUBST(UNBOUND_EVENT_INSTALL, [unbound-event-install])
1268      AC_SUBST(UNBOUND_EVENT_UNINSTALL, [unbound-event-uninstall])
1269      ;;
1270    *)
1271      ;;
1272esac
1273
1274AC_ARG_ENABLE(tfo-client, AS_HELP_STRING([--enable-tfo-client],[Enable TCP Fast Open for client mode]))
1275case "$enable_tfo_client" in
1276	yes)
1277		case "$host_os" in
1278			linux*) AC_CHECK_DECL([MSG_FASTOPEN], [AC_MSG_WARN([Check the platform specific TFO kernel parameters are correctly configured to support client mode TFO])],
1279				[AC_MSG_ERROR([TCP Fast Open is not available for client mode: please rerun without --enable-tfo-client])],
1280				[AC_INCLUDES_DEFAULT
1281#include <netinet/tcp.h>
1282])
1283				AC_DEFINE_UNQUOTED([USE_MSG_FASTOPEN], [1], [Define this to enable client TCP Fast Open.])
1284				;;
1285			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])],
1286				[AC_MSG_ERROR([TCP Fast Open is not available for client mode: please rerun without --enable-tfo-client])],
1287				[AC_INCLUDES_DEFAULT
1288#include <sys/socket.h>
1289])
1290				AC_DEFINE_UNQUOTED([USE_OSX_MSG_FASTOPEN], [1], [Define this to enable client TCP Fast Open.])
1291				;;
1292		esac
1293		;;
1294	no|*)
1295		;;
1296esac
1297
1298AC_ARG_ENABLE(tfo-server, AS_HELP_STRING([--enable-tfo-server],[Enable TCP Fast Open for server mode]))
1299case "$enable_tfo_server" in
1300	yes)
1301	      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
1302#include <netinet/tcp.h>
1303	      ])
1304		AC_DEFINE_UNQUOTED([USE_TCP_FASTOPEN], [1], [Define this to enable server TCP Fast Open.])
1305		;;
1306	no|*)
1307		;;
1308esac
1309
1310# check for libevent
1311AC_ARG_WITH(libevent, AS_HELP_STRING([--with-libevent=pathname],[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.]),
1312    [ ],[ with_libevent="no" ])
1313if test "x_$with_libevent" != x_no; then
1314        AC_DEFINE([USE_LIBEVENT], [1], [Define if you enable libevent])
1315        AC_MSG_CHECKING(for libevent)
1316        if test "x_$with_libevent" = x_ -o "x_$with_libevent" = x_yes; then
1317            with_libevent="/usr/local /opt/local /usr/lib /usr/pkg /usr/sfw /usr"
1318        fi
1319        for dir in $with_libevent; do
1320            thedir="$dir"
1321            if test -f "$dir/include/event.h" -o -f "$dir/include/event2/event.h"; then
1322                found_libevent="yes"
1323				dnl assume /usr is in default path.
1324				if test "$thedir" != "/usr"; then
1325				    CPPFLAGS="$CPPFLAGS -I$thedir/include"
1326				fi
1327				break;
1328		    fi
1329        done
1330        if test x_$found_libevent != x_yes; then
1331		if test -f "$dir/event.h" -a \( -f "$dir/libevent.la" -o -f "$dir/libev.la" \) ; then
1332			# libevent source directory
1333			AC_MSG_RESULT(found in $thedir)
1334			CPPFLAGS="$CPPFLAGS -I$thedir -I$thedir/include"
1335			BAK_LDFLAGS_SET="1"
1336			BAK_LDFLAGS="$LDFLAGS"
1337			# remove evdns from linking
1338			mkdir build >/dev/null 2>&1
1339			mkdir build/libevent >/dev/null 2>&1
1340			mkdir build/libevent/.libs >/dev/null 2>&1
1341			ev_files_o=`ls $thedir/*.o | grep -v evdns\.o | grep -v bufferevent_openssl\.o`
1342			ev_files_lo=`ls $thedir/*.lo | grep -v evdns\.lo | grep -v bufferevent_openssl\.lo`
1343			ev_files_libso=`ls $thedir/.libs/*.o | grep -v evdns\.o | grep -v bufferevent_openssl\.o`
1344			cp $ev_files_o build/libevent
1345			cp $ev_files_lo build/libevent
1346			cp $ev_files_libso build/libevent/.libs
1347			LATE_LDFLAGS="build/libevent/*.lo -lm"
1348			LDFLAGS="build/libevent/*.o $LDFLAGS -lm"
1349		else
1350            AC_MSG_ERROR([Cannot find the libevent library in $with_libevent
1351You can restart ./configure --with-libevent=no to use a builtin alternative.
1352Please note that this alternative is not as capable as libevent when using
1353large outgoing port ranges.  ])
1354		fi
1355        else
1356            AC_MSG_RESULT(found in $thedir)
1357	    dnl if event2 exists and no event lib in dir itself, use subdir
1358	    if test ! -f $thedir/lib/libevent.a -a ! -f $thedir/lib/libevent.so -a -d "$thedir/lib/event2"; then
1359		    LDFLAGS="$LDFLAGS -L$thedir/lib/event2"
1360		    ACX_RUNTIME_PATH_ADD([$thedir/lib/event2])
1361	    else
1362		    dnl assume /usr is in default path, do not add "".
1363		    if test "$thedir" != "/usr" -a "$thedir" != ""; then
1364			LDFLAGS="$LDFLAGS -L$thedir/lib"
1365			ACX_RUNTIME_PATH_ADD([$thedir/lib])
1366		    fi
1367	    fi
1368        fi
1369	# check for library used by libevent after 1.3c
1370	AC_SEARCH_LIBS([clock_gettime], [rt])
1371
1372	# is the event.h header libev or libevent?
1373	AC_CHECK_HEADERS([event.h],,, [AC_INCLUDES_DEFAULT])
1374	AC_CHECK_DECL(EV_VERSION_MAJOR, [
1375		AC_SEARCH_LIBS(event_set, [ev])
1376	],[
1377		AC_SEARCH_LIBS(event_set, [event])
1378	],[AC_INCLUDES_DEFAULT
1379#include <event.h>
1380	])
1381	AC_CHECK_FUNCS([event_base_free]) # only in libevent 1.2 and later
1382	AC_CHECK_FUNCS([event_base_once]) # only in libevent 1.4.1 and later
1383	AC_CHECK_FUNCS([event_base_new]) # only in libevent 1.4.1 and later
1384	AC_CHECK_FUNCS([event_base_get_method]) # only in libevent 1.4.3 and later
1385	AC_CHECK_FUNCS([ev_loop]) # only in libev. (tested on 3.51)
1386	AC_CHECK_FUNCS([ev_default_loop]) # only in libev. (tested on 4.00)
1387	AC_CHECK_FUNCS([event_assign]) # in libevent, for thread-safety
1388	AC_CHECK_DECLS([evsignal_assign], [], [], [AC_INCLUDES_DEFAULT
1389#ifdef HAVE_EVENT_H
1390#  include <event.h>
1391#else
1392#  include "event2/event.h"
1393#endif
1394	])
1395        PC_LIBEVENT_DEPENDENCY="libevent"
1396        AC_SUBST(PC_LIBEVENT_DEPENDENCY)
1397	if test -n "$BAK_LDFLAGS_SET"; then
1398		LDFLAGS="$BAK_LDFLAGS"
1399	fi
1400else
1401	AC_DEFINE(USE_MINI_EVENT, 1, [Define if you want to use internal select based events])
1402fi
1403
1404# check for libexpat
1405AC_ARG_WITH(libexpat, AS_HELP_STRING([--with-libexpat=path],[specify explicit path for libexpat.]),
1406    [ ],[ withval="/usr/local /opt/local /usr/lib /usr/pkg /usr/sfw /usr" ])
1407AC_MSG_CHECKING(for libexpat)
1408found_libexpat="no"
1409for dir in $withval ; do
1410            if test -f "$dir/include/expat.h"; then
1411		found_libexpat="yes"
1412		dnl assume /usr is in default path.
1413		if test "$dir" != "/usr"; then
1414                    CPPFLAGS="$CPPFLAGS -I$dir/include"
1415		    LDFLAGS="$LDFLAGS -L$dir/lib"
1416		fi
1417            	AC_MSG_RESULT(found in $dir)
1418                break;
1419            fi
1420done
1421if test x_$found_libexpat != x_yes; then
1422	AC_MSG_ERROR([Could not find libexpat, expat.h])
1423fi
1424AC_CHECK_HEADERS([expat.h],,, [AC_INCLUDES_DEFAULT])
1425AC_CHECK_DECLS([XML_StopParser], [], [], [AC_INCLUDES_DEFAULT
1426#include <expat.h>
1427])
1428
1429# hiredis (redis C client for cachedb)
1430AC_ARG_WITH(libhiredis, AS_HELP_STRING([--with-libhiredis=path],[specify explicit path for libhiredis.]),
1431    [ ],[ withval="no" ])
1432found_libhiredis="no"
1433if test x_$withval = x_yes -o x_$withval != x_no; then
1434   AC_MSG_CHECKING(for libhiredis)
1435   if test x_$withval = x_ -o x_$withval = x_yes; then
1436            withval="/usr/local /opt/local /usr/lib /usr/pkg /usr/sfw /usr"
1437   fi
1438   for dir in $withval ; do
1439            if test -f "$dir/include/hiredis/hiredis.h"; then
1440		found_libhiredis="yes"
1441		dnl assume /usr is in default path.
1442		if test "$dir" != "/usr"; then
1443                    CPPFLAGS="$CPPFLAGS -I$dir/include"
1444		    LDFLAGS="$LDFLAGS -L$dir/lib"
1445		fi
1446		AC_MSG_RESULT(found in $dir)
1447		AC_DEFINE([USE_REDIS], [1], [Define this to use hiredis client.])
1448		LIBS="$LIBS -lhiredis"
1449                break;
1450            fi
1451    done
1452    if test x_$found_libhiredis != x_yes; then
1453	AC_MSG_ERROR([Could not find libhiredis, hiredis.h])
1454    fi
1455    AC_CHECK_HEADERS([hiredis/hiredis.h],,, [AC_INCLUDES_DEFAULT])
1456    AC_CHECK_DECLS([redisConnect], [], [], [AC_INCLUDES_DEFAULT
1457    #include <hiredis/hiredis.h>
1458    ])
1459fi
1460
1461# nghttp2
1462AC_ARG_WITH(libnghttp2, AS_HELP_STRING([--with-libnghttp2=path],[specify explicit path for libnghttp2.]),
1463    [ ],[ withval="no" ])
1464found_libnghttp2="no"
1465if test x_$withval = x_yes -o x_$withval != x_no; then
1466   AC_MSG_CHECKING(for libnghttp2)
1467   if test x_$withval = x_ -o x_$withval = x_yes; then
1468            withval="/usr/local /opt/local /usr/lib /usr/pkg /usr/sfw /usr"
1469   fi
1470   for dir in $withval ; do
1471            if test -f "$dir/include/nghttp2/nghttp2.h"; then
1472		found_libnghttp2="yes"
1473		dnl assume /usr is in default path.
1474		if test "$dir" != "/usr"; then
1475                    CPPFLAGS="$CPPFLAGS -I$dir/include"
1476		    LDFLAGS="$LDFLAGS -L$dir/lib"
1477		fi
1478		AC_MSG_RESULT(found in $dir)
1479		AC_DEFINE([HAVE_NGHTTP2], [1], [Define this to use nghttp2 client.])
1480		LIBS="$LIBS -lnghttp2"
1481                break;
1482            fi
1483    done
1484    if test x_$found_libnghttp2 != x_yes; then
1485	AC_MSG_ERROR([Could not find libnghttp2, nghttp2.h])
1486    fi
1487    AC_CHECK_HEADERS([nghttp2/nghttp2.h],,, [AC_INCLUDES_DEFAULT])
1488    AC_CHECK_DECLS([nghttp2_session_server_new], [], [], [AC_INCLUDES_DEFAULT
1489    #include <nghttp2/nghttp2.h>
1490    ])
1491fi
1492
1493# set static linking for uninstalled libraries if requested
1494AC_SUBST(staticexe)
1495staticexe=""
1496AC_ARG_ENABLE(static-exe, AS_HELP_STRING([--enable-static-exe],[ enable to compile executables statically against (event) uninstalled libs, for debug purposes ]),
1497	, )
1498if test x_$enable_static_exe = x_yes; then
1499	staticexe="-static"
1500	if test "$on_mingw" = yes; then
1501		staticexe="-all-static"
1502		# for static compile, include gdi32 and zlib here.
1503		if echo $LIBS | grep 'lgdi32' >/dev/null; then
1504			:
1505		else
1506			LIBS="$LIBS -lgdi32"
1507		fi
1508		AC_CHECK_LIB([z], [compress], [ LIBS="$LIBS -lz" ])
1509		LIBS="$LIBS -l:libssp.a"
1510	fi
1511fi
1512
1513# set full static linking if requested
1514AC_ARG_ENABLE(fully-static, AS_HELP_STRING([--enable-fully-static],[ enable to compile fully static ]),
1515	, )
1516if test x_$enable_fully_static = x_yes; then
1517	staticexe="-all-static"
1518	if test "$on_mingw" = yes; then
1519		# for static compile, include gdi32 and zlib here.
1520		if echo $LIBS | grep 'lgdi32' >/dev/null; then
1521			:
1522		else
1523			LIBS="$LIBS -lgdi32"
1524		fi
1525		AC_CHECK_LIB([z], [compress], [ LIBS="$LIBS -lz" ])
1526		LIBS="$LIBS -l:libssp.a"
1527	fi
1528fi
1529
1530# set lock checking if requested
1531AC_ARG_ENABLE(lock_checks, AS_HELP_STRING([--enable-lock-checks],[ enable to check lock and unlock calls, for debug purposes ]),
1532	, )
1533if test x_$enable_lock_checks = x_yes; then
1534	AC_DEFINE(ENABLE_LOCK_CHECKS, 1, [Define if you want to use debug lock checking (slow).])
1535	CHECKLOCK_OBJ="checklocks.lo"
1536	AC_SUBST(CHECKLOCK_OBJ)
1537fi
1538
1539ACX_CHECK_GETADDRINFO_WITH_INCLUDES
1540if test "$USE_WINSOCK" = 1; then
1541	AC_DEFINE(UB_ON_WINDOWS, 1, [Use win32 resources and API])
1542	AC_CHECK_HEADERS([iphlpapi.h],,, [AC_INCLUDES_DEFAULT
1543#include <windows.h>
1544	])
1545	AC_CHECK_TOOL(WINDRES, windres)
1546	LIBS="$LIBS -liphlpapi -lcrypt32"
1547	WINAPPS="unbound-service-install.exe unbound-service-remove.exe anchor-update.exe"
1548	AC_SUBST(WINAPPS)
1549	WIN_DAEMON_SRC="winrc/win_svc.c winrc/w_inst.c"
1550	AC_SUBST(WIN_DAEMON_SRC)
1551	WIN_DAEMON_OBJ="win_svc.lo w_inst.lo"
1552	AC_SUBST(WIN_DAEMON_OBJ)
1553	WIN_DAEMON_OBJ_LINK="rsrc_unbound.o"
1554	AC_SUBST(WIN_DAEMON_OBJ_LINK)
1555	WIN_HOST_OBJ_LINK="rsrc_unbound_host.o"
1556	AC_SUBST(WIN_HOST_OBJ_LINK)
1557	WIN_UBANCHOR_OBJ_LINK="rsrc_unbound_anchor.o log.lo locks.lo"
1558	AC_SUBST(WIN_UBANCHOR_OBJ_LINK)
1559	WIN_CONTROL_OBJ_LINK="rsrc_unbound_control.o"
1560	AC_SUBST(WIN_CONTROL_OBJ_LINK)
1561	WIN_CHECKCONF_OBJ_LINK="rsrc_unbound_checkconf.o"
1562	AC_SUBST(WIN_CHECKCONF_OBJ_LINK)
1563	AC_DEFINE(__USE_MINGW_ANSI_STDIO, 1, [defined to use gcc ansi snprintf and sscanf that understands %lld when compiled for windows.])
1564fi
1565if test $ac_cv_func_getaddrinfo = no; then
1566	AC_LIBOBJ([fake-rfc2553])
1567fi
1568# check after getaddrinfo for its libraries
1569ACX_FUNC_IOCTLSOCKET
1570
1571# see if daemon(3) exists, and if it is deprecated.
1572AC_CHECK_FUNCS([daemon])
1573if test $ac_cv_func_daemon = yes; then
1574	ACX_FUNC_DEPRECATED([daemon], [(void)daemon(0, 0);], [
1575#include <stdlib.h>
1576#include <unistd.h>
1577])
1578fi
1579
1580AC_CHECK_MEMBERS([struct sockaddr_un.sun_len],,,[
1581AC_INCLUDES_DEFAULT
1582#ifdef HAVE_SYS_UN_H
1583#include <sys/un.h>
1584#endif
1585])
1586AC_CHECK_MEMBERS([struct in_pktinfo.ipi_spec_dst],,,[
1587AC_INCLUDES_DEFAULT
1588#if HAVE_SYS_PARAM_H
1589#include <sys/param.h>
1590#endif
1591
1592#ifdef HAVE_SYS_SOCKET_H
1593#include <sys/socket.h>
1594#endif
1595
1596#ifdef HAVE_SYS_UIO_H
1597#include <sys/uio.h>
1598#endif
1599
1600#ifdef HAVE_NETINET_IN_H
1601#include <netinet/in.h>
1602#endif
1603
1604#ifdef HAVE_NETINET_TCP_H
1605#include <netinet/tcp.h>
1606#endif
1607
1608#ifdef HAVE_ARPA_INET_H
1609#include <arpa/inet.h>
1610#endif
1611
1612#ifdef HAVE_WINSOCK2_H
1613#include <winsock2.h>
1614#endif
1615
1616#ifdef HAVE_WS2TCPIP_H
1617#include <ws2tcpip.h>
1618#endif
1619])
1620
1621AC_MSG_CHECKING([for htobe64])
1622AC_LINK_IFELSE([AC_LANG_PROGRAM([
1623#include <stdio.h>
1624#ifdef HAVE_ENDIAN_H
1625#  include <endian.h>
1626#endif
1627#ifdef HAVE_SYS_ENDIAN_H
1628#  include <sys/endian.h>
1629#endif
1630], [unsigned long long x = htobe64(0); printf("%u", (unsigned)x);])],
1631  AC_MSG_RESULT(yes)
1632  AC_DEFINE(HAVE_HTOBE64, 1, [If we have htobe64]),
1633  AC_MSG_RESULT(no))
1634
1635AC_MSG_CHECKING([for be64toh])
1636AC_LINK_IFELSE([AC_LANG_PROGRAM([
1637#include <stdio.h>
1638#ifdef HAVE_ENDIAN_H
1639#  include <endian.h>
1640#endif
1641#ifdef HAVE_SYS_ENDIAN_H
1642#  include <sys/endian.h>
1643#endif
1644], [unsigned long long x = be64toh(0); printf("%u", (unsigned)x);])],
1645  AC_MSG_RESULT(yes)
1646  AC_DEFINE(HAVE_BE64TOH, 1, [If we have be64toh]),
1647  AC_MSG_RESULT(no))
1648
1649AC_SEARCH_LIBS([setusercontext], [util])
1650AC_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 accept4 getifaddrs if_nametoindex poll gettid])
1651AC_CHECK_FUNCS([setresuid],,[AC_CHECK_FUNCS([setreuid])])
1652AC_CHECK_FUNCS([setresgid],,[AC_CHECK_FUNCS([setregid])])
1653
1654# check if setreuid en setregid fail, on MacOSX10.4(darwin8).
1655if echo $host_os | grep darwin8 > /dev/null; then
1656	AC_DEFINE(DARWIN_BROKEN_SETREUID, 1, [Define this if on macOSX10.4-darwin8 and setreuid and setregid do not work])
1657fi
1658AC_CHECK_DECLS([inet_pton,inet_ntop], [], [], [
1659AC_INCLUDES_DEFAULT
1660#ifdef HAVE_NETINET_IN_H
1661#include <netinet/in.h>
1662#endif
1663
1664#ifdef HAVE_NETINET_TCP_H
1665#include <netinet/tcp.h>
1666#endif
1667
1668#ifdef HAVE_ARPA_INET_H
1669#include <arpa/inet.h>
1670#endif
1671
1672#ifdef HAVE_WINSOCK2_H
1673#include <winsock2.h>
1674#endif
1675
1676#ifdef HAVE_WS2TCPIP_H
1677#include <ws2tcpip.h>
1678#endif
1679])
1680AC_REPLACE_FUNCS(inet_aton)
1681AC_REPLACE_FUNCS(inet_pton)
1682AC_REPLACE_FUNCS(inet_ntop)
1683AC_REPLACE_FUNCS(snprintf)
1684# test if snprintf return the proper length
1685if test "x$ac_cv_func_snprintf" = xyes; then
1686    if test c${cross_compiling} = cno; then
1687	AC_MSG_CHECKING([for correct snprintf return value])
1688	AC_RUN_IFELSE([AC_LANG_SOURCE(AC_INCLUDES_DEFAULT
1689[[
1690int main(void) { return !(snprintf(NULL, 0, "test") == 4); }
1691]])], [AC_MSG_RESULT(yes)], [
1692		AC_MSG_RESULT(no)
1693		AC_DEFINE([SNPRINTF_RET_BROKEN], [], [define if (v)snprintf does not return length needed, (but length used)])
1694		AC_LIBOBJ(snprintf)
1695	  ])
1696    fi
1697fi
1698AC_REPLACE_FUNCS(strlcat)
1699AC_REPLACE_FUNCS(strlcpy)
1700AC_REPLACE_FUNCS(memmove)
1701AC_REPLACE_FUNCS(gmtime_r)
1702AC_REPLACE_FUNCS(isblank)
1703AC_REPLACE_FUNCS(explicit_bzero)
1704dnl without CTIME, ARC4-functions and without reallocarray.
1705LIBOBJ_WITHOUT_CTIMEARC4="$LIBOBJS"
1706AC_SUBST(LIBOBJ_WITHOUT_CTIMEARC4)
1707AC_MSG_CHECKING([for reallocarray])
1708AC_LINK_IFELSE([AC_LANG_SOURCE(AC_INCLUDES_DEFAULT
1709[[
1710#ifndef _OPENBSD_SOURCE
1711#define _OPENBSD_SOURCE 1
1712#endif
1713#include <stdlib.h>
1714int main(void) {
1715	void* p = reallocarray(NULL, 10, 100);
1716	free(p);
1717	return 0;
1718}
1719]])], [AC_MSG_RESULT(yes)
1720	AC_DEFINE(HAVE_REALLOCARRAY, 1, [If we have reallocarray(3)])
1721], [
1722	AC_MSG_RESULT(no)
1723	AC_LIBOBJ(reallocarray)
1724])
1725AC_CHECK_DECLS([reallocarray])
1726if test "$USE_NSS" = "no"; then
1727	AC_REPLACE_FUNCS(arc4random)
1728	AC_REPLACE_FUNCS(arc4random_uniform)
1729	if test "$ac_cv_func_arc4random" = "no"; then
1730		AC_LIBOBJ(arc4_lock)
1731		AC_CHECK_FUNCS([getentropy],,[
1732		    if test "$USE_WINSOCK" = 1; then
1733			AC_LIBOBJ(getentropy_win)
1734		    else
1735			case "$host" in
1736			Darwin|*darwin*)
1737				AC_LIBOBJ(getentropy_osx)
1738			;;
1739			*solaris*|*sunos*|SunOS)
1740				AC_LIBOBJ(getentropy_solaris)
1741				AC_CHECK_HEADERS([sys/sha2.h],, [
1742					AC_CHECK_FUNCS([SHA512_Update],,[
1743						AC_LIBOBJ(sha512)
1744					])
1745				], [AC_INCLUDES_DEFAULT])
1746				if test "$ac_cv_header_sys_sha2_h" = "yes"; then
1747					# this lib needed for sha2 on solaris
1748					LIBS="$LIBS -lmd"
1749				fi
1750				AC_SEARCH_LIBS([clock_gettime], [rt])
1751			;;
1752			*freebsd*|*FreeBSD)
1753				AC_LIBOBJ(getentropy_freebsd)
1754			;;
1755			*linux*|Linux|*)
1756				AC_LIBOBJ(getentropy_linux)
1757				AC_CHECK_FUNCS([SHA512_Update],,[
1758					AC_DEFINE([COMPAT_SHA512], [1], [Do sha512 definitions in config.h])
1759					AC_LIBOBJ(sha512)
1760				])
1761				AC_CHECK_HEADERS([sys/sysctl.h],,, [AC_INCLUDES_DEFAULT])
1762				AC_CHECK_FUNCS([getauxval])
1763				AC_SEARCH_LIBS([clock_gettime], [rt])
1764			;;
1765			esac
1766		    fi
1767		])
1768	fi
1769fi
1770LIBOBJ_WITHOUT_CTIME="$LIBOBJS"
1771AC_SUBST(LIBOBJ_WITHOUT_CTIME)
1772AC_REPLACE_FUNCS(ctime_r)
1773AC_REPLACE_FUNCS(strsep)
1774
1775AC_ARG_ENABLE(allsymbols, AS_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]))
1776case "$enable_allsymbols" in
1777	yes)
1778	COMMON_OBJ_ALL_SYMBOLS=""
1779	UBSYMS=""
1780	EXTRALINK="libunbound.la"
1781	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])
1782	;;
1783	no|*)
1784	COMMON_OBJ_ALL_SYMBOLS='$(COMMON_OBJ)'
1785	UBSYMS='-export-symbols $(srcdir)/libunbound/ubsyms.def'
1786	EXTRALINK=""
1787	;;
1788esac
1789AC_SUBST(COMMON_OBJ_ALL_SYMBOLS)
1790AC_SUBST(EXTRALINK)
1791AC_SUBST(UBSYMS)
1792if test x_$enable_lock_checks = x_yes; then
1793	UBSYMS="-export-symbols clubsyms.def"
1794	cp ${srcdir}/libunbound/ubsyms.def clubsyms.def
1795	echo lock_protect >> clubsyms.def
1796	echo lock_unprotect >> clubsyms.def
1797	echo lock_get_mem >> clubsyms.def
1798	echo checklock_start >> clubsyms.def
1799	echo checklock_stop >> clubsyms.def
1800	echo checklock_lock >> clubsyms.def
1801	echo checklock_unlock >> clubsyms.def
1802	echo checklock_init >> clubsyms.def
1803	echo checklock_thrcreate >> clubsyms.def
1804	echo checklock_thrjoin >> clubsyms.def
1805fi
1806
1807# check for dnstap if requested
1808dt_DNSTAP([$UNBOUND_RUN_DIR/dnstap.sock],
1809    [
1810        AC_DEFINE([USE_DNSTAP], [1], [Define to 1 to enable dnstap support])
1811        AC_SUBST([ENABLE_DNSTAP], [1])
1812
1813        AC_SUBST([opt_dnstap_socket_path])
1814        ACX_ESCAPE_BACKSLASH($opt_dnstap_socket_path, hdr_dnstap_socket_path)
1815        AC_DEFINE_UNQUOTED(DNSTAP_SOCKET_PATH,
1816            ["$hdr_dnstap_socket_path"], [default dnstap socket path])
1817	AC_SUBST(DNSTAP_SOCKET_PATH,["$hdr_dnstap_socket_path"])
1818	AC_SUBST(DNSTAP_SOCKET_TESTBIN,['unbound-dnstap-socket$(EXEEXT)'])
1819        AC_SUBST([DNSTAP_SRC], ["dnstap/dnstap.c dnstap/dnstap.pb-c.c dnstap/dnstap_fstrm.c dnstap/dtstream.c"])
1820        AC_SUBST([DNSTAP_OBJ], ["dnstap.lo dnstap.pb-c.lo dnstap_fstrm.lo dtstream.lo"])
1821    ],
1822    [
1823        AC_SUBST([ENABLE_DNSTAP], [0])
1824    ]
1825)
1826
1827# check for dnscrypt if requested
1828dnsc_DNSCRYPT([
1829        AC_DEFINE([USE_DNSCRYPT], [1], [Define to 1 to enable dnscrypt support])
1830        AC_SUBST([ENABLE_DNSCRYPT], [1])
1831
1832        AC_SUBST([DNSCRYPT_SRC], ["dnscrypt/dnscrypt.c"])
1833        AC_SUBST([DNSCRYPT_OBJ], ["dnscrypt.lo"])
1834    ],
1835    [
1836        AC_SUBST([ENABLE_DNSCRYPT], [0])
1837    ]
1838)
1839
1840# check for cachedb if requested
1841AC_ARG_ENABLE(cachedb, AS_HELP_STRING([--enable-cachedb],[enable cachedb module that can use external cache storage]))
1842# turn on cachedb when hiredis support is enabled.
1843if test "$found_libhiredis" = "yes"; then enable_cachedb="yes"; fi
1844case "$enable_cachedb" in
1845    yes)
1846    	AC_DEFINE([USE_CACHEDB], [1], [Define to 1 to use cachedb support])
1847	AC_SUBST([CACHEDB_SRC], ["cachedb/cachedb.c cachedb/redis.c"])
1848	AC_SUBST([CACHEDB_OBJ], ["cachedb.lo redis.lo"])
1849    	;;
1850    no|*)
1851    	# nothing
1852    	;;
1853esac
1854
1855# check for ipsecmod if requested
1856AC_ARG_ENABLE(ipsecmod, AS_HELP_STRING([--enable-ipsecmod],[Enable ipsecmod module that facilitates opportunistic IPsec]))
1857case "$enable_ipsecmod" in
1858	yes)
1859		AC_DEFINE([USE_IPSECMOD], [1], [Define to 1 to use ipsecmod support.])
1860		IPSECMOD_OBJ="ipsecmod.lo ipsecmod-whitelist.lo"
1861		AC_SUBST(IPSECMOD_OBJ)
1862		IPSECMOD_HEADER='$(srcdir)/ipsecmod/ipsecmod.h $(srcdir)/ipsecmod/ipsecmod-whitelist.h'
1863		AC_SUBST(IPSECMOD_HEADER)
1864		;;
1865	no|*)
1866		# nothing
1867		;;
1868esac
1869
1870# check for ipset if requested
1871AC_ARG_ENABLE(ipset, AS_HELP_STRING([--enable-ipset],[enable ipset module]))
1872case "$enable_ipset" in
1873    yes)
1874		AC_DEFINE([USE_IPSET], [1], [Define to 1 to use ipset support])
1875		IPSET_SRC="ipset/ipset.c"
1876		AC_SUBST(IPSET_SRC)
1877		IPSET_OBJ="ipset.lo"
1878		AC_SUBST(IPSET_OBJ)
1879
1880		# mnl
1881		AC_ARG_WITH(libmnl, AS_HELP_STRING([--with-libmnl=path],[specify explicit path for libmnl.]),
1882			[ ],[ withval="yes" ])
1883		found_libmnl="no"
1884		AC_MSG_CHECKING(for libmnl)
1885		if test x_$withval = x_ -o x_$withval = x_yes; then
1886			withval="/usr/local /opt/local /usr/lib /usr/pkg /usr/sfw /usr"
1887		fi
1888		for dir in $withval ; do
1889			if test -f "$dir/include/libmnl/libmnl.h" -o -f "$dir/include/libmnl/libmnl/libmnl.h"; then
1890				found_libmnl="yes"
1891				dnl assume /usr is in default path.
1892				extralibmnl=""
1893				if test -f "$dir/include/libmnl/libmnl/libmnl.h"; then
1894					extralibmnl="/libmnl"
1895				fi
1896				if test "$dir" != "/usr" -o -n "$extralibmnl"; then
1897					CPPFLAGS="$CPPFLAGS -I$dir/include$extralibmnl"
1898				fi
1899				if test "$dir" != "/usr"; then
1900					LDFLAGS="$LDFLAGS -L$dir/lib"
1901				fi
1902				AC_MSG_RESULT(found in $dir)
1903				LIBS="$LIBS -lmnl"
1904				break;
1905			fi
1906		done
1907		if test x_$found_libmnl != x_yes; then
1908			AC_MSG_ERROR([Could not find libmnl, libmnl.h])
1909		fi
1910		;;
1911    no|*)
1912    	# nothing
1913		;;
1914esac
1915AC_ARG_ENABLE(explicit-port-randomisation, AS_HELP_STRING([--disable-explicit-port-randomisation],[disable explicit source port randomisation and rely on the kernel to provide random source ports]))
1916case "$enable_explicit_port_randomisation" in
1917	no)
1918		AC_DEFINE([DISABLE_EXPLICIT_PORT_RANDOMISATION], [1], [Define this to enable kernel based UDP source port randomization.])
1919		;;
1920	yes|*)
1921		;;
1922esac
1923
1924if echo "$host" | $GREP -i -e linux >/dev/null; then
1925	AC_ARG_ENABLE(linux-ip-local-port-range, AC_HELP_STRING([--enable-linux-ip-local-port-range], [Define this to enable use of /proc/sys/net/ipv4/ip_local_port_range as a default outgoing port range. This is only for the libunbound on Linux and does not affect unbound resolving daemon itself. This may severely limit the number of available outgoing ports and thus decrease randomness. Define this only when the target system restricts (e.g. some of SELinux enabled distributions) the use of non-ephemeral ports.]))
1926	case "$enable_linux_ip_local_port_range" in
1927		yes)
1928			AC_DEFINE([USE_LINUX_IP_LOCAL_PORT_RANGE], [1], [Define this to enable use of /proc/sys/net/ipv4/ip_local_port_range as a default outgoing port range. This is only for the libunbound on Linux and does not affect unbound resolving daemon itself. This may severely limit the number of available outgoing ports and thus decrease randomness. Define this only when the target system restricts (e.g. some of SELinux enabled distributions) the use of non-ephemeral ports.])
1929			;;
1930		no|*)
1931			;;
1932	esac
1933fi
1934
1935
1936AC_MSG_CHECKING([if ${MAKE:-make} supports $< with implicit rule in scope])
1937# on openBSD, the implicit rule make $< work.
1938# on Solaris, it does not work ($? is changed sources, $^ lists dependencies).
1939# gmake works.
1940cat >conftest.make <<EOF
1941all:	conftest.lo
1942
1943conftest.lo foo.lo bla.lo:
1944	if test -f "\$<"; then touch \$@; fi
1945
1946.SUFFIXES: .lo
1947.c.lo:
1948	if test -f "\$<"; then touch \$@; fi
1949
1950conftest.lo:        conftest.dir/conftest.c
1951EOF
1952mkdir conftest.dir
1953touch conftest.dir/conftest.c
1954rm -f conftest.lo conftest.c
1955${MAKE:-make} -f conftest.make >/dev/null
1956rm -f conftest.make conftest.c conftest.dir/conftest.c
1957rm -rf conftest.dir
1958if test ! -f conftest.lo; then
1959	AC_MSG_RESULT(no)
1960	SOURCEDETERMINE='echo "$^" | awk "-F " "{print \$$1;}" > .source'
1961	SOURCEFILE='`cat .source`'
1962else
1963	AC_MSG_RESULT(yes)
1964	SOURCEDETERMINE=':'
1965	SOURCEFILE='$<'
1966fi
1967rm -f conftest.lo
1968AC_SUBST(SOURCEDETERMINE)
1969AC_SUBST(SOURCEFILE)
1970
1971# see if we want to build the library or everything
1972ALLTARGET="alltargets"
1973INSTALLTARGET="install-all"
1974AC_ARG_WITH(libunbound-only, AS_HELP_STRING([--with-libunbound-only],[do not build daemon and tool programs]),
1975	[
1976	if test "$withval" = "yes"; then
1977		ALLTARGET="lib"
1978		INSTALLTARGET="install-lib"
1979	fi
1980])
1981if test $ALLTARGET = "alltargets"; then
1982	if test $USE_NSS = "yes"; then
1983		AC_MSG_ERROR([--with-nss can only be used in combination with --with-libunbound-only.])
1984	fi
1985	if test $USE_NETTLE = "yes"; then
1986		AC_MSG_ERROR([--with-nettle can only be used in combination with --with-libunbound-only.])
1987	fi
1988fi
1989
1990AC_SUBST(ALLTARGET)
1991AC_SUBST(INSTALLTARGET)
1992
1993ACX_STRIP_EXT_FLAGS
1994if test -n "$LATE_LDFLAGS"; then
1995  LDFLAGS="$LATE_LDFLAGS $LDFLAGS"
1996fi
1997# remove start spaces
1998LDFLAGS=`echo "$LDFLAGS"|sed -e 's/^ *//'`
1999LIBS=`echo "$LIBS"|sed -e 's/^ *//'`
2000
2001AC_DEFINE_UNQUOTED([MAXSYSLOGMSGLEN], [10240], [Define to the maximum message length to pass to syslog.])
2002
2003AH_BOTTOM(
2004dnl this must be first AH_CONFIG, to define the flags before any includes.
2005AHX_CONFIG_EXT_FLAGS
2006
2007dnl includes
2008[
2009#ifndef _OPENBSD_SOURCE
2010#define _OPENBSD_SOURCE 1
2011#endif
2012
2013#ifndef UNBOUND_DEBUG
2014# ifndef NDEBUG
2015#  define NDEBUG
2016# endif
2017#endif
2018
2019/** Use small-ldns codebase */
2020#define USE_SLDNS 1
2021#ifdef HAVE_SSL
2022#  define LDNS_BUILD_CONFIG_HAVE_SSL 1
2023#endif
2024
2025#include <stdio.h>
2026#include <string.h>
2027#include <unistd.h>
2028#include <assert.h>
2029
2030#if STDC_HEADERS
2031#include <stdlib.h>
2032#include <stddef.h>
2033#endif
2034
2035#ifdef HAVE_STDARG_H
2036#include <stdarg.h>
2037#endif
2038
2039#ifdef HAVE_STDINT_H
2040#include <stdint.h>
2041#endif
2042
2043#include <errno.h>
2044
2045#if HAVE_SYS_PARAM_H
2046#include <sys/param.h>
2047#endif
2048
2049#ifdef HAVE_SYS_SOCKET_H
2050#include <sys/socket.h>
2051#endif
2052
2053#ifdef HAVE_SYS_UIO_H
2054#include <sys/uio.h>
2055#endif
2056
2057#ifdef HAVE_NETINET_IN_H
2058#include <netinet/in.h>
2059#endif
2060
2061#ifdef HAVE_NETINET_TCP_H
2062#include <netinet/tcp.h>
2063#endif
2064
2065#ifdef HAVE_ARPA_INET_H
2066#include <arpa/inet.h>
2067#endif
2068
2069#ifdef HAVE_WINSOCK2_H
2070#include <winsock2.h>
2071#endif
2072
2073#ifdef HAVE_WS2TCPIP_H
2074#include <ws2tcpip.h>
2075#endif
2076
2077#if !defined(USE_WINSOCK) || !defined(HAVE_SNPRINTF) || defined(SNPRINTF_RET_BROKEN) || defined(__USE_MINGW_ANSI_STDIO)
2078#define ARG_LL "%ll"
2079#else
2080#define ARG_LL "%I64"
2081#endif
2082
2083#ifndef AF_LOCAL
2084#define AF_LOCAL AF_UNIX
2085#endif
2086]
2087
2088AHX_CONFIG_FORMAT_ATTRIBUTE
2089AHX_CONFIG_UNUSED_ATTRIBUTE
2090AHX_CONFIG_FSEEKO
2091AHX_CONFIG_MAXHOSTNAMELEN
2092#if !defined(HAVE_SNPRINTF) || defined(SNPRINTF_RET_BROKEN)
2093#define snprintf snprintf_unbound
2094#define vsnprintf vsnprintf_unbound
2095#include <stdarg.h>
2096int snprintf (char *str, size_t count, const char *fmt, ...);
2097int vsnprintf (char *str, size_t count, const char *fmt, va_list arg);
2098#endif /* HAVE_SNPRINTF or SNPRINTF_RET_BROKEN */
2099AHX_CONFIG_INET_PTON(unbound)
2100AHX_CONFIG_INET_NTOP(unbound)
2101AHX_CONFIG_INET_ATON(unbound)
2102AHX_CONFIG_MEMMOVE(unbound)
2103AHX_CONFIG_STRLCAT(unbound)
2104AHX_CONFIG_STRLCPY(unbound)
2105AHX_CONFIG_GMTIME_R(unbound)
2106AHX_CONFIG_REALLOCARRAY(unbound)
2107AHX_CONFIG_W32_SLEEP
2108AHX_CONFIG_W32_USLEEP
2109AHX_CONFIG_W32_RANDOM
2110AHX_CONFIG_W32_SRANDOM
2111AHX_CONFIG_W32_FD_SET_T
2112AHX_CONFIG_IPV6_MIN_MTU
2113AHX_MEMCMP_BROKEN(unbound)
2114
2115[
2116#ifndef HAVE_CTIME_R
2117#define ctime_r unbound_ctime_r
2118char *ctime_r(const time_t *timep, char *buf);
2119#endif
2120
2121#ifndef HAVE_STRSEP
2122#define strsep unbound_strsep
2123char *strsep(char **stringp, const char *delim);
2124#endif
2125
2126#ifndef HAVE_ISBLANK
2127#define isblank unbound_isblank
2128int isblank(int c);
2129#endif
2130
2131#ifndef HAVE_EXPLICIT_BZERO
2132#define explicit_bzero unbound_explicit_bzero
2133void explicit_bzero(void* buf, size_t len);
2134#endif
2135
2136#if defined(HAVE_INET_NTOP) && !HAVE_DECL_INET_NTOP
2137const char *inet_ntop(int af, const void *src, char *dst, size_t size);
2138#endif
2139
2140#if defined(HAVE_INET_PTON) && !HAVE_DECL_INET_PTON
2141int inet_pton(int af, const char* src, void* dst);
2142#endif
2143
2144#if !defined(HAVE_STRPTIME) || !defined(STRPTIME_WORKS)
2145#define strptime unbound_strptime
2146struct tm;
2147char *strptime(const char *s, const char *format, struct tm *tm);
2148#endif
2149
2150#if !HAVE_DECL_REALLOCARRAY
2151void *reallocarray(void *ptr, size_t nmemb, size_t size);
2152#endif
2153
2154#ifdef HAVE_LIBBSD
2155#include <bsd/string.h>
2156#include <bsd/stdlib.h>
2157#endif
2158
2159#ifdef HAVE_LIBRESSL
2160#  if !HAVE_DECL_STRLCPY
2161size_t strlcpy(char *dst, const char *src, size_t siz);
2162#  endif
2163#  if !HAVE_DECL_STRLCAT
2164size_t strlcat(char *dst, const char *src, size_t siz);
2165#  endif
2166#  if !HAVE_DECL_ARC4RANDOM && defined(HAVE_ARC4RANDOM)
2167uint32_t arc4random(void);
2168#  endif
2169#  if !HAVE_DECL_ARC4RANDOM_UNIFORM && defined(HAVE_ARC4RANDOM_UNIFORM)
2170uint32_t arc4random_uniform(uint32_t upper_bound);
2171#  endif
2172#endif /* HAVE_LIBRESSL */
2173#ifndef HAVE_ARC4RANDOM
2174int getentropy(void* buf, size_t len);
2175uint32_t arc4random(void);
2176void arc4random_buf(void* buf, size_t n);
2177void _ARC4_LOCK(void);
2178void _ARC4_UNLOCK(void);
2179void _ARC4_LOCK_DESTROY(void);
2180#endif
2181#ifndef HAVE_ARC4RANDOM_UNIFORM
2182uint32_t arc4random_uniform(uint32_t upper_bound);
2183#endif
2184#ifdef COMPAT_SHA512
2185#ifndef SHA512_DIGEST_LENGTH
2186#define SHA512_BLOCK_LENGTH		128
2187#define SHA512_DIGEST_LENGTH		64
2188#define SHA512_DIGEST_STRING_LENGTH	(SHA512_DIGEST_LENGTH * 2 + 1)
2189typedef struct _SHA512_CTX {
2190	uint64_t	state[8];
2191	uint64_t	bitcount[2];
2192	uint8_t	buffer[SHA512_BLOCK_LENGTH];
2193} SHA512_CTX;
2194#endif /* SHA512_DIGEST_LENGTH */
2195void SHA512_Init(SHA512_CTX*);
2196void SHA512_Update(SHA512_CTX*, void*, size_t);
2197void SHA512_Final(uint8_t[SHA512_DIGEST_LENGTH], SHA512_CTX*);
2198unsigned char *SHA512(void* data, unsigned int data_len, unsigned char *digest);
2199#endif /* COMPAT_SHA512 */
2200
2201
2202
2203#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))
2204   /* using version of libevent that is not threadsafe. */
2205#  define LIBEVENT_SIGNAL_PROBLEM 1
2206#endif
2207
2208#ifndef CHECKED_INET6
2209#  define CHECKED_INET6
2210#  ifdef AF_INET6
2211#    define INET6
2212#  else
2213#    define AF_INET6        28
2214#  endif
2215#endif /* CHECKED_INET6 */
2216
2217#ifndef HAVE_GETADDRINFO
2218struct sockaddr_storage;
2219#include "compat/fake-rfc2553.h"
2220#endif
2221
2222#ifdef UNBOUND_ALLOC_STATS
2223#  define malloc(s) unbound_stat_malloc_log(s, __FILE__, __LINE__, __func__)
2224#  define calloc(n,s) unbound_stat_calloc_log(n, s, __FILE__, __LINE__, __func__)
2225#  define free(p) unbound_stat_free_log(p, __FILE__, __LINE__, __func__)
2226#  define realloc(p,s) unbound_stat_realloc_log(p, s, __FILE__, __LINE__, __func__)
2227void *unbound_stat_malloc(size_t size);
2228void *unbound_stat_calloc(size_t nmemb, size_t size);
2229void unbound_stat_free(void *ptr);
2230void *unbound_stat_realloc(void *ptr, size_t size);
2231void *unbound_stat_malloc_log(size_t size, const char* file, int line,
2232	const char* func);
2233void *unbound_stat_calloc_log(size_t nmemb, size_t size, const char* file,
2234	int line, const char* func);
2235void unbound_stat_free_log(void *ptr, const char* file, int line,
2236	const char* func);
2237void *unbound_stat_realloc_log(void *ptr, size_t size, const char* file,
2238	int line, const char* func);
2239#elif defined(UNBOUND_ALLOC_LITE)
2240#  include "util/alloc.h"
2241#endif /* UNBOUND_ALLOC_LITE and UNBOUND_ALLOC_STATS */
2242
2243/** default port for DNS traffic. */
2244#define UNBOUND_DNS_PORT 53
2245/** default port for DNS over TLS traffic. */
2246#define UNBOUND_DNS_OVER_TLS_PORT 853
2247/** default port for DNS over HTTPS traffic. */
2248#define UNBOUND_DNS_OVER_HTTPS_PORT 443
2249/** default port for unbound control traffic, registered port with IANA,
2250    ub-dns-control  8953/tcp    unbound dns nameserver control */
2251#define UNBOUND_CONTROL_PORT 8953
2252/** the version of unbound-control that this software implements */
2253#define UNBOUND_CONTROL_VERSION 1
2254
2255])
2256
2257dnl if we build from source tree, the man pages need @date@ and @version@
2258dnl if this is a distro tarball, that was already done by makedist.sh
2259AC_SUBST(version, [VERSION_MAJOR.VERSION_MINOR.VERSION_MICRO])
2260AC_SUBST(date, [`date +'%b %e, %Y'`])
2261
2262AC_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 contrib/unbound_portable.service])
2263AC_CONFIG_HEADERS([config.h])
2264AC_OUTPUT
2265