configure.ac 53.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])
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

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

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

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

132 133
# 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"
134

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

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

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

157
AS_IF([test "$enable_developer" = "yes"],
158
      [STD_CPPFLAGS="$STD_CPPFLAGS -DISC_MEM_DEFAULTFILL=1 -DISC_LIST_CHECKINIT=1"
159 160 161 162 163
       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
164
       test "${enable_warn_error+set}" = set || enable_warn_error=yes
165
       ])
166 167 168 169

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

170 171 172 173 174 175 176
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"])

177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
#
# 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]))
195

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
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])])
      ])
227

228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248
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

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

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

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

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

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

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

276 277 278 279 280
#
# 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" != ":"])
281

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

287 288
AX_PYTHON_MODULE([dns])
AM_CONDITIONAL([HAVE_PYMOD_DNS], [test "$HAVE_PYMOD_DNS" = "yes"])
289

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

295 296 297 298 299 300 301 302 303 304 305
#
# 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])
		  ])
	])

306 307
AC_HEADER_STDC

308 309 310 311 312 313 314 315 316
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
		 ])
317

318 319 320
#
# Check for thread local storage
#
321 322 323 324
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])])
325

326 327
AC_C_CONST
AC_C_INLINE
328
AC_C_VOLATILE
329
AC_C_FLEXIBLE_ARRAY_MEMBER
330

331 332 333 334
#
# Check for yield support on ARM processors
#
AS_CASE([$host],
335 336 337 338 339 340 341 342 343
	[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])])])
344

345 346 347 348 349 350 351 352 353 354 355 356 357 358
#
# 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])])])

359 360
AC_CHECK_FUNCS([sysctlbyname])

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

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

372
AC_TYPE_SIZE_T
373 374 375
AC_TYPE_SSIZE_T
AC_TYPE_UINTPTR_T

376 377
AC_HEADER_TIME

378 379 380
#
# check for uname library routine
#
381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398
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])
  ])
399

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

405 406 407
#
# check if we have kqueue
#
408 409 410 411 412 413 414
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])])
415 416

#
417 418
# 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.
419
#
420 421 422 423 424 425 426
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])])
427 428 429 430

#
# check if we support /dev/poll
#
431 432 433 434 435 436
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])])
437

Michael Graff's avatar
Michael Graff committed
438
#
Evan Hunt's avatar
Evan Hunt committed
439
# GeoIP support?
Michael Graff's avatar
Michael Graff committed
440
#
441 442 443 444 445 446 447 448 449
# 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],
450
			    [Build with MaxMind GeoIP2 support (auto|yes|no|path) [default=auto]])],
451
	    [], [with_maxminddb="auto"])
452

453 454 455 456 457 458 459 460 461 462 463 464 465 466
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"
467
		   MAXMINDDB_LIBS="-L$with_maxminddb/lib"
468
		   CFLAGS="$CFLAGS $MAXMINDDB_CFLAGS"
469
		   LIBS="$LIBS $MAXMINDDB_LIBS"
470 471 472 473 474 475 476
		   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])])
477
		   AX_RESTORE_FLAGS([maxminddb])
478 479 480 481
	       ])
       AC_ARG_VAR([MAXMINDDB_PREFIX], [value of prefix for MAXMINDDB, overriding pkg-config])
])

482 483
AM_CONDITIONAL([HAVE_GEOIP2], [test -n "$MAXMINDDB_LIBS"])

484 485
AC_SUBST([MAXMINDDB_CFLAGS])
AC_SUBST([MAXMINDDB_LIBS])
Francis Dupont's avatar
Francis Dupont committed
486

487
AX_PTHREAD
Francis Dupont's avatar
Francis Dupont committed
488

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

493
AC_CHECK_FUNCS([pthread_attr_getstacksize pthread_attr_setstacksize])
Witold Krecicki's avatar
Witold Krecicki committed
494

495
AC_ARG_WITH([locktype],
Witold Krecicki's avatar
Witold Krecicki committed
496 497
	    AS_HELP_STRING([--with-locktype=ARG],
			   [Specify mutex lock type
498 499 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
			    (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
529

Witold Krecicki's avatar
Witold Krecicki committed
530 531 532 533
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
534
# Look for functions relating to thread naming
535
AC_CHECK_FUNCS([pthread_setname_np pthread_set_name_np])
Witold Krecicki's avatar
Witold Krecicki committed
536 537
AC_CHECK_HEADERS([pthread_np.h], [], [], [#include <pthread.h>])

538
# libuv
539
AC_MSG_CHECKING([for libuv])
540 541 542 543 544 545 546
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"

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

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

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

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

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])
      ])
575

Ondřej Surý's avatar
Ondřej Surý committed
576
CRYPTO=OpenSSL
577

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

584 585
AX_SAVE_FLAGS([openssl])

586
CFLAGS="$CFLAGS $OPENSSL_CFLAGS"
Ondřej Surý's avatar
Ondřej Surý committed
587 588 589 590 591 592 593 594 595 596 597 598
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])])

599 600 601 602 603 604 605 606 607
#
# 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
608 609 610 611 612 613 614 615 616
#
# 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(
617 618 619
    [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
620 621 622 623 624
    [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(
625 626 627
    [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
628 629 630 631 632
    [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(
633 634 635
    [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
636 637 638
    [AC_DEFINE([HAVE_OPENSSL_ED25519], [1], [define if OpenSSL supports Ed25519])
     AC_MSG_RESULT([yes])],
    [AC_MSG_RESULT([no])])
639

Ondřej Surý's avatar
Ondřej Surý committed
640
AC_MSG_CHECKING([for Ed448 support])
Mark Andrews's avatar
Mark Andrews committed
641 642 643 644 645 646 647
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])])
648

649 650 651 652 653 654 655 656 657 658 659 660 661
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
662 663 664 665 666
#
# Check for OpenSSL SHA-1 support
#
AC_CHECK_FUNCS([EVP_sha1], [:],
	       [AC_MSG_FAILURE([SHA-1 support in OpenSSL is mandatory.])])
667

Ondřej Surý's avatar
Ondřej Surý committed
668 669 670 671 672
#
# 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.])])
673

Ondřej Surý's avatar
Ondřej Surý committed
674 675 676 677 678
#
# 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.])])
679

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

685 686 687 688 689 690 691 692 693 694 695 696 697 698 699
#
# 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])])

700
AX_RESTORE_FLAGS([openssl])
701

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

705
#
Ondřej Surý's avatar
Ondřej Surý committed
706
# was --enable-native-pkcs11 specified?
707
#
708
AC_ARG_ENABLE([native-pkcs11],
Ondřej Surý's avatar
Ondřej Surý committed
709 710 711 712 713 714 715
	      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])],
716
	[yes],[CRYPTO=pkcs11
Ondřej Surý's avatar
Ondřej Surý committed
717 718
	       AC_MSG_RESULT([yes])
	       AC_CHECK_FUNCS([getpassphrase])
719
	      ])
720
AM_CONDITIONAL([HAVE_PKCS11], [test "$CRYPTO" = "pkcs11"])
Ondřej Surý's avatar
Ondřej Surý committed
721

722
AC_SUBST([CRYPTO])
Ondřej Surý's avatar
Ondřej Surý committed
723 724 725 726
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])])

727
#
Ondřej Surý's avatar
Ondřej Surý committed
728
# was --with-pkcs11 specified?
729
#
Ondřej Surý's avatar
Ondřej Surý committed
730 731 732 733
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"])
734

Ondřej Surý's avatar
Ondřej Surý committed
735 736 737 738 739
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])

740
AC_CHECK_FUNCS([clock_gettime])
Ondřej Surý's avatar
Ondřej Surý committed
741

742 743
AC_ARG_WITH([gssapi],
	    [AS_HELP_STRING([--with-gssapi=[PATH|[/path/]krb5-config]],
Ondřej Surý's avatar
Ondřej Surý committed
744
			   [Specify path for system-supplied GSSAPI
745 746 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
				[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
803

804 805 806 807
#
# was --with-lmdb specified?
#

Ondřej Surý's avatar
Ondřej Surý committed
808 809 810 811 812
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"])
813

Ondřej Surý's avatar
Ondřej Surý committed
814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839
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])
840
AM_CONDITIONAL([HAVE_LMDB], [test -n "$LMDB_LIBS"])
841

842 843 844
#
# was --with-libxml2 specified?
#
845 846 847 848 849 850 851 852 853 854 855 856 857
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])])
858

859
AM_CONDITIONAL([HAVE_LIBXML2], [test -n "$LIBXML2_LIBS"])
860

861 862 863 864 865 866
#
# 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)])],
867
	    [], [with_json_c="detect"])
868

869 870 871 872 873 874 875 876 877
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])]
       )
878

879 880
AM_CONDITIONAL([HAVE_JSON_C], [test -n "$JSON_C_LIBS"])

881 882
AC_SUBST([JSON_C_CFLAGS])
AC_SUBST([JSON_C_LIBS])
883

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

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
901 902
AC_SUBST([ZLIB_CFLAGS])
AC_SUBST([ZLIB_LIBS])
903

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

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
924

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

932
AM_CONDITIONAL([HAVE_BACKTRACE], [test "$ac_cv_func_backtrace" = "yes"])
933

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

959
#
960 961 962
# 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).
963
#
964

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

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

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

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

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

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],
			[],
1067 1068
			[AC_MSG_ERROR(m4_normalize([sys/capability.h header is required for Linux capabilities support.
						    Either install libcap or use --disable-linux-caps.]))])
1069
       AX_SAVE_FLAGS([cap])
1070 1071
       AC_SEARCH_LIBS([cap_set_proc], [cap],
		      [LIBCAP_LIBS="$ac_cv_search_cap_set_proc"],
1072 1073
		      [AC_MSG_ERROR(m4_normalize([libcap is required for Linux capabilities support.
						  Either install libcap or use --disable-linux-caps.]))])
1074
       AX_RESTORE_FLAGS([cap])],
1075 1076 1077
      [AC_MSG_RESULT([no])])
AC_SUBST([LIBCAP_LIBS])

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

1085 1086 1087
#
# Time Zone Stuff
#
1088
AC_CHECK_FUNCS([tzset])
1089

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

1100 1101 1102
#
# Check for nanoseconds in file stats
#
1103 1104 1105 1106 1107 1108 1109 1110
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])])
1111

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

1117
AC_CHECK_FUNCS(nanosleep usleep explicit_bzero)
1118

1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135
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])],
1136
	[ISC_ATOMIC_LIBS="-latomic"
1137
	 AX_SAVE_FLAGS([atomic])
1138 1139 1140 1141 1142 1143 1144 1145
	 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.])])
1146
	 AX_RESTORE_FLAGS([atomic])
1147 1148
	])
     ],
1149
     [AC_MSG_FAILURE([stdatomic.h header found, but compilation failed, please fix your toolchain.])]
1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165
   )],
  [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])],
1166
	[ISC_ATOMIC_LIBS="-latomic"
1167
	 AX_SAVE_FLAGS([atomic])
1168 1169 1170 1171 1172 1173 1174 1175
	 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.])])
1176
	 AX_RESTORE_FLAGS([atomic])
1177 1178 1179 1180 1181 1182
	])
     ],
     [AC_MSG_RESULT([__sync builtins])
     ])
  ])
LIBS="$LIBS $ISC_ATOMIC_LIBS"
1183

1184 1185
AC_CHECK_HEADERS([stdalign.h])

1186 1187
AC_CHECK_HEADERS([uchar.h])

1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202
#
# 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])
  ])

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

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

1237 1238 1239
#
# Activate "rrset-order fixed" or not?
#
1240 1241 1242 1243 1244 1245 1246
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.])])
1247

Evan Hunt's avatar
Evan Hunt committed
1248 1249 1250
#
# Activate dnstap?
#
1251 1252 1253 1254 1255 1256 1257 1258 1259
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.])])
1260 1261
       AC_PATH_PROG([FSTRM_CAPTURE], [fstrm_capture])
       AC_PATH_PROG([PROTOC_C], [protoc-c])
1262 1263 1264 1265
       AS_IF([test -z "$PROTOC_C"],
	     [AC_MSG_ERROR([protoc-c compiler not found])])
       AC_DEFINE([HAVE_DNSTAP], 1, [Define to 1 to enable dnstap support])
      ])
1266