configure.ac 54.8 KB
Newer Older
1
# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
Tinderbox User's avatar
Tinderbox User committed
2
#
3 4 5
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 7 8
#
# See the COPYRIGHT file distributed with this work for additional
# information regarding copyright ownership.
9

10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
#
# Defining the version in m4 requires a bit of dancing around,
# so the strings are properly concatenated, as you can't use
# a shell variable in AC_INIT()
#
m4_define([bind_VERSION_MAJOR], 9)dnl
m4_define([bind_VERSION_MINOR], 17)dnl
m4_define([bind_VERSION_PATCH], 1)dnl
m4_define([bind_VERSION_EXTRA], -dev)dnl
m4_define([bind_DESCRIPTION], [(Development Release)])dnl
m4_define([bind_SRCID], [m4_esyscmd_s([if test -f srcid; then cat srcid; else git rev-parse --short HEAD 2>/dev/null; fi])])dnl
m4_define([bind_PKG_VERSION], [[bind_VERSION_MAJOR.bind_VERSION_MINOR.bind_VERSION_PATCH]bind_VERSION_EXTRA])dnl

#
# Autoconf initialization
#
AC_INIT([BIND], bind_PKG_VERSION, [info@isc.org], [], [https://www.isc.org/downloads/])
AC_PREREQ(2.60)

AC_DEFINE([PACKAGE_VERSION_MAJOR], ["][bind_VERSION_MAJOR]["], [BIND 9 Major part of the version])
AC_DEFINE([PACKAGE_VERSION_MINOR], ["][bind_VERSION_MINOR]["], [BIND 9 Minor part of the version])
AC_DEFINE([PACKAGE_VERSION_PATCH], ["][bind_VERSION_PATCH]["], [BIND 9 Patch part of the version])
AC_DEFINE([PACKAGE_VERSION_EXTRA], ["][bind_VERSION_EXTRA]["], [BIND 9 Extra part of the version])
AC_DEFINE([PACKAGE_DESCRIPTION], [m4_ifnblank(bind_DESCRIPTION, [" ]bind_DESCRIPTION["], [])], [An extra string to print after PACKAGE_STRING])
AC_DEFINE([PACKAGE_SRCID], ["][bind_SRCID]["], [A short hash from git])

# This value should be increased whenever changing the structure of
# any object that will appear in a type 'map' master file (which
# contains a working memory image of an RBT database), as loading 
# an incorrect memory image produces an inconsistent and probably
# nonfunctional database.  These structures include but are not
# necessarily limited to dns_masterrawheader, rbtdb_file_header,
# rbt_file_header, dns_rbtdb, dns_rbt, dns_rbtnode, rdatasetheader.
#
# Err on the side of caution: if anything in the RBTDB is changed,
# bump the value.  Making map files unreadable protects the system
# from instability; it's a feature not a bug.
#
# Whenever releasing a new major release of BIND9, set this value
# back to 1.0 when releasing the first alpha.  Map files are *never*
# compatible across major releases.
AC_DEFINE([MAPAPI], ["2.0"], [BIND 9 MAPAPI Version])

bind_CONFIGARGS="${ac_configure_args:-default}"
AC_DEFINE_UNQUOTED([PACKAGE_CONFIGARGS], ["$bind_CONFIGARGS"], [Either 'defaults' or used ./configure options])

AC_DEFINE([PACKAGE_BUILDER], ["make"], [make or Visual Studio])

AC_CONFIG_SRCDIR([bin/named/main.c])
AM_INIT_AUTOMAKE([foreign subdir-objects dist-xz -Wall -Werror])
AM_SILENT_RULES([yes])
61
AM_EXTRA_RECURSIVE_TARGETS([test unit doc])
62 63 64

AC_CONFIG_HEADERS([config.h])
AC_CONFIG_MACRO_DIR([m4])
Bob Halley's avatar
Bob Halley committed
65

66 67 68 69 70
#
# Enable maintainer mode by default, but allow to disable it in the CI
#
AM_MAINTAINER_MODE([enable])

71 72
# Set the library versions
# https://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html
Bob Halley's avatar
Bob Halley committed
73

74 75 76 77 78 79 80
AX_BIND9_LIB_VERSION([bind9])
AX_BIND9_LIB_VERSION([dns])
AX_BIND9_LIB_VERSION([irs])
AX_BIND9_LIB_VERSION([isc])
AX_BIND9_LIB_VERSION([isccc])
AX_BIND9_LIB_VERSION([isccfg])
AX_BIND9_LIB_VERSION([ns])
81 82 83 84

#
# Enable system extensions to C and POSIX
#
85
AC_USE_SYSTEM_EXTENSIONS
86 87 88 89 90 91 92 93 94 95 96 97
AC_CANONICAL_HOST

#
# Compiler compatibility flags
#
AC_PROG_CC_C99
AC_PROG_CPP_WERROR

#
# Find the machine's endian flavor.
#
AC_C_BIGENDIAN
98

99 100 101 102 103 104
#
# Enable large file support
#
AC_SYS_LARGEFILE
AC_FUNC_FSEEKO

105 106
# Enable RFC 3542 APIs on macOS
AC_DEFINE([__APPLE_USE_RFC_3542], [1], [Select RFC3542 IPv6 API on macOS])
Bob Halley's avatar
Bob Halley committed
107

108
AC_PROG_MAKE_SET
109

110 111 112
# Checks for programs.
m4_ifdef([AM_PROG_AR], [AM_PROG_AR]) # call AM_PROG_AR only if available

113
AC_PROG_LIBTOOL
114 115
AS_IF([test -z "$LIBTOOL"],
      [AC_MSG_ERROR([The libtool script could not be found.])])
116
AC_PROG_INSTALL
117
AC_PROG_LN_S
118
AX_POSIX_SHELL
119
AC_PROG_MKDIR_P
120

121 122 123 124 125 126
# Initialize libtool
LT_INIT([dlopen])

LT_CONFIG_LTDL_DIR([libltdl])
LTDL_INIT([recursive])
AC_CONFIG_FILES([libltdl/Makefile])
127

128
#
129
# Set the default CFLAGS and CPPFLAGS
130
#
131
STD_CFLAGS="-Wall -Wextra -Wwrite-strings -Wcast-qual -Wpointer-arith -Wno-missing-field-initializers -Wformat -Wshadow"
132

133 134
# These should be always errors
STD_CFLAGS="$STD_CFLAGS -Werror=implicit-function-declaration -Werror=missing-prototypes -Werror=format-security -Werror=parentheses -Werror=implicit -Werror=strict-prototypes"
135

136 137
# Fortify the sources by default
STD_CPPFLAGS="-D_FORTIFY_SOURCE=2"
138

139 140 141 142 143
#
# Additional compiler settings.
#
AX_CHECK_COMPILE_FLAG([-fno-strict-aliasing],
		      [STD_CFLAGS="$STD_CFLAGS -fno-strict-aliasing"])
144 145
# Clang only issues a warning so use -Werror to force a error.
AX_CHECK_COMPILE_FLAG([-Werror -fno-delete-null-pointer-checks],
146 147 148
		      [STD_CFLAGS="$STD_CFLAGS -fno-delete-null-pointer-checks"])
AX_CHECK_COMPILE_FLAG([-fdiagnostics-show-option],
		      [STD_CFLAGS="$STD_CFLAGS -fdiagnostics-show-option"])
149

150 151 152 153
#
# Change defaults for developers if not explicity set.
# Needs to be before the option is tested.
#
154 155 156
AC_ARG_ENABLE([developer],
	      [AS_HELP_STRING([--enable-developer],
			      [enable developer build settings])])
157

158
AS_IF([test "$enable_developer" = "yes"],
159
      [STD_CPPFLAGS="$STD_CPPFLAGS -DISC_MEM_DEFAULTFILL=1 -DISC_LIST_CHECKINIT=1"
160 161 162 163 164
       test "${enable_fixed_rrset+set}" = set || enable_fixed_rrset=yes
       test "${enable_querytrace+set}" = set || enable_querytrace=yes
       test "${with_cmocka+set}" = set || with_cmocka=yes
       test "${with_dlz_filesystem+set}" = set || with_dlz_filesystem=yes
       test "${with_zlib+set}" = set || with_zlib=yes
165
       test "${enable_warn_error+set}" = set || enable_warn_error=yes
166
       ])
167 168 169 170

AC_SUBST([STD_CFLAGS])
AC_SUBST([STD_CPPFLAGS])

171 172 173 174 175 176 177
AC_ARG_ENABLE([warn_error],
	      [AS_HELP_STRING([--enable-warn-error],
			      [turn on -Werror when compiling])],
	      [],[enable_warn_error=no])
AS_IF([test "$enable_warn_error" = "yes"],
      [STD_CFLAGS="$STD_CFLAGS -Werror"])

178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
#
# Use pkg-config
#

PKG_PROG_PKG_CONFIG
AS_IF([test -z "$PKG_CONFIG"],
      [AC_MSG_ERROR([The pkg-config script could not be found or is too old.])])

AC_ARG_ENABLE(buffer_useinline,
	      AS_HELP_STRING([--enable-buffer-useinline],
		             [define ISC_BUFFER_USEINLINE when compiling
				[default=yes]]),
	      if test yes = "${enable}"
	      then
		      AC_DEFINE([ISC_BUFFER_USEINLINE], [1],
			        [Define if you want to use inline buffers])
	      fi,
	      AC_DEFINE([ISC_BUFFER_USEINLINE], [1]))
196

197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
AC_ARG_ENABLE([fuzzing],
	      [AS_HELP_STRING([--enable-fuzzing=<afl|libfuzzer>],
			      [Enable fuzzing using American Fuzzy Lop or libFuzzer (default=no)])],
	      [],
	      [enable_fuzzing=no])

AC_MSG_CHECKING([whether to enable fuzzing mode])
AS_CASE([$enable_fuzzing],
	[no],[AC_MSG_RESULT([no])],
	[afl],[
	  AC_MSG_RESULT([using AFL])
	  AC_DEFINE([ENABLE_AFL], [1],
		    [Define to enable American Fuzzy Lop test harness])
	  CFLAGS="$CFLAGS -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION=1"
	  LIBS="$LIBS -lpthread"],
	[libfuzzer],[
	  AC_MSG_RESULT([using libFuzzer])
	  CFLAGS="$CFLAGS -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION=1 -fsanitize=fuzzer,address,undefined"
	  LDFLAGS="$LDFLAGS -fsanitize=fuzzer,address,undefined"],
	[*],[AC_MSG_ERROR([You need to explicitly select the fuzzer])])

AS_IF([test "$enable_fuzzing" = "afl"],
      [AC_MSG_CHECKING("for AFL enabled compiler")
       AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
					  [#ifndef __AFL_COMPILER
					   #error AFL compiler required
					   #endif
					  ])],
			 [AC_MSG_RESULT([yes])],
			 [AC_MSG_ERROR([set CC=afl-<gcc|clang> when --enable-fuzzing=afl is used])])
      ])
228

229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249
AC_ARG_ENABLE(mutex_atomics,
	      AS_HELP_STRING([--enable-mutex-atomics],
		             [emulate atomics by mutex-locked variables, useful for debugging
				[default=no]]),
	      [],
	      [enable_mutex_atomics=no])

AC_MSG_CHECKING([whether to emulate atomics with mutexes])
case "$enable_mutex_atomics" in
yes)
        AC_MSG_RESULT(yes)
        AC_DEFINE(ISC_MUTEX_ATOMICS, 1, [Define to emulate atomic variables with mutexes.])
        ;;
no)
        AC_MSG_RESULT(no)
        ;;
*)
        AC_MSG_ERROR("--enable-mutex-atomics requires yes or no")
        ;;
esac

250 251 252
#
# Perl is optional; it is used only by some of the system test scripts.
#
253 254 255
AC_PATH_PROGS([PERL], [perl5 perl])
AC_SUBST([PERL])
AM_CONDITIONAL([HAVE_PERL], [test -n "$PERL"])
256

257 258 259
AX_PERL_MODULE([Digest::HMAC])
AM_CONDITIONAL([HAVE_PERLMOD_DIGEST_HMAC],
	       [test "$HAVE_PERLMOD_DIGEST__HMAC" = "yes"])
260

261 262 263
AX_PERL_MODULE([File::Fetch])
AM_CONDITIONAL([HAVE_PERLMOD_FILE_FETCH],
	       [test "$HAVE_PERLMOD_FILE__FETCH" = "yes"])
264

265 266 267
AX_PERL_MODULE([Net::DNS])
AM_CONDITIONAL([HAVE_PERLMOD_NET_DNS],
	       [test "$HAVE_PERLMOD_NET__DNS" = "yes"])
268

269 270 271
AX_PERL_MODULE([Net::DNS::Nameserver])
AM_CONDITIONAL([HAVE_PERLMOD_NET_DNS_NAMESERVER],
	       [test "$HAVE_PERLMOD_NET__DNS__NAMESERVER" = "yes"])
272

273 274 275
AX_PERL_MODULE([Time::HiRes])
AM_CONDITIONAL([HAVE_PERLMOD_TIME_HIRES],
	       [test "$HAVE_PERLMOD_TIME__HIRES" = "yes"])
276

277 278 279 280 281
#
# Python is optional, it is used only by some of the system test scripts.
#
AM_PATH_PYTHON([3.4], [], [:])
AM_CONDITIONAL([HAVE_PYTHON], [test "$PYTHON" != ":"])
282

283
AC_PATH_PROGS([PYTEST], [pytest-3 py.test-3 pytest pytest-pypy], [])
Ondřej Surý's avatar
Ondřej Surý committed
284 285 286
AS_IF([test -z "$PYTEST"],
      [AC_MSG_WARN([pytest not found, some system tests will be skipped])])
AC_SUBST([PYTEST])
287
AM_CONDITIONAL([HAVE_PYTEST], [test -n "$PYTEST"])
Ondřej Surý's avatar
Ondřej Surý committed
288

289 290
AX_PYTHON_MODULE([dns])
AM_CONDITIONAL([HAVE_PYMOD_DNS], [test "$HAVE_PYMOD_DNS" = "yes"])
291

292
#
293
# xsltproc is optional, it is used only by system test scripts.
294
#
295
AC_PATH_PROG([XSLTPROC], [xsltproc])
296

297 298 299 300 301 302 303 304 305 306 307
#
# Using Solaris linker with gcc on Solaris breaks Thread Local Storage
#
AS_CASE([$host],
	[*-solaris*],[
	    AS_IF([test "$GCC" = "yes"],
		  [LDFLAGS="$LDFLAGS -zrelax=transtls"
		   AC_MSG_WARN([When using GNU C Compiler on Solaris, -zrelax=transtls linker flag is used to fix bug in Thread Local Storage])
		  ])
	])

308 309
AC_HEADER_STDC

310 311 312 313 314 315 316 317 318
AC_CHECK_HEADERS([fcntl.h regex.h sys/time.h unistd.h sys/mman.h sys/sockio.h sys/select.h sys/param.h sys/sysctl.h net/if6.h sys/socket.h net/route.h linux/netlink.h linux/rtnetlink.h], [], [],
		 [$ac_includes_default
		  #ifdef HAVE_SYS_PARAM_H
		  # include <sys/param.h>
		  #endif
		  #ifdef HAVE_SYS_SOCKET_H
		  # include <sys/socket.h>
		  #endif
		 ])
319

320 321 322
#
# Check for thread local storage
#
323 324 325 326
AC_CHECK_HEADERS([threads.h])
AX_TLS([AS_IF([test "$ac_cv_tls" != "thread_local"],
	      [AC_DEFINE_UNQUOTED([thread_local], [$ac_cv_tls], [Define if the compiler uses a different keyword than thread_local for TLS variables])])],
       [AC_MSG_ERROR([Thread Local Storage support required, update your toolchain to build BIND 9])])
327

328 329
AC_C_CONST
AC_C_INLINE
330
AC_C_VOLATILE
331
AC_C_FLEXIBLE_ARRAY_MEMBER
332

333 334 335 336
#
# Check for yield support on ARM processors
#
AS_CASE([$host],
337 338 339 340 341 342 343 344 345
	[arm*],
	[AC_MSG_CHECKING([for yield instruction support])
	 AC_COMPILE_IFELSE(
	     [AC_LANG_PROGRAM([[]],
			     [[__asm__ __volatile__ ("yield")]])],
	     [AC_MSG_RESULT([yes])
	      AC_DEFINE([HAVE_ARM_YIELD], [1],
			[define if the ARM yield instruction is available])],
	     [AC_MSG_RESULT([no])])])
346

347 348 349 350 351 352 353 354 355 356 357 358 359 360
#
# Check for pause support on SPARC processors
#
AS_CASE([$host],
	[sparc*],
	[AC_MSG_CHECKING([for pause instruction support])
	 AC_COMPILE_IFELSE(
	     [AC_LANG_PROGRAM([[]],
			     [[__asm__ __volatile__ ("pause")]])],
	     [AC_MSG_RESULT([yes])
	      AC_DEFINE([HAVE_SPARC_PAUSE], [1],
			[define if the SPARC pause instruction is available])],
	     [AC_MSG_RESULT([no])])])

361 362
AC_CHECK_FUNCS([sysctlbyname])

Evan Hunt's avatar
Evan Hunt committed
363 364 365 366 367
#
# Check for the existence of mmap to enable the fast format zones
#
AC_CHECK_FUNCS(mmap)

368 369 370
#
# Older versions of HP/UX don't define seteuid() and setegid()
#
371 372
AC_CHECK_FUNCS([seteuid setresuid])
AC_CHECK_FUNCS([setegid setresgid])
373

374
AC_TYPE_SIZE_T
375 376 377
AC_TYPE_SSIZE_T
AC_TYPE_UINTPTR_T

378 379
AC_HEADER_TIME

380 381 382
#
# check for uname library routine
#
383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400
AC_MSG_CHECKING([for uname])
AC_COMPILE_IFELSE(
  [AC_LANG_PROGRAM(
     [[#include <sys/utsname.h>
       #include <stdio.h>
      ]],
     [[
       struct utsname uts;
       uname(&uts);
       printf("running on %s %s %s for %s\n",
	      uts.sysname, uts.release, uts.version, uts.machine);
     ]])],
  [AC_MSG_RESULT(yes)
   AC_DEFINE([HAVE_UNAME], [1], [define if uname is available])
  ],
  [AC_MSG_RESULT(no)
   AC_MSG_WARN([uname is not correctly supported])
  ])
401

Francis Dupont's avatar
Francis Dupont committed
402 403 404
#
# check for GCC noreturn attribute
#
405
AX_GCC_FUNC_ATTRIBUTE([noreturn])
Francis Dupont's avatar
Francis Dupont committed
406

407 408 409
#
# check if we have kqueue
#
410 411 412 413 414 415 416
AC_ARG_ENABLE([kqueue],
	      [AS_HELP_STRING([--enable-kqueue],
			      [use BSD kqueue when available [default=yes]])],
	      [], enable_kqueue="yes")

AS_IF([test "$enable_kqueue" = "yes"],
      [AC_CHECK_FUNCS([kqueue])])
417 418

#
419 420
# check if we have epoll.  Linux kernel 2.4 has epoll_create() which fails,
# so we need to try running the code, not just test its existence.
421
#
422 423 424 425 426 427 428
AC_ARG_ENABLE([epoll],
	      [AS_HELP_STRING([--enable-epoll],
			      [use Linux epoll when available [default=auto]])],
	      [], [enable_epoll="yes"])

AS_IF([test "$enable_epoll" = "yes"],
      [AC_CHECK_FUNCS([epoll_create1])])
429 430 431 432

#
# check if we support /dev/poll
#
433 434 435 436 437 438
AC_ARG_ENABLE([devpoll],
	      [AS_HELP_STRING([--enable-devpoll],
			      [use /dev/poll when available [default=yes]])],
	      [], [enable_devpoll="yes"])
AS_IF([test "$enable_devpoll" = "yes"],
      [AC_CHECK_HEADERS([sys/devpoll.h devpoll.h])])
439

Michael Graff's avatar
Michael Graff committed
440
#
Evan Hunt's avatar
Evan Hunt committed
441
# GeoIP support?
Michael Graff's avatar
Michael Graff committed
442
#
443 444 445 446 447 448 449 450 451
# Should be on by default if libmaxminddb exists.
#
AC_ARG_ENABLE([geoip],
	      [AS_HELP_STRING([--disable-geoip],
			      [support GeoIP2 geolocation ACLs if available [default=yes]])],
	      [], [enable_geoip="yes"])

AC_ARG_WITH([maxminddb],
	    [AS_HELP_STRING([--with-maxminddb=PATH],
452
			    [Build with MaxMind GeoIP2 support (auto|yes|no|path) [default=auto]])],
453
	    [], [with_maxminddb="auto"])
454

455 456 457 458 459 460 461 462 463 464 465 466 467 468
AS_IF([test "$enable_geoip" = "yes"],
      [AS_CASE([$with_maxminddb],
	       [no],[AC_MSG_ERROR([Use '--disable-geoip' to disable the GeoIP])],
	       [auto],[PKG_CHECK_MODULES([MAXMINDDB], [libmaxminddb],
					 [AC_DEFINE([HAVE_GEOIP2], [1], [Build with GeoIP2 support])
					  PKG_CHECK_VAR([MAXMINDDB_PREFIX], [libmaxminddb], [prefix], [], [AC_MSG_ERROR([libmaxminddb prefix not found in pkg-config; set MAXMINDDB_PREFIX in the environment])])
					 ],[:])],
	       [yes],[PKG_CHECK_MODULES([MAXMINDDB], [libmaxminddb],
					[AC_DEFINE([HAVE_GEOIP2], [1], [Build with GeoIP2 support])
					 PKG_CHECK_VAR([MAXMINDDB_PREFIX], [libmaxminddb], [prefix], [], [AC_MSG_ERROR([libmaxminddb prefix not found in pkg-config; set MAXMINDDB_PREFIX in the environment])])
					])],
	       [ # default
		   AX_SAVE_FLAGS([maxminddb])
		   MAXMINDDB_CFLAGS="-I$with_maxminddb/include"
469
		   MAXMINDDB_LIBS="-L$with_maxminddb/lib"
470
		   CFLAGS="$CFLAGS $MAXMINDDB_CFLAGS"
471
		   LIBS="$LIBS $MAXMINDDB_LIBS"
472 473 474 475 476 477 478
		   AC_SEARCH_LIBS([MMDB_open], [maxminddb],
				  [AC_DEFINE([HAVE_GEOIP2], [1], [Build with GeoIP2 support])
				   MAXMINDDB_LIBS="$MAXMINDDB_LIBS $ac_cv_search_mmdb_open"
				   AC_MSG_NOTICE([GeoIP2 default database path set to $with_maxminddb/share/GeoIP])
				   AS_VAR_COPY([MAXMINDDB_PREFIX], [$with_maxminddb])
				  ],
				  [AC_MSG_ERROR([GeoIP2 requested, but libmaxminddb not found])])
479
		   AX_RESTORE_FLAGS([maxminddb])
480 481 482 483
	       ])
       AC_ARG_VAR([MAXMINDDB_PREFIX], [value of prefix for MAXMINDDB, overriding pkg-config])
])

484 485
AM_CONDITIONAL([HAVE_GEOIP2], [test -n "$MAXMINDDB_LIBS"])

486 487
AC_SUBST([MAXMINDDB_CFLAGS])
AC_SUBST([MAXMINDDB_LIBS])
Francis Dupont's avatar
Francis Dupont committed
488

489
AX_PTHREAD
Francis Dupont's avatar
Francis Dupont committed
490

491 492 493
LIBS="$PTHREAD_LIBS $LIBS"
CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
CC="$PTHREAD_CC"
Evan Hunt's avatar
Evan Hunt committed
494

495
AC_CHECK_FUNCS([pthread_attr_getstacksize pthread_attr_setstacksize])
Witold Krecicki's avatar
Witold Krecicki committed
496

497
AC_ARG_WITH([locktype],
Witold Krecicki's avatar
Witold Krecicki committed
498 499
	    AS_HELP_STRING([--with-locktype=ARG],
			   [Specify mutex lock type
500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530
			    (adaptive or standard)]),
	    [], [with_locktype="adaptive"])

AS_CASE([$with_locktype],
	[adaptive],[
	  AC_MSG_CHECKING([for PTHREAD_MUTEX_ADAPTIVE_NP])
	  AC_COMPILE_IFELSE(
	    [AC_LANG_PROGRAM(
	       [[
		 #ifndef _GNU_SOURCE
		 #define _GNU_SOURCE
		 #endif
		 #include <pthread.h>
	       ]],
	       [[
		 return (PTHREAD_MUTEX_ADAPTIVE_NP);
	       ]]
	     )],
	    [AC_MSG_RESULT([using adaptive lock type])
	     AC_DEFINE([HAVE_PTHREAD_MUTEX_ADAPTIVE_NP], 1,
		       [Support for PTHREAD_MUTEX_ADAPTIVE_NP]) ],
	    [AC_MSG_RESULT([using standard lock type])]
	  )],
	[standard],[AC_MSG_RESULT([using standard lock type])],
	[AC_MSG_ERROR([You must specify "adaptive" or "standard" for --with-locktype.])]
       )

AC_CHECK_HEADERS([sched.h])

AC_SEARCH_LIBS([sched_yield],[rt])
AC_CHECK_FUNCS([sched_yield pthread_yield pthread_yield_np])
Witold Krecicki's avatar
Witold Krecicki committed
531

Witold Krecicki's avatar
Witold Krecicki committed
532 533 534 535
AC_CHECK_HEADERS([sys/cpuset.h])
AC_CHECK_HEADERS([sys/procset.h])
AC_CHECK_FUNCS([pthread_setaffinity_np cpuset_setaffinity processor_bind sched_setaffinity])

Witold Krecicki's avatar
Witold Krecicki committed
536
# Look for functions relating to thread naming
537
AC_CHECK_FUNCS([pthread_setname_np pthread_set_name_np])
Witold Krecicki's avatar
Witold Krecicki committed
538 539
AC_CHECK_HEADERS([pthread_np.h], [], [], [#include <pthread.h>])

540
# libuv
541
AC_MSG_CHECKING([for libuv])
542 543 544 545 546 547 548
PKG_CHECK_MODULES([LIBUV], [libuv >= 1.0.0], [],
		  [AC_MSG_ERROR([libuv not found])])
AX_SAVE_FLAGS([libuv])

CFLAGS="$CFLAGS $LIBUV_CFLAGS"
LIBS="$LIBS $LIBUV_LIBS"

549 550
# Those functions are only provided in newer versions of libuv, we'll be emulating them
# for now
551
AC_CHECK_FUNCS([uv_handle_get_data uv_handle_set_data uv_import])
552
AX_RESTORE_FLAGS([libuv])
553

554 555 556 557 558
#
# flockfile is usually provided by pthreads
#
AC_CHECK_FUNCS([flockfile getc_unlocked])

Witold Krecicki's avatar
Witold Krecicki committed
559 560 561
#
# Look for sysconf to allow detection of the number of processors.
#
562
AC_CHECK_FUNCS([sysconf])
563

564
#
565
# Do we want to use pthread rwlock?
566 567
#
AC_ARG_ENABLE([pthread_rwlock],
568 569 570
	      [AS_HELP_STRING([--enable-pthread-rwlock],
			      [use pthread rwlock instead of internal rwlock implementation])],
	      [], [enable_pthread_rwlock=no])
571 572 573 574 575 576

AS_IF([test "$enable_pthread_rwlock" = "yes"],
      [AC_CHECK_FUNCS([pthread_rwlock_rdlock], [],
		      [AC_MSG_ERROR([pthread_rwlock_rdlock requested but not found])])
       AC_DEFINE([USE_PTHREAD_RWLOCK],[1],[Define if you want to use pthread rwlock implementation])
      ])
577

Ondřej Surý's avatar
Ondřej Surý committed
578
CRYPTO=OpenSSL
579

Ondřej Surý's avatar
Ondřej Surý committed
580
#
581
# OpenSSL/LibreSSL is mandatory
Ondřej Surý's avatar
Ondřej Surý committed
582
#
583 584
PKG_CHECK_MODULES([OPENSSL], [libcrypto], [],
		  [AX_CHECK_OPENSSL([:],[AC_MSG_FAILURE([OpenSSL/LibreSSL not found])])])
Ondřej Surý's avatar
Ondřej Surý committed
585

586 587
AX_SAVE_FLAGS([openssl])

588
CFLAGS="$CFLAGS $OPENSSL_CFLAGS"
Ondřej Surý's avatar
Ondřej Surý committed
589 590 591 592 593 594 595 596 597 598 599 600
LIBS="$LIBS $OPENSSL_LIBS"

AC_MSG_CHECKING([for OpenSSL >= 1.0.0 or LibreSSL])
AC_COMPILE_IFELSE(
    [AC_LANG_PROGRAM([[#include <openssl/opensslv.h>]],
		     [[#if !defined(LIBRESSL_VERSION_NUMBER) && (OPENSSL_VERSION_NUMBER < 0x1000000fL)
		       #error OpenSSL >= 1.0.0 or LibreSSL required
		       #endif
		      ]])],
    [AC_MSG_RESULT([yes])],
    [AC_MSG_FAILURE([not found])])

601 602 603 604 605 606 607 608 609
#
# Check for functions added in OpenSSL or LibreSSL
#

AC_CHECK_FUNCS([CRYPTO_zalloc])
AC_CHECK_FUNCS([EVP_CIPHER_CTX_new EVP_CIPHER_CTX_free])
AC_CHECK_FUNCS([EVP_MD_CTX_new EVP_MD_CTX_free EVP_MD_CTX_reset])
AC_CHECK_FUNCS([HMAC_CTX_new HMAC_CTX_free HMAC_CTX_reset HMAC_CTX_get_md])

Ondřej Surý's avatar
Ondřej Surý committed
610 611 612 613 614 615 616 617 618
#
# Check for algorithm support in OpenSSL
#

AC_CHECK_FUNCS([ECDSA_sign ECDSA_verify], [:],
	       [AC_MSG_FAILURE([ECDSA support in OpenSSL is mandatory.])])

AC_MSG_CHECKING([for ECDSA P-256 support])
AC_COMPILE_IFELSE(
619 620 621
    [AC_LANG_PROGRAM([[#include <openssl/evp.h>
		       #include <openssl/ec.h>]],
		     [[EC_KEY *key = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1);]])],
Ondřej Surý's avatar
Ondřej Surý committed
622 623 624 625 626
    [AC_MSG_RESULT([yes])],
    [AC_MSG_FAILURE([not found.  ECDSA P-256 support in OpenSSL is mandatory.])])

AC_MSG_CHECKING([for ECDSA P-384 support])
AC_COMPILE_IFELSE(
627 628 629
    [AC_LANG_PROGRAM([[#include <openssl/evp.h>
		       #include <openssl/ec.h>]],
		     [[EC_KEY *key = EC_KEY_new_by_curve_name(NID_secp384r1);]])],
Ondřej Surý's avatar
Ondřej Surý committed
630 631 632 633 634
    [AC_MSG_RESULT([yes])],
    [AC_MSG_FAILURE([not found.  ECDSA P-384 support in OpenSSL is mandatory.])])

AC_MSG_CHECKING([for Ed25519 support])
AC_COMPILE_IFELSE(
635 636 637
    [AC_LANG_PROGRAM([[#include <openssl/evp.h>
		       #include <openssl/ec.h>]],
		     [[EC_KEY *key = EC_KEY_new_by_curve_name(NID_ED25519);]])],
Ondřej Surý's avatar
Ondřej Surý committed
638 639 640
    [AC_DEFINE([HAVE_OPENSSL_ED25519], [1], [define if OpenSSL supports Ed25519])
     AC_MSG_RESULT([yes])],
    [AC_MSG_RESULT([no])])
641

Ondřej Surý's avatar
Ondřej Surý committed
642
AC_MSG_CHECKING([for Ed448 support])
Mark Andrews's avatar
Mark Andrews committed
643 644 645 646 647 648 649
AC_COMPILE_IFELSE(
    [AC_LANG_PROGRAM([[#include <openssl/evp.h>
		       #include <openssl/ec.h>]],
		     [[EC_KEY *key = EC_KEY_new_by_curve_name(NID_ED448);]])],
    [AC_DEFINE([HAVE_OPENSSL_ED448], [1], [define if OpenSSL supports Ed448])
     AC_MSG_RESULT([yes])],
    [AC_MSG_RESULT([no])])
650

651 652 653 654 655 656 657 658 659 660 661 662 663
AC_MSG_CHECKING([for SipHash support])
AC_COMPILE_IFELSE(
    [AC_LANG_PROGRAM([[#include <openssl/evp.h>
		       #include <openssl/opensslv.h>]],
		     [[#if OPENSSL_VERSION_NUMBER < 0x10101010L
		       #error OpenSSL >= 1.1.1a required for working SipHash initialization
		       #endif
		       EVP_PKEY *key = EVP_PKEY_new_raw_private_key(
			   EVP_PKEY_SIPHASH, NULL, NULL, 0);]])],
    [AC_DEFINE([HAVE_OPENSSL_SIPHASH], [1], [define if OpenSSL supports SipHash])
     AC_MSG_RESULT([yes])],
    [AC_MSG_RESULT([no])])

Ondřej Surý's avatar
Ondřej Surý committed
664 665 666 667 668
#
# Check for OpenSSL SHA-1 support
#
AC_CHECK_FUNCS([EVP_sha1], [:],
	       [AC_MSG_FAILURE([SHA-1 support in OpenSSL is mandatory.])])
669

Ondřej Surý's avatar
Ondřej Surý committed
670 671 672 673 674
#
# Check for OpenSSL SHA-2 support
#
AC_CHECK_FUNCS([EVP_sha224 EVP_sha256 EVP_sha384 EVP_sha512], [:],
	       [AC_MSG_FAILURE([SHA-2 support in OpenSSL is mandatory.])])
675

Ondřej Surý's avatar
Ondřej Surý committed
676 677 678 679 680
#
# Check for OpenSSL AES support
#
AC_CHECK_FUNCS([EVP_aes_128_ecb EVP_aes_192_ecb EVP_aes_256_ecb], [:],
	       [AC_MSG_FAILURE([AES support in OpenSSL is mandatory.])])
681

Evan Hunt's avatar
Evan Hunt committed
682
#
Ondřej Surý's avatar
Ondřej Surý committed
683
# Check for OpenSSL 1.1.x/LibreSSL functions
Evan Hunt's avatar
Evan Hunt committed
684
#
685
AC_CHECK_FUNCS([DH_get0_key ECDSA_SIG_get0 RSA_set0_key])
686

687 688 689 690 691 692 693 694 695 696 697 698 699 700 701
#
# Check whether FIPS mode is available and whether we should enable it
#
AC_ARG_ENABLE([fips-mode],
	      [AS_HELP_STRING([--enable-fips-mode],
			      [enable FIPS mode in OpenSSL library [default=no]])],
	      [], [enable_fips_mode="no"])

AC_MSG_CHECKING([whether to enable FIPS mode in OpenSSL library])
AS_CASE([$enable_fips_mode],
	[yes], [AC_MSG_RESULT([yes])
		AC_CHECK_FUNCS([FIPS_mode],
			       [], [AC_MSG_FAILURE([OpenSSL FIPS mode requested but not available.])])],
	[no], [AC_MSG_RESULT([no])])

702
AX_RESTORE_FLAGS([openssl])
703

704
AC_SUBST([OPENSSL_CFLAGS])
Ondřej Surý's avatar
Ondřej Surý committed
705
AC_SUBST([OPENSSL_LIBS])
706

707
#
Ondřej Surý's avatar
Ondřej Surý committed
708
# was --enable-native-pkcs11 specified?
709
#
710
AC_ARG_ENABLE([native-pkcs11],
Ondřej Surý's avatar
Ondřej Surý committed
711 712 713 714 715 716 717
	      AS_HELP_STRING([--enable-native-pkcs11],
			     [use native PKCS11 for public-key crypto [default=no]]),
	      [:], [enable_native_pkcs11="no"])

AC_MSG_CHECKING([for PKCS11 for Public-Key Cryptography])
AS_CASE([$enable_native_pkcs11],
	[no],[AC_MSG_RESULT([no])],
718
	[yes],[CRYPTO=pkcs11
Ondřej Surý's avatar
Ondřej Surý committed
719 720
	       AC_MSG_RESULT([yes])
	       AC_CHECK_FUNCS([getpassphrase])
721
	      ])
722
AM_CONDITIONAL([HAVE_PKCS11], [test "$CRYPTO" = "pkcs11"])
Ondřej Surý's avatar
Ondřej Surý committed
723

724
AC_SUBST([CRYPTO])
Ondřej Surý's avatar
Ondřej Surý committed
725 726 727 728
AS_CASE([$CRYPTO],
	[pkcs11],[AC_DEFINE([USE_PKCS11], [1], [define if PKCS11 is used for Public-Key Cryptography])],
	[AC_DEFINE([USE_OPENSSL], [1], [define if OpenSSL is used for Public-Key Cryptography])])

729
#
Ondřej Surý's avatar
Ondřej Surý committed
730
# was --with-pkcs11 specified?
731
#
Ondřej Surý's avatar
Ondřej Surý committed
732 733 734 735
AC_ARG_WITH([pkcs11],
	    [AS_HELP_STRING([--with-pkcs11[=PATH]],
			    [Build with PKCS11 support [no|path] (PATH is for the PKCS11 provider)])],
	    [:], [with_pkcs11="undefined"])
736

Ondřej Surý's avatar
Ondřej Surý committed
737 738 739 740 741
AS_CASE([$with_pkcs11],
	[yes|auto],[AC_MSG_ERROR([--with-pkcs11 needs explicit path to the PKCS11 library])],
	[no|undefined],[with_pkcs11="undefined"])
AC_DEFINE_UNQUOTED([PK11_LIB_LOCATION], ["$with_pkcs11"], [define the default PKCS11 library path])

742
AC_CHECK_FUNCS([clock_gettime])
Ondřej Surý's avatar
Ondřej Surý committed
743

744 745
AC_ARG_WITH([gssapi],
	    [AS_HELP_STRING([--with-gssapi=[PATH|[/path/]krb5-config]],
Ondřej Surý's avatar
Ondřej Surý committed
746
			   [Specify path for system-supplied GSSAPI
747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804
				[default=auto]])],
	    [], [with_gssapi="auto"])

KRB5_CONFIG=
AS_CASE([$with_gssapi],
	[no],[AC_MSG_CHECKING([for GSSAPI support])
	      AC_MSG_RESULT([no])],
	[yes],[AC_PATH_PROG([KRB5_CONFIG], [krb5-config])
	       AS_IF([test -z "$KRB5_CONFIG"],
		     [AC_MSG_ERROR([krb5-config required but not found])])],
	[auto],[AC_PATH_PROG([KRB5_CONFIG], [krb5-config])],
	[*krb5-config*],[KRB5_CONFIG="$with_gssapi"],
	[AC_MSG_ERROR([--with-gssapi requires yes|no|auto|/path/to/krb5-config])])

GSSAPI_CFLAGS=
GSSAPI_LIBS=
KRB5_CFLAGS=
KRB5_LIBS=
AS_IF([test -n "$KRB5_CONFIG"],
      [AC_MSG_CHECKING([for gssapi libraries])
       AX_SAVE_FLAGS([gssapi])
       GSSAPI_CFLAGS=`"$KRB5_CONFIG" --cflags gssapi`
       GSSAPI_LIBS=`"$KRB5_CONFIG" --libs gssapi`
       CFLAGS="$CFLAGS $GSSAPI_CFLAGS"
       LIBS="$LIBS $GSSAPI_LIBS"
       AC_MSG_RESULT([$GSSAPI_CFLAGS $GSSAPI_LIBS])
       AC_CHECK_HEADERS([gssapi/gssapi.h], [],
			[AC_CHECK_HEADERS([gssapi.h], [],
					  [AC_MSG_ERROR([neither gssapi/gssapi.h nor gssapi.h found])])])
       AC_CHECK_HEADERS([gssapi/gssapi_krb5.h],
			[AC_CHECK_HEADERS([gssapi_krb5.h], []
					  [AC_MSG_ERROR([neither gssapi/gssapi_krb5.h nor gssapi_krb5.h found])])])
       AC_CHECK_FUNCS([gss_acquire_cred],[],
		      [AC_MSG_ERROR([linking with $GSSAPI_LIBS does not work])])
       AX_RESTORE_FLAGS([gssapi])

       AC_MSG_CHECKING([for krb5 libraries])
       AX_SAVE_FLAGS([krb5])
       KRB5_CFLAGS=`"$KRB5_CONFIG" --cflags krb5`
       KRB5_LIBS=`$KRB5_CONFIG --libs krb5`
       CFLAGS="$CFLAGS $KRB5_CFLAGS"
       LIBS="$CFLAGS $KRB5_LIBS"
       AC_MSG_RESULT([$KRB5_CFLAGS $KRB5_LIBS])
       AC_CHECK_HEADERS([krb5/krb5.h], [],
			[AC_CHECK_HEADERS([krb5.h], [],
					  [AC_MSG_ERROR([neither krb5/krb5.h nor krb5 found])])])
       AC_CHECK_FUNCS([krb5_init_context], [],
		      [AC_MSG_ERROR([linking with $KRB5_LIBS failed])])
       AX_RESTORE_FLAGS([krb5])

       AC_DEFINE([HAVE_GSSAPI], [1], [Define to 1 if you have the Kerberos Framework available])
       # kludge to silence compiler warnings which recommend use of GSS.framework on macOS
       AS_CASE([$host],[*-darwin*],[CFLAGS="$CFLAGS -Wno-deprecated-declarations"])])
AM_CONDITIONAL([HAVE_GSSAPI], [test -n "$GSSAPI_LIBS"])
AC_SUBST([GSSAPI_CFLAGS])
AC_SUBST([GSSAPI_LIBS])
AC_SUBST([KRB5_CFLAGS])
AC_SUBST([KRB5_LIBS])
Francis Dupont's avatar
Francis Dupont committed
805

806 807 808 809
#
# was --with-lmdb specified?
#

Ondřej Surý's avatar
Ondřej Surý committed
810 811 812 813 814
AC_ARG_WITH([lmdb],
	    [AS_HELP_STRING([--with-lmdb=@<:@PATH@:>@],
			    [use LMDB library @<:@default=auto@:>@, optionally specify the prefix for lmdb library])],
	    [:],
	    [with_lmdb="auto"])
815

Ondřej Surý's avatar
Ondřej Surý committed
816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841
ac_lib_lmdb_found=no
AS_CASE([$with_lmdb],
	[no],[],
	[auto|yes], [PKG_CHECK_MODULES([LMDB], [lmdb],
				       [ac_lib_lmdb_found=yes],
				       [for ac_lib_lmdb_path in /usr /usr/local /opt /opt/local; do
						AX_LIB_LMDB([$ac_lib_lmdb_path],
							    [ac_lib_lmdb_found=yes
							     break])
					done
				       ])],
	[AX_LIB_LMDB([$with_lmdb],[ac_lib_lmdb_found=yes])])

# don't fail when in automatic mode
AS_IF([test "$with_lmdb" = "auto" && test "$ac_lib_lmdb_found" = "no"],
      [with_lmdb=no])

# hard fail when LMDB requested, but not found
AS_IF([test "$with_lmdb" != "no" && test "$ac_lib_lmdb_found" != "yes"],
      [AC_MSG_ERROR([LMDB requested, but not found])])

AS_IF([test "$ac_lib_lmdb_found" = "yes"],
      [AC_DEFINE([HAVE_LMDB], [1], [Use lmdb library])])

AC_SUBST([LMDB_CFLAGS])
AC_SUBST([LMDB_LIBS])
842
AM_CONDITIONAL([HAVE_LMDB], [test -n "$LMDB_LIBS"])
843

844 845 846
#
# was --with-libxml2 specified?
#
847 848 849 850 851 852 853 854 855 856 857 858 859
AC_ARG_WITH([libxml2],
	    [AS_HELP_STRING([--with-libxml2],
			    [build with libxml2 library [yes|no|auto] (default is auto)])],
	    [], [with_libxml2="auto"])

AS_CASE([$with_libxml2],
	[no],[],
	[auto],[PKG_CHECK_MODULES([LIBXML2], [libxml-2.0 >= 2.6.0],
				  [AC_DEFINE([HAVE_LIBXML2], [1], [Use libxml2 library])],
				  [:])],
	[yes],[PKG_CHECK_MODULES([LIBXML2], [libxml-2.0 >= 2.6.0],
				 [AC_DEFINE([HAVE_LIBXML2], [1], [Use libxml2 library])])],
	[AC_MSG_ERROR([Specifying libxml2 installation path is not supported, adjust PKG_CONFIG_PATH instead])])
860

861
AM_CONDITIONAL([HAVE_LIBXML2], [test -n "$LIBXML2_LIBS"])
862

863 864 865 866 867 868
#
# was --with-json-c specified?
#
AC_ARG_WITH([json-c],
	    [AS_HELP_STRING([--with-json-c],
			    [build with json-c library [yes|no|detect] (default is detect)])],
869
	    [], [with_json_c="detect"])
870

871 872 873 874 875 876 877 878 879
AS_CASE([$with_json_c],
	[no],[],
	[detect],[PKG_CHECK_MODULES([JSON_C], [json-c >= 0.11],
				    [AC_DEFINE([HAVE_JSON_C], [1], [Use json-c library])],
				    [:])],
	[yes],[PKG_CHECK_MODULES([JSON_C], [json-c >= 0.11],
				 [AC_DEFINE([HAVE_JSON_C], [1], [Use json-c library])])],
	[AC_MSG_ERROR([Specifying json-c installation path is not supported, adjust PKG_CONFIG_PATH instead])]
       )
880

881 882
AM_CONDITIONAL([HAVE_JSON_C], [test -n "$JSON_C_LIBS"])

883 884
AC_SUBST([JSON_C_CFLAGS])
AC_SUBST([JSON_C_LIBS])
885

886 887 888
#
# was --with-zlib specified?
#
889
AC_ARG_WITH([zlib],
890 891 892 893
	    [AS_HELP_STRING([--with-zlib],
			    [build with zlib for HTTP compression
			     [default=yes]])],
	    [], with_zlib="auto")
894 895 896 897 898 899 900 901 902

AS_CASE([$with_zlib],
       [no],[],
       [auto],[PKG_CHECK_MODULES([ZLIB], [zlib],
                                 [AC_DEFINE([HAVE_ZLIB], [1], [Use zlib library])],
                                 [:])],
       [yes],[PKG_CHECK_MODULES([ZLIB], [zlib],
                                [AC_DEFINE([HAVE_ZLIB], [1], [Use zlib library])])],
       [AC_MSG_ERROR([Specifying zlib installation path is not supported, adjust PKG_CONFIG_PATH instead])])
Evan Hunt's avatar
Evan Hunt committed
903 904
AC_SUBST([ZLIB_CFLAGS])
AC_SUBST([ZLIB_LIBS])
905

906 907 908 909 910
#
# Google/Great Performance Tools CPU Profiler
#
AC_MSG_CHECKING(whether to use gperftools profiler)
AC_ARG_WITH(gperftools-profiler,
911 912 913
	    AS_HELP_STRING([--with-gperftools-profiler],
			   [use gperftools CPU profiler]),
	    use_profiler="$withval", use_profiler="no")
914 915 916 917 918 919 920 921 922 923 924 925

case $use_profiler in
	yes)
		AC_MSG_RESULT(yes)
		AC_DEFINE([HAVE_GPERFTOOLS_PROFILER], 1,
		[Define to use gperftools CPU profiler.])
		LIBS="$LIBS -lprofiler"
		;;
	*)
		AC_MSG_RESULT(no)
		;;
esac
926

927
#
928
# Check if the system supports glibc-compatible backtrace() function.
929
#
930 931 932
AC_CHECK_HEADERS([execinfo.h],
		 [AC_SEARCH_LIBS([backtrace], [execinfo],
				 [AC_CHECK_FUNCS([backtrace backtrace_symbols])])])
933

934
AM_CONDITIONAL([HAVE_BACKTRACE], [test "$ac_cv_func_backtrace" = "yes"])
935

936 937 938 939
#
# We do the IPv6 compilation checking after libtool so that we can put
# the right suffix on the files.
#
940 941 942 943 944 945 946 947 948
AC_MSG_CHECKING([for IPv6 structures])
AC_COMPILE_IFELSE(
  [AC_LANG_PROGRAM(
     [[
       #include <sys/types.h>
       #include <sys/socket.h>
       #include <netinet/in.h>
     ]],
     [[
949 950
       struct sockaddr_in6 sin6;
       struct in6_addr in6;
951
       struct in6_pktinfo in6_pi;
952
       struct sockaddr_storage storage;
953
       in6 = in6addr_any;
954
       in6 = in6addr_loopback;
955
       sin6.sin6_scope_id = 0;
956
       return (0);
957 958 959
     ]])],
  [AC_MSG_RESULT([yes])],
  [AC_MSG_FAILURE([IPv6 support is mandatory])])
960

961
#
962 963 964
# Allow forcibly disabling TCP Fast Open support as autodetection might yield
# confusing results on some systems (e.g. FreeBSD; see set_tcp_fastopen()
# comment in lib/isc/unix/socket.c).
965
#
966

967 968 969
AC_ARG_ENABLE([tcp_fastopen],
	      [AS_HELP_STRING([--disable-tcp-fastopen],
			      [disable TCP Fast Open support [default=yes]])],
970
	      [], [enable_tcp_fastopen="yes"])
971

972 973
AS_IF([test "$enable_tcp_fastopen" = "yes"],
      [AC_DEFINE([ENABLE_TCP_FASTOPEN], [1], [define if you want TCP_FASTOPEN enabled if available])])
974

975
#
976
# Check for some other useful functions that are not ever-present.
977
#
978
AC_CHECK_FUNCS([strlcpy strlcat])
979

980
AC_SUBST(READLINE_LIB)
981
AC_ARG_WITH(readline,
982 983 984
	    AS_HELP_STRING([--with-readline[=LIBSPEC]],
			   [specify readline library [default auto]]),
	    use_readline="$withval", use_readline="auto")
985
case "$use_readline" in
986
no)	;;
987
*)
Evan Hunt's avatar
Evan Hunt committed
988
	saved_LIBS="$LIBS"
989 990 991 992 993
	case "$use_readline" in
	yes|auto) try_readline="-ledit"; or_readline="-lreadline" ;;
	*) try_readline="$use_readline"
	esac
	for readline in "$try_readline" $or_readline
Evan Hunt's avatar
Evan Hunt committed
994
	do
995 996
		LIBS="$readline"
		AC_MSG_NOTICE(checking for readline with $readline)
Evan Hunt's avatar
Evan Hunt committed
997
		AC_CHECK_FUNCS(readline)
998
		if test "yes" = "$ac_cv_func_readline"
Evan Hunt's avatar
Evan Hunt committed
999
		then
1000
			READLINE_LIB="$readline"
Evan Hunt's avatar
Evan Hunt committed
1001 1002 1003 1004
			break
		fi
		for lib in -lterminfo -ltermcap -lncurses -lcurses
		do
1005
			AC_MSG_NOTICE(checking for readline with $readline $lib)
Evan Hunt's avatar
Evan Hunt committed
1006
			unset ac_cv_func_readline
1007
			LIBS="$readline $lib"
Evan Hunt's avatar
Evan Hunt committed
1008
			AC_CHECK_FUNCS(readline)
1009
			if test "yes" = "$ac_cv_func_readline"
Evan Hunt's avatar
Evan Hunt committed
1010
			then
1011
				READLINE_LIB="$readline $lib"
Evan Hunt's avatar
Evan Hunt committed
1012 1013 1014
				break
			fi
		done
1015
		if test "yes" = "$ac_cv_func_readline"
1016 1017 1018
		then
			break
		fi
Evan Hunt's avatar
Evan Hunt committed
1019
	done
1020
	if test "auto" != "$use_readline" &&
1021
	   test "X$READLINE_LIB" = "X"
1022 1023 1024
	then
		AC_MSG_ERROR([The readline library was not found.])
	fi
1025
	LIBS="$saved_LIBS"
1026
	;;
1027
esac
1028
if test "yes" = "$ac_cv_func_readline"
1029 1030 1031 1032
then
	case "$READLINE_LIB" in
	*edit*)
		AC_CHECK_HEADERS(editline/readline.h)
1033 1034
		AC_CHECK_HEADERS(edit/readline/readline.h)
		AC_CHECK_HEADERS(edit/readline/history.h)
1035 1036 1037 1038 1039
		;;
	esac
	AC_CHECK_HEADERS(readline/readline.h)
	AC_CHECK_HEADERS(readline/history.h)
fi
1040

1041 1042 1043
#
# Security Stuff
#
1044 1045
# Note it is very recommended to *not* disable chroot(),
# this is only because chroot() was made obsolete by Posix.
1046
AC_ARG_ENABLE(chroot, AS_HELP_STRING([--disable-chroot], [disable chroot]))
1047 1048 1049 1050 1051 1052 1053
case "$enable_chroot" in
	yes|'')
		AC_CHECK_FUNCS(chroot)
		;;
	no)
		;;
esac
1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068

LIBCAP_LIBS=""
AC_MSG_CHECKING([whether to enable Linux capabilities])
AC_ARG_ENABLE([linux-caps],
	      [AS_HELP_STRING([--disable-linux-caps],
			      [disable Linux capabilities])],
	      [],
	      [AS_CASE([$host],
		       [*-linux*],[enable_linux_caps=yes],
		       [enable_linux_caps=no])])

AS_IF([test "$enable_linux_caps" = "yes"],
      [AC_MSG_RESULT([yes])
       AC_CHECK_HEADERS([sys/capability.h],
			[],
1069 1070
			[AC_MSG_ERROR(m4_normalize([sys/capability.h header is required for Linux capabilities support.
						    Either install libcap or use --disable-linux-caps.]))])
1071
       AX_SAVE_FLAGS([cap])
1072 1073
       AC_SEARCH_LIBS([cap_set_proc], [cap],
		      [LIBCAP_LIBS="$ac_cv_search_cap_set_proc"],
1074 1075
		      [AC_MSG_ERROR(m4_normalize([libcap is required for Linux capabilities support.
						  Either install libcap or use --disable-linux-caps.]))])
1076
       AX_RESTORE_FLAGS([cap])],
1077 1078 1079
      [AC_MSG_RESULT([no])])
AC_SUBST([LIBCAP_LIBS])

1080 1081 1082 1083 1084 1085 1086
case "$host" in
*-solaris*)
	AC_DEFINE(NEED_SECURE_DIRECTORY, 1,
		  [Define if connect does not honour the permission on the UNIX domain socket.])
	;;
esac

1087 1088 1089
#
# Time Zone Stuff
#
1090
AC_CHECK_FUNCS([tzset])
1091

Francis Dupont's avatar
Francis Dupont committed
1092
AC_MSG_CHECKING(for optarg declaration)
1093 1094 1095 1096 1097 1098
AC_TRY_COMPILE([
#include <unistd.h>
],
[optarg = 0;],
[AC_MSG_RESULT(yes)],
[AC_MSG_RESULT(no)
1099
GEN_NEED_OPTARG="-DNEED_OPTARG=1"
1100 1101
AC_DEFINE(NEED_OPTARG, 1, [Defined if extern char *optarg is not declared.])])

1102 1103 1104
#
# Check for nanoseconds in file stats
#
1105 1106 1107 1108 1109 1110 1111 1112
AC_MSG_CHECKING([for st_mtim.tv_nsec])
AC_COMPILE_IFELSE(
  [AC_LANG_PROGRAM(
     [[#include <sys/fcntl.h>]],
     [[struct stat s;
       return(s.st_mtim.tv_nsec);
      ]])],
   [AC_DEFINE([HAVE_STAT_NSEC], [1], [define if struct stat has st_mtim.tv_nsec field])])
1113

1114 1115 1116
#
# Check for if_nametoindex() for IPv6 scoped addresses support
#
1117
AC_CHECK_FUNCS([if_nametoindex])
1118

1119
AC_CHECK_FUNCS(nanosleep usleep explicit_bzero)
1120

1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137
ISC_ATOMIC_LIBS=""
AC_CHECK_HEADERS(
  [stdatomic.h],
  [AC_MSG_CHECKING([for memory model aware atomic operations])
   AC_COMPILE_IFELSE(
     [AC_LANG_PROGRAM(
	[[#include <stdatomic.h>]],
	[[atomic_int_fast32_t val = 0; atomic_fetch_add_explicit(&val, 1, memory_order_relaxed);]]
      )],
     [AC_MSG_RESULT([stdatomic.h])
      AC_MSG_CHECKING([whether -latomic is needed for 64-bit stdatomic.h functions])
      AC_LINK_IFELSE(
	[AC_LANG_PROGRAM(
	   [[#include <stdatomic.h>]],
	   [[atomic_int_fast64_t val = 0; atomic_fetch_add_explicit(&val, 1, memory_order_relaxed);]]
	 )],
	[AC_MSG_RESULT([no])],
1138
	[ISC_ATOMIC_LIBS="-latomic"
1139
	 AX_SAVE_FLAGS([atomic])
1140 1141 1142 1143 1144 1145 1146 1147
	 LIBS="$LIBS $ISC_ATOMIC_LIBS"
	 AC_LINK_IFELSE(
	   [AC_LANG_PROGRAM(
	      [[#include <stdatomic.h>]],
	      [[atomic_int_fast64_t val = 0; atomic_fetch_add_explicit(&val, 1, memory_order_relaxed);]]
	    )],
	   [AC_MSG_RESULT([yes])],
	   [AC_MSG_FAILURE([libatomic needed, but linking with -latomic failed, please fix your toolchain.])])
1148
	 AX_RESTORE_FLAGS([atomic])
1149 1150
	])
     ],
1151
     [AC_MSG_FAILURE([stdatomic.h header found, but compilation failed, please fix your toolchain.])]
1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167
   )],
  [AC_MSG_CHECKING([for memory model aware atomic operations])
   AC_COMPILE_IFELSE(
     [AC_LANG_PROGRAM(
	[[#include <inttypes.h>]],
	[[int32_t val = 0; __atomic_fetch_add(&val, 1, __ATOMIC_RELAXED);]]
      )],
     [AC_MSG_RESULT([__atomic builtins])
      AC_DEFINE([HAVE___ATOMIC], [1], [define if __atomic builtins are not available])
      AC_MSG_CHECKING([whether -latomic is needed for 64-bit __atomic builtins])
      AC_LINK_IFELSE(
	[AC_LANG_PROGRAM(
	   [[#include <inttypes.h>]],
	   [[int64_t val = 0; __atomic_fetch_add(&val, 1, __ATOMIC_RELAXED);]]
	 )],
	[AC_MSG_RESULT([no])],
1168
	[ISC_ATOMIC_LIBS="-latomic"
1169
	 AX_SAVE_FLAGS([atomic])
1170 1171 1172 1173 1174 1175 1176 1177
	 LIBS="$LIBS $ISC_ATOMIC_LIBS"
	 AC_LINK_IFELSE(
	   [AC_LANG_PROGRAM(
	      [[#include <inttypes.h>]],
	      [[int64_t val = 0; __atomic_fetch_add(&val, 1, __ATOMIC_RELAXED);]]
	    )],
	   [AC_MSG_RESULT([yes])],
	   [AC_MSG_FAILURE([libatomic needed, but linking with -latomic failed, please fix your toolchain.])])
1178
	 AX_RESTORE_FLAGS([atomic])
1179 1180 1181 1182 1183 1184
	])
     ],
     [AC_MSG_RESULT([__sync builtins])
     ])
  ])
LIBS="$LIBS $ISC_ATOMIC_LIBS"
1185

1186 1187
AC_CHECK_HEADERS([stdalign.h])

1188 1189
AC_CHECK_HEADERS([uchar.h])

1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204
#
# Check for __builtin_unreachable
#
AC_MSG_CHECKING([compiler support for __builtin_unreachable()])
AC_LINK_IFELSE(
  [AC_LANG_PROGRAM(
     [[]],
     [[__builtin_unreachable();]]
   )],
  [AC_MSG_RESULT([yes])
   AC_DEFINE([HAVE_BUILTIN_UNREACHABLE], [1], [define if the compiler supports __builtin_unreachable().])
  ],
  [AC_MSG_RESULT([no])
  ])

1205 1206 1207 1208 1209
#
# Check for __builtin_expect
#
AC_MSG_CHECKING([compiler support for __builtin_expect])
AC_TRY_LINK(, [
1210
	return (__builtin_expect(1, 1) ? 1 : 0);
1211
], [
1212 1213
	have_builtin_expect=yes
	AC_MSG_RESULT(yes)
1214
], [
1215 1216
	have_builtin_expect=no
	AC_MSG_RESULT(no)
1217
])
1218
if test "yes" = "$have_builtin_expect"; then
1219
	AC_DEFINE(HAVE_BUILTIN_EXPECT, 1, [Define to 1 if the compiler supports __builtin_expect.])
1220 1221
fi

1222 1223 1224 1225 1226
#
# Check for __builtin_clz
#
AC_MSG_CHECKING([compiler support for __builtin_clz])
AC_TRY_LINK(, [
1227
	return (__builtin_clz(0xff) == 24 ? 1 : 0);
1228
], [
1229 1230
	have_builtin_clz=yes
	AC_MSG_RESULT(yes)
1231
], [
1232 1233
	have_builtin_clz=no
	AC_MSG_RESULT(no)
1234
])
1235
if test "yes" = "$have_builtin_clz"; then
1236
	AC_DEFINE(HAVE_BUILTIN_CLZ, 1, [Define to 1 if the compiler supports __builtin_clz.])
1237 1238
fi

1239 1240 1241
#
# Activate "rrset-order fixed" or not?
#
1242 1243 1244 1245 1246 1247 1248
AC_ARG_ENABLE([fixed-rrset],
	      [AS_HELP_STRING([--enable-fixed-rrset],
			      [enable fixed rrset ordering [default=no]])],
	      [], [enable_fixed_rrset="no"])
AS_IF([test "$enable_fixed_rrset" = "yes"],
      [AC_DEFINE([DNS_RDATASET_FIXED], [1],
		 [Define to enable "rrset-order fixed" syntax.])])
1249

Evan Hunt's avatar
Evan Hunt committed
1250 1251 1252
#
# Activate dnstap?
#
1253 1254 1255 1256 1257 1258 1259 1260 1261
AC_ARG_ENABLE([dnstap],
	      [AS_HELP_STRING([--enable-dnstap],
			      [enable dnstap support
			       (requires fstrm, protobuf-c)])],
	      [], [enable_dnstap=no])

AS_IF([test "$enable_dnstap" != "no"],
      [PKG_CHECK_MODULES([DNSTAP], [libfstrm libprotobuf-c], [],
			 [AC_MSG_FAILURE([Required libraries (fstrm, protobuf-c) were not found, please install them.])])