configure.ac 55.5 KB
Newer Older
1 2
#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
3 4
# known to work with autconf version: autoconf (GNU Autoconf) 2.69
#
5 6
# @configure_input@
#
7
# Copyright (c) 2013, Verisign, Inc., NLnet Labs
8
# All rights reserved.
9
#
10 11 12 13 14 15 16
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
#   notice, this list of conditions and the following disclaimer in the
#   documentation and/or other materials provided with the distribution.
17
# * Neither the names of the copyright holders nor the
18 19
#   names of its contributors may be used to endorse or promote products
#   derived from this software without specific prior written permission.
20
#
21 22 23 24 25 26 27 28 29 30
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31

32
AC_PREREQ([2.68])
33
AC_CONFIG_MACRO_DIRS([m4])
34
sinclude(./m4/acx_openssl.m4)
35
sinclude(./m4/acx_getaddrinfo.m4)
36 37
sinclude(./m4/ax_check_compile_flag.m4)
sinclude(./m4/pkg.m4)
38

39
AC_INIT([getdns], [1.5.1], [team@getdnsapi.net], [getdns], [https://getdnsapi.net])
40

41 42 43 44 45 46 47 48 49 50 51
# Autoconf 2.70 will have set up runstatedir. 2.69 is frequently (Debian)
# patched to do the same, but frequently (MacOS) not. So add a with option
# for pid file location, and default it to runstatedir if present.
default_piddir=${runstatedir:-"${localstatedir}/run"}
AC_ARG_WITH([piddir],
  [AS_HELP_STRING([--with-piddir=DIR],
                  [directory for pid files @<:@default=RUNSTATEDIR or LOCALSTATEDIR/run@:>@])],
  [],
  [with_piddir=${default_piddir}])
AC_SUBST([runstatedir], [$with_piddir])

52
# Don't forget to put a dash in front of the release candidate!!!
53 54
# That is how it is done with semantic versioning!
#
Willem Toorop's avatar
Willem Toorop committed
55
AC_SUBST(RELEASE_CANDIDATE, [])
56
AC_SUBST(STUBBY_RELEASE_CANDIDATE, [])
57 58 59 60 61 62

# Set current date from system if not set
AC_ARG_WITH([current-date],
  [AS_HELP_STRING([--with-current-date]
    [current date of the compilation, set to fixed date for reproducible builds @<:@default=system@:>@])],
  [CURRENT_DATE="$with_current_date"],
63
  [CURRENT_DATE="`date -u +%Y-%m-%dT%H:%M:%SZ`"])
64 65

AC_SUBST(GETDNS_VERSION, ["AC_PACKAGE_VERSION$RELEASE_CANDIDATE"])
66
AC_SUBST(GETDNS_NUMERIC_VERSION, [0x01050100])
67 68
AC_SUBST(API_VERSION, ["December 2015"])
AC_SUBST(API_NUMERIC_VERSION, [0x07df0c00])
69 70
GETDNS_COMPILATION_COMMENT="AC_PACKAGE_NAME $GETDNS_VERSION configured on $CURRENT_DATE for the $API_VERSION version of the API"

71
AC_DEFINE_UNQUOTED([STUBBY_PACKAGE], ["stubby"], [Stubby package])
72
AC_DEFINE_UNQUOTED([STUBBY_PACKAGE_STRING], ["0.2.5$STUBBY_RELEASE_CANDIDATE"], [Stubby package string])
73 74 75 76 77 78 79 80 81 82 83 84 85 86

# Library version
# ---------------
# current:revision:age
# (binary-api-number):(which-binary-api-version):(how-many-nrs-backwardscompat)
# if source code changes increment revision
# if any interfaces have been added/removed/changed since last update then
#   increment current and set revision to 0
# if any interfaces have been added since the last public release then increment age
# if any interfaces have been removed or changed since the last public release then
#   set age to 0
#
# getdns-0.1.4 had libversion 0:0:0
# getdns-0.1.5 had libversion 1:0:0
Willem Toorop's avatar
Willem Toorop committed
87
# getdns-0.1.6 had libversion 1:1:0
88 89
# getdns-0.1.7 had libversion 1:2:1 (but should have had 2:0:1)
# getdns-0.1.8 had libversion 1:3:0 (but should have had 2:1:1)
Willem Toorop's avatar
Willem Toorop committed
90
# getdns-0.2.0 had libversion 2:2:1
91
# getdns-0.3.0 had libversion 3:3:2
Willem Toorop's avatar
Willem Toorop committed
92
# getdns-0.3.1 had libversion 3:4:2
Willem Toorop's avatar
Willem Toorop committed
93
# getdns-0.3.2 had libversion 3:5:2
94 95
# getdns-0.3.3 had libversion 3:6:2
# getdns-0.5.0 had libversion 4:0:3
96
# getdns-0.5.1 had libversion 4:1:3 (but should have been getdns-0.6.0)
Willem Toorop's avatar
Willem Toorop committed
97
# getdns-0.9.0 had libversion 5:0:4
Willem Toorop's avatar
Willem Toorop committed
98 99
# getdns-1.0.0 had libversion 5:1:4
# getdns-1.1.0 had libversion 6:0:0
Willem Toorop's avatar
Willem Toorop committed
100
# getdns-1.1.1 had libversion 6:1:0
101 102
# getdns-1.1.2 had libversion 7:0:1
# getdns-1.1.3 had libversion 7:1:1
Willem Toorop's avatar
Willem Toorop committed
103
# getdns-1.2.0 had libversion 8:0:2
Willem Toorop's avatar
Willem Toorop committed
104
# getdns-1.2.1 had libversion 8:1:2
Willem Toorop's avatar
Willem Toorop committed
105
# getdns-1.3.0 had libversion 9:0:3
106
# getdns-1.4.0 had libversion 10:0:0
Willem Toorop's avatar
Willem Toorop committed
107
# getdns-1.4.1 had libversion 10:1:0
Willem Toorop's avatar
Willem Toorop committed
108 109
# getdns-1.4.2 had libversion 10:2:0
# getdns-1.5.0 has libversion 11:0:1
110 111
# getdns-1.5.1 has libversion 11:1:1
GETDNS_LIBVERSION=11:1:1
112

113
AC_SUBST(GETDNS_COMPILATION_COMMENT)
114
AC_SUBST(GETDNS_LIBVERSION)
115
AC_CONFIG_SRCDIR([src/getdns/getdns.h.in])
Melinda Shore's avatar
Melinda Shore committed
116 117
# AM_INIT_AUTOMAKE
# LT_INIT
118
AC_CONFIG_MACRO_DIR([m4])
119

120 121 122
AC_PROG_CC
AC_PROG_CPP

123
# Checks for programs.
124
HOSTOS="unix"
Melinda Shore's avatar
Melinda Shore committed
125
AC_CANONICAL_HOST
126 127 128 129 130 131 132 133 134 135
case "${host_os}" in
cygwin*|mingw*)
	HOSTOS=windows
	;;
darwin*)
	HOSTOS=macos
	;;
esac
AC_SUBST(HOSTOS)

136 137

CFLAGS="$CFLAGS"
138 139
WPEDANTICFLAG=""
WNOERRORFLAG=""
140 141 142
AC_PROG_CC_C99
AX_CHECK_COMPILE_FLAG([-xc99],[CFLAGS="$CFLAGS -xc99"],[],[])
AX_CHECK_COMPILE_FLAG([-Wall],[CFLAGS="$CFLAGS -Wall"],[],[])
143 144 145
AX_CHECK_COMPILE_FLAG([-Wextra],[CFLAGS="$CFLAGS -Wextra"],[],[])
AX_CHECK_COMPILE_FLAG([-Wpedantic],[WPEDANTICFLAG="-Wpedantic"],[],[])
AX_CHECK_COMPILE_FLAG([-Wno-error=unused-parameter],[WNOERRORFLAG="-Wno-error=unused-parameter"],[],[])
146
AX_CHECK_COMPILE_FLAG([-Wno-unused-parameter],[WNOERRORFLAG="$WNOERRORFLAG -Wno-unused-parameter"],[],[])
147 148
AC_SUBST(WPEDANTICFLAG)
AC_SUBST(WNOERRORFLAG)
149

Melinda Shore's avatar
Melinda Shore committed
150
case "$host_os" in
151
  linux* ) CFLAGS="$CFLAGS -D_BSD_SOURCE -D_DEFAULT_SOURCE"
152 153 154
  ;;
  solaris* ) CFLAGS="$CFLAGS -D__EXTENSIONS__"  # for strdup() from <string.h>
  ;;
155 156
  darwin* ) CFLAGS="$CFLAGS -D_DARWIN_C_SOURCE"  # for strlcpy() from <string.h>
  ;;
Melinda Shore's avatar
Melinda Shore committed
157 158
esac

159 160 161 162 163 164 165 166
# always use ./libtool unless override from commandline (libtool=mylibtool)
if test -z "$libtool"; then
	libtool="`pwd`/libtool"
fi
AC_SUBST(libtool)
AC_PROG_LIBTOOL
AC_PROG_INSTALL

167

168 169
initial_LIBS="$LIBS"
initial_LDFLAGS="$LDFLAGS"
170

171 172 173 174 175 176
dnl Add option to disable the evil rpath. Check whether to use rpath or not.
dnl Adds the --disable-rpath option. Uses trick to edit the ./libtool.
AC_DEFUN([ACX_ARG_RPATH],
[
AC_ARG_ENABLE(rpath,
        [  --disable-rpath         disable hardcoded rpath (default=enabled)],
177
	enable_rpath="$enableval", enable_rpath=yes)
178 179 180 181 182 183 184 185 186 187 188 189 190
if test "x$enable_rpath" = xno; then
	dnl AC_MSG_RESULT([Fixing libtool for -rpath problems.])
	AC_CONFIG_COMMANDS([disable-rpath], [
	sed < libtool > libtool-2 \
	's/^hardcode_libdir_flag_spec.*$'/'hardcode_libdir_flag_spec=" -D__LIBTOOL_RPATH_SED__ "/'
	mv libtool-2 libtool
	chmod 755 libtool
	libtool="./libtool"
	])
fi
])
ACX_ARG_RPATH

191
AC_ARG_ENABLE(debug-req, AC_HELP_STRING([--enable-debug-req], [Enable request debugging]))
192
AC_ARG_ENABLE(debug-sched, AC_HELP_STRING([--enable-debug-sched], [Enable scheduling debugging messages]))
193
AC_ARG_ENABLE(debug-stub, AC_HELP_STRING([--enable-debug-stub], [Enable stub debugging messages]))
194
AC_ARG_ENABLE(debug-daemon, AC_HELP_STRING([--enable-debug-daemon], [Enable daemon debugging messages]))
195
AC_ARG_ENABLE(debug-sec, AC_HELP_STRING([--enable-debug-sec], [Enable dnssec debugging messages]))
196
AC_ARG_ENABLE(debug-server, AC_HELP_STRING([--enable-debug-server], [Enable server debugging messages]))
197
AC_ARG_ENABLE(debug-anchor, AC_HELP_STRING([--enable-debug-anchor], [Enable anchor debugging messages]))
198 199 200
AC_ARG_ENABLE(all-debugging, AC_HELP_STRING([--enable-all-debugging], [Enable scheduling, stub and dnssec debugging]))
case "$enable_all_debugging" in
	yes)
201
		enable_debug_req=yes
202 203
		enable_debug_sched=yes
		enable_debug_stub=yes
204
		enable_debug_daemon=yes
205
		enable_debug_sec=yes
206
		enable_debug_server=yes
207
		enable_debug_anchor=yes
208 209 210 211
		;;
	no|*)
		;;
esac
212 213 214 215 216 217 218
case "$enable_debug_req" in
	yes)
		AC_DEFINE_UNQUOTED([REQ_DEBUG], [1], [Define this to enable printing of request debugging messages.])
		;;
	no|*)
		;;
esac
219 220 221 222 223 224 225 226 227 228 229 230 231 232
case "$enable_debug_sched" in
	yes)
		AC_DEFINE_UNQUOTED([SCHED_DEBUG], [1], [Define this to enable printing of scheduling debugging messages.])
		;;
	no|*)
		;;
esac
case "$enable_debug_stub" in
	yes)
		AC_DEFINE_UNQUOTED([STUB_DEBUG], [1], [Define this to enable printing of stub debugging messages.])
		;;
	no|*)
		;;
esac
233 234 235 236 237 238 239
case "$enable_debug_daemon" in
	yes)
		AC_DEFINE_UNQUOTED([DAEMON_DEBUG], [1], [Define this to enable printing of daemon debugging messages.])
		;;
	no|*)
		;;
esac
240 241 242 243 244 245 246
case "$enable_debug_sec" in
	yes)
		AC_DEFINE_UNQUOTED([SEC_DEBUG], [1], [Define this to enable printing of dnssec debugging messages.])
		;;
	no|*)
		;;
esac
247
case "$enable_debug_server" in
248
	yes)
249
		AC_DEFINE_UNQUOTED([SERVER_DEBUG], [1], [Define this enable printing of server debugging messages.])
250 251 252 253
		;;
	no|*)
		;;
esac
254 255 256 257 258 259 260
case "$enable_debug_anchor" in
	yes)
		AC_DEFINE_UNQUOTED([ANCHOR_DEBUG], [1], [Define this enable printing of anchor debugging messages.])
		;;
	no|*)
		;;
esac
261 262 263 264 265 266 267 268 269 270 271 272


dnl  Hidden debugging options
dnl
AC_ARG_ENABLE(debug-keep-connections-open,[])
case "$enable_debug_keep_connections_open" in
	yes)
		AC_DEFINE_UNQUOTED([KEEP_CONNECTIONS_OPEN_DEBUG], [1], [Do not set this])
		;;
	no)
		;;
esac
273

274 275

DEFAULT_EVENTLOOP=select_eventloop
276
AC_CHECK_HEADERS([signal.h sys/poll.h poll.h sys/resource.h sys/types.h sys/stat.h],,, [AC_INCLUDES_DEFAULT])
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297
AC_ARG_ENABLE(poll-eventloop, AC_HELP_STRING([--disable-poll-eventloop], [Disable default eventloop based on poll (default=enabled if available)]))
case "$enable_poll_eventloop" in
	no)
		;;
	yes|*)
AC_MSG_CHECKING(for poll)
AC_LINK_IFELSE([AC_LANG_PROGRAM([
#ifdef HAVE_SYS_POLL_H
#include <sys/poll.h>
#else
#include <poll.h>
#endif
], [int rc; rc = poll((struct pollfd *)(0), 0, 0);])], [
AC_MSG_RESULT(yes)
AC_DEFINE_UNQUOTED([USE_POLL_DEFAULT_EVENTLOOP], [1], [Define this to enable a default eventloop based on poll().])
DEFAULT_EVENTLOOP=poll_eventloop
],[AC_MSG_RESULT(no)])
		;;
esac
AC_SUBST(DEFAULT_EVENTLOOP)

298 299 300 301 302
AC_ARG_ENABLE(tcp-fastopen, AC_HELP_STRING([--disable-tcp-fastopen], Disable TCP Fast Open (default=enabled if available)),
    enable_tcp_fastopen="$enableval", enable_tcp_fastopen=yes)
if test "x$enable_tcp_fastopen" = xno; then
        AC_MSG_WARN([TCP Fast Open is disabled])
else
303 304 305 306 307 308 309 310 311 312
    case `uname` in
        Linux) AC_CHECK_DECL([MSG_FASTOPEN], [AC_DEFINE_UNQUOTED([USE_TCP_FASTOPEN], [1], [Define this to enable TCP fast open.])],
                          [AC_MSG_WARN([TCP Fast Open is not available, continuing without])], [#include <sys/socket.h>])
          ;;
        Darwin) AC_CHECK_DECL([CONNECT_RESUME_ON_READ_WRITE], [AC_DEFINE_UNQUOTED([USE_OSX_TCP_FASTOPEN], [1], [Define this to enable TCP fast open.])],
                      [AC_MSG_WARN([TCP Fast Open is not available, continuing without])], [#include <sys/socket.h>])
          ;;
        *) AC_MSG_WARN([TCP Fast Open is not available, continuing without])
          ;;
    esac
313
fi
314

Willem Toorop's avatar
Willem Toorop committed
315
AC_ARG_ENABLE(native-stub-dnssec, AC_HELP_STRING([--disable-native-stub-dnssec], [Disable native stub DNSSEC support]))
316 317
case "$enable_native_stub_dnssec" in
	no)
318
		;;
Willem Toorop's avatar
Willem Toorop committed
319 320
	yes|*)
		AC_DEFINE_UNQUOTED([STUB_NATIVE_DNSSEC], [1], [Define this to enable native stub DNSSEC support.])
321 322 323
		;;
esac

Willem Toorop's avatar
Willem Toorop committed
324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350
# check wether strptime also works
AC_DEFUN([AC_CHECK_STRPTIME_WORKS],
[AC_REQUIRE([AC_PROG_CC])
AC_MSG_CHECKING(whether strptime works)
if test c${cross_compiling} = cno; then
AC_RUN_IFELSE([AC_LANG_SOURCE([[
#define _XOPEN_SOURCE 600
#include <time.h>
int main(void) { struct tm tm; char *res;
res = strptime("2010-07-15T00:00:00+00:00", "%t%Y%t-%t%m%t-%t%d%tT%t%H%t:%t%M%t:%t%S%t", &tm);
if (!res) return 2;
res = strptime("20070207111842", "%Y%m%d%H%M%S", &tm);
if (!res) return 1; return 0; }
]])] , [eval "ac_cv_c_strptime_works=yes"], [eval "ac_cv_c_strptime_works=no"])
else
eval "ac_cv_c_strptime_works=maybe"
fi
AC_MSG_RESULT($ac_cv_c_strptime_works)
if test $ac_cv_c_strptime_works = no; then
AC_LIBOBJ(strptime)
else
AC_DEFINE_UNQUOTED([STRPTIME_WORKS], 1, [use default strptime.])
fi
])dnl

AC_CHECK_FUNCS([strptime],[AC_CHECK_STRPTIME_WORKS],[AC_LIBOBJ([strptime])])

351 352 353 354 355
# search to set include and library paths right
# find libidn (no libidn on windows though)
AC_CHECK_HEADERS([windows.h winsock.h stdio.h winsock2.h ws2tcpip.h],,, [AC_INCLUDES_DEFAULT])
ACX_CHECK_GETADDRINFO_WITH_INCLUDES

356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371
AC_ARG_WITH(resolvconf, AS_HELP_STRING([--with-resolvconf=PATH],
	[Set the resolver configuration file path.  Defaults to /etc/resolv.conf or values retrieved via GetNetworkParams() on Windows]),
	[], [withval="/etc/resolv.conf"])
AC_DEFINE_UNQUOTED([GETDNS_FN_RESOLVCONF], ["$withval"], [Path to resolver configuration file])

AC_ARG_WITH(hosts, AS_HELP_STRING([--with-hosts=PATH],
	[Set the static table lookup for hostnames path.  Defaults to /etc/hosts or C:\Windows\System32\Drivers\etc\hosts on Windows]),
	[], [
if test "$USE_WINSOCK" = 1; then
	withval="C:\\\\Windows\\\\System32\\\\Drivers\\\\etc\\\\hosts"
else
	withval="/etc/hosts"
fi
])
AC_DEFINE_UNQUOTED([GETDNS_FN_HOSTS], ["$withval"], [Path to static table lookup for hostnames])

372 373 374 375 376 377 378 379 380 381 382 383
AC_ARG_WITH(fd-setsize, AS_HELP_STRING([--with-fd-setsize=size],
	[Set maximum file descriptor number that can be used by select]),
	[], [withval="no"])
case "$withval" in
no)
	;;
*)
	AC_DEFINE_UNQUOTED([FD_SETSIZE], [$withval], [Alternate value for the FD_SETSIZE])
	my_enable_unbound_event_api=1
	;;
esac

384 385 386 387
AC_ARG_WITH(max-udp-backoff, AS_HELP_STRING([--with-max-udp-backoff=<number of queries>],
    [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"])
AC_DEFINE_UNQUOTED([UDP_MAX_BACKOFF], [$withval], [Maximum number of queries an failed UDP upstream passes before it will retry])

388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403
#---- check for pthreads library
AC_ARG_WITH(libpthread, AS_HELP_STRING([--without-libpthread],
	[Disable libpthread (default is autodetect)]),
	[], [withval="yes"])

case "$withval" in
yes)
	AC_SEARCH_LIBS([pthread_mutex_init],[pthread], [
		AC_DEFINE([HAVE_PTHREAD], [1], [Have pthreads library])
		LIBS="-lpthread $LIBS"
	], [AC_MSG_WARN([pthreads not available])])
	;;
*)
	;;
esac

404
USE_NSS="no"
Willem Toorop's avatar
Willem Toorop committed
405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422
dnl AC_ARG_WITH([nss], AC_HELP_STRING([--with-nss=path],
dnl         [use libnss instead of openssl, installed at path.]),
dnl         [
dnl         USE_NSS="yes"
dnl         AC_DEFINE(HAVE_NSS, 1, [Use libnss for crypto])
dnl         if test "$withval" != "" -a "$withval" != "yes"; then
dnl                 CPPFLAGS="$CPPFLAGS -I$withval/include/nss3"
dnl                 LDFLAGS="$LDFLAGS -L$withval/lib"
dnl                 ACX_RUNTIME_PATH_ADD([$withval/lib])
dnl                 CPPFLAGS="-I$withval/include/nspr4 $CPPFLAGS"
dnl         else
dnl                 CPPFLAGS="$CPPFLAGS -I/usr/include/nss3"
dnl                 CPPFLAGS="-I/usr/include/nspr4 $CPPFLAGS"
dnl         fi
dnl         LIBS="$LIBS -lnss3 -lnspr4"
dnl         SSLLIB=""
dnl         ]
dnl )
423 424 425

# libnettle
USE_NETTLE="no"
Willem Toorop's avatar
Willem Toorop committed
426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442
dnl AC_ARG_WITH([nettle], AC_HELP_STRING([--with-nettle=path],
dnl         [use libnettle as crypto library, installed at path.]),
dnl         [
dnl         USE_NETTLE="yes"
dnl         AC_DEFINE(HAVE_NETTLE, 1, [Use libnettle for crypto])
dnl         AC_CHECK_HEADERS([nettle/dsa-compat.h],,, [AC_INCLUDES_DEFAULT])
dnl         if test "$withval" != "" -a "$withval" != "yes"; then
dnl                 CPPFLAGS="$CPPFLAGS -I$withval/include/nettle"
dnl                 LDFLAGS="$LDFLAGS -L$withval/lib"
dnl                 ACX_RUNTIME_PATH_ADD([$withval/lib])
dnl         else
dnl                 CPPFLAGS="$CPPFLAGS -I/usr/include/nettle"
dnl         fi
dnl         LIBS="$LIBS -lhogweed -lnettle -lgmp"
dnl         SSLLIB=""
dnl         ]
dnl )
443

444
# openssl
445
if test $USE_NSS = "no" -a $USE_NETTLE = "no"; then
Willem Toorop's avatar
Willem Toorop committed
446 447
ACX_WITH_SSL
fi
448 449 450 451 452 453 454
ACX_LIB_SSL
AC_MSG_CHECKING([for LibreSSL])
if grep VERSION_TEXT $ssldir/include/openssl/opensslv.h | grep "LibreSSL" >/dev/null; then
	AC_MSG_RESULT([yes])
	AC_DEFINE([HAVE_LIBRESSL], [1], [Define if we have LibreSSL])
	# libressl provides these compat functions, but they may also be
	# declared by the OS in libc.  See if they have been declared.
455
	AC_CHECK_DECLS([strlcpy,arc4random,arc4random_uniform])
456 457 458
else
	AC_MSG_RESULT([no])
fi
Willem Toorop's avatar
Willem Toorop committed
459
AC_CHECK_HEADERS([openssl/conf.h openssl/ssl.h],,, [AC_INCLUDES_DEFAULT])
460
AC_CHECK_HEADERS([openssl/engine.h],,, [AC_INCLUDES_DEFAULT])
Willem Toorop's avatar
Willem Toorop committed
461
AC_CHECK_HEADERS([openssl/bn.h openssl/rsa.h openssl/dsa.h],,, [AC_INCLUDES_DEFAULT])
462 463
AC_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 SSL_CTX_set_min_proto_version 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])
AC_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], [], [], [
464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483
AC_INCLUDES_DEFAULT
#ifdef HAVE_OPENSSL_ERR_H
#include <openssl/err.h>
#endif

#ifdef HAVE_OPENSSL_RAND_H
#include <openssl/rand.h>
#endif

#ifdef HAVE_OPENSSL_CONF_H
#include <openssl/conf.h>
#endif

#ifdef HAVE_OPENSSL_ENGINE_H
#include <openssl/engine.h>
#endif
#include <openssl/ssl.h>
#include <openssl/evp.h>
])

484 485 486 487 488 489 490 491 492 493
AC_MSG_CHECKING([whether we need to compile/link DANE support])
DANESSL_XTRA_OBJS=""
AC_LANG_PUSH(C)
AC_COMPILE_IFELSE(
	[AC_LANG_PROGRAM([
		[#include <openssl/opensslv.h>]
		[#if OPENSSL_VERSION_NUMBER <  0x1000000fL]
		[#error "OpenSSL 1.0.0 or higher required for DANE library"]
		[#elif defined(HAVE_SSL_DANE_ENABLE)]
		[#error "OpenSSL has native DANE support"]
494 495
		[#elif defined(LIBRESSL_VERSION_NUMBER)]
		[#error "dane_ssl library does not work with LibreSSL"]
496 497 498 499 500 501 502 503 504 505
		[#endif]
	],[[]])],
	[
		AC_MSG_RESULT([yes])
		AC_DEFINE([USE_DANESSL], [1], [Define this to use DANE functions from the ssl_dane/danessl library.])
		DANESSL_XTRA_OBJS="danessl.lo"
	],
	[AC_MSG_RESULT([no])])
AC_LANG_POP(C)
AC_SUBST(DANESSL_XTRA_OBJS)
506

Willem Toorop's avatar
Willem Toorop committed
507 508 509 510 511 512 513 514 515
AC_ARG_ENABLE(sha1, AC_HELP_STRING([--disable-sha1], [Disable SHA1 RRSIG support, does not disable nsec3 support]))
	case "$enable_sha1" in
	no)
	;;
	yes|*)
	AC_DEFINE([USE_SHA1], [1], [Define this to enable SHA1 support.])
	;;
esac

516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539
AC_ARG_ENABLE(sha2, AC_HELP_STRING([--disable-sha2], [Disable SHA256 and SHA512 RRSIG support]))
case "$enable_sha2" in
	no)
	;;
	yes|*)
	AC_DEFINE([USE_SHA2], [1], [Define this to enable SHA256 and SHA512 support.])
	;;
esac

# check wether gost also works
AC_DEFUN([AC_CHECK_GOST_WORKS],
[AC_REQUIRE([AC_PROG_CC])
AC_MSG_CHECKING([if GOST works])
if test c${cross_compiling} = cno; then
BAKCFLAGS="$CFLAGS"
if test -n "$ssldir"; then
	CFLAGS="$CFLAGS -Wl,-rpath,$ssldir/lib"
fi
AC_RUN_IFELSE([AC_LANG_SOURCE([[
#include <string.h>
#include <openssl/ssl.h>
#include <openssl/evp.h>
#include <openssl/engine.h>
#include <openssl/conf.h>
540
/* routine to load gost (from gldns) */
541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624
int load_gost_id(void)
{
	static int gost_id = 0;
	const EVP_PKEY_ASN1_METHOD* meth;
	ENGINE* e;

	if(gost_id) return gost_id;

	/* see if configuration loaded gost implementation from other engine*/
	meth = EVP_PKEY_asn1_find_str(NULL, "gost2001", -1);
	if(meth) {
		EVP_PKEY_asn1_get0_info(&gost_id, NULL, NULL, NULL, NULL, meth);
		return gost_id;
	}

	/* see if engine can be loaded already */
	e = ENGINE_by_id("gost");
	if(!e) {
		/* load it ourself, in case statically linked */
		ENGINE_load_builtin_engines();
		ENGINE_load_dynamic();
		e = ENGINE_by_id("gost");
	}
	if(!e) {
		/* no gost engine in openssl */
		return 0;
	}
	if(!ENGINE_set_default(e, ENGINE_METHOD_ALL)) {
		ENGINE_finish(e);
		ENGINE_free(e);
		return 0;
	}

	meth = EVP_PKEY_asn1_find_str(&e, "gost2001", -1);
	if(!meth) {
		/* algo not found */
		ENGINE_finish(e);
		ENGINE_free(e);
		return 0;
	}
	EVP_PKEY_asn1_get0_info(&gost_id, NULL, NULL, NULL, NULL, meth);
	return gost_id;
}
int main(void) { 
	EVP_MD_CTX* ctx;
	const EVP_MD* md;
	unsigned char digest[64]; /* its a 256-bit digest, so uses 32 bytes */
	const char* str = "Hello world";
	const unsigned char check[] = {
		0x40 , 0xed , 0xf8 , 0x56 , 0x5a , 0xc5 , 0x36 , 0xe1 ,
		0x33 , 0x7c , 0x7e , 0x87 , 0x62 , 0x1c , 0x42 , 0xe0 ,
		0x17 , 0x1b , 0x5e , 0xce , 0xa8 , 0x46 , 0x65 , 0x4d ,
		0x8d , 0x3e , 0x22 , 0x9b , 0xe1 , 0x30 , 0x19 , 0x9d
	};
	OPENSSL_config(NULL);
	(void)load_gost_id();
	md = EVP_get_digestbyname("md_gost94");
	if(!md) return 1;
	memset(digest, 0, sizeof(digest));
	ctx = EVP_MD_CTX_create();
	if(!ctx) return 2;
	if(!EVP_DigestInit_ex(ctx, md, NULL)) return 3;
	if(!EVP_DigestUpdate(ctx, str, 10)) return 4;
	if(!EVP_DigestFinal_ex(ctx, digest, NULL)) return 5;
	/* uncomment to see the hash calculated.
		{int i;
		for(i=0; i<32; i++)
			printf(" %2.2x", (int)digest[i]);
		printf("\n");}
	*/
	if(memcmp(digest, check, sizeof(check)) != 0)
		return 6;
	return 0;
}
]])] , [eval "ac_cv_c_gost_works=yes"], [eval "ac_cv_c_gost_works=no"])
CFLAGS="$BAKCFLAGS"
else
eval "ac_cv_c_gost_works=maybe"
fi
AC_MSG_RESULT($ac_cv_c_gost_works)
])dnl

AC_ARG_ENABLE(gost, AC_HELP_STRING([--disable-gost], [Disable GOST support]))
use_gost="no"
625
if test $USE_NSS = "no" -a $USE_NETTLE = "no"; then
626 627 628 629 630 631 632 633 634 635 636 637 638
case "$enable_gost" in
	no)
	;;
	*)
	AC_CHECK_FUNC(EVP_PKEY_set_type_str, [:],[AC_MSG_ERROR([OpenSSL 1.0.0 is needed for GOST support])])
	AC_CHECK_FUNC(EC_KEY_new, [], [AC_MSG_ERROR([OpenSSL does not support ECC, needed for GOST support])])
	AC_CHECK_GOST_WORKS
	if test "$ac_cv_c_gost_works" != no; then
		use_gost="yes"
		AC_DEFINE([USE_GOST], [1], [Define this to enable GOST support.])
	fi
	;;
esac
639
fi dnl !USE_NSS && !USE_NETTLE
640 641 642 643 644 645 646

AC_ARG_ENABLE(ecdsa, AC_HELP_STRING([--disable-ecdsa], [Disable ECDSA support]))
use_ecdsa="no"
case "$enable_ecdsa" in
    no)
      ;;
    *)
647
      if test $USE_NSS = "no" -a $USE_NETTLE = "no"; then
648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672
	      AC_CHECK_FUNC(ECDSA_sign, [], [AC_MSG_ERROR([OpenSSL does not support ECDSA: please upgrade or rerun with --disable-ecdsa])])
	      AC_CHECK_FUNC(SHA384_Init, [], [AC_MSG_ERROR([OpenSSL does not support SHA384: please upgrade or rerun with --disable-ecdsa])])
	      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
#include <openssl/evp.h>
	      ])
	      # see if OPENSSL 1.0.0 or later (has EVP MD and Verify independency)
	      AC_MSG_CHECKING([if openssl supports SHA2 and ECDSA with EVP])
	      if grep OPENSSL_VERSION_TEXT $ssldir/include/openssl/opensslv.h | grep "OpenSSL" >/dev/null; then
		if grep OPENSSL_VERSION_NUMBER $ssldir/include/openssl/opensslv.h | grep 0x0 >/dev/null; then
		  AC_MSG_RESULT([no])
		  AC_DEFINE_UNQUOTED([USE_ECDSA_EVP_WORKAROUND], [1], [Define this to enable an EVP workaround for older openssl])
		else
		  AC_MSG_RESULT([yes])
		fi
	      else
		# not OpenSSL, thus likely LibreSSL, which supports it
		AC_MSG_RESULT([yes])
	      fi
      fi
      # we now know we have ECDSA and the required curves.
      AC_DEFINE_UNQUOTED([USE_ECDSA], [1], [Define this to enable ECDSA support.])
      use_ecdsa="yes"
      ;;
esac

Willem Toorop's avatar
Willem Toorop committed
673 674 675 676 677 678
AC_ARG_ENABLE(dsa, AC_HELP_STRING([--disable-dsa], [Disable DSA support]))
case "$enable_dsa" in
    no)
      ;;
    *) dnl default
      # detect if DSA is supported, and turn it off if not.
679
      if test $USE_NSS = "no" -a $USE_NETTLE = "no"; then
680
      AC_CHECK_FUNC(DSA_SIG_new, [
681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701
	AC_CHECK_TYPE(DSA_SIG*, [
		AC_DEFINE_UNQUOTED([USE_DSA], [1], [Define this to enable DSA support.])
	], [if test "x$enable_dsa" = "xyes"; then AC_MSG_ERROR([OpenSSL does not support DSA and you used --enable-dsa.])
	  fi ], [
AC_INCLUDES_DEFAULT
#ifdef HAVE_OPENSSL_ENGINE_H
# include <openssl/engine.h>
#endif

#ifdef HAVE_OPENSSL_RAND_H
#include <openssl/rand.h>
#endif

#ifdef HAVE_OPENSSL_CONF_H
#include <openssl/conf.h>
#endif

#ifdef HAVE_OPENSSL_ENGINE_H
#include <openssl/engine.h>
#endif
])
Willem Toorop's avatar
Willem Toorop committed
702 703
      ], [if test "x$enable_dsa" = "xyes"; then AC_MSG_ERROR([OpenSSL does not support DSA and you used --enable-dsa.])
	  fi ])
704 705 706
      else
      AC_DEFINE_UNQUOTED([USE_DSA], [1], [Define this to enable DSA support.])
      fi
Willem Toorop's avatar
Willem Toorop committed
707 708
      ;;
esac
709

Willem Toorop's avatar
Willem Toorop committed
710 711 712 713 714 715
AC_ARG_ENABLE(ed25519, AC_HELP_STRING([--disable-ed25519], [Disable ED25519 support]))
use_ed25519="no"
case "$enable_ed25519" in
    no)
      ;;
    *)
716
      if test $USE_NSS = "no" -a $USE_NETTLE = "no"; then
Willem Toorop's avatar
Willem Toorop committed
717 718 719 720 721 722 723
              AC_CHECK_DECLS([NID_ED25519], [
                use_ed25519="yes"
              ], [ if test "x$enable_ed25519" = "xyes"; then AC_MSG_ERROR([OpenSSL does not support ED25519 and you used --enable-ed25519.])
                fi ], [AC_INCLUDES_DEFAULT
#include <openssl/evp.h>
              ])
      fi
724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749
      if test $USE_NETTLE = "yes"; then
                AC_CHECK_HEADERS([nettle/eddsa.h], use_ed25519="yes",, [AC_INCLUDES_DEFAULT])
      fi
      if test $use_ed25519 = "yes"; then
                AC_DEFINE_UNQUOTED([USE_ED25519], [1], [Define this to enable ED25519 support.])
      fi
      ;;
esac

AC_ARG_ENABLE(ed448, AC_HELP_STRING([--disable-ed448], [Disable ED448 support]))
use_ed448="no"
case "$enable_ed448" in
    no)
      ;;
    *)
      if test $USE_NSS = "no" -a $USE_NETTLE = "no"; then
              AC_CHECK_DECLS([NID_ED448], [
                use_ed448="yes"
              ], [ if test "x$enable_ed448" = "xyes"; then AC_MSG_ERROR([OpenSSL does not support ED448 and you used --enable-ed448.])
                fi ], [AC_INCLUDES_DEFAULT
#include <openssl/evp.h>
              ])
      fi
      if test $use_ed448 = "yes"; then
                AC_DEFINE_UNQUOTED([USE_ED448], [1], [Define this to enable ED448 support.])
      fi
Willem Toorop's avatar
Willem Toorop committed
750 751 752
      ;;
esac

753
AC_ARG_ENABLE(all-drafts, AC_HELP_STRING([--enable-all-drafts], [Enables the draft mdns client support]))
754 755
case "$enable_all_drafts" in
	yes)
756
		AC_DEFINE_UNQUOTED([HAVE_MDNS_SUPPORT], [1], [Define this to enable the draft mdns client support.])
757 758 759 760
		;;
	no|*)
		;;
esac
761 762 763
AC_ARG_ENABLE(dnssec-roadblock-avoidance, AC_HELP_STRING([--disable-dnssec-roadblock-avoidance], [Disable dnssec roadblock avoidance]))
case "$enable_dnssec_roadblock_avoidance" in
	no)
764
		;;
765 766
	yes|*)
		AC_DEFINE_UNQUOTED([DNSSEC_ROADBLOCK_AVOIDANCE], [1], [Define this to enable the experimental dnssec roadblock avoidance.])
767 768
		;;
esac
769 770 771 772 773 774

AC_ARG_ENABLE(edns-cookies, AC_HELP_STRING([--disable-edns-cookies], [Disable edns cookies]))
case "$enable_edns_cookies" in
	no)
		;;
	yes|*)
775
		if test "x_$HAVE_SSL" != "x_yes"; then
776
			AC_MSG_ERROR([edns cookies need openssl libcrypto which is not available, please rerun with --disable-edns-cookies])
777
		fi
778
		AC_DEFINE_UNQUOTED([EDNS_COOKIES], [1], [Define this to enable the experimental edns cookies.])
779 780
		;;
esac
781
AC_DEFINE_UNQUOTED([EDNS_COOKIE_OPCODE], [10], [The edns cookie option code.])
782
AC_DEFINE_UNQUOTED([EDNS_COOKIE_ROLLOVER_TIME], [(24 * 60 * 60)], [How often the edns client cookie is refreshed.])
783

784
AC_DEFINE_UNQUOTED([MAXIMUM_UPSTREAM_OPTION_SPACE], [3000], [limit for dynamically-generated DNS options])
785
AC_DEFINE_UNQUOTED([EDNS_PADDING_OPCODE], [12], [The edns padding option code.])
786

787 788 789 790 791 792 793 794 795
AC_ARG_ENABLE(draft-mdns-support, AC_HELP_STRING([--enable-draft-mdns-support], [Enable draft mdns client support]))
case "$enable_draft_mdns_support" in
	yes)
		AC_DEFINE_UNQUOTED([HAVE_MDNS_SUPPORT], [1], [Define this to enable the draft mdns client support.])
		;;
	no|*)
		;;
esac

796 797 798 799 800 801 802 803 804 805
my_with_libunbound=1
AC_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.]))
case "$enable_stub_only" in
	yes)
		my_with_libunbound=0
		;;
	no|*)
		;;
esac

806 807
my_with_yaml=0
AC_ARG_ENABLE(yaml-config,)
808
case "$enable_yaml_config" in
809
	yes)
810
		AC_DEFINE_UNQUOTED([USE_YAML_CONFIG], [1], [Define this to enable YAML config support.])
811 812 813 814 815 816 817
		AC_DEFINE_UNQUOTED([HAVE_GETDNS_YAML2DICT], [1], [Define this to enable getdns_yaml2dict function.])

		GETDNS_XTRA_OBJS="convert_yaml_to_json.lo"
		my_with_yaml=1
		;;
	no|*)
		GETDNS_XTRA_OBJS=""
818 819
		;;
esac
820
AC_SUBST(GETDNS_XTRA_OBJS)
821

822 823 824 825 826 827
if test "$USE_WINSOCK" = 1; then
	AC_MSG_NOTICE([ Building on Windows ... YES! ])
	AC_DEFINE_UNQUOTED([GETDNS_ON_WINDOWS], [1], [Define this to enable Windows build.])
	AC_DEFINE_UNQUOTED([STUB_NATIVE_DNSSEC], [1])
	LIBS="$LIBS -lgdi32 -liphlpapi"
fi
828

829 830 831 832 833 834 835 836 837 838
dnl sigset_t or _sigset_t? MinGW is latter by default.
AC_CHECK_TYPES([sigset_t],
               [],
               [AC_CHECK_TYPES([_sigset_t],
                               [],
                               [AC_MSG_ERROR([Can't find type `sigset_t' or type `_sigset_t'])],
                               [AC_INCLUDES_DEFAULT
#ifdef HAVE_SIGNAL_H
#include <signal.h>
#endif
839 840 841
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
842 843 844 845 846 847
                               ])
              ],
              [AC_INCLUDES_DEFAULT
#ifdef HAVE_SIGNAL_H
#include <signal.h>
#endif
848 849 850 851
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
])
852 853
AC_CHECK_FUNCS(sigemptyset sigfillset sigaddset)

854 855 856 857 858 859 860 861 862 863 864
my_with_libidn=1
AC_ARG_WITH(libidn, AS_HELP_STRING([--with-libidn=pathname],
	[path to libidn (default: search /usr/local ..)]),
	[], [withval="yes"])
if test x_$withval = x_yes; then
	for dir in /usr/local /opt/local /usr/pkg /usr/sfw; do
		if test -f "$dir/include/idna.h"; then
			CFLAGS="$CFLAGS -I$dir/include"
			LDFLAGS="$LDFLAGS -L$dir/lib"
			AC_MSG_NOTICE([Found libidn in $dir])
			break
865
		fi
866 867 868 869 870
		if test -f "$dir/include/idn/idna.h"; then
			CFLAGS="$CFLAGS -I$dir/include/idn"
			LDFLAGS="$LDFLAGS -L$dir/lib"
			AC_MSG_NOTICE([Found libidn in $dir])
			break
871
		fi
872 873 874 875 876 877 878 879 880 881 882 883
	done
	if test -f "/usr/include/idn/idna.h"; then
		CFLAGS="$CFLAGS -I/usr/include/idn"
		#LDFLAGS="$LDFLAGS -L/usr/lib"
		AC_MSG_NOTICE([Found libidn in /usr])
	fi
else
	if test x_$withval != x_no; then
		CFLAGS="$CFLAGS -I$withval/include"
		LDFLAGS="$LDFLAGS -L$withval/lib"
	else
		my_with_libidn=0
884
	fi
885 886
fi

887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919
my_with_libidn2=1
AC_ARG_WITH(libidn2, AS_HELP_STRING([--with-libidn2=pathname],
	[path to libidn2 (default: search /usr/local ..)]),
	[], [withval="yes"])
if test x_$withval = x_yes; then
	for dir in /usr/local /opt/local /usr/pkg /usr/sfw; do
		if test -f "$dir/include/idn2.h"; then
			CFLAGS="$CFLAGS -I$dir/include"
			LDFLAGS="$LDFLAGS -L$dir/lib"
			AC_MSG_NOTICE([Found libidn2 in $dir])
			break
		fi
		if test -f "$dir/include/idn2/idn2.h"; then
			CFLAGS="$CFLAGS -I$dir/include/idn2"
			LDFLAGS="$LDFLAGS -L$dir/lib"
			AC_MSG_NOTICE([Found libidn2 in $dir])
			break
		fi
	done
	if test -f "/usr/include/idn2/idn2.h"; then
		CFLAGS="$CFLAGS -I/usr/include/idn2"
		#LDFLAGS="$LDFLAGS -L/usr/lib"
		AC_MSG_NOTICE([Found libidn2 in /usr])
	fi
else
	if test x_$withval != x_no; then
		CFLAGS="$CFLAGS -I$withval/include"
		LDFLAGS="$LDFLAGS -L$withval/lib"
	else
		my_with_libidn2=0
	fi
fi

920 921 922 923 924 925 926 927 928 929 930 931 932 933 934
if test $my_with_libunbound = 1
then
	# find libunbound
	AC_ARG_WITH(libunbound, AS_HELP_STRING([--with-libunbound=pathname],
		[path to libunbound (default: search /usr/local ..)]),
		[], [withval="yes"])
	if test x_$withval = x_yes; then
		for dir in /usr/local /opt/local /usr/pkg /usr/sfw; do
			if test -f "$dir/include/unbound.h"; then
				CFLAGS="$CFLAGS -I$dir/include"
				LDFLAGS="$LDFLAGS -L$dir/lib"
				AC_MSG_NOTICE([Found libunbound in $dir])
				break
			fi
		done
935
	else
936 937 938 939 940 941 942
		if test x_$withval != x_no; then
			CFLAGS="$CFLAGS -I$withval/include"
			LDFLAGS="$LDFLAGS -L$withval/lib"
		else
			AC_DEFINE_UNQUOTED([DISABLE_RESOLUTION_RECURSING], [1], [Define this to disable recursing resolution type.])
			my_with_libunbound=0
		fi
943
	fi
944 945
fi

946
# Checks for libraries.
947
found_all_libs=1
948 949
MISSING_DEPS=""
MISSING_SEP=""
950 951 952

working_libidn2=0
if test $my_with_libidn2 = 1
953
then
954 955 956 957 958 959
	AC_MSG_NOTICE([Checking for dependency libidn2])
	AC_CHECK_LIB([idn2], [idn2_to_unicode_8z8z], [
		working_libidn2=1
		LIBS="-lidn2 $LIBS"
		AC_DEFINE_UNQUOTED([HAVE_LIBIDN2], [1], [Define to 1 if you have the `idn2' library (-lidn).]) dnl `
	], [
960
		MISSING_DEPS="${MISSING_DEPS}${MISSING_SEP}libidn2 (version 2.0.0 or higher)"
961 962
		MISSING_SEP=", "
	])
963
fi
964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980
if test $working_libidn2 = 0
then
	if test $my_with_libidn = 1
	then
		AC_MSG_NOTICE([Checking for dependency libidn])
		AC_CHECK_LIB([idn], [idna_to_ascii_8z], [], [
			MISSING_DEPS="${MISSING_DEPS}${MISSING_SEP}libidn"
			MISSING_SEP=", "
			found_all_libs=0
		])
	else
		if test $my_with_libidn2 = 1
		then
			found_all_libs=0
		fi
	fi
fi
981

982 983 984 985 986 987 988 989 990 991 992
AC_ARG_ENABLE(unbound-event-api, AC_HELP_STRING([--disable-unbound-event-api], [Disable usage of libunbounds event API]))
case "$enable_unbound_event_api" in
	no)
		my_enable_unbound_event_api=0
		;;
	yes|*)
		my_enable_unbound_event_api=1
		;;
esac


993
if test $my_with_libunbound = 1
994
then
995
	AC_CHECK_HEADERS([unbound-event.h],,, [AC_INCLUDES_DEFAULT])
996
	AC_MSG_NOTICE([Checking for dependency libunbound])
997
	AC_CHECK_LIB([unbound], [ub_fd], [
998
		AC_DEFINE_UNQUOTED([HAVE_LIBUNBOUND], [1], [Define to 1 if you have the `unbound' library (-lunbound).]) dnl `
999
		LIBS="-lunbound $LIBS"
1000 1001 1002 1003 1004 1005 1006

		if test $my_enable_unbound_event_api = 1
		then
			AC_CHECK_FUNC([ub_ctx_create_ub_event], [
				AC_DEFINE_UNQUOTED([HAVE_UNBOUND_EVENT_API], [1], [Define this when libunbound is compiled with the --enable-event-api option.])
			])
		fi
1007
		AC_CHECK_FUNCS([ub_ctx_set_stub])
1008 1009 1010 1011 1012
	], [
		MISSING_DEPS="${MISSING_DEPS}${MISSING_SEP}libunbound"
		MISSING_SEP=", "
		found_all_libs=0
	])
1013
fi
1014

1015
AC_PATH_PROG([DOXYGEN], [doxygen])
1016
if test -z "$DOXYGEN";
1017
    then AC_MSG_WARN([doxygen not found, continuing without])
1018
fi
Melinda Shore's avatar
Melinda Shore committed
1019

1020
# Checks for header files.
Neel Goyal's avatar
Neel Goyal committed
1021
AC_CHECK_HEADERS([inttypes.h netinet/in.h stdint.h stdlib.h string.h],,, [AC_INCLUDES_DEFAULT])
1022 1023 1024 1025 1026 1027 1028

# Checks for typedefs, structures, and compiler characteristics.
AC_TYPE_SIZE_T
AC_TYPE_UINT16_T
AC_TYPE_UINT32_T
AC_TYPE_UINT64_T
AC_TYPE_UINT8_T
1029
AC_CHECK_TYPES([u_char])
1030

1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044
AC_CHECK_FUNCS([fcntl])
# check ioctlsocket
AC_MSG_CHECKING(for ioctlsocket)
AC_LINK_IFELSE([AC_LANG_PROGRAM([
#ifdef HAVE_WINSOCK2_H
#include <winsock2.h>
#endif
], [
	(void)ioctlsocket(0, 0, NULL);
])], [
AC_MSG_RESULT(yes)
AC_DEFINE(HAVE_IOCTLSOCKET, 1, [if the function 'ioctlsocket' is available])
],[AC_MSG_RESULT(no)])

1045 1046 1047 1048

# Check for libraries for other things than libgetdns after this point,
# so the getdns libraries can be reset with:
#
1049 1050
#	LIBS="$getdns_LIBS"
#	LDFLAGS="$getdns_LDFLAGS"
1051 1052
# 
# afterwards.
1053 1054
getdns_LIBS="$LIBS"
getdns_LDFLAGS="$LDFLAGS"
1055
getdns_CFLAGS="$CFLAGS"
1056

1057
#-------------------- libraries needed for libcheck
1058
LIBS="$initial_LIBS"
1059

1060 1061 1062 1063 1064
CHECK_GETDNS=""
CHECK_LIBS=""
CHECK_CFLAGS=""

PKG_CHECK_MODULES([CHECK],[check >= 0.9.6],[CHECK_GETDNS="check_getdns"],[
1065 1066 1067
AC_SEARCH_LIBS([floor], [m])
AC_SEARCH_LIBS([timer_create], [rt])
AC_SEARCH_LIBS([pthread_create], [pthread])
1068 1069 1070
AC_SEARCH_LIBS([srunner_create],[check check_pic],[
CHECK_GETDNS="check_getdns"
CHECK_LIBS="$LIBS"],[
1071
AC_SUBST(NOLIBCHECK, [nolibcheck])
1072 1073 1074
AC_MSG_WARN([libcheck not found or usable; unit tests will not be compiled and run])])])

LIBS="$getdns_LIBS"
1075

1076 1077 1078
AC_SUBST([CHECK_GETDNS])
AC_SUBST([CHECK_LIBS])
AC_SUBST([CHECK_CFLAGS])
1079 1080
# end libraries needed for libcheck

1081 1082 1083 1084 1085
#-------------------- libevent extension
AC_ARG_WITH([libevent],
    [AS_HELP_STRING([--with-libevent], [path to libevent (default: search /usr/local ..)])],
    [with_libevent=search],
    [withval=no])
1086

1087 1088 1089 1090 1091 1092 1093
# libevent 1.x requires a u_char typedef which is not always available
# on some systems so our check is a little complicated
# we further need to ensure that this is included in the getdns headers
# that get installed later so some users may not be building in an
# environment that has the generated config.h SO we need to generate
# this one extra header in that case

1094
have_libevent=0
1095
EXTENSION_LIBEVENT_EXT_LIBS=""
1096 1097
EXTENSION_LIBEVENT_LIB=""
EXTENSION_LIBEVENT_LDFLAGS=""
1098
CHECK_EVENT_PROG=""
1099 1100 1101 1102 1103 1104 1105 1106
AS_IF([test x_$withval = x_no],
    [],
    [AS_IF([test x_$withval = x_yes],
        [AC_SEARCH_LIBS([event_loop],
        	[event_core event],
            [AC_CHECK_FUNCS([event_base_new event_base_free])]
            [AC_CHECK_HEADERS([event2/event.h],
                [have_libevent=1]
1107
                [AS_IF([test "x_$ac_cv_search_event_loop" = "x_none required"],[],[EXTENSION_LIBEVENT_EXT_LIBS="$ac_cv_search_event_loop"])],
1108 1109
                [AC_CHECK_HEADERS([event.h],
                    [have_libevent=1]
1110
                    [AS_IF([test "x_$ac_cv_search_event_loop" = "x_none required"],[],[EXTENSION_LIBEVENT_EXT_LIBS="$ac_cv_search_event_loop"])],
1111 1112
                    [AC_MSG_ERROR([event2/event.h and event.h missing, try without libevent])]
                    [have_libevent=0],
1113
                    [AC_INCLUDES_DEFAULT]
1114
                    [#ifndef HAVE_U_CHAR
1115 1116
                     typedef unsigned char u_char;
                     #endif])],
1117
                [AC_INCLUDES_DEFAULT])],
1118
             [AC_MSG_ERROR([libevent missing, try without libevent])]
1119 1120 1121 1122 1123 1124 1125 1126 1127
            )],
        [have_libevent=1]
        [AC_MSG_NOTICE([assuming libevent in $withval])]
        [CFLAGS="$CFLAGS -I$withval/include"]
		[EXTENSION_LIBEVENT_LDFLAGS="-L$withval/lib"]
        [EXTENSION_LIBEVENT_EXT_LIBS="-levent"])]
    )

AS_IF([test x_$have_libevent = x_1],
1128
    [EXTENSION_LIBEVENT_LIB="libgetdns_ext_event.la"]
1129 1130 1131 1132 1133 1134 1135 1136
    [CHECK_EVENT_PROG=check_getdns_event]
# libunbound version 1.4.22 and older, not linked against libevent, on FreeBSD,
# =============================================================================
# cannot be linked against a program that also links libevent, because of
# symbol clash.  Libunbound has a libevent clone (called mini_event) build when
# not linked against libevent that uses the same symbols as libevent.

# First detect if the libevent symbols are visible when linking with libunbound
1137 1138
    [LIBS="$getdns_LIBS"]
    [LDFLAGS="$getdns_LDFLAGS"]
1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166
    [AC_MSG_CHECKING([if event_get_version symbol is leaking from libunbound])]
    [AC_LANG_PUSH(C)]
     AC_LINK_IFELSE(
	     [AC_LANG_PROGRAM(
		     [[const char *event_get_version(void);]],
		     [[const char *v = event_get_version();]])
	     ],[[AC_MSG_RESULT([yes])]
                [AC_MSG_CHECKING([if libunbound is linked against libevent])]
		 AC_RUN_IFELSE(
			[AC_LANG_PROGRAM(
				[[const char *event_get_version(void);]],
				[[const char *v = event_get_version();]
				 [return v@<:@0@:>@ == 'm' && v@<:@1@:>@ == 'i' &&
				         v@<:@2@:>@ == 'n' && v@<:@3@:>@ == 'i' ? 1 : 0;]])
			],[[AC_MSG_RESULT([yes])]
			],[[AC_MSG_RESULT([no])]
			   [AC_MSG_FAILURE([
***
*** On this system, when using libevent,  libunbound must
*** also have been compiled with libevent.  Please recompile
*** libunbound with libevent, or configure --without-libevent.
***])]
			]
		)
             ],[[AC_MSG_RESULT([no])]
	     ]
     )
    [AC_LANG_POP(C)])
Neel Goyal's avatar
Neel Goyal committed
1167 1168

AC_SUBST(have_libevent)
1169 1170
AC_SUBST(EXTENSION_LIBEVENT_LIB)
AC_SUBST(EXTENSION_LIBEVENT_EXT_LIBS)
1171
AC_SUBST(EXTENSION_LIBEVENT_LDFLAGS)
1172
AS_IF([test "x$have_libcheck" = x1], [AC_SUBST(CHECK_EVENT_PROG)])
1173

1174 1175
LIBS="$getdns_LIBS"
LDFLAGS="$getdns_LDFLAGS"
1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188
# end libevent extension

#-------------------- libuv extension
# if user says nothing about libuv, or specifies --with-libuv=no or --without-libuv
# then we do not want libuv extensions built
# if user specifies --with-libuv then search for it
# if user specifies --with-libuv=/path then check the lib at that path
AC_ARG_WITH([libuv],
    [AS_HELP_STRING([--with-libuv], [path to libuv (default: search /usr/local ..)])],
    [with_libuv=search],
    [withval=no])

have_libuv=0
1189
EXTENSION_LIBUV_EXT_LIBS=""
1190 1191
EXTENSION_LIBUV_LIB=""
EXTENSION_LIBUV_LDFLAGS=""
1192
CHECK_UV_PROG=""
1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213
AS_IF([test x_$withval = x_no],
    [],
    [AS_IF([test x_$withval = x_yes],
        [AC_SEARCH_LIBS([uv_run],
        	[uv],
        	[AC_CHECK_HEADERS([uv.h],
                [have_libuv=1]
                [EXTENSION_LIBUV_EXT_LIBS="$ac_cv_search_uv_run"],
                [AC_MSG_ERROR([uv.h missing, try without libuv])]
                [have_libuv=0],
                [AC_INCLUDES_DEFAULT])],
                [AC_MSG_ERROR([libuv missing, try without libuv])]
            )],
        [have_libuv=1]
        [AC_MSG_NOTICE([assuming libuv in $withval])]
        [CFLAGS="$CFLAGS -I$withval/include"]
		[EXTENSION_LIBUV_LDFLAGS="-L$withval/lib"]
        [EXTENSION_LIBUV_EXT_LIBS="-luv"])]
    )

AS_IF([test x_$have_libuv = x_1],
1214
    [EXTENSION_LIBUV_LIB="libgetdns_ext_uv.la"]
1215 1216 1217 1218 1219
    [CHECK_UV_PROG=check_getdns_uv]
    [AC_MSG_CHECKING([for new signature of uv_timer_cb])
     AC_LANG_PUSH(C)
     AC_COMPILE_IFELSE(
	     [AC_LANG_PROGRAM(
1220 1221 1222 1223
		     [[#include <uv.h>]
		      [void test_cb(uv_timer_t *handle);]],
		     [[uv_timer_cb cb = test_cb;]
		      [(*cb)(0);]])
1224 1225 1226 1227 1228 1229
	     ],[AC_MSG_RESULT([yes])
		AC_DEFINE(HAVE_NEW_UV_TIMER_CB, [1], [Does libuv have the new uv_time_cb signature])
             ],[AC_MSG_RESULT([no])
	     ])
     AC_LANG_POP(C)] 
)
1230 1231

AC_SUBST(have_libuv)
1232 1233
AC_SUBST(EXTENSION_LIBUV_LIB)
AC_SUBST(EXTENSION_LIBUV_EXT_LIBS)
1234
AC_SUBST(EXTENSION_LIBUV_LDFLAGS)
1235
AS_IF([test "x$have_libcheck" = x1], [AC_SUBST(CHECK_UV_PROG)])
1236

1237 1238
LIBS="$getdns_LIBS"
LDFLAGS="$getdns_LDFLAGS"
1239 1240 1241 1242 1243 1244 1245 1246 1247
# end libuv extension

#-------------------- libev extension
AC_ARG_WITH([libev],
    [AS_HELP_STRING([--with-libev], [path to libev (default: search /usr/local ..)])],
    [with_libev=search],
    [withval=no])

have_libev=0
1248
EXTENSION_LIBEV_EXT_LIBS=""
1249 1250 1251 1252 1253 1254 1255 1256 1257
EXTENSION_LIBEV_LIB=""
EXTENSION_LIBEV_LDFLAGS=""
CHECK_EV_PROG=""
AS_IF([test x_$withval = x_no],
    [],
    [AS_IF([test x_$withval = x_yes],
        [AC_SEARCH_LIBS([ev_run],
        	[ev],
        	[AC_CHECK_HEADERS([ev.h],
1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268
			[have_libev=1]
			[EXTENSION_LIBEV_EXT_LIBS="$ac_cv_search_ev_run"],
			[AC_CHECK_HEADERS([libev/ev.h],
				[have_libev=1]
				[EXTENSION_LIBEV_EXT_LIBS="$ac_cv_search_ev_run"],
				[AC_MSG_ERROR([ev.h missing, try without libev])]
				[have_libev=0],
				[AC_INCLUDES_DEFAULT])
			],
			[AC_INCLUDES_DEFAULT])
		],
1269 1270 1271 1272 1273 1274 1275 1276
                [AC_MSG_ERROR([libev missing, try without libev])]
            )],
        [have_libev=1]
        [AC_MSG_NOTICE([assuming libev in $withval])]
        [CFLAGS="$CFLAGS -I$withval/include"]
		[EXTENSION_LIBEV_LDFLAGS="-L$withval/lib"]
        [EXTENSION_LIBEV_EXT_LIBS="-lev"])]
    )
1277

1278
AS_IF([test x_$have_libev = x_1],
1279
    [EXTENSION_LIBEV_LIB="libgetdns_ext_ev.la"]
1280
    [CHECK_EV_PROG=check_getdns_ev])
1281 1282

AC_SUBST(have_libev)
1283 1284
AC_SUBST(EXTENSION_LIBEV_LIB)
AC_SUBST(EXTENSION_LIBEV_EXT_LIBS)
1285
AC_SUBST(EXTENSION_LIBEV_LDFLAGS)
1286
AS_IF([test "x$have_libcheck" = x1], [AC_SUBST(CHECK_EV_PROG)])
1287

1288 1289
LIBS="$getdns_LIBS"
LDFLAGS="$getdns_LDFLAGS"
1290
# end libev extension
1291

1292 1293
# --with-trust-anchor=
AC_DEFINE([SYSCONFDIR], [sysconfdir], [System configuration dir])
1294
AC_ARG_WITH(trust-anchor, AS_HELP_STRING([--with-trust-anchor=KEYFILE], [Default location of the trust anchor file. [default=SYSCONFDIR/unbound/getdns-root.key]]), [
1295 1296 1297 1298 1299
 TRUST_ANCHOR_FILE="$withval"
],[
 if test "x$TRUST_ANCHOR_FILE" = "x"; then
  if test "x$sysconfdir" = 'x${prefix}/etc' ; then
   if test "x$prefix" = 'xNONE' ; then
1300
    TRUST_ANCHOR_FILE="/etc/unbound/getdns-root.key"
1301
   else
1302
    TRUST_ANCHOR_FILE="${prefix}/etc/unbound/getdns-root.key"
1303 1304
   fi
  else
1305
    TRUST_ANCHOR_FILE="${sysconfdir}/unbound/getdns-root.key"
1306 1307 1308 1309 1310 1311 1312
  fi
 fi
])
AC_DEFINE_UNQUOTED([TRUST_ANCHOR_FILE], ["$TRUST_ANCHOR_FILE"], [Default trust anchor file])
AC_SUBST(TRUST_ANCHOR_FILE)
AC_MSG_NOTICE([Default trust anchor: $TRUST_ANCHOR_FILE])

1313 1314 1315
AC_ARG_WITH(getdns_query, AS_HELP_STRING([--without-getdns_query],
	[Do not compile and install the getdns_query tool]),
	[], [withval="yes"])
1316 1317 1318 1319 1320 1321 1322 1323 1324
if test x_$withval = x_no; then
	GETDNS_QUERY=""
	INSTALL_GETDNS_QUERY=""
	UNINSTALL_GETDNS_QUERY=""
else
	GETDNS_QUERY="getdns_query"
	INSTALL_GETDNS_QUERY="install-getdns_query"
	UNINSTALL_GETDNS_QUERY="uninstall-getdns_query"
fi
1325 1326 1327 1328
AC_SUBST(GETDNS_QUERY)
AC_SUBST(INSTALL_GETDNS_QUERY)
AC_SUBST(UNINSTALL_GETDNS_QUERY)

1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344
AC_ARG_WITH(getdns_server_mon, AS_HELP_STRING([--without-getdns_server_mon],
	[Do not compile and install the getdns_server_mon tool]),
	[], [withval="yes"])
if test x_$withval = x_no; then
	GETDNS_SERVER_MON=""
	INSTALL_GETDNS_SERVER_MON=""
	UNINSTALL_GETDNS_SERVER_MON=""
else
	GETDNS_SERVER_MON="getdns_server_mon"
	INSTALL_GETDNS_SERVER_MON="install-getdns_server_mon"
	UNINSTALL_GETDNS_SERVER_MON="uninstall-getdns_server_mon"
fi
AC_SUBST(GETDNS_SERVER_MON)
AC_SUBST(INSTALL_GETDNS_SERVER_MON)
AC_SUBST(UNINSTALL_GETDNS_SERVER_MON)

1345
stubby_with_yaml=0
1346 1347 1348 1349
AC_ARG_WITH(stubby, AS_HELP_STRING([--with-stubby],
	[Compile and install stubby, the (stub) resolver daemon]),
	[], [withval="no"])
if test x_$withval = x_yes; then
1350 1351 1352
	STUBBY="stubby"
	INSTALL_STUBBY="install-stubby"
	UNINSTALL_STUBBY="uninstall-stubby"
1353 1354 1355 1356 1357 1358
	if test $my_with_yaml = 0
	then
		STUBBY_XTRA_OBJS="convert_yaml_to_json.lo gbuffer.lo"
		stubby_with_yaml=1
		my_with_yaml=1
	fi
1359 1360 1361 1362
else
	STUBBY=""
	INSTALL_STUBBY=""
	UNINSTALL_STUBBY=""
1363
	STUBBY_XTRA_OBJS=""
1364 1365 1366 1367
fi
AC_SUBST(STUBBY)
AC_SUBST(INSTALL_STUBBY)
AC_SUBST(UNINSTALL_STUBBY)
1368
AC_SUBST(STUBBY_XTRA_OBJS)
1369

1370
STUBBY_LIBS=""
1371
STUBBY_LDFLAGS=""
1372 1373 1374 1375 1376 1377 1378

if test $my_with_yaml = 1
then
	if test $stubby_with_yaml = 1
	then
		getdns_LIBS="$LIBS"
		getdns_LDFLAGS="$LDFLAGS"
1379 1380
		LIBS="$initial_LIBS"
		LDFLAGS="$initial_LDFLAGS"
1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429
	fi
	AC_ARG_WITH(libyaml, AS_HELP_STRING([--with-libyaml=pathname],
		[path to libyaml (default: search /usr/local ..)]),
		[], [withval="yes"])
	if test x_$withval = x_yes; then
		for dir in /usr/local /opt/local /usr/pkg /usr/sfw; do
			if test -f "$dir/include/yaml.h"; then
				CFLAGS="$CFLAGS -I$dir/include"
				LDFLAGS="$LDFLAGS -L$dir/lib"
				AC_MSG_NOTICE([Found libyaml in $dir])
				break
			fi
		done
	else
		if test x_$withval != x_no; then
			CFLAGS="$CFLAGS -I$withval/include"
			LDFLAGS="$LDFLAGS -L$withval/lib"
		else
			if test $stubby_with_yaml = 1
			then
    				AC_MSG_ERROR([libyaml required for building Stubby])
			fi
			my_with_yaml=0
		fi
	fi
	if test $my_with_yaml = 1
	then
		AC_MSG_NOTICE([Checking for dependency libyaml])
		AC_CHECK_LIB([yaml], [yaml_parser_parse], [], [
			MISSING_DEPS="${MISSING_DEPS}${MISSING_SEP}libyaml"
			MISSING_SEP=", "
			found_all_libs=0
		])
	fi
	if test $stubby_with_yaml = 1
	then
		STUBBY_LDFLAGS="$LDFLAGS"
		STUBBY_LIBS="$LIBS"
		LIBS="$getdns_LIBS"
		LDFLAGS="$getdns_LDFLAGS"
	fi
fi
AC_SUBST(STUBBY_LDFLAGS)
AC_SUBST(STUBBY_LIBS)

if test $found_all_libs = 0
then
    AC_MSG_ERROR([Missing dependencies: $MISSING_DEPS])
fi
1430

1431
AC_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])
1432 1433 1434
if [ test -n "$DOXYGEN" ]
    then AC_CONFIG_FILES([src/Doxyfile])
fi
1435

1436 1437 1438 1439 1440 1441 1442 1443
AC_MSG_CHECKING([whether the C compiler (${CC-cc}) supports the __func__ variable])
AC_LANG_PUSH(C)
AC_COMPILE_IFELSE(
	[AC_LANG_PROGRAM([[char*s=__func__;]],[[]])],
	[AC_MSG_RESULT([yes])
	 AC_DEFINE(HAVE___FUNC__, [1], [Whether the C compiler support the __func__ variable])],
	[AC_MSG_RESULT([no])])
AC_LANG_POP(C)
1444

1445 1446 1447 1448 1449
dnl -----
dnl ----- Start of "Things needed for gldns" section
dnl -----
dnl ---------------------------------------------------------------------------

1450
AC_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])
1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472

dnl Check the printf-format attribute (if any)
dnl result in HAVE_ATTR_FORMAT.  
dnl
AC_MSG_CHECKING(whether the C compiler (${CC-cc}) accepts the "format" attribute)
AC_CACHE_VAL(ac_cv_c_format_attribute,
[ac_cv_c_format_attribute=no
AC_TRY_COMPILE(
[#include <stdio.h>
void f (char *format, ...) __attribute__ ((format (printf, 1, 2)));
void (*pf) (char *format, ...) __attribute__ ((format (printf, 1, 2)));
], [
   f ("%s", "str");
],
[ac_cv_c_format_attribute="yes"],
[ac_cv_c_format_attribute="no"])
])
AC_MSG_RESULT($ac_cv_c_format_attribute)
if test $ac_cv_c_format_attribute = yes; then
  AC_DEFINE(HAVE_ATTR_FORMAT, 1, [Whether the C compiler accepts the "format" attribute])
fi

1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488
AC_MSG_CHECKING(whether the C compiler (${CC-cc}) accepts the "unused" attribute)
AC_CACHE_VAL(ac_cv_c_unused_attribute,
[ac_cv_c_unused_attribute=no
AC_TRY_COMPILE(
[#include <stdio.h>
void f (char *u __attribute__((unused)));
], [
   f ("x");
],
[ac_cv_c_unused_attribute="yes"],
[ac_cv_c_unused_attribute="no"])
])
AC_MSG_RESULT($ac_cv_c_unused_attribute)
if test $ac_cv_c_unused_attribute = yes; then
  AC_DEFINE(HAVE_ATTR_UNUSED, 1, [Whether the C compiler accepts the "unused" attribute])
fi
1489 1490 1491 1492
# Check for libbsd, so that the next function checks pick it as their
# system implementation.
PKG_CHECK_MODULES([LIBBSD],[libbsd-overlay],[
LIBS="$LIBS $LIBBSD_LIBS"
1493
STUBBY_LIBS="$STUBBY_LIBS $LIBBSD_LIBS"
1494 1495 1496 1497
CFLAGS="$CFLAGS $LIBBSD_CFLAGS"
],[
AC_MSG_WARN([libbsd not found or usable; using embedded code instead])
])
1498
AC_CHECK_DECLS([inet_pton,inet_ntop,strlcpy,arc4random,arc4random_uniform])
1499 1500
AC_REPLACE_FUNCS(inet_pton)
AC_REPLACE_FUNCS(inet_ntop)
1501
AC_REPLACE_FUNCS(strlcpy)
1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541
AC_REPLACE_FUNCS(arc4random)
AC_REPLACE_FUNCS(arc4random_uniform)
if test "$ac_cv_func_arc4random" = "no"; then
	AC_LIBOBJ(explicit_bzero)
	AC_LIBOBJ(arc4_lock)
	AC_CHECK_FUNCS([getentropy],,[
	    if test "$USE_WINSOCK" = 1; then
		AC_LIBOBJ(getentropy_win)
	    else
		case `uname` in
		Darwin)
			AC_LIBOBJ(getentropy_osx)
		;;
		SunOS)
			AC_LIBOBJ(getentropy_solaris)
			AC_CHECK_HEADERS([sys/sha2.h],, [
				AC_CHECK_FUNCS([SHA512_Update],,[
					AC_LIBOBJ(sha512)
				])
			], [AC_INCLUDES_DEFAULT])
			if test "$ac_cv_header_sys_sha2_h" = "yes"; then
				# this lib needed for sha2 on solaris
				LIBS="$LIBS -lmd"
			fi
			AC_SEARCH_LIBS([clock_gettime], [rt])
		;;
		Linux|*)
			AC_LIBOBJ(getentropy_linux)
			dnl AC_CHECK_FUNCS([SHA512_Update],,[
			dnl	AC_DEFINE([COMPAT_SHA512], [1], [Do sha512 definitions in config.h])
			dnl	AC_LIBOBJ(sha512)
			dnl])
			AC_CHECK_HEADERS([sys/sysctl.h],,, [AC_INCLUDES_DEFAULT])
			AC_CHECK_FUNCS([getauxval])
			AC_SEARCH_LIBS([clock_gettime], [rt])
		;;
		esac
	    fi
	])
fi
1542

1543 1544
AC_TYPE_SIGNAL

1545 1546 1547 1548 1549 1550 1551 1552 1553 1554
case `uname` in
FreeBSD)
	C99COMPATFLAGS=""
;;
*)
	C99COMPATFLAGS="-D_POSIX_C_SOURCE=200112L -D_XOPEN_SOURCE=600"
;;
esac
AC_SUBST(C99COMPATFLAGS)

Willem Toorop's avatar
Willem Toorop committed
1555
AC_DEFINE_UNQUOTED([MAX_CNAME_REFERRALS], [100], [The maximum number of cname referrals.])
1556
AC_DEFINE_UNQUOTED([DRAFT_RRTYPES], [1], [Define this to enable all rrtypes in gldns.])
Willem Toorop's avatar
Willem Toorop committed
1557

1558
AH_BOTTOM([
1559

1560 1561 1562 1563 1564 1565
#ifdef HAVE___FUNC__
#define __FUNC__ __func__
#else
#define __FUNC__ __FUNCTION__
#endif

1566
#ifdef GETDNS_ON_WINDOWS
1567
 /* On windows it is allowed to increase the FD_SETSIZE
1568
  * (and necessary to make our custom eventloop work)
1569 1570 1571
  * See: https://support.microsoft.com/en-us/kb/111855
  */
# ifndef FD_SETSIZE
1572
#  define FD_SETSIZE 1024
1573
# endif
1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605

/* the version of the windows API enabled */
# ifndef WINVER
#  define WINVER 0x0600 // 0x0502
# endif
# ifndef _WIN32_WINNT
#  define _WIN32_WINNT 0x0600 // 0x0502
# endif
# ifdef HAVE_WS2TCPIP_H
#  include <ws2tcpip.h>
# endif

# ifdef _MSC_VER
#  if _MSC_VER >= 1800
#   define PRIsz "zu"
#  else
#   define PRIsz "Iu"
#  endif
# else
#  define PRIsz "Iu"
# endif

# ifdef HAVE_WINSOCK2_H
#  include <winsock2.h>
# endif

/* detect if we need to cast to unsigned int for FD_SET to avoid warnings */
# ifdef HAVE_WINSOCK2_H
#  define FD_SET_T (u_int)
# else
#  define FD_SET_T 
# endif
1606 1607 1608 1609 1610

 /* Windows wants us to use _strdup instead of strdup */
# ifndef strdup
#  define strdup _strdup
# endif
1611
#else
1612
# define PRIsz "zu"
1613 1614
#endif

1615 1616 1617 1618 1619 1620
#include <stdint.h>
#include <stdio.h>
#include <unistd.h>
#include <assert.h>
#include <string.h>

1621 1622 1623
#ifdef __cplusplus
extern "C" {
#endif
1624

1625 1626 1627 1628 1629
#if STDC_HEADERS
#include <stdlib.h>
#include <stddef.h>
#endif

1630
#if !defined(HAVE_STRLCPY) || !HAVE_DECL_STRLCPY || !defined(strlcpy)
1631 1632
size_t strlcpy(char *dst, const char *src, size_t siz);
#else
1633
#ifndef __BSD_VISIBLE
1634 1635
#define __BSD_VISIBLE 1
#endif
1636
#endif
1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665
#if !defined(HAVE_ARC4RANDOM) || !HAVE_DECL_ARC4RANDOM
uint32_t arc4random(void);
#endif
#if !defined(HAVE_ARC4RANDOM_UNIFORM) || !HAVE_DECL_ARC4RANDOM_UNIFORM 
uint32_t arc4random_uniform(uint32_t upper_bound);
#endif
#ifndef HAVE_ARC4RANDOM
void explicit_bzero(void* buf, size_t len);
int getentropy(void* buf, size_t len);
void arc4random_buf(void* buf, size_t n);
void _ARC4_LOCK(void);
void _ARC4_UNLOCK(void);
#endif
#ifdef COMPAT_SHA512
#ifndef SHA512_DIGEST_LENGTH
#define SHA512_BLOCK_LENGTH             128
#define SHA512_DIGEST_LENGTH            64
#define SHA512_DIGEST_STRING_LENGTH     (SHA512_DIGEST_LENGTH * 2 + 1)
typedef struct _SHA512_CTX {
        uint64_t        state[8];
        uint64_t        bitcount[2];
        uint8_t buffer[SHA512_BLOCK_LENGTH];
} SHA512_CTX;
#endif /* SHA512_DIGEST_LENGTH */
void SHA512_Init(SHA512_CTX*);
void SHA512_Update(SHA512_CTX*, void*, size_t);
void SHA512_Final(uint8_t[SHA512_DIGEST_LENGTH], SHA512_CTX*);
unsigned char *SHA512(void* data, unsigned int data_len, unsigned char *digest);
#endif /* COMPAT_SHA512 */
1666

1667
#ifndef HAVE_DECL_INET_PTON
1668 1669 1670
int inet_pton(int af, const char* src, void* dst);
#endif /* HAVE_INET_PTON */

1671
#ifndef HAVE_DECL_INET_NTOP
1672 1673 1674
const char *inet_ntop(int af, const void *src, char *dst, size_t size);
#endif

1675
#ifdef USE_WINSOCK
1676 1677
# ifndef  _CUSTOM_VSNPRINTF
#  define _CUSTOM_VSNPRINTF
1678 1679
static inline int _gldns_custom_vsnprintf(char *str, size_t size, const char *format, va_list ap)
{ int r = vsnprintf(str, size, format, ap); return r == -1 ? _vscprintf(format, ap) : r; }
1680 1681
#  define vsnprintf _gldns_custom_vsnprintf
# endif
1682 1683
#endif

1684 1685 1686 1687 1688
#ifdef __cplusplus
}
#endif

/** Use on-board gldns */
1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699
#define USE_GLDNS 1
#ifdef HAVE_SSL
#  define GLDNS_BUILD_CONFIG_HAVE_SSL 1
#endif

#ifdef HAVE_STDARG_H
#include <stdarg.h>
#endif

#include <errno.h>

1700 1701 1702 1703
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif

1704 1705 1706 1707
#ifdef HAVE_SYS_SELECT_H
#include <sys/select.h>
#endif

1708 1709 1710 1711
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif

1712 1713 1714 1715
#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif

1716 1717 1718 1719 1720 1721 1722 1723
#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif

#ifdef HAVE_ARPA_INET_H
#include <arpa/inet.h>
#endif

1724 1725 1726 1727
#ifdef HAVE_OPENSSL_SSL_H
#include <openssl/ssl.h>
#endif

1728 1729 1730 1731
#ifdef HAVE_INTTYPES_H
#include <inttypes.h>
#endif

1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745
#ifdef HAVE_LIMITS_H
#include <limits.h>
#endif

#ifdef HAVE_SYS_LIMITS_H
#include <sys/limits.h>
#endif

#ifdef PATH_MAX
#define _GETDNS_PATH_MAX PATH_MAX
#else
#define _GETDNS_PATH_MAX 2048
#endif

1746 1747 1748 1749
#ifndef PRIu64
#define PRIu64 "llu"
#endif

1750 1751 1752 1753 1754 1755 1756
#ifdef HAVE_ATTR_FORMAT
#  define ATTR_FORMAT(archetype, string_index, first_to_check) \
    __attribute__ ((format (archetype, string_index, first_to_check)))
#else /* !HAVE_ATTR_FORMAT */
#  define ATTR_FORMAT(archetype, string_index, first_to_check) /* empty */
#endif /* !HAVE_ATTR_FORMAT */

1757 1758 1759 1760 1761 1762 1763 1764 1765 1766
#if defined(DOXYGEN)
#  define ATTR_UNUSED(x)  x
#elif defined(__cplusplus)
#  define ATTR_UNUSED(x)
#elif defined(HAVE_ATTR_UNUSED)
#  define ATTR_UNUSED(x)  x __attribute__((unused))
#else /* !HAVE_ATTR_UNUSED */
#  define ATTR_UNUSED(x)  x
#endif /* !HAVE_ATTR_UNUSED */

1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777
#ifdef TIME_WITH_SYS_TIME
# include <sys/time.h>
# include <time.h>
#else
# ifdef HAVE_SYS_TIME_H
#  include <sys/time.h>
# else
#  include <time.h>
# endif
#endif

1778 1779 1780 1781
#ifdef __cplusplus
extern "C" {
#endif

Willem Toorop's avatar
Willem Toorop committed
1782 1783 1784 1785 1786 1787
#if !defined(HAVE_STRPTIME) || !defined(STRPTIME_WORKS)
#define strptime unbound_strptime
struct tm;
char *strptime(const char *s, const char *format, struct tm *tm);
#endif

1788 1789 1790
#if !defined(HAVE_SIGSET_T) && defined(HAVE__SIGSET_T)
typedef _sigset_t sigset_t;
#endif
1791 1792 1793 1794
#if !defined(HAVE_SIGEMPTYSET)
#  define sigemptyset(pset)    (*(pset) = 0)
#endif
#if !defined(HAVE_SIGFILLSET)
1795
#  define sigfillset(pset)     (*(pset) = (sigset_t)-1)
1796 1797 1798 1799 1800
#endif
#if !defined(HAVE_SIGADDSET)
#  define sigaddset(pset, num) (*(pset) |= (1L<<(num)))
#endif

1801
#ifdef HAVE_LIBUNBOUND
1802
# include <unbound.h>
1803
# ifdef HAVE_UNBOUND_EVENT_H
1804
#  include <unbound-event.h>
1805
# else
1806 1807 1808
#  ifdef HAVE_UNBOUND_EVENT_API
#   ifndef _UB_EVENT_PRIMITIVES
#    define _UB_EVENT_PRIMITIVES
1809 1810 1811 1812 1813
struct ub_event_base;
struct ub_ctx* ub_ctx_create_ub_event(struct ub_event_base* base);
typedef void (*ub_event_callback_t)(void*, int, void*, int, int, char*);
int ub_resolve_event(struct ub_ctx* ctx, const char* name, int rrtype, 
        int rrclass, void* mydata, ub_event_callback_t callback, int* async_id);
1814
#   endif
Willem Toorop's avatar
Willem Toorop committed
1815
#  endif
1816
# endif
1817
#endif
1818 1819 1820 1821

#ifdef __cplusplus
}
#endif
1822 1823 1824 1825 1826 1827 1828 1829
])

dnl ---------------------------------------------------------------------------
dnl -----
dnl ----- End of "Things needed for gldns" section
dnl -----


1830
AC_CONFIG_HEADER([src/config.h])
1831
AC_OUTPUT