1#                                               -*- Autoconf -*-
2# Process this file with autoconf to produce a configure script.
3# known to work with autconf version: autoconf (GNU Autoconf) 2.69
4#
5# @configure_input@
6#
7# Copyright (c) 2013, Verisign, Inc., NLnet Labs
8# All rights reserved.
9#
10# Redistribution and use in source and binary forms, with or without
11# modification, are permitted provided that the following conditions are met:
12# * Redistributions of source code must retain the above copyright
13# notice, this list of conditions and the following disclaimer.
14# * Redistributions in binary form must reproduce the above copyright
15#   notice, this list of conditions and the following disclaimer in the
16#   documentation and/or other materials provided with the distribution.
17# * Neither the names of the copyright holders nor the
18#   names of its contributors may be used to endorse or promote products
19#   derived from this software without specific prior written permission.
20#
21# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
22# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24# DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY
25# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
32AC_PREREQ([2.68])
33AC_CONFIG_MACRO_DIRS([m4])
34sinclude(./m4/acx_openssl.m4)
35sinclude(./m4/acx_getaddrinfo.m4)
36sinclude(./m4/ac_lib_nettle.m4)
37sinclude(./m4/ax_check_compile_flag.m4)
38sinclude(./m4/pkg.m4)
39
40AC_INIT([getdns], [1.5.2], [team@getdnsapi.net], [getdns], [https://getdnsapi.net])
41
42# Autoconf 2.70 will have set up runstatedir. 2.69 is frequently (Debian)
43# patched to do the same, but frequently (MacOS) not. So add a with option
44# for pid file location, and default it to runstatedir if present.
45default_piddir=${runstatedir:-"${localstatedir}/run"}
46AC_ARG_WITH([piddir],
47  [AS_HELP_STRING([--with-piddir=DIR],
48                  [directory for pid files @<:@default=RUNSTATEDIR or LOCALSTATEDIR/run@:>@])],
49  [],
50  [with_piddir=${default_piddir}])
51AC_SUBST([runstatedir], [$with_piddir])
52
53# Don't forget to put a dash in front of the release candidate!!!
54# That is how it is done with semantic versioning!
55#
56AC_SUBST(RELEASE_CANDIDATE, [])
57AC_SUBST(STUBBY_RELEASE_CANDIDATE, [])
58
59# Set current date from system if not set
60AC_ARG_WITH([current-date],
61  [AS_HELP_STRING([--with-current-date]
62    [current date of the compilation, set to fixed date for reproducible builds @<:@default=system@:>@])],
63  [CURRENT_DATE="$with_current_date"],
64  [CURRENT_DATE="`date -u +%Y-%m-%dT%H:%M:%SZ`"])
65
66AC_SUBST(GETDNS_VERSION, ["AC_PACKAGE_VERSION$RELEASE_CANDIDATE"])
67AC_SUBST(GETDNS_NUMERIC_VERSION, [0x01050200])
68AC_SUBST(API_VERSION, ["December 2015"])
69AC_SUBST(API_NUMERIC_VERSION, [0x07df0c00])
70GETDNS_COMPILATION_COMMENT="AC_PACKAGE_NAME $GETDNS_VERSION configured on $CURRENT_DATE for the $API_VERSION version of the API"
71
72AC_DEFINE_UNQUOTED([STUBBY_PACKAGE], ["stubby"], [Stubby package])
73AC_DEFINE_UNQUOTED([STUBBY_PACKAGE_STRING], ["0.2.6$STUBBY_RELEASE_CANDIDATE"], [Stubby package string])
74
75# Library version
76# ---------------
77# current:revision:age
78# (binary-api-number):(which-binary-api-version):(how-many-nrs-backwardscompat)
79# if source code changes increment revision
80# if any interfaces have been added/removed/changed since last update then
81#   increment current and set revision to 0
82# if any interfaces have been added since the last public release then increment age
83# if any interfaces have been removed or changed since the last public release then
84#   set age to 0
85#
86# getdns-0.1.4 had libversion 0:0:0
87# getdns-0.1.5 had libversion 1:0:0
88# getdns-0.1.6 had libversion 1:1:0
89# getdns-0.1.7 had libversion 1:2:1 (but should have had 2:0:1)
90# getdns-0.1.8 had libversion 1:3:0 (but should have had 2:1:1)
91# getdns-0.2.0 had libversion 2:2:1
92# getdns-0.3.0 had libversion 3:3:2
93# getdns-0.3.1 had libversion 3:4:2
94# getdns-0.3.2 had libversion 3:5:2
95# getdns-0.3.3 had libversion 3:6:2
96# getdns-0.5.0 had libversion 4:0:3
97# getdns-0.5.1 had libversion 4:1:3 (but should have been getdns-0.6.0)
98# getdns-0.9.0 had libversion 5:0:4
99# getdns-1.0.0 had libversion 5:1:4
100# getdns-1.1.0 had libversion 6:0:0
101# getdns-1.1.1 had libversion 6:1:0
102# getdns-1.1.2 had libversion 7:0:1
103# getdns-1.1.3 had libversion 7:1:1
104# getdns-1.2.0 had libversion 8:0:2
105# getdns-1.2.1 had libversion 8:1:2
106# getdns-1.3.0 had libversion 9:0:3
107# getdns-1.4.0 had libversion 10:0:0
108# getdns-1.4.1 had libversion 10:1:0
109# getdns-1.4.2 had libversion 10:2:0
110# getdns-1.5.0 had libversion 11:0:1
111# getdns-1.5.1 had libversion 11:1:1
112# getdns-1.5.2 has libversion 11:2:1
113GETDNS_LIBVERSION=11:2:1
114
115AC_SUBST(GETDNS_COMPILATION_COMMENT)
116AC_SUBST(GETDNS_LIBVERSION)
117AC_CONFIG_SRCDIR([src/getdns/getdns.h.in])
118# AM_INIT_AUTOMAKE
119# LT_INIT
120AC_CONFIG_MACRO_DIR([m4])
121
122AC_PROG_CC
123AC_PROG_CPP
124
125# Checks for programs.
126HOSTOS="unix"
127AC_CANONICAL_HOST
128case "${host_os}" in
129cygwin*|mingw*)
130	HOSTOS=windows
131	;;
132darwin*)
133	HOSTOS=macos
134	;;
135esac
136AC_SUBST(HOSTOS)
137
138
139CFLAGS="$CFLAGS"
140WPEDANTICFLAG=""
141WNOERRORFLAG=""
142AC_PROG_CC_C99
143AX_CHECK_COMPILE_FLAG([-xc99],[CFLAGS="$CFLAGS -xc99"],[],[])
144AX_CHECK_COMPILE_FLAG([-Wall],[CFLAGS="$CFLAGS -Wall"],[],[])
145AX_CHECK_COMPILE_FLAG([-Wextra],[CFLAGS="$CFLAGS -Wextra"],[],[])
146AX_CHECK_COMPILE_FLAG([-Wpedantic],[WPEDANTICFLAG="-Wpedantic"],[],[])
147AX_CHECK_COMPILE_FLAG([-Wno-error=unused-parameter],[WNOERRORFLAG="-Wno-error=unused-parameter"],[],[])
148AX_CHECK_COMPILE_FLAG([-Wno-unused-parameter],[WNOERRORFLAG="$WNOERRORFLAG -Wno-unused-parameter"],[],[])
149AC_SUBST(WPEDANTICFLAG)
150AC_SUBST(WNOERRORFLAG)
151
152case "$host_os" in
153  linux* ) CFLAGS="$CFLAGS -D_BSD_SOURCE -D_DEFAULT_SOURCE"
154  ;;
155  solaris* ) CFLAGS="$CFLAGS -D__EXTENSIONS__"  # for strdup() from <string.h>
156  ;;
157  darwin* ) CFLAGS="$CFLAGS -D_DARWIN_C_SOURCE"  # for strlcpy() from <string.h>
158  ;;
159esac
160
161# always use ./libtool unless override from commandline (libtool=mylibtool)
162if test -z "$libtool"; then
163	libtool="`pwd`/libtool"
164fi
165AC_SUBST(libtool)
166AC_PROG_LIBTOOL
167AC_PROG_INSTALL
168
169
170initial_LIBS="$LIBS"
171initial_LDFLAGS="$LDFLAGS"
172
173dnl Add option to disable the evil rpath. Check whether to use rpath or not.
174dnl Adds the --disable-rpath option. Uses trick to edit the ./libtool.
175AC_DEFUN([ACX_ARG_RPATH],
176[
177AC_ARG_ENABLE(rpath,
178        [  --disable-rpath         disable hardcoded rpath (default=enabled)],
179	enable_rpath="$enableval", enable_rpath=yes)
180if test "x$enable_rpath" = xno; then
181	dnl AC_MSG_RESULT([Fixing libtool for -rpath problems.])
182	AC_CONFIG_COMMANDS([disable-rpath], [
183	sed < libtool > libtool-2 \
184	's/^hardcode_libdir_flag_spec.*$'/'hardcode_libdir_flag_spec=" -D__LIBTOOL_RPATH_SED__ "/'
185	mv libtool-2 libtool
186	chmod 755 libtool
187	libtool="./libtool"
188	])
189fi
190])
191ACX_ARG_RPATH
192
193AC_ARG_ENABLE(debug-req, AC_HELP_STRING([--enable-debug-req], [Enable request debugging]))
194AC_ARG_ENABLE(debug-sched, AC_HELP_STRING([--enable-debug-sched], [Enable scheduling debugging messages]))
195AC_ARG_ENABLE(debug-stub, AC_HELP_STRING([--enable-debug-stub], [Enable stub debugging messages]))
196AC_ARG_ENABLE(debug-daemon, AC_HELP_STRING([--enable-debug-daemon], [Enable daemon debugging messages]))
197AC_ARG_ENABLE(debug-sec, AC_HELP_STRING([--enable-debug-sec], [Enable dnssec debugging messages]))
198AC_ARG_ENABLE(debug-server, AC_HELP_STRING([--enable-debug-server], [Enable server debugging messages]))
199AC_ARG_ENABLE(debug-anchor, AC_HELP_STRING([--enable-debug-anchor], [Enable anchor debugging messages]))
200AC_ARG_ENABLE(all-debugging, AC_HELP_STRING([--enable-all-debugging], [Enable scheduling, stub and dnssec debugging]))
201case "$enable_all_debugging" in
202	yes)
203		enable_debug_req=yes
204		enable_debug_sched=yes
205		enable_debug_stub=yes
206		enable_debug_daemon=yes
207		enable_debug_sec=yes
208		enable_debug_server=yes
209		enable_debug_anchor=yes
210		;;
211	no|*)
212		;;
213esac
214case "$enable_debug_req" in
215	yes)
216		AC_DEFINE_UNQUOTED([REQ_DEBUG], [1], [Define this to enable printing of request debugging messages.])
217		;;
218	no|*)
219		;;
220esac
221case "$enable_debug_sched" in
222	yes)
223		AC_DEFINE_UNQUOTED([SCHED_DEBUG], [1], [Define this to enable printing of scheduling debugging messages.])
224		;;
225	no|*)
226		;;
227esac
228case "$enable_debug_stub" in
229	yes)
230		AC_DEFINE_UNQUOTED([STUB_DEBUG], [1], [Define this to enable printing of stub debugging messages.])
231		;;
232	no|*)
233		;;
234esac
235case "$enable_debug_daemon" in
236	yes)
237		AC_DEFINE_UNQUOTED([DAEMON_DEBUG], [1], [Define this to enable printing of daemon debugging messages.])
238		;;
239	no|*)
240		;;
241esac
242case "$enable_debug_sec" in
243	yes)
244		AC_DEFINE_UNQUOTED([SEC_DEBUG], [1], [Define this to enable printing of dnssec debugging messages.])
245		;;
246	no|*)
247		;;
248esac
249case "$enable_debug_server" in
250	yes)
251		AC_DEFINE_UNQUOTED([SERVER_DEBUG], [1], [Define this enable printing of server debugging messages.])
252		;;
253	no|*)
254		;;
255esac
256case "$enable_debug_anchor" in
257	yes)
258		AC_DEFINE_UNQUOTED([ANCHOR_DEBUG], [1], [Define this enable printing of anchor debugging messages.])
259		;;
260	no|*)
261		;;
262esac
263
264
265dnl  Hidden debugging options
266dnl
267AC_ARG_ENABLE(debug-keep-connections-open,[])
268case "$enable_debug_keep_connections_open" in
269	yes)
270		AC_DEFINE_UNQUOTED([KEEP_CONNECTIONS_OPEN_DEBUG], [1], [Do not set this])
271		;;
272	no)
273		;;
274esac
275
276
277DEFAULT_EVENTLOOP=select_eventloop
278AC_CHECK_HEADERS([signal.h sys/poll.h poll.h sys/resource.h sys/types.h sys/stat.h],,, [AC_INCLUDES_DEFAULT])
279AC_ARG_ENABLE(poll-eventloop, AC_HELP_STRING([--disable-poll-eventloop], [Disable default eventloop based on poll (default=enabled if available)]))
280case "$enable_poll_eventloop" in
281	no)
282		;;
283	yes|*)
284AC_MSG_CHECKING(for poll)
285AC_LINK_IFELSE([AC_LANG_PROGRAM([
286#ifdef HAVE_SYS_POLL_H
287#include <sys/poll.h>
288#else
289#include <poll.h>
290#endif
291], [int rc; rc = poll((struct pollfd *)(0), 0, 0);])], [
292AC_MSG_RESULT(yes)
293AC_DEFINE_UNQUOTED([USE_POLL_DEFAULT_EVENTLOOP], [1], [Define this to enable a default eventloop based on poll().])
294DEFAULT_EVENTLOOP=poll_eventloop
295],[AC_MSG_RESULT(no)])
296		;;
297esac
298AC_SUBST(DEFAULT_EVENTLOOP)
299
300AC_ARG_ENABLE(tcp-fastopen, AC_HELP_STRING([--disable-tcp-fastopen], Disable TCP Fast Open (default=enabled if available)),
301    enable_tcp_fastopen="$enableval", enable_tcp_fastopen=yes)
302if test "x$enable_tcp_fastopen" = xno; then
303        AC_MSG_WARN([TCP Fast Open is disabled])
304else
305    case `uname` in
306        Darwin) AC_CHECK_DECL([CONNECT_RESUME_ON_READ_WRITE], [AC_DEFINE_UNQUOTED([USE_OSX_TCP_FASTOPEN], [1], [Define this to enable TCP fast open.])],
307                      [AC_MSG_WARN([TCP Fast Open is not available, continuing without])], [#include <sys/socket.h>])
308          ;;
309        *)
310		AC_CHECK_HEADERS([sys/socket.h netinet/tcp.h],,, [AC_INCLUDES_DEFAULT])
311		AC_CHECK_DECL([TCP_FASTOPEN], [
312			AC_DEFINE_UNQUOTED([USE_TCP_FASTOPEN], [1], [Define this to enable TCP fast open.])
313			AC_CHECK_DECLS([TCP_FASTOPEN,MSG_FASTOPEN,TCP_FASTOPEN_CONNECT], [], [], [AC_INCLUDES_DEFAULT
314#ifdef HAVE_SYS_SOCKET_H
315# include <sys/socket.h>
316#endif
317#ifdef HAVE_NETINET_TCP_H
318# include <netinet/tcp.h>
319#endif
320])
321		], [
322			AC_MSG_WARN([TCP Fast Open is not available, continuing without])
323		], [AC_INCLUDES_DEFAULT
324#ifdef HAVE_SYS_SOCKET_H
325# include <sys/socket.h>
326#endif
327#ifdef HAVE_NETINET_TCP_H
328# include <netinet/tcp.h>
329#endif
330])
331          ;;
332    esac
333fi
334
335AC_ARG_ENABLE(native-stub-dnssec, AC_HELP_STRING([--disable-native-stub-dnssec], [Disable native stub DNSSEC support]))
336case "$enable_native_stub_dnssec" in
337	no)
338		;;
339	yes|*)
340		AC_DEFINE_UNQUOTED([STUB_NATIVE_DNSSEC], [1], [Define this to enable native stub DNSSEC support.])
341		;;
342esac
343
344# check wether strptime also works
345AC_DEFUN([AC_CHECK_STRPTIME_WORKS],
346[AC_REQUIRE([AC_PROG_CC])
347AC_MSG_CHECKING(whether strptime works)
348if test c${cross_compiling} = cno; then
349AC_RUN_IFELSE([AC_LANG_SOURCE([[
350#define _XOPEN_SOURCE 600
351#include <time.h>
352int main(void) { struct tm tm; char *res;
353res = 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);
354if (!res) return 2;
355res = strptime("20070207111842", "%Y%m%d%H%M%S", &tm);
356if (!res) return 1; return 0; }
357]])] , [eval "ac_cv_c_strptime_works=yes"], [eval "ac_cv_c_strptime_works=no"])
358else
359eval "ac_cv_c_strptime_works=maybe"
360fi
361AC_MSG_RESULT($ac_cv_c_strptime_works)
362if test $ac_cv_c_strptime_works = no; then
363AC_LIBOBJ(strptime)
364else
365AC_DEFINE_UNQUOTED([STRPTIME_WORKS], 1, [use default strptime.])
366fi
367])dnl
368
369AC_CHECK_FUNCS([strptime],[AC_CHECK_STRPTIME_WORKS],[AC_LIBOBJ([strptime])])
370
371# search to set include and library paths right
372# find libidn (no libidn on windows though)
373AC_CHECK_HEADERS([windows.h winsock.h stdio.h winsock2.h ws2tcpip.h],,, [AC_INCLUDES_DEFAULT])
374ACX_CHECK_GETADDRINFO_WITH_INCLUDES
375
376AC_ARG_WITH(resolvconf, AS_HELP_STRING([--with-resolvconf=PATH],
377	[Set the resolver configuration file path.  Defaults to /etc/resolv.conf or values retrieved via GetNetworkParams() on Windows]),
378	[], [withval="/etc/resolv.conf"])
379AC_DEFINE_UNQUOTED([GETDNS_FN_RESOLVCONF], ["$withval"], [Path to resolver configuration file])
380
381AC_ARG_WITH(hosts, AS_HELP_STRING([--with-hosts=PATH],
382	[Set the static table lookup for hostnames path.  Defaults to /etc/hosts or C:\Windows\System32\Drivers\etc\hosts on Windows]),
383	[], [
384if test "$USE_WINSOCK" = 1; then
385	withval="C:\\\\Windows\\\\System32\\\\Drivers\\\\etc\\\\hosts"
386else
387	withval="/etc/hosts"
388fi
389])
390AC_DEFINE_UNQUOTED([GETDNS_FN_HOSTS], ["$withval"], [Path to static table lookup for hostnames])
391
392AC_ARG_WITH(fd-setsize, AS_HELP_STRING([--with-fd-setsize=size],
393	[Set maximum file descriptor number that can be used by select]),
394	[], [withval="no"])
395case "$withval" in
396no)
397	;;
398*)
399	AC_DEFINE_UNQUOTED([FD_SETSIZE], [$withval], [Alternate value for the FD_SETSIZE])
400	my_enable_unbound_event_api=1
401	;;
402esac
403
404AC_ARG_WITH(max-udp-backoff, AS_HELP_STRING([--with-max-udp-backoff=<number of queries>],
405    [Set the maximum number of messages that can be sent to other upstreams before the upstream which has previously timed out will be tried again. (defaults to 1000)]),, [withval="1000"])
406AC_DEFINE_UNQUOTED([UDP_MAX_BACKOFF], [$withval], [Maximum number of queries an failed UDP upstream passes before it will retry])
407
408#---- check for pthreads library
409AC_ARG_WITH(libpthread, AS_HELP_STRING([--without-libpthread],
410	[Disable libpthread (default is autodetect)]),
411	[], [withval="yes"])
412
413case "$withval" in
414yes)
415	AC_SEARCH_LIBS([pthread_mutex_init],[pthread], [
416		AC_DEFINE([HAVE_PTHREAD], [1], [Have pthreads library])
417		LIBS="-lpthread $LIBS"
418	], [AC_MSG_WARN([pthreads not available])])
419	;;
420*)
421	;;
422esac
423
424USE_NSS="no"
425dnl AC_ARG_WITH([nss], AC_HELP_STRING([--with-nss=path],
426dnl         [use libnss instead of openssl, installed at path.]),
427dnl         [
428dnl         USE_NSS="yes"
429dnl         AC_DEFINE(HAVE_NSS, 1, [Use libnss for crypto])
430dnl         if test "$withval" != "" -a "$withval" != "yes"; then
431dnl                 CPPFLAGS="$CPPFLAGS -I$withval/include/nss3"
432dnl                 LDFLAGS="$LDFLAGS -L$withval/lib"
433dnl                 ACX_RUNTIME_PATH_ADD([$withval/lib])
434dnl                 CPPFLAGS="-I$withval/include/nspr4 $CPPFLAGS"
435dnl         else
436dnl                 CPPFLAGS="$CPPFLAGS -I/usr/include/nss3"
437dnl                 CPPFLAGS="-I/usr/include/nspr4 $CPPFLAGS"
438dnl         fi
439dnl         LIBS="$LIBS -lnss3 -lnspr4"
440dnl         SSLLIB=""
441dnl         ]
442dnl )
443
444# libnettle
445USE_NETTLE="no"
446dnl AC_ARG_WITH([nettle], AC_HELP_STRING([--with-nettle=path],
447dnl         [use libnettle as crypto library, installed at path.]),
448dnl         [
449dnl         USE_NETTLE="yes"
450dnl         AC_DEFINE(HAVE_NETTLE, 1, [Use libnettle for crypto])
451dnl         AC_CHECK_HEADERS([nettle/dsa-compat.h],,, [AC_INCLUDES_DEFAULT])
452dnl         if test "$withval" != "" -a "$withval" != "yes"; then
453dnl                 CPPFLAGS="$CPPFLAGS -I$withval/include/nettle"
454dnl                 LDFLAGS="$LDFLAGS -L$withval/lib"
455dnl                 ACX_RUNTIME_PATH_ADD([$withval/lib])
456dnl         else
457dnl                 CPPFLAGS="$CPPFLAGS -I/usr/include/nettle"
458dnl         fi
459dnl         LIBS="$LIBS -lhogweed -lnettle -lgmp"
460dnl         SSLLIB=""
461dnl         ]
462dnl )
463
464# Which TLS and crypto libs to use.
465AC_ARG_WITH([gnutls],
466    [AS_HELP_STRING([--with-gnutls],
467        [use GnuTLS instead of OpenSSL])],
468    [
469        PKG_CHECK_MODULES([libgnutls], [gnutls >= 3.5.0])
470        PKG_CHECK_MODULES([libgnutlsdane], [gnutls-dane >= 3.5.0])
471        LIBS="$libgnutls_LIBS $libgnutlsdane_LIBS $LIBS"
472        CFLAGS="$libgnutls_CFLAGS $libgnutlsdane_CFLAGS $CFLAGS"
473        AC_SUBST([TLSDIR], 'gnutls')
474        AC_DEFINE([USE_GNUTLS], [1], [Use the GnuTLS library])
475	if test $USE_NSS = "no" -a $USE_NETTLE = "no"; then
476
477	        AX_LIB_NETTLE(yes)
478		USE_NETTLE="yes"
479		AC_DEFINE(HAVE_NETTLE, 1, [Use libnettle for crypto])
480        	AC_CHECK_HEADERS([nettle/dsa-compat.h],,, [AC_INCLUDES_DEFAULT])
481	fi
482	# Zero configuration DNSSEC we still need libcrypto
483	AC_CHECK_HEADERS([openssl/x509.h],,, [AC_INCLUDES_DEFAULT])
484	AC_CHECK_LIB([crypto], [X509_STORE_new], [
485	AC_DEFINE_UNQUOTED([HAVE_LIBCRYPTO], [2], [Define to 1 if you have the `crypto' library (-lcrypto).]) dnl
486		LIBS="-lcrypto $LIBS"
487	], [
488	AC_MSG_ERROR([libcrypto still needed for Zero configuration DNSSEC])
489	])
490    ],
491    [
492	if test $USE_NSS = "no" -a $USE_NETTLE = "no"; then
493        ACX_WITH_SSL
494	fi
495        ACX_LIB_SSL
496        AC_SUBST([TLSDIR], 'openssl')
497
498        # Verify OpenSSL is at least version 1.0.2.
499        # We also check it's not LibreSSL, but that's a little later, not here.
500        AC_CHECK_FUNCS([X509_check_host SSL_dane_enable])
501        if test "x$ac_cv_func_X509_check_host" != xyes; then
502           AC_MSG_ERROR([getdns requires OpenSSL version 1.0.2 or later])
503        fi
504
505        AC_MSG_CHECKING([whether we need to compile/link DANE support])
506        DANESSL_XTRA_OBJS=""
507        if test "x$ac_cv_func_SSL_dane_enable" = xyes; then
508            AC_MSG_RESULT([no])
509        else
510            AC_MSG_RESULT([yes])
511            AC_DEFINE([USE_DANESSL], [1], [Define this to use DANE functions from the ssl_dane/danessl library.])
512            DANESSL_XTRA_OBJS="danessl.lo"
513        fi
514        AC_SUBST(DANESSL_XTRA_OBJS)
515    ])
516
517
518# openssl
519if test $USE_NSS = "no" -a $USE_NETTLE = "no" ; then
520AC_MSG_CHECKING([for LibreSSL])
521if grep VERSION_TEXT $ssldir/include/openssl/opensslv.h | grep "LibreSSL" >/dev/null; then
522	AC_MSG_RESULT([yes])
523        AC_MSG_ERROR([getdns does not support LibreSSL])
524else
525	AC_MSG_RESULT([no])
526fi
527AC_CHECK_HEADERS([openssl/conf.h openssl/ssl.h],,, [AC_INCLUDES_DEFAULT])
528AC_CHECK_HEADERS([openssl/engine.h],,, [AC_INCLUDES_DEFAULT])
529AC_CHECK_HEADERS([openssl/bn.h openssl/rsa.h openssl/dsa.h],,, [AC_INCLUDES_DEFAULT])
530AC_CHECK_FUNCS([OPENSSL_config EVP_md5 EVP_sha1 EVP_sha224 EVP_sha256 EVP_sha384 EVP_sha512 FIPS_mode ENGINE_load_cryptodev EVP_PKEY_keygen ECDSA_SIG_get0 EVP_MD_CTX_new EVP_PKEY_base_id HMAC_CTX_new HMAC_CTX_free TLS_client_method DSA_SIG_set0 EVP_dss1 EVP_DigestVerify OpenSSL_version_num OpenSSL_version SSL_CTX_dane_enable SSL_dane_enable SSL_dane_tlsa_add X509_check_host X509_get_notAfter X509_get0_notAfter SSL_CTX_set_ciphersuites SSL_set_ciphersuites OPENSSL_init_crypto DSA_set0_pqg DSA_set0_key RSA_set0_key])
531AC_CHECK_DECLS([SSL_COMP_get_compression_methods,sk_SSL_COMP_pop_free,SSL_CTX_set_ecdh_auto,SSL_CTX_set1_curves_list,SSL_set1_curves_list,SSL_set_min_proto_version,SSL_get_min_proto_version], [], [], [
532AC_INCLUDES_DEFAULT
533#ifdef HAVE_OPENSSL_ERR_H
534#include <openssl/err.h>
535#endif
536
537#ifdef HAVE_OPENSSL_RAND_H
538#include <openssl/rand.h>
539#endif
540
541#ifdef HAVE_OPENSSL_CONF_H
542#include <openssl/conf.h>
543#endif
544
545#ifdef HAVE_OPENSSL_ENGINE_H
546#include <openssl/engine.h>
547#endif
548#include <openssl/ssl.h>
549#include <openssl/evp.h>
550])
551fi
552
553AC_ARG_ENABLE(sha1, AC_HELP_STRING([--disable-sha1], [Disable SHA1 RRSIG support, does not disable nsec3 support]))
554	case "$enable_sha1" in
555	no)
556	;;
557	yes|*)
558	AC_DEFINE([USE_SHA1], [1], [Define this to enable SHA1 support.])
559	;;
560esac
561
562AC_ARG_ENABLE(sha2, AC_HELP_STRING([--disable-sha2], [Disable SHA256 and SHA512 RRSIG support]))
563case "$enable_sha2" in
564	no)
565	;;
566	yes|*)
567	AC_DEFINE([USE_SHA2], [1], [Define this to enable SHA256 and SHA512 support.])
568	;;
569esac
570
571# check wether gost also works
572AC_DEFUN([AC_CHECK_GOST_WORKS],
573[AC_REQUIRE([AC_PROG_CC])
574AC_MSG_CHECKING([if GOST works])
575if test c${cross_compiling} = cno; then
576BAKCFLAGS="$CFLAGS"
577if test -n "$ssldir"; then
578	CFLAGS="$CFLAGS -Wl,-rpath,$ssldir/lib"
579fi
580AC_RUN_IFELSE([AC_LANG_SOURCE([[
581#include <string.h>
582#include <openssl/ssl.h>
583#include <openssl/evp.h>
584#include <openssl/engine.h>
585#include <openssl/conf.h>
586/* routine to load gost (from gldns) */
587int load_gost_id(void)
588{
589	static int gost_id = 0;
590	const EVP_PKEY_ASN1_METHOD* meth;
591	ENGINE* e;
592
593	if(gost_id) return gost_id;
594
595	/* see if configuration loaded gost implementation from other engine*/
596	meth = EVP_PKEY_asn1_find_str(NULL, "gost2001", -1);
597	if(meth) {
598		EVP_PKEY_asn1_get0_info(&gost_id, NULL, NULL, NULL, NULL, meth);
599		return gost_id;
600	}
601
602	/* see if engine can be loaded already */
603	e = ENGINE_by_id("gost");
604	if(!e) {
605		/* load it ourself, in case statically linked */
606		ENGINE_load_builtin_engines();
607		ENGINE_load_dynamic();
608		e = ENGINE_by_id("gost");
609	}
610	if(!e) {
611		/* no gost engine in openssl */
612		return 0;
613	}
614	if(!ENGINE_set_default(e, ENGINE_METHOD_ALL)) {
615		ENGINE_finish(e);
616		ENGINE_free(e);
617		return 0;
618	}
619
620	meth = EVP_PKEY_asn1_find_str(&e, "gost2001", -1);
621	if(!meth) {
622		/* algo not found */
623		ENGINE_finish(e);
624		ENGINE_free(e);
625		return 0;
626	}
627	EVP_PKEY_asn1_get0_info(&gost_id, NULL, NULL, NULL, NULL, meth);
628	return gost_id;
629}
630int main(void) {
631	EVP_MD_CTX* ctx;
632	const EVP_MD* md;
633	unsigned char digest[64]; /* its a 256-bit digest, so uses 32 bytes */
634	const char* str = "Hello world";
635	const unsigned char check[] = {
636		0x40 , 0xed , 0xf8 , 0x56 , 0x5a , 0xc5 , 0x36 , 0xe1 ,
637		0x33 , 0x7c , 0x7e , 0x87 , 0x62 , 0x1c , 0x42 , 0xe0 ,
638		0x17 , 0x1b , 0x5e , 0xce , 0xa8 , 0x46 , 0x65 , 0x4d ,
639		0x8d , 0x3e , 0x22 , 0x9b , 0xe1 , 0x30 , 0x19 , 0x9d
640	};
641	OPENSSL_config(NULL);
642	(void)load_gost_id();
643	md = EVP_get_digestbyname("md_gost94");
644	if(!md) return 1;
645	memset(digest, 0, sizeof(digest));
646	ctx = EVP_MD_CTX_create();
647	if(!ctx) return 2;
648	if(!EVP_DigestInit_ex(ctx, md, NULL)) return 3;
649	if(!EVP_DigestUpdate(ctx, str, 10)) return 4;
650	if(!EVP_DigestFinal_ex(ctx, digest, NULL)) return 5;
651	/* uncomment to see the hash calculated.
652		{int i;
653		for(i=0; i<32; i++)
654			printf(" %2.2x", (int)digest[i]);
655		printf("\n");}
656	*/
657	if(memcmp(digest, check, sizeof(check)) != 0)
658		return 6;
659	return 0;
660}
661]])] , [eval "ac_cv_c_gost_works=yes"], [eval "ac_cv_c_gost_works=no"])
662CFLAGS="$BAKCFLAGS"
663else
664eval "ac_cv_c_gost_works=maybe"
665fi
666AC_MSG_RESULT($ac_cv_c_gost_works)
667])dnl
668
669AC_ARG_ENABLE(gost, AC_HELP_STRING([--disable-gost], [Disable GOST support]))
670use_gost="no"
671if test $USE_NSS = "no" -a $USE_NETTLE = "no"; then
672case "$enable_gost" in
673	no)
674	;;
675	*)
676	AC_CHECK_FUNC(EVP_PKEY_set_type_str, [:],[AC_MSG_ERROR([OpenSSL 1.0.0 is needed for GOST support])])
677	AC_CHECK_FUNC(EC_KEY_new, [], [AC_MSG_ERROR([OpenSSL does not support ECC, needed for GOST support])])
678	AC_CHECK_GOST_WORKS
679	if test "$ac_cv_c_gost_works" != no; then
680		use_gost="yes"
681		AC_DEFINE([USE_GOST], [1], [Define this to enable GOST support.])
682	fi
683	;;
684esac
685fi dnl !USE_NSS && !USE_NETTLE
686
687AC_ARG_ENABLE(ecdsa, AC_HELP_STRING([--disable-ecdsa], [Disable ECDSA support]))
688use_ecdsa="no"
689case "$enable_ecdsa" in
690    no)
691      ;;
692    *)
693      if test $USE_NSS = "no" -a $USE_NETTLE = "no"; then
694	      AC_CHECK_FUNC(ECDSA_sign, [], [AC_MSG_ERROR([OpenSSL does not support ECDSA: please upgrade or rerun with --disable-ecdsa])])
695	      AC_CHECK_FUNC(SHA384_Init, [], [AC_MSG_ERROR([OpenSSL does not support SHA384: please upgrade or rerun with --disable-ecdsa])])
696	      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
697#include <openssl/evp.h>
698	      ])
699	      # see if OPENSSL 1.0.0 or later (has EVP MD and Verify independency)
700	      AC_MSG_CHECKING([if openssl supports SHA2 and ECDSA with EVP])
701	      if grep OPENSSL_VERSION_TEXT $ssldir/include/openssl/opensslv.h | grep "OpenSSL" >/dev/null; then
702		if grep OPENSSL_VERSION_NUMBER $ssldir/include/openssl/opensslv.h | grep 0x0 >/dev/null; then
703		  AC_MSG_RESULT([no])
704		  AC_DEFINE_UNQUOTED([USE_ECDSA_EVP_WORKAROUND], [1], [Define this to enable an EVP workaround for older openssl])
705		else
706		  AC_MSG_RESULT([yes])
707		fi
708	      else
709		# not OpenSSL, thus likely LibreSSL, which supports it
710		AC_MSG_RESULT([yes])
711	      fi
712      fi
713      # we now know we have ECDSA and the required curves.
714      AC_DEFINE_UNQUOTED([USE_ECDSA], [1], [Define this to enable ECDSA support.])
715      use_ecdsa="yes"
716      ;;
717esac
718
719AC_ARG_ENABLE(dsa, AC_HELP_STRING([--disable-dsa], [Disable DSA support]))
720case "$enable_dsa" in
721    no)
722      ;;
723    *) dnl default
724      # detect if DSA is supported, and turn it off if not.
725      if test $USE_NSS = "no" -a $USE_NETTLE = "no"; then
726      AC_CHECK_FUNC(DSA_SIG_new, [
727	AC_CHECK_TYPE(DSA_SIG*, [
728		AC_DEFINE_UNQUOTED([USE_DSA], [1], [Define this to enable DSA support.])
729	], [if test "x$enable_dsa" = "xyes"; then AC_MSG_ERROR([OpenSSL does not support DSA and you used --enable-dsa.])
730	  fi ], [
731AC_INCLUDES_DEFAULT
732#ifdef HAVE_OPENSSL_ENGINE_H
733# include <openssl/engine.h>
734#endif
735
736#ifdef HAVE_OPENSSL_RAND_H
737#include <openssl/rand.h>
738#endif
739
740#ifdef HAVE_OPENSSL_CONF_H
741#include <openssl/conf.h>
742#endif
743
744#ifdef HAVE_OPENSSL_ENGINE_H
745#include <openssl/engine.h>
746#endif
747])
748      ], [if test "x$enable_dsa" = "xyes"; then AC_MSG_ERROR([OpenSSL does not support DSA and you used --enable-dsa.])
749	  fi ])
750      else
751      AC_DEFINE_UNQUOTED([USE_DSA], [1], [Define this to enable DSA support.])
752      fi
753      ;;
754esac
755
756AC_ARG_ENABLE(ed25519, AC_HELP_STRING([--disable-ed25519], [Disable ED25519 support]))
757use_ed25519="no"
758case "$enable_ed25519" in
759    no)
760      ;;
761    *)
762      if test $USE_NSS = "no" -a $USE_NETTLE = "no"; then
763              AC_CHECK_DECLS([NID_ED25519], [
764                use_ed25519="yes"
765              ], [ if test "x$enable_ed25519" = "xyes"; then AC_MSG_ERROR([OpenSSL does not support ED25519 and you used --enable-ed25519.])
766                fi ], [AC_INCLUDES_DEFAULT
767#include <openssl/evp.h>
768              ])
769      fi
770      if test $USE_NETTLE = "yes"; then
771                AC_CHECK_HEADERS([nettle/eddsa.h], use_ed25519="yes",, [AC_INCLUDES_DEFAULT])
772      fi
773      if test $use_ed25519 = "yes"; then
774                AC_DEFINE_UNQUOTED([USE_ED25519], [1], [Define this to enable ED25519 support.])
775      fi
776      ;;
777esac
778
779AC_ARG_ENABLE(ed448, AC_HELP_STRING([--disable-ed448], [Disable ED448 support]))
780use_ed448="no"
781case "$enable_ed448" in
782    no)
783      ;;
784    *)
785      if test $USE_NSS = "no" -a $USE_NETTLE = "no"; then
786              AC_CHECK_DECLS([NID_ED448], [
787                use_ed448="yes"
788              ], [ if test "x$enable_ed448" = "xyes"; then AC_MSG_ERROR([OpenSSL does not support ED448 and you used --enable-ed448.])
789                fi ], [AC_INCLUDES_DEFAULT
790#include <openssl/evp.h>
791              ])
792      fi
793      if test $use_ed448 = "yes"; then
794                AC_DEFINE_UNQUOTED([USE_ED448], [1], [Define this to enable ED448 support.])
795      fi
796      ;;
797esac
798
799AC_ARG_ENABLE(all-drafts, AC_HELP_STRING([--enable-all-drafts], [Enables the draft mdns client support]))
800case "$enable_all_drafts" in
801	yes)
802		AC_DEFINE_UNQUOTED([HAVE_MDNS_SUPPORT], [1], [Define this to enable the draft mdns client support.])
803		;;
804	no|*)
805		;;
806esac
807AC_ARG_ENABLE(dnssec-roadblock-avoidance, AC_HELP_STRING([--disable-dnssec-roadblock-avoidance], [Disable dnssec roadblock avoidance]))
808case "$enable_dnssec_roadblock_avoidance" in
809	no)
810		;;
811	yes|*)
812		AC_DEFINE_UNQUOTED([DNSSEC_ROADBLOCK_AVOIDANCE], [1], [Define this to enable the experimental dnssec roadblock avoidance.])
813		;;
814esac
815
816AC_ARG_ENABLE(edns-cookies, AC_HELP_STRING([--disable-edns-cookies], [Disable edns cookies]))
817case "$enable_edns_cookies" in
818	no)
819		;;
820	yes|*)
821		if test "x_$HAVE_SSL" != "x_yes" -a $USE_NETTLE = "no"; then
822			AC_MSG_ERROR([edns cookies needs crypto library which is not available, please rerun with --disable-edns-cookies])
823		fi
824		AC_DEFINE_UNQUOTED([EDNS_COOKIES], [1], [Define this to enable the experimental edns cookies.])
825		;;
826esac
827AC_DEFINE_UNQUOTED([EDNS_COOKIE_OPCODE], [10], [The edns cookie option code.])
828AC_DEFINE_UNQUOTED([EDNS_COOKIE_ROLLOVER_TIME], [(24 * 60 * 60)], [How often the edns client cookie is refreshed.])
829
830AC_DEFINE_UNQUOTED([MAXIMUM_UPSTREAM_OPTION_SPACE], [3000], [limit for dynamically-generated DNS options])
831AC_DEFINE_UNQUOTED([EDNS_PADDING_OPCODE], [12], [The edns padding option code.])
832
833AC_ARG_ENABLE(draft-mdns-support, AC_HELP_STRING([--enable-draft-mdns-support], [Enable draft mdns client support]))
834case "$enable_draft_mdns_support" in
835	yes)
836		AC_DEFINE_UNQUOTED([HAVE_MDNS_SUPPORT], [1], [Define this to enable the draft mdns client support.])
837		;;
838	no|*)
839		;;
840esac
841
842my_with_libunbound=1
843AC_ARG_ENABLE(stub-only, AC_HELP_STRING([--enable-stub-only], [Restricts resolution modes to STUB (which will be the default mode).  Removes the libunbound dependency.]))
844case "$enable_stub_only" in
845	yes)
846		my_with_libunbound=0
847		;;
848	no|*)
849		;;
850esac
851
852my_with_yaml=0
853AC_ARG_ENABLE(yaml-config,)
854case "$enable_yaml_config" in
855	yes)
856		AC_DEFINE_UNQUOTED([USE_YAML_CONFIG], [1], [Define this to enable YAML config support.])
857		AC_DEFINE_UNQUOTED([HAVE_GETDNS_YAML2DICT], [1], [Define this to enable getdns_yaml2dict function.])
858
859		GETDNS_XTRA_OBJS="convert_yaml_to_json.lo"
860		my_with_yaml=1
861		;;
862	no|*)
863		GETDNS_XTRA_OBJS=""
864		;;
865esac
866AC_SUBST(GETDNS_XTRA_OBJS)
867
868if test "$USE_WINSOCK" = 1; then
869	AC_MSG_NOTICE([ Building on Windows ... YES! ])
870	AC_DEFINE_UNQUOTED([GETDNS_ON_WINDOWS], [1], [Define this to enable Windows build.])
871	AC_DEFINE_UNQUOTED([STUB_NATIVE_DNSSEC], [1])
872	LIBS="$LIBS -lgdi32 -liphlpapi"
873fi
874
875dnl sigset_t or _sigset_t? MinGW is latter by default.
876AC_CHECK_TYPES([sigset_t],
877               [],
878               [AC_CHECK_TYPES([_sigset_t],
879                               [],
880                               [AC_MSG_ERROR([Can't find type `sigset_t' or type `_sigset_t'])],
881                               [AC_INCLUDES_DEFAULT
882#ifdef HAVE_SIGNAL_H
883#include <signal.h>
884#endif
885#ifdef HAVE_SYS_TYPES_H
886#include <sys/types.h>
887#endif
888                               ])
889              ],
890              [AC_INCLUDES_DEFAULT
891#ifdef HAVE_SIGNAL_H
892#include <signal.h>
893#endif
894#ifdef HAVE_SYS_TYPES_H
895#include <sys/types.h>
896#endif
897])
898AC_CHECK_FUNCS(sigemptyset sigfillset sigaddset)
899
900my_with_libidn=1
901AC_ARG_WITH(libidn, AS_HELP_STRING([--with-libidn=pathname],
902	[path to libidn (default: search /usr/local ..)]),
903	[], [withval="yes"])
904if test x_$withval = x_yes; then
905	for dir in /usr/local /opt/local /usr/pkg /usr/sfw; do
906		if test -f "$dir/include/idna.h"; then
907			CFLAGS="$CFLAGS -I$dir/include"
908			LDFLAGS="$LDFLAGS -L$dir/lib"
909			AC_MSG_NOTICE([Found libidn in $dir])
910			break
911		fi
912		if test -f "$dir/include/idn/idna.h"; then
913			CFLAGS="$CFLAGS -I$dir/include/idn"
914			LDFLAGS="$LDFLAGS -L$dir/lib"
915			AC_MSG_NOTICE([Found libidn in $dir])
916			break
917		fi
918	done
919	if test -f "/usr/include/idn/idna.h"; then
920		CFLAGS="$CFLAGS -I/usr/include/idn"
921		#LDFLAGS="$LDFLAGS -L/usr/lib"
922		AC_MSG_NOTICE([Found libidn in /usr])
923	fi
924else
925	if test x_$withval != x_no; then
926		CFLAGS="$CFLAGS -I$withval/include"
927		LDFLAGS="$LDFLAGS -L$withval/lib"
928	else
929		my_with_libidn=0
930	fi
931fi
932
933my_with_libidn2=1
934AC_ARG_WITH(libidn2, AS_HELP_STRING([--with-libidn2=pathname],
935	[path to libidn2 (default: search /usr/local ..)]),
936	[], [withval="yes"])
937if test x_$withval = x_yes; then
938	for dir in /usr/local /opt/local /usr/pkg /usr/sfw; do
939		if test -f "$dir/include/idn2.h"; then
940			CFLAGS="$CFLAGS -I$dir/include"
941			LDFLAGS="$LDFLAGS -L$dir/lib"
942			AC_MSG_NOTICE([Found libidn2 in $dir])
943			break
944		fi
945		if test -f "$dir/include/idn2/idn2.h"; then
946			CFLAGS="$CFLAGS -I$dir/include/idn2"
947			LDFLAGS="$LDFLAGS -L$dir/lib"
948			AC_MSG_NOTICE([Found libidn2 in $dir])
949			break
950		fi
951	done
952	if test -f "/usr/include/idn2/idn2.h"; then
953		CFLAGS="$CFLAGS -I/usr/include/idn2"
954		#LDFLAGS="$LDFLAGS -L/usr/lib"
955		AC_MSG_NOTICE([Found libidn2 in /usr])
956	fi
957else
958	if test x_$withval != x_no; then
959		CFLAGS="$CFLAGS -I$withval/include"
960		LDFLAGS="$LDFLAGS -L$withval/lib"
961	else
962		my_with_libidn2=0
963	fi
964fi
965
966if test $my_with_libunbound = 1
967then
968	# find libunbound
969	AC_ARG_WITH(libunbound, AS_HELP_STRING([--with-libunbound=pathname],
970		[path to libunbound (default: search /usr/local ..)]),
971		[], [withval="yes"])
972	if test x_$withval = x_yes; then
973		for dir in /usr/local /opt/local /usr/pkg /usr/sfw; do
974			if test -f "$dir/include/unbound.h"; then
975				CFLAGS="$CFLAGS -I$dir/include"
976				LDFLAGS="$LDFLAGS -L$dir/lib"
977				AC_MSG_NOTICE([Found libunbound in $dir])
978				break
979			fi
980		done
981	else
982		if test x_$withval != x_no; then
983			CFLAGS="$CFLAGS -I$withval/include"
984			LDFLAGS="$LDFLAGS -L$withval/lib"
985		else
986			AC_DEFINE_UNQUOTED([DISABLE_RESOLUTION_RECURSING], [1], [Define this to disable recursing resolution type.])
987			my_with_libunbound=0
988		fi
989	fi
990fi
991
992# Checks for libraries.
993found_all_libs=1
994MISSING_DEPS=""
995MISSING_SEP=""
996
997working_libidn2=0
998if test $my_with_libidn2 = 1
999then
1000	AC_MSG_NOTICE([Checking for dependency libidn2])
1001	AC_CHECK_LIB([idn2], [idn2_to_unicode_8z8z], [
1002		working_libidn2=1
1003		LIBS="-lidn2 $LIBS"
1004		AC_DEFINE_UNQUOTED([HAVE_LIBIDN2], [1], [Define to 1 if you have the `idn2' library (-lidn).]) dnl `
1005	], [
1006		MISSING_DEPS="${MISSING_DEPS}${MISSING_SEP}libidn2 (version 2.0.0 or higher)"
1007		MISSING_SEP=", "
1008	])
1009fi
1010if test $working_libidn2 = 0
1011then
1012	if test $my_with_libidn = 1
1013	then
1014		AC_MSG_NOTICE([Checking for dependency libidn])
1015		AC_CHECK_LIB([idn], [idna_to_ascii_8z], [], [
1016			MISSING_DEPS="${MISSING_DEPS}${MISSING_SEP}libidn"
1017			MISSING_SEP=", "
1018			found_all_libs=0
1019		])
1020	else
1021		if test $my_with_libidn2 = 1
1022		then
1023			found_all_libs=0
1024		fi
1025	fi
1026fi
1027
1028AC_ARG_ENABLE(unbound-event-api, AC_HELP_STRING([--disable-unbound-event-api], [Disable usage of libunbounds event API]))
1029case "$enable_unbound_event_api" in
1030	no)
1031		my_enable_unbound_event_api=0
1032		;;
1033	yes|*)
1034		my_enable_unbound_event_api=1
1035		;;
1036esac
1037
1038
1039if test $my_with_libunbound = 1
1040then
1041	AC_CHECK_HEADERS([unbound-event.h],,, [AC_INCLUDES_DEFAULT])
1042	AC_MSG_NOTICE([Checking for dependency libunbound])
1043	AC_CHECK_LIB([unbound], [ub_fd], [
1044		AC_DEFINE_UNQUOTED([HAVE_LIBUNBOUND], [1], [Define to 1 if you have the `unbound' library (-lunbound).]) dnl `
1045		LIBS="-lunbound $LIBS"
1046
1047		if test $my_enable_unbound_event_api = 1
1048		then
1049			AC_CHECK_FUNC([ub_ctx_create_ub_event], [
1050				AC_DEFINE_UNQUOTED([HAVE_UNBOUND_EVENT_API], [1], [Define this when libunbound is compiled with the --enable-event-api option.])
1051			])
1052		fi
1053		AC_CHECK_FUNCS([ub_ctx_set_stub])
1054	], [
1055		MISSING_DEPS="${MISSING_DEPS}${MISSING_SEP}libunbound"
1056		MISSING_SEP=", "
1057		found_all_libs=0
1058	])
1059fi
1060
1061AC_PATH_PROG([DOXYGEN], [doxygen])
1062if test -z "$DOXYGEN";
1063    then AC_MSG_WARN([doxygen not found, continuing without])
1064fi
1065
1066# Checks for header files.
1067AC_CHECK_HEADERS([inttypes.h netinet/in.h stdint.h stdlib.h string.h],,, [AC_INCLUDES_DEFAULT])
1068
1069# Checks for typedefs, structures, and compiler characteristics.
1070AC_TYPE_SIZE_T
1071AC_TYPE_UINT16_T
1072AC_TYPE_UINT32_T
1073AC_TYPE_UINT64_T
1074AC_TYPE_UINT8_T
1075AC_CHECK_TYPES([u_char])
1076
1077AC_CHECK_FUNCS([fcntl])
1078# check ioctlsocket
1079AC_MSG_CHECKING(for ioctlsocket)
1080AC_LINK_IFELSE([AC_LANG_PROGRAM([
1081#ifdef HAVE_WINSOCK2_H
1082#include <winsock2.h>
1083#endif
1084], [
1085	(void)ioctlsocket(0, 0, NULL);
1086])], [
1087AC_MSG_RESULT(yes)
1088AC_DEFINE(HAVE_IOCTLSOCKET, 1, [if the function 'ioctlsocket' is available])
1089],[AC_MSG_RESULT(no)])
1090
1091
1092# Check for libraries for other things than libgetdns after this point,
1093# so the getdns libraries can be reset with:
1094#
1095#	LIBS="$getdns_LIBS"
1096#	LDFLAGS="$getdns_LDFLAGS"
1097#
1098# afterwards.
1099getdns_LIBS="$LIBS"
1100getdns_LDFLAGS="$LDFLAGS"
1101getdns_CFLAGS="$CFLAGS"
1102
1103#-------------------- libraries needed for libcheck
1104LIBS="$initial_LIBS"
1105
1106CHECK_GETDNS=""
1107CHECK_LIBS=""
1108CHECK_CFLAGS=""
1109
1110PKG_CHECK_MODULES([CHECK],[check >= 0.9.6],[CHECK_GETDNS="check_getdns"],[
1111AC_SEARCH_LIBS([floor], [m])
1112AC_SEARCH_LIBS([timer_create], [rt])
1113AC_SEARCH_LIBS([pthread_create], [pthread])
1114AC_SEARCH_LIBS([srunner_create],[check check_pic],[
1115CHECK_GETDNS="check_getdns"
1116CHECK_LIBS="$LIBS"],[
1117AC_SUBST(NOLIBCHECK, [nolibcheck])
1118AC_MSG_WARN([libcheck not found or usable; unit tests will not be compiled and run])])])
1119
1120LIBS="$getdns_LIBS"
1121
1122AC_SUBST([CHECK_GETDNS])
1123AC_SUBST([CHECK_LIBS])
1124AC_SUBST([CHECK_CFLAGS])
1125# end libraries needed for libcheck
1126
1127#-------------------- libevent extension
1128AC_ARG_WITH([libevent],
1129    [AS_HELP_STRING([--with-libevent], [path to libevent (default: search /usr/local ..)])],
1130    [with_libevent=search],
1131    [withval=no])
1132
1133# libevent 1.x requires a u_char typedef which is not always available
1134# on some systems so our check is a little complicated
1135# we further need to ensure that this is included in the getdns headers
1136# that get installed later so some users may not be building in an
1137# environment that has the generated config.h SO we need to generate
1138# this one extra header in that case
1139
1140have_libevent=0
1141EXTENSION_LIBEVENT_EXT_LIBS=""
1142EXTENSION_LIBEVENT_LIB=""
1143EXTENSION_LIBEVENT_LDFLAGS=""
1144CHECK_EVENT_PROG=""
1145AS_IF([test x_$withval = x_no],
1146    [],
1147    [AS_IF([test x_$withval = x_yes],
1148        [AC_SEARCH_LIBS([event_loop],
1149        	[event_core event],
1150            [AC_CHECK_FUNCS([event_base_new event_base_free])]
1151            [AC_CHECK_HEADERS([event2/event.h],
1152                [have_libevent=1]
1153                [AS_IF([test "x_$ac_cv_search_event_loop" = "x_none required"],[],[EXTENSION_LIBEVENT_EXT_LIBS="$ac_cv_search_event_loop"])],
1154                [AC_CHECK_HEADERS([event.h],
1155                    [have_libevent=1]
1156                    [AS_IF([test "x_$ac_cv_search_event_loop" = "x_none required"],[],[EXTENSION_LIBEVENT_EXT_LIBS="$ac_cv_search_event_loop"])],
1157                    [AC_MSG_ERROR([event2/event.h and event.h missing, try without libevent])]
1158                    [have_libevent=0],
1159                    [AC_INCLUDES_DEFAULT]
1160                    [#ifndef HAVE_U_CHAR
1161                     typedef unsigned char u_char;
1162                     #endif])],
1163                [AC_INCLUDES_DEFAULT])],
1164             [AC_MSG_ERROR([libevent missing, try without libevent])]
1165            )],
1166        [have_libevent=1]
1167        [AC_MSG_NOTICE([assuming libevent in $withval])]
1168        [CFLAGS="$CFLAGS -I$withval/include"]
1169		[EXTENSION_LIBEVENT_LDFLAGS="-L$withval/lib"]
1170        [EXTENSION_LIBEVENT_EXT_LIBS="-levent"])]
1171    )
1172
1173AS_IF([test x_$have_libevent = x_1],
1174    [EXTENSION_LIBEVENT_LIB="libgetdns_ext_event.la"]
1175    [CHECK_EVENT_PROG=check_getdns_event]
1176# libunbound version 1.4.22 and older, not linked against libevent, on FreeBSD,
1177# =============================================================================
1178# cannot be linked against a program that also links libevent, because of
1179# symbol clash.  Libunbound has a libevent clone (called mini_event) build when
1180# not linked against libevent that uses the same symbols as libevent.
1181
1182# First detect if the libevent symbols are visible when linking with libunbound
1183    [LIBS="$getdns_LIBS"]
1184    [LDFLAGS="$getdns_LDFLAGS"]
1185    [AC_MSG_CHECKING([if event_get_version symbol is leaking from libunbound])]
1186    [AC_LANG_PUSH(C)]
1187     AC_LINK_IFELSE(
1188	     [AC_LANG_PROGRAM(
1189		     [[const char *event_get_version(void);]],
1190		     [[const char *v = event_get_version();]])
1191	     ],[[AC_MSG_RESULT([yes])]
1192                [AC_MSG_CHECKING([if libunbound is linked against libevent])]
1193		 AC_RUN_IFELSE(
1194			[AC_LANG_PROGRAM(
1195				[[const char *event_get_version(void);]],
1196				[[const char *v = event_get_version();]
1197				 [return v@<:@0@:>@ == 'm' && v@<:@1@:>@ == 'i' &&
1198				         v@<:@2@:>@ == 'n' && v@<:@3@:>@ == 'i' ? 1 : 0;]])
1199			],[[AC_MSG_RESULT([yes])]
1200			],[[AC_MSG_RESULT([no])]
1201			   [AC_MSG_FAILURE([
1202***
1203*** On this system, when using libevent,  libunbound must
1204*** also have been compiled with libevent.  Please recompile
1205*** libunbound with libevent, or configure --without-libevent.
1206***])]
1207			]
1208		)
1209             ],[[AC_MSG_RESULT([no])]
1210	     ]
1211     )
1212    [AC_LANG_POP(C)])
1213
1214AC_SUBST(have_libevent)
1215AC_SUBST(EXTENSION_LIBEVENT_LIB)
1216AC_SUBST(EXTENSION_LIBEVENT_EXT_LIBS)
1217AC_SUBST(EXTENSION_LIBEVENT_LDFLAGS)
1218AS_IF([test "x$have_libcheck" = x1], [AC_SUBST(CHECK_EVENT_PROG)])
1219
1220LIBS="$getdns_LIBS"
1221LDFLAGS="$getdns_LDFLAGS"
1222# end libevent extension
1223
1224#-------------------- libuv extension
1225# if user says nothing about libuv, or specifies --with-libuv=no or --without-libuv
1226# then we do not want libuv extensions built
1227# if user specifies --with-libuv then search for it
1228# if user specifies --with-libuv=/path then check the lib at that path
1229AC_ARG_WITH([libuv],
1230    [AS_HELP_STRING([--with-libuv], [path to libuv (default: search /usr/local ..)])],
1231    [with_libuv=search],
1232    [withval=no])
1233
1234have_libuv=0
1235EXTENSION_LIBUV_EXT_LIBS=""
1236EXTENSION_LIBUV_LIB=""
1237EXTENSION_LIBUV_LDFLAGS=""
1238CHECK_UV_PROG=""
1239AS_IF([test x_$withval = x_no],
1240    [],
1241    [AS_IF([test x_$withval = x_yes],
1242        [AC_SEARCH_LIBS([uv_run],
1243        	[uv],
1244        	[AC_CHECK_HEADERS([uv.h],
1245                [have_libuv=1]
1246                [EXTENSION_LIBUV_EXT_LIBS="$ac_cv_search_uv_run"],
1247                [AC_MSG_ERROR([uv.h missing, try without libuv])]
1248                [have_libuv=0],
1249                [AC_INCLUDES_DEFAULT])],
1250                [AC_MSG_ERROR([libuv missing, try without libuv])]
1251            )],
1252        [have_libuv=1]
1253        [AC_MSG_NOTICE([assuming libuv in $withval])]
1254        [CFLAGS="$CFLAGS -I$withval/include"]
1255		[EXTENSION_LIBUV_LDFLAGS="-L$withval/lib"]
1256        [EXTENSION_LIBUV_EXT_LIBS="-luv"])]
1257    )
1258
1259AS_IF([test x_$have_libuv = x_1],
1260    [EXTENSION_LIBUV_LIB="libgetdns_ext_uv.la"]
1261    [CHECK_UV_PROG=check_getdns_uv]
1262    [AC_MSG_CHECKING([for new signature of uv_timer_cb])
1263     AC_LANG_PUSH(C)
1264     AC_COMPILE_IFELSE(
1265	     [AC_LANG_PROGRAM(
1266		     [[#include <uv.h>]
1267		      [void test_cb(uv_timer_t *handle);]],
1268		     [[uv_timer_cb cb = test_cb;]
1269		      [(*cb)(0);]])
1270	     ],[AC_MSG_RESULT([yes])
1271		AC_DEFINE(HAVE_NEW_UV_TIMER_CB, [1], [Does libuv have the new uv_time_cb signature])
1272             ],[AC_MSG_RESULT([no])
1273	     ])
1274     AC_LANG_POP(C)]
1275)
1276
1277AC_SUBST(have_libuv)
1278AC_SUBST(EXTENSION_LIBUV_LIB)
1279AC_SUBST(EXTENSION_LIBUV_EXT_LIBS)
1280AC_SUBST(EXTENSION_LIBUV_LDFLAGS)
1281AS_IF([test "x$have_libcheck" = x1], [AC_SUBST(CHECK_UV_PROG)])
1282
1283LIBS="$getdns_LIBS"
1284LDFLAGS="$getdns_LDFLAGS"
1285# end libuv extension
1286
1287#-------------------- libev extension
1288AC_ARG_WITH([libev],
1289    [AS_HELP_STRING([--with-libev], [path to libev (default: search /usr/local ..)])],
1290    [with_libev=search],
1291    [withval=no])
1292
1293have_libev=0
1294EXTENSION_LIBEV_EXT_LIBS=""
1295EXTENSION_LIBEV_LIB=""
1296EXTENSION_LIBEV_LDFLAGS=""
1297CHECK_EV_PROG=""
1298AS_IF([test x_$withval = x_no],
1299    [],
1300    [AS_IF([test x_$withval = x_yes],
1301        [AC_SEARCH_LIBS([ev_run],
1302        	[ev],
1303        	[AC_CHECK_HEADERS([ev.h],
1304			[have_libev=1]
1305			[EXTENSION_LIBEV_EXT_LIBS="$ac_cv_search_ev_run"],
1306			[AC_CHECK_HEADERS([libev/ev.h],
1307				[have_libev=1]
1308				[EXTENSION_LIBEV_EXT_LIBS="$ac_cv_search_ev_run"],
1309				[AC_MSG_ERROR([ev.h missing, try without libev])]
1310				[have_libev=0],
1311				[AC_INCLUDES_DEFAULT])
1312			],
1313			[AC_INCLUDES_DEFAULT])
1314		],
1315                [AC_MSG_ERROR([libev missing, try without libev])]
1316            )],
1317        [have_libev=1]
1318        [AC_MSG_NOTICE([assuming libev in $withval])]
1319        [CFLAGS="$CFLAGS -I$withval/include"]
1320		[EXTENSION_LIBEV_LDFLAGS="-L$withval/lib"]
1321        [EXTENSION_LIBEV_EXT_LIBS="-lev"])]
1322    )
1323
1324AS_IF([test x_$have_libev = x_1],
1325    [EXTENSION_LIBEV_LIB="libgetdns_ext_ev.la"]
1326    [CHECK_EV_PROG=check_getdns_ev])
1327
1328AC_SUBST(have_libev)
1329AC_SUBST(EXTENSION_LIBEV_LIB)
1330AC_SUBST(EXTENSION_LIBEV_EXT_LIBS)
1331AC_SUBST(EXTENSION_LIBEV_LDFLAGS)
1332AS_IF([test "x$have_libcheck" = x1], [AC_SUBST(CHECK_EV_PROG)])
1333
1334LIBS="$getdns_LIBS"
1335LDFLAGS="$getdns_LDFLAGS"
1336# end libev extension
1337
1338# --with-trust-anchor=
1339AC_DEFINE([SYSCONFDIR], [sysconfdir], [System configuration dir])
1340AC_ARG_WITH(trust-anchor, AS_HELP_STRING([--with-trust-anchor=KEYFILE], [Default location of the trust anchor file. [default=SYSCONFDIR/unbound/getdns-root.key]]), [
1341 TRUST_ANCHOR_FILE="$withval"
1342],[
1343 if test "x$TRUST_ANCHOR_FILE" = "x"; then
1344  if test "x$sysconfdir" = 'x${prefix}/etc' ; then
1345   if test "x$prefix" = 'xNONE' ; then
1346    TRUST_ANCHOR_FILE="/etc/unbound/getdns-root.key"
1347   else
1348    TRUST_ANCHOR_FILE="${prefix}/etc/unbound/getdns-root.key"
1349   fi
1350  else
1351    TRUST_ANCHOR_FILE="${sysconfdir}/unbound/getdns-root.key"
1352  fi
1353 fi
1354])
1355AC_DEFINE_UNQUOTED([TRUST_ANCHOR_FILE], ["$TRUST_ANCHOR_FILE"], [Default trust anchor file])
1356AC_SUBST(TRUST_ANCHOR_FILE)
1357AC_MSG_NOTICE([Default trust anchor: $TRUST_ANCHOR_FILE])
1358
1359AC_ARG_WITH(getdns_query, AS_HELP_STRING([--without-getdns_query],
1360	[Do not compile and install the getdns_query tool]),
1361	[], [withval="yes"])
1362if test x_$withval = x_no; then
1363	GETDNS_QUERY=""
1364	INSTALL_GETDNS_QUERY=""
1365	UNINSTALL_GETDNS_QUERY=""
1366else
1367	GETDNS_QUERY="getdns_query"
1368	INSTALL_GETDNS_QUERY="install-getdns_query"
1369	UNINSTALL_GETDNS_QUERY="uninstall-getdns_query"
1370fi
1371AC_SUBST(GETDNS_QUERY)
1372AC_SUBST(INSTALL_GETDNS_QUERY)
1373AC_SUBST(UNINSTALL_GETDNS_QUERY)
1374
1375AC_ARG_WITH(getdns_server_mon, AS_HELP_STRING([--without-getdns_server_mon],
1376	[Do not compile and install the getdns_server_mon tool]),
1377	[], [withval="yes"])
1378if test x_$withval = x_no; then
1379	GETDNS_SERVER_MON=""
1380	INSTALL_GETDNS_SERVER_MON=""
1381	UNINSTALL_GETDNS_SERVER_MON=""
1382else
1383	GETDNS_SERVER_MON="getdns_server_mon"
1384	INSTALL_GETDNS_SERVER_MON="install-getdns_server_mon"
1385	UNINSTALL_GETDNS_SERVER_MON="uninstall-getdns_server_mon"
1386fi
1387AC_SUBST(GETDNS_SERVER_MON)
1388AC_SUBST(INSTALL_GETDNS_SERVER_MON)
1389AC_SUBST(UNINSTALL_GETDNS_SERVER_MON)
1390
1391stubby_with_yaml=0
1392AC_ARG_WITH(stubby, AS_HELP_STRING([--with-stubby],
1393	[Compile and install stubby, the (stub) resolver daemon]),
1394	[], [withval="no"])
1395if test x_$withval = x_yes; then
1396	STUBBY="stubby"
1397	INSTALL_STUBBY="install-stubby"
1398	UNINSTALL_STUBBY="uninstall-stubby"
1399	if test $my_with_yaml = 0
1400	then
1401		STUBBY_XTRA_OBJS="convert_yaml_to_json.lo gbuffer.lo"
1402		stubby_with_yaml=1
1403		my_with_yaml=1
1404	fi
1405else
1406	STUBBY=""
1407	INSTALL_STUBBY=""
1408	UNINSTALL_STUBBY=""
1409	STUBBY_XTRA_OBJS=""
1410fi
1411AC_SUBST(STUBBY)
1412AC_SUBST(INSTALL_STUBBY)
1413AC_SUBST(UNINSTALL_STUBBY)
1414AC_SUBST(STUBBY_XTRA_OBJS)
1415
1416STUBBY_LIBS=""
1417STUBBY_LDFLAGS=""
1418
1419if test $my_with_yaml = 1
1420then
1421	if test $stubby_with_yaml = 1
1422	then
1423		getdns_LIBS="$LIBS"
1424		getdns_LDFLAGS="$LDFLAGS"
1425		LIBS="$initial_LIBS"
1426		LDFLAGS="$initial_LDFLAGS"
1427	fi
1428	AC_ARG_WITH(libyaml, AS_HELP_STRING([--with-libyaml=pathname],
1429		[path to libyaml (default: search /usr/local ..)]),
1430		[], [withval="yes"])
1431	if test x_$withval = x_yes; then
1432		for dir in /usr/local /opt/local /usr/pkg /usr/sfw; do
1433			if test -f "$dir/include/yaml.h"; then
1434				CFLAGS="$CFLAGS -I$dir/include"
1435				LDFLAGS="$LDFLAGS -L$dir/lib"
1436				AC_MSG_NOTICE([Found libyaml in $dir])
1437				break
1438			fi
1439		done
1440	else
1441		if test x_$withval != x_no; then
1442			CFLAGS="$CFLAGS -I$withval/include"
1443			LDFLAGS="$LDFLAGS -L$withval/lib"
1444		else
1445			if test $stubby_with_yaml = 1
1446			then
1447    				AC_MSG_ERROR([libyaml required for building Stubby])
1448			fi
1449			my_with_yaml=0
1450		fi
1451	fi
1452	if test $my_with_yaml = 1
1453	then
1454		AC_MSG_NOTICE([Checking for dependency libyaml])
1455		AC_CHECK_LIB([yaml], [yaml_parser_parse], [], [
1456			MISSING_DEPS="${MISSING_DEPS}${MISSING_SEP}libyaml"
1457			MISSING_SEP=", "
1458			found_all_libs=0
1459		])
1460	fi
1461	if test $stubby_with_yaml = 1
1462	then
1463		STUBBY_LDFLAGS="$LDFLAGS"
1464		STUBBY_LIBS="$LIBS"
1465		LIBS="$getdns_LIBS"
1466		LDFLAGS="$getdns_LDFLAGS"
1467	fi
1468fi
1469AC_SUBST(STUBBY_LDFLAGS)
1470AC_SUBST(STUBBY_LIBS)
1471
1472if test $found_all_libs = 0
1473then
1474    AC_MSG_ERROR([Missing dependencies: $MISSING_DEPS])
1475fi
1476
1477AC_CONFIG_FILES([Makefile src/Makefile src/version.c src/getdns/getdns.h src/getdns/getdns_extra.h spec/example/Makefile src/test/Makefile src/tools/Makefile doc/Makefile getdns.pc getdns_ext_event.pc])
1478if [ test -n "$DOXYGEN" ]
1479    then AC_CONFIG_FILES([src/Doxyfile])
1480fi
1481
1482AC_MSG_CHECKING([whether the C compiler (${CC-cc}) supports the __func__ variable])
1483AC_LANG_PUSH(C)
1484AC_COMPILE_IFELSE(
1485	[AC_LANG_PROGRAM([[char*s=__func__;]],[[]])],
1486	[AC_MSG_RESULT([yes])
1487	 AC_DEFINE(HAVE___FUNC__, [1], [Whether the C compiler support the __func__ variable])],
1488	[AC_MSG_RESULT([no])])
1489AC_LANG_POP(C)
1490
1491dnl -----
1492dnl ----- Start of "Things needed for gldns" section
1493dnl -----
1494dnl ---------------------------------------------------------------------------
1495
1496AC_CHECK_HEADERS([stdarg.h stdint.h netinet/in.h arpa/inet.h netdb.h sys/socket.h time.h sys/time.h sys/select.h endian.h limits.h sys/limits.h],,, [AC_INCLUDES_DEFAULT])
1497
1498dnl Check the printf-format attribute (if any)
1499dnl result in HAVE_ATTR_FORMAT.
1500dnl
1501AC_MSG_CHECKING(whether the C compiler (${CC-cc}) accepts the "format" attribute)
1502AC_CACHE_VAL(ac_cv_c_format_attribute,
1503[ac_cv_c_format_attribute=no
1504AC_TRY_COMPILE(
1505[#include <stdio.h>
1506void f (char *format, ...) __attribute__ ((format (printf, 1, 2)));
1507void (*pf) (char *format, ...) __attribute__ ((format (printf, 1, 2)));
1508], [
1509   f ("%s", "str");
1510],
1511[ac_cv_c_format_attribute="yes"],
1512[ac_cv_c_format_attribute="no"])
1513])
1514AC_MSG_RESULT($ac_cv_c_format_attribute)
1515if test $ac_cv_c_format_attribute = yes; then
1516  AC_DEFINE(HAVE_ATTR_FORMAT, 1, [Whether the C compiler accepts the "format" attribute])
1517fi
1518
1519AC_MSG_CHECKING(whether the C compiler (${CC-cc}) accepts the "unused" attribute)
1520AC_CACHE_VAL(ac_cv_c_unused_attribute,
1521[ac_cv_c_unused_attribute=no
1522AC_TRY_COMPILE(
1523[#include <stdio.h>
1524void f (char *u __attribute__((unused)));
1525], [
1526   f ("x");
1527],
1528[ac_cv_c_unused_attribute="yes"],
1529[ac_cv_c_unused_attribute="no"])
1530])
1531AC_MSG_RESULT($ac_cv_c_unused_attribute)
1532if test $ac_cv_c_unused_attribute = yes; then
1533  AC_DEFINE(HAVE_ATTR_UNUSED, 1, [Whether the C compiler accepts the "unused" attribute])
1534fi
1535# Check for libbsd, so that the next function checks pick it as their
1536# system implementation.
1537PKG_CHECK_MODULES([LIBBSD],[libbsd-overlay],[
1538LIBS="$LIBS $LIBBSD_LIBS"
1539STUBBY_LIBS="$STUBBY_LIBS $LIBBSD_LIBS"
1540CFLAGS="$CFLAGS $LIBBSD_CFLAGS"
1541],[
1542AC_MSG_WARN([libbsd not found or usable; using embedded code instead])
1543])
1544AC_CHECK_DECLS([inet_pton,inet_ntop,strlcpy,arc4random,arc4random_uniform], [], [], [
1545AC_INCLUDES_DEFAULT
1546#ifdef HAVE_WS2TCPIP_H
1547#include <ws2tcpip.h>
1548#endif
1549])
1550AS_IF([test "x$ac_cv_have_decl_inet_pton" = xyes],
1551    [],
1552    [AC_REPLACE_FUNCS(inet_pton)]
1553)
1554AS_IF([test "x$ac_cv_have_decl_inet_ntop" = xyes],
1555    [],
1556    [AC_REPLACE_FUNCS(inet_ntop)]
1557)
1558AC_REPLACE_FUNCS(strlcpy)
1559AC_REPLACE_FUNCS(arc4random)
1560AC_REPLACE_FUNCS(arc4random_uniform)
1561if test "$ac_cv_func_arc4random" = "no"; then
1562	AC_LIBOBJ(explicit_bzero)
1563	AC_LIBOBJ(arc4_lock)
1564	AC_CHECK_FUNCS([getentropy],,[
1565	    if test "$USE_WINSOCK" = 1; then
1566		AC_LIBOBJ(getentropy_win)
1567	    else
1568		case `uname` in
1569		Darwin)
1570			AC_LIBOBJ(getentropy_osx)
1571		;;
1572		SunOS)
1573			AC_LIBOBJ(getentropy_solaris)
1574			AC_CHECK_HEADERS([sys/sha2.h],, [
1575				AC_CHECK_FUNCS([SHA512_Update],,[
1576					AC_LIBOBJ(sha512)
1577				])
1578			], [AC_INCLUDES_DEFAULT])
1579			if test "$ac_cv_header_sys_sha2_h" = "yes"; then
1580				# this lib needed for sha2 on solaris
1581				LIBS="$LIBS -lmd"
1582			fi
1583			AC_SEARCH_LIBS([clock_gettime], [rt])
1584		;;
1585		Linux|*)
1586			AC_LIBOBJ(getentropy_linux)
1587			dnl AC_CHECK_FUNCS([SHA512_Update],,[
1588			dnl	AC_DEFINE([COMPAT_SHA512], [1], [Do sha512 definitions in config.h])
1589			dnl	AC_LIBOBJ(sha512)
1590			dnl])
1591			AC_CHECK_HEADERS([sys/sysctl.h],,, [AC_INCLUDES_DEFAULT])
1592			AC_CHECK_FUNCS([getauxval])
1593			AC_SEARCH_LIBS([clock_gettime], [rt])
1594		;;
1595		esac
1596	    fi
1597	])
1598fi
1599
1600AC_TYPE_SIGNAL
1601
1602case `uname` in
1603FreeBSD)
1604	C99COMPATFLAGS=""
1605;;
1606*)
1607	C99COMPATFLAGS="-D_POSIX_C_SOURCE=200112L -D_XOPEN_SOURCE=600"
1608;;
1609esac
1610AC_SUBST(C99COMPATFLAGS)
1611
1612AC_DEFINE_UNQUOTED([MAX_CNAME_REFERRALS], [100], [The maximum number of cname referrals.])
1613AC_DEFINE_UNQUOTED([DRAFT_RRTYPES], [1], [Define this to enable all rrtypes in gldns.])
1614
1615AH_BOTTOM([
1616
1617#ifdef HAVE___FUNC__
1618#define __FUNC__ __func__
1619#else
1620#define __FUNC__ __FUNCTION__
1621#endif
1622
1623#ifdef GETDNS_ON_WINDOWS
1624 /* On windows it is allowed to increase the FD_SETSIZE
1625  * (and necessary to make our custom eventloop work)
1626  * See: https://support.microsoft.com/en-us/kb/111855
1627  */
1628# ifndef FD_SETSIZE
1629#  define FD_SETSIZE 1024
1630# endif
1631
1632/* the version of the windows API enabled */
1633# ifndef WINVER
1634#  define WINVER 0x0600 // 0x0502
1635# endif
1636# ifndef _WIN32_WINNT
1637#  define _WIN32_WINNT 0x0600 // 0x0502
1638# endif
1639# ifdef HAVE_WS2TCPIP_H
1640#  include <ws2tcpip.h>
1641# endif
1642
1643# ifdef _MSC_VER
1644#  if _MSC_VER >= 1800
1645#   define PRIsz "zu"
1646#  else
1647#   define PRIsz "Iu"
1648#  endif
1649# else
1650#  define PRIsz "Iu"
1651# endif
1652
1653# ifdef HAVE_WINSOCK2_H
1654#  include <winsock2.h>
1655# endif
1656
1657/* detect if we need to cast to unsigned int for FD_SET to avoid warnings */
1658# ifdef HAVE_WINSOCK2_H
1659#  define FD_SET_T (u_int)
1660# else
1661#  define FD_SET_T
1662# endif
1663
1664 /* Windows wants us to use _strdup instead of strdup */
1665# ifndef strdup
1666#  define strdup _strdup
1667# endif
1668#else
1669# define PRIsz "zu"
1670#endif
1671
1672#include <stdint.h>
1673#include <stdio.h>
1674#include <unistd.h>
1675#include <assert.h>
1676#include <string.h>
1677
1678#ifdef __cplusplus
1679extern "C" {
1680#endif
1681
1682#if STDC_HEADERS
1683#include <stdlib.h>
1684#include <stddef.h>
1685#endif
1686
1687#if !defined(HAVE_STRLCPY) || !HAVE_DECL_STRLCPY || !defined(strlcpy)
1688size_t strlcpy(char *dst, const char *src, size_t siz);
1689#else
1690#ifndef __BSD_VISIBLE
1691#define __BSD_VISIBLE 1
1692#endif
1693#endif
1694#if !defined(HAVE_ARC4RANDOM) || !HAVE_DECL_ARC4RANDOM
1695uint32_t arc4random(void);
1696#endif
1697#if !defined(HAVE_ARC4RANDOM_UNIFORM) || !HAVE_DECL_ARC4RANDOM_UNIFORM
1698uint32_t arc4random_uniform(uint32_t upper_bound);
1699#endif
1700#ifndef HAVE_ARC4RANDOM
1701void explicit_bzero(void* buf, size_t len);
1702int getentropy(void* buf, size_t len);
1703void arc4random_buf(void* buf, size_t n);
1704void _ARC4_LOCK(void);
1705void _ARC4_UNLOCK(void);
1706#endif
1707#ifdef COMPAT_SHA512
1708#ifndef SHA512_DIGEST_LENGTH
1709#define SHA512_BLOCK_LENGTH             128
1710#define SHA512_DIGEST_LENGTH            64
1711#define SHA512_DIGEST_STRING_LENGTH     (SHA512_DIGEST_LENGTH * 2 + 1)
1712typedef struct _SHA512_CTX {
1713        uint64_t        state[8];
1714        uint64_t        bitcount[2];
1715        uint8_t buffer[SHA512_BLOCK_LENGTH];
1716} SHA512_CTX;
1717#endif /* SHA512_DIGEST_LENGTH */
1718void SHA512_Init(SHA512_CTX*);
1719void SHA512_Update(SHA512_CTX*, void*, size_t);
1720void SHA512_Final(uint8_t[SHA512_DIGEST_LENGTH], SHA512_CTX*);
1721unsigned char *SHA512(void* data, unsigned int data_len, unsigned char *digest);
1722#endif /* COMPAT_SHA512 */
1723
1724#ifndef HAVE_DECL_INET_PTON
1725int inet_pton(int af, const char* src, void* dst);
1726#endif /* HAVE_INET_PTON */
1727
1728#ifndef HAVE_DECL_INET_NTOP
1729const char *inet_ntop(int af, const void *src, char *dst, size_t size);
1730#endif
1731
1732#ifdef USE_WINSOCK
1733# ifndef  _CUSTOM_VSNPRINTF
1734#  define _CUSTOM_VSNPRINTF
1735static inline int _gldns_custom_vsnprintf(char *str, size_t size, const char *format, va_list ap)
1736{ int r = vsnprintf(str, size, format, ap); return r == -1 ? _vscprintf(format, ap) : r; }
1737#  define vsnprintf _gldns_custom_vsnprintf
1738# endif
1739#endif
1740
1741#ifdef __cplusplus
1742}
1743#endif
1744
1745/** Use on-board gldns */
1746#define USE_GLDNS 1
1747#ifdef HAVE_SSL
1748#  define GLDNS_BUILD_CONFIG_HAVE_SSL 1
1749#endif
1750
1751#ifdef HAVE_STDARG_H
1752#include <stdarg.h>
1753#endif
1754
1755#include <errno.h>
1756
1757#ifdef HAVE_SYS_SOCKET_H
1758#include <sys/socket.h>
1759#endif
1760
1761#ifdef HAVE_NETINET_TCP_H
1762#include <netinet/tcp.h>
1763#endif
1764
1765#ifdef HAVE_SYS_SELECT_H
1766#include <sys/select.h>
1767#endif
1768
1769#ifdef HAVE_SYS_TYPES_H
1770#include <sys/types.h>
1771#endif
1772
1773#ifdef HAVE_SYS_STAT_H
1774#include <sys/stat.h>
1775#endif
1776
1777#ifdef HAVE_NETINET_IN_H
1778#include <netinet/in.h>
1779#endif
1780
1781#ifdef HAVE_ARPA_INET_H
1782#include <arpa/inet.h>
1783#endif
1784
1785#ifdef HAVE_INTTYPES_H
1786#include <inttypes.h>
1787#endif
1788
1789#ifdef HAVE_LIMITS_H
1790#include <limits.h>
1791#endif
1792
1793#ifdef HAVE_SYS_LIMITS_H
1794#include <sys/limits.h>
1795#endif
1796
1797#ifdef PATH_MAX
1798#define _GETDNS_PATH_MAX PATH_MAX
1799#else
1800#define _GETDNS_PATH_MAX 2048
1801#endif
1802
1803#ifndef PRIu64
1804#define PRIu64 "llu"
1805#endif
1806
1807#ifdef HAVE_ATTR_FORMAT
1808#  define ATTR_FORMAT(archetype, string_index, first_to_check) \
1809    __attribute__ ((format (archetype, string_index, first_to_check)))
1810#else /* !HAVE_ATTR_FORMAT */
1811#  define ATTR_FORMAT(archetype, string_index, first_to_check) /* empty */
1812#endif /* !HAVE_ATTR_FORMAT */
1813
1814#if defined(DOXYGEN)
1815#  define ATTR_UNUSED(x)  x
1816#elif defined(__cplusplus)
1817#  define ATTR_UNUSED(x)
1818#elif defined(HAVE_ATTR_UNUSED)
1819#  define ATTR_UNUSED(x)  x __attribute__((unused))
1820#else /* !HAVE_ATTR_UNUSED */
1821#  define ATTR_UNUSED(x)  x
1822#endif /* !HAVE_ATTR_UNUSED */
1823
1824#ifdef TIME_WITH_SYS_TIME
1825# include <sys/time.h>
1826# include <time.h>
1827#else
1828# ifdef HAVE_SYS_TIME_H
1829#  include <sys/time.h>
1830# else
1831#  include <time.h>
1832# endif
1833#endif
1834
1835#ifdef __cplusplus
1836extern "C" {
1837#endif
1838
1839#if !defined(HAVE_STRPTIME) || !defined(STRPTIME_WORKS)
1840#define strptime unbound_strptime
1841struct tm;
1842char *strptime(const char *s, const char *format, struct tm *tm);
1843#endif
1844
1845#if !defined(HAVE_SIGSET_T) && defined(HAVE__SIGSET_T)
1846typedef _sigset_t sigset_t;
1847#endif
1848#if !defined(HAVE_SIGEMPTYSET)
1849#  define sigemptyset(pset)    (*(pset) = 0)
1850#endif
1851#if !defined(HAVE_SIGFILLSET)
1852#  define sigfillset(pset)     (*(pset) = (sigset_t)-1)
1853#endif
1854#if !defined(HAVE_SIGADDSET)
1855#  define sigaddset(pset, num) (*(pset) |= (1L<<(num)))
1856#endif
1857
1858#ifdef HAVE_LIBUNBOUND
1859# include <unbound.h>
1860# ifdef HAVE_UNBOUND_EVENT_H
1861#  include <unbound-event.h>
1862# else
1863#  ifdef HAVE_UNBOUND_EVENT_API
1864#   ifndef _UB_EVENT_PRIMITIVES
1865#    define _UB_EVENT_PRIMITIVES
1866struct ub_event_base;
1867struct ub_ctx* ub_ctx_create_ub_event(struct ub_event_base* base);
1868typedef void (*ub_event_callback_t)(void*, int, void*, int, int, char*);
1869int ub_resolve_event(struct ub_ctx* ctx, const char* name, int rrtype,
1870        int rrclass, void* mydata, ub_event_callback_t callback, int* async_id);
1871#   endif
1872#  endif
1873# endif
1874#endif
1875
1876#ifdef __cplusplus
1877}
1878#endif
1879])
1880
1881dnl ---------------------------------------------------------------------------
1882dnl -----
1883dnl ----- End of "Things needed for gldns" section
1884dnl -----
1885
1886
1887AC_CONFIG_HEADER([src/config.h])
1888AC_OUTPUT
1889