Home | History | Annotate | Line # | Download | only in dist
      1 # Copyright (C) Internet Systems Consortium, Inc. ("ISC")
      2 #
      3 # SPDX-License-Identifier: MPL-2.0
      4 #
      5 # This Source Code Form is subject to the terms of the Mozilla Public
      6 # License, v. 2.0.  If a copy of the MPL was not distributed with this
      7 # file, you can obtain one at https://mozilla.org/MPL/2.0/.
      8 #
      9 # See the COPYRIGHT file distributed with this work for additional
     10 # information regarding copyright ownership.
     11 
     12 #
     13 # Defining the version in m4 requires a bit of dancing around,
     14 # so the strings are properly concatenated, as you can't use
     15 # a shell variable in AC_INIT
     16 #
     17 m4_define([bind_VERSION_MAJOR], 9)dnl
     18 m4_define([bind_VERSION_MINOR], 20)dnl
     19 m4_define([bind_VERSION_PATCH], 29)dnl
     20 m4_define([bind_VERSION_EXTRA], )dnl
     21 m4_define([bind_DESCRIPTION], [(Stable Release)])dnl
     22 m4_define([bind_SRCID], [m4_esyscmd_s([git rev-parse --short HEAD | cut -b1-7])])dnl
     23 m4_define([bind_PKG_VERSION], [[bind_VERSION_MAJOR.bind_VERSION_MINOR.bind_VERSION_PATCH]bind_VERSION_EXTRA])dnl
     24 
     25 #
     26 # Autoconf initialization
     27 #
     28 AC_INIT([BIND], bind_PKG_VERSION, [https://gitlab.isc.org/isc-projects/bind9/-/issues/new?issuable_template=Bug], [], [https://www.isc.org/downloads/])
     29 AC_PREREQ([2.69])
     30 
     31 AC_DEFINE([PACKAGE_VERSION_MAJOR], ["][bind_VERSION_MAJOR]["], [BIND 9 Major part of the version])
     32 AC_DEFINE([PACKAGE_VERSION_MINOR], ["][bind_VERSION_MINOR]["], [BIND 9 Minor part of the version])
     33 AC_DEFINE([PACKAGE_VERSION_PATCH], ["][bind_VERSION_PATCH]["], [BIND 9 Patch part of the version])
     34 AC_DEFINE([PACKAGE_VERSION_EXTRA], ["][bind_VERSION_EXTRA]["], [BIND 9 Extra part of the version])
     35 AC_DEFINE([PACKAGE_DESCRIPTION], [m4_ifnblank(bind_DESCRIPTION, [" ]bind_DESCRIPTION["], [])], [An extra string to print after PACKAGE_STRING])
     36 AC_DEFINE([PACKAGE_SRCID], ["][bind_SRCID]["], [A short hash from git])
     37 
     38 bind_CONFIGARGS="${ac_configure_args:-default}"
     39 AC_DEFINE_UNQUOTED([PACKAGE_CONFIGARGS], ["$bind_CONFIGARGS"], [Either 'defaults' or used ./configure options])
     40 
     41 AC_DEFINE([PACKAGE_BUILDER], ["make"], [make or Visual Studio])
     42 
     43 #
     44 # Get the Canonical System Type
     45 #
     46 AC_CANONICAL_BUILD
     47 AC_CANONICAL_HOST
     48 AC_CANONICAL_TARGET
     49 
     50 AC_CONFIG_SRCDIR([bin/named/main.c])
     51 AM_INIT_AUTOMAKE([1.14 tar-pax foreign subdir-objects dist-xz no-dist-gzip -Wall -Werror])
     52 AM_SILENT_RULES([yes])
     53 AM_EXTRA_RECURSIVE_TARGETS([test unit doc])
     54 
     55 AC_CONFIG_HEADERS([config.h])
     56 AC_CONFIG_MACRO_DIR([m4])
     57 
     58 #
     59 # Enable maintainer mode by default only when building from git repository
     60 # and not cross compling
     61 #
     62 AS_IF([test "$cross_compiling" = no],
     63       [AM_MAINTAINER_MODE(m4_ifset([bind_SRCID],[enable],[disable]))],
     64       [AM_MAINTAINER_MODE([disable])])
     65 
     66 #
     67 # Enable system extensions to C and POSIX
     68 #
     69 AC_USE_SYSTEM_EXTENSIONS
     70 
     71 #
     72 # Compiler compatibility flags
     73 #
     74 m4_version_prereq([2.70],
     75 		  [AC_PROG_CC],
     76 		  [AC_PROG_CC_C99])
     77 AC_PROG_CPP_WERROR
     78 
     79 #
     80 # Find build compiler when cross compiling
     81 #
     82 AX_PROG_CC_FOR_BUILD
     83 
     84 #
     85 # Find the machine's endian flavor.
     86 #
     87 AC_C_BIGENDIAN
     88 
     89 #
     90 # Enable large file support
     91 #
     92 AC_SYS_LARGEFILE
     93 AC_FUNC_FSEEKO
     94 
     95 # Enable RFC 3542 APIs on macOS
     96 AC_DEFINE([__APPLE_USE_RFC_3542], [1], [Select RFC3542 IPv6 API on macOS])
     97 
     98 AC_PROG_MAKE_SET
     99 
    100 # Checks for programs.
    101 m4_ifdef([AM_PROG_AR], [AM_PROG_AR]) # call AM_PROG_AR only if available
    102 
    103 AC_PROG_INSTALL
    104 AC_PROG_LN_S
    105 AX_POSIX_SHELL
    106 AC_PROG_MKDIR_P
    107 
    108 # Initialize libtool
    109 LT_INIT([disable-static dlopen pic-only])
    110 
    111 DLOPEN_LIBS="$lt_cv_dlopen_libs"
    112 AC_SUBST(DLOPEN_LIBS)
    113 
    114 AS_IF([test "$enable_static" != "no" && test "$enable_developer" != "yes"],
    115       [AC_MSG_ERROR([Static linking is not supported as it disables dlopen() and certain security features (e.g. RELRO, ASLR)])])
    116 
    117 
    118 #
    119 # Set the default CFLAGS, CPPFLAGS, and LDFLAGS
    120 #
    121 STD_CFLAGS="-Wall -Wextra -Wwrite-strings -Wpointer-arith -Wno-missing-field-initializers -Wformat -Wshadow"
    122 
    123 # These should be always errors
    124 STD_CFLAGS="$STD_CFLAGS -Werror=implicit-function-declaration -Werror=missing-prototypes -Werror=format-security -Werror=parentheses -Werror=implicit -Werror=strict-prototypes -Werror=vla"
    125 
    126 # Disable false positives generated by GCC 11+ and ASAN
    127 AC_COMPILE_IFELSE(
    128   [AC_LANG_PROGRAM([[]],
    129 		   [[#if __GNUC__ >= 11 && defined(__SANITIZE_ADDRESS__)
    130 		     #error Address Sanitizer enabled
    131 		     #endif
    132 		    ]])],
    133   [],
    134   [STD_CFLAGS="$STD_CFLAGS -Wno-stringop-overread"])
    135 
    136 # Silence GCC 11.1+ note about the changed alignment, see GL #4841
    137 AS_CASE([$target_cpu],[i?86],[STD_CFLAGS="$STD_CFLAGS -Wno-psabi"])
    138 
    139 STD_LDFLAGS=""
    140 
    141 # ... except in test code
    142 TEST_CFLAGS="-Wno-vla"
    143 
    144 # Fortify the sources by default (we undefine the macro first in case
    145 # the compiler has a different built-in setting)
    146 STD_CPPFLAGS="-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2"
    147 
    148 #
    149 # Additional compiler settings.
    150 #
    151 AX_CHECK_COMPILE_FLAG([-fno-strict-aliasing],
    152 		      [STD_CFLAGS="$STD_CFLAGS -fno-strict-aliasing"])
    153 # Clang only issues a warning so use -Werror to force a error.
    154 AX_CHECK_COMPILE_FLAG([-Werror -fno-delete-null-pointer-checks],
    155 		      [STD_CFLAGS="$STD_CFLAGS -fno-delete-null-pointer-checks"])
    156 AX_CHECK_COMPILE_FLAG([-fdiagnostics-show-option],
    157 		      [STD_CFLAGS="$STD_CFLAGS -fdiagnostics-show-option"])
    158 
    159 AX_CHECK_LINK_FLAG([-Wl,--export-dynamic],
    160 		   [STD_LDFLAGS="$STD_LDFLAGS -Wl,--export-dynamic"])
    161 
    162 host_macos=no
    163 AS_CASE([$host],[*-darwin*],[host_macos=yes])
    164 AM_CONDITIONAL([HOST_MACOS], [test "$host_macos" = "yes"])
    165 
    166 #
    167 # Change defaults for developers if not explicity set.
    168 # Needs to be before the option is tested.
    169 #
    170 # [pairwise: --enable-developer, --disable-developer]
    171 AC_ARG_ENABLE([developer],
    172 	      [AS_HELP_STRING([--enable-developer],
    173 			      [enable developer build settings])])
    174 
    175 AS_IF([test "$enable_developer" = "yes"],
    176       [DEVELOPER_MODE=yes
    177        STD_CPPFLAGS="$STD_CPPFLAGS -DDEVELOPER_MODE=1 -DISC_MEM_DEFAULTFILL=1 -DISC_MEM_TRACKLINES=1 -DISC_LIST_CHECKINIT=1 -DISC_STATS_CHECKUNDERFLOW=1 -DDNS_RBTDB_STRONG_RWLOCK_CHECK=1 -DISC_MUTEX_ERROR_CHECK=1"
    178        test "${enable_fixed_rrset+set}" = set || enable_fixed_rrset=yes
    179        test "${enable_querytrace+set}" = set || enable_querytrace=yes
    180        test "${with_cmocka+set}" = set || with_cmocka=yes
    181        test "${with_zlib+set}" = set || with_zlib=yes
    182        test "${enable_warn_error+set}" = set || enable_warn_error=yes
    183        ])
    184 
    185 AC_SUBST([DEVELOPER_MODE])
    186 AC_SUBST([STD_CFLAGS])
    187 AC_SUBST([STD_CPPFLAGS])
    188 AC_SUBST([STD_LDFLAGS])
    189 AC_SUBST([TEST_CFLAGS])
    190 
    191 # [pairwise: --enable-warn-error, --disable-warn-error]
    192 AC_ARG_ENABLE([warn_error],
    193 	      [AS_HELP_STRING([--enable-warn-error],
    194 			      [turn on -Werror when compiling])],
    195 	      [],[enable_warn_error=no])
    196 AS_IF([test "$enable_warn_error" = "yes"],
    197       [STD_CFLAGS="$STD_CFLAGS -Werror"])
    198 
    199 #
    200 # Use pkg-config
    201 #
    202 
    203 PKG_PROG_PKG_CONFIG
    204 AS_IF([test -z "$PKG_CONFIG"],
    205       [AC_MSG_ERROR([The pkg-config script could not be found or is too old.])])
    206 
    207 #
    208 # Pick Userspace-RCU flavor (developer only option)
    209 #
    210 # [pairwise: skip]
    211 AC_ARG_WITH([liburcu],
    212 	    [AS_HELP_STRING([--with-liburcu=FLAVOR],
    213 			     [Build with Userspace-RCU variant (developer-only option) (membarrier|qsbr|mb|bp) [default=membarrier]]))],
    214 	    [], [with_liburcu=membarrier])
    215 
    216 AC_MSG_CHECKING([liburcu flavor])
    217 AS_CASE([$with_liburcu],
    218 	[membarrier],
    219 	[RCU_FLAVOR="liburcu"
    220 	 AC_DEFINE([RCU_MEMBARRIER], [1], [Build with membarrier Userspace-RCU flavor])],
    221 	[qsbr],
    222 	[RCU_FLAVOR="liburcu-qsbr"
    223 	 AC_DEFINE([RCU_QSBR], [1], [Build with QSBR Userspace-RCU flavor])],
    224 	[mb],
    225 	[RCU_FLAVOR="liburcu-mb"
    226 	 AC_DEFINE([RCU_MB], [1], [Build with mb Userspace-RCU flavor])],
    227 	[bp],
    228 	[RCU_FLAVOR="liburcu-bp"
    229 	 AC_DEFINE([RCU_BP], [1], [Build with bulletproof Userspace-RCU flavor])],
    230 	[AC_MSG_ERROR([Invalid Userspace-RCU flavor picked])])
    231 
    232 AS_IF([test "$with_liburcu" != "membarrier" && test "$enable_developer" != "yes"],
    233       [AC_MSG_ERROR([Changing Userspace-RCU variant is allowed only in developer mode])])
    234 
    235 AC_MSG_RESULT([$RCU_FLAVOR])
    236 
    237 #
    238 # liburcu << v0.13.0 didn't add -lurcu-common and some toolchains would
    239 # not add it automatically - we need to add it explicitly in such case.
    240 #
    241 PKG_CHECK_MODULES([LIBURCU], [$RCU_FLAVOR >= 0.13.0 liburcu-cds >= 0.13.0], [],
    242 		  [PKG_CHECK_MODULES([LIBURCU], [$RCU_FLAVOR >= 0.10.0 liburcu-cds >= 0.10.0],
    243 				     [LIBURCU_LIBS="$LIBURCU_LIBS -lurcu-common"])])
    244 
    245 AC_DEFINE_UNQUOTED([RCU_FLAVOR], ["$RCU_FLAVOR"], [Chosen Userspace-RCU flavor])
    246 
    247 PKG_CHECK_VERSION([RCU_VERSION], [$RCU_FLAVOR])
    248 AC_DEFINE_UNQUOTED([RCU_VERSION], ["$RCU_VERSION"], [Compile-time Userspace-RCU version])
    249 
    250 CFLAGS="$CFLAGS $LIBURCU_CFLAGS"
    251 LIBS="$LIBS $LIBURCU_LIBS"
    252 
    253 AC_CHECK_HEADERS([urcu/assert.h urcu/uatomic.h urcu/pointer.h])
    254 
    255 #
    256 # Userspace-RCU inlining doesn't work for rcu_deference() with some combination
    257 # of C compiler and library version.
    258 #
    259 AC_MSG_CHECKING([whether we can inline small liburcu functions])
    260 AC_COMPILE_IFELSE(
    261   [AC_LANG_PROGRAM([[#define URCU_INLINE_SMALL_FUNCTIONS 1
    262 		     #include <urcu.h>]],
    263 		   [[struct opaque *a; struct opaque *b = rcu_dereference(a);]])],
    264   [AC_MSG_RESULT([yes])
    265    AC_DEFINE([URCU_INLINE_SMALL_FUNCTIONS], [1], [Inline small (less than 10 lines) functions])],
    266   [AC_MSG_RESULT([no])])
    267 
    268 # Fuzzing is not included in pairwise testing as fuzzing tools are
    269 # not present in the relevant Docker image.
    270 #
    271 # [pairwise: skip]
    272 AC_ARG_ENABLE([fuzzing],
    273 	      [AS_HELP_STRING([--enable-fuzzing=<afl|libfuzzer|ossfuzz>],
    274 			      [Enable fuzzing using American Fuzzy Lop or libFuzzer (default=no)])],
    275 	      [],
    276 	      [enable_fuzzing=no])
    277 
    278 AC_MSG_CHECKING([whether to enable fuzzing mode])
    279 AS_CASE([$enable_fuzzing],
    280 	[no],[AC_MSG_RESULT([no])],
    281 	[afl],[
    282 	  AC_MSG_RESULT([using AFL])
    283 	  AC_DEFINE([ENABLE_AFL], [1],
    284 		    [Define to enable American Fuzzy Lop test harness])
    285 	  STD_CFLAGS="$STD_CFLAGS -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION=1"
    286 	  FUZZ_LOG_COMPILER="afl.sh"],
    287 	[libfuzzer],[
    288 	  AC_MSG_RESULT([using libFuzzer])
    289 	  STD_CFLAGS="$STD_CFLAGS -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION=1 -fsanitize=fuzzer-no-link,address,undefined"
    290 	  LDFLAGS="$LDFLAGS -fsanitize=address,undefined"
    291 	  FUZZ_LDFLAGS="-fsanitize=fuzzer,address,undefined"
    292 	  FUZZ_LOG_COMPILER="libfuzzer.sh"],
    293 	[ossfuzz],[
    294 	    AC_MSG_RESULT([using OSS-Fuzz])
    295 	    FUZZ_LDFLAGS="$LIB_FUZZING_ENGINE"],
    296 	[*],[AC_MSG_ERROR([You need to explicitly select the fuzzer])])
    297 AM_CONDITIONAL([HAVE_FUZZ_LOG_COMPILER], [test -n "$FUZZ_LOG_COMPILER"])
    298 AC_SUBST([FUZZ_LOG_COMPILER])
    299 AC_SUBST([FUZZ_LDFLAGS])
    300 
    301 AS_IF([test "$enable_fuzzing" = "afl"],
    302       [AC_MSG_CHECKING("for AFL enabled compiler")
    303        AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
    304 					  [#ifndef __AFL_COMPILER
    305 					   #error AFL compiler required
    306 					   #endif
    307 					  ])],
    308 			 [AC_MSG_RESULT([yes])],
    309 			 [AC_MSG_ERROR([set CC=afl-<gcc|clang> when --enable-fuzzing=afl is used])])
    310       ])
    311 
    312 #
    313 # Perl is optional; it is used only by some of the system test scripts.
    314 #
    315 AC_PATH_PROGS([PERL], [perl5 perl])
    316 AC_SUBST([PERL])
    317 AM_CONDITIONAL([HAVE_PERL], [test -n "$PERL"])
    318 
    319 #
    320 # Python is optional, it is used only by some of the system test scripts.
    321 #
    322 AM_PATH_PYTHON([3.10], [], [:])
    323 AM_CONDITIONAL([HAVE_PYTHON], [test "$PYTHON" != ":"])
    324 
    325 AC_PATH_PROGS([PYTEST], [pytest-3 py.test-3 pytest py.test pytest-pypy], [])
    326 AS_IF([test -z "$PYTEST"],
    327       [AC_MSG_WARN([pytest not found, some system tests will be skipped])])
    328 AC_SUBST([PYTEST])
    329 AM_CONDITIONAL([HAVE_PYTEST], [test -n "$PYTEST"])
    330 
    331 #
    332 # Optional utilities, only used by system tests.
    333 #
    334 AC_PATH_PROG([JQ], [jq])
    335 AC_PATH_PROG([XMLLINT], [xmllint])
    336 AC_PATH_PROG([XSLTPROC], [xsltproc])
    337 
    338 #
    339 # Using Solaris linker with gcc on Solaris breaks Thread Local Storage
    340 #
    341 AS_CASE([$host],
    342 	[*-solaris*],[
    343 	    AS_IF([test "$GCC" = "yes"],
    344 		  [LDFLAGS="$LDFLAGS -zrelax=transtls"
    345 		   AC_MSG_WARN([When using GNU C Compiler on Solaris, -zrelax=transtls linker flag is used to fix bug in Thread Local Storage])
    346 		  ])
    347 	])
    348 
    349 AC_CHECK_HEADERS([sys/param.h sys/socket.h])
    350 AC_CHECK_HEADERS([fcntl.h regex.h sys/time.h unistd.h sys/mman.h sys/sockio.h sys/select.h sys/sysctl.h net/if6.h net/route.h linux/netlink.h linux/rtnetlink.h], [], [],
    351 		 [$ac_includes_default
    352 		  #ifdef HAVE_SYS_PARAM_H
    353 		  # include <sys/param.h>
    354 		  #endif
    355 		  #ifdef HAVE_SYS_SOCKET_H
    356 		  # include <sys/socket.h>
    357 		  #endif
    358 		 ])
    359 
    360 #
    361 # Check for C11 thread local storage
    362 #
    363 # NOTE: OpenBSD doesn't ship <threads.h>, so we can't require it (yet).
    364 #
    365 AC_CHECK_HEADERS([threads.h])
    366 
    367 #
    368 # C11 Atomic Operations
    369 #
    370 
    371 AC_CHECK_HEADERS([stdatomic.h],
    372 		 [],
    373 		 [AC_MSG_ERROR([C11 Atomic Operations required, update your toolchain to build BIND 9])])
    374 
    375 AC_COMPILE_IFELSE(
    376   [AC_LANG_PROGRAM(
    377      [[#include <stdatomic.h>]],
    378      [[atomic_int_fast32_t val = 0; atomic_fetch_add_explicit(&val, 1, memory_order_relaxed);]]
    379    )],
    380   [AC_MSG_CHECKING([whether -latomic is needed for 64-bit stdatomic.h functions])
    381    AC_LINK_IFELSE(
    382      [AC_LANG_PROGRAM(
    383 	[[#include <stdatomic.h>]],
    384 	[[atomic_int_fast64_t val = 0; atomic_fetch_add_explicit(&val, 1, memory_order_relaxed);]]
    385       )],
    386      [AC_MSG_RESULT([no])],
    387      [LIBS="$LIBS -latomic"
    388       AC_LINK_IFELSE(
    389 	[AC_LANG_PROGRAM(
    390 	   [[#include <stdatomic.h>]],
    391 	   [[atomic_int_fast64_t val = 0; atomic_fetch_add_explicit(&val, 1, memory_order_relaxed);]]
    392 	 )],
    393 	[AC_MSG_RESULT([yes])],
    394 	[AC_MSG_FAILURE([libatomic needed, but linking with -latomic failed, please fix your toolchain.])])
    395      ])
    396   ],
    397   [AC_MSG_FAILURE([stdatomic.h header found, but compilation failed, please fix your toolchain.])])
    398 
    399 AC_CHECK_HEADERS([stdnoreturn.h],
    400 		 [],
    401 		 [AC_MSG_ERROR([C11 standard headers not found, update your toolchain.])])
    402 
    403 AC_C_CONST
    404 AC_C_INLINE
    405 AC_C_VOLATILE
    406 
    407 #
    408 # Check for yield support on ARM processors
    409 #
    410 AS_CASE([$host],
    411 	[arm*|aarch64*],
    412 	[AC_MSG_CHECKING([for ARM yield instruction support])
    413 	 AC_COMPILE_IFELSE(
    414 	     [AC_LANG_PROGRAM([[]],
    415 			     [[__asm__ __volatile__ ("yield")]])],
    416 	     [AC_MSG_RESULT([yes])
    417 	      AC_DEFINE([HAVE_ARM_YIELD], [1],
    418 			[define if the ARM yield instruction is available])],
    419 	     [AC_MSG_RESULT([no])])])
    420 
    421 #
    422 # Check for pause support on SPARC processors
    423 #
    424 AS_CASE([$host],
    425 	[sparc*],
    426 	[AC_MSG_CHECKING([for pause instruction support])
    427 	 AC_COMPILE_IFELSE(
    428 	     [AC_LANG_PROGRAM([[]],
    429 			     [[__asm__ __volatile__ ("pause")]])],
    430 	     [AC_MSG_RESULT([yes])
    431 	      AC_DEFINE([HAVE_SPARC_PAUSE], [1],
    432 			[define if the SPARC pause instruction is available])],
    433 	     [AC_MSG_RESULT([no])])])
    434 
    435 AC_CHECK_FUNCS([sysctlbyname])
    436 
    437 AC_TYPE_SIZE_T
    438 AC_TYPE_SSIZE_T
    439 AC_TYPE_UINTPTR_T
    440 
    441 #
    442 # check for uname library routine
    443 #
    444 AC_MSG_CHECKING([for uname])
    445 AC_COMPILE_IFELSE(
    446   [AC_LANG_PROGRAM(
    447      [[#include <sys/utsname.h>
    448        #include <stdio.h>
    449       ]],
    450      [[
    451        struct utsname uts;
    452        uname(&uts);
    453        printf("running on %s %s %s for %s\n",
    454 	      uts.sysname, uts.release, uts.version, uts.machine);
    455      ]])],
    456   [AC_MSG_RESULT(yes)
    457    AC_DEFINE([HAVE_UNAME], [1], [define if uname is available])
    458   ],
    459   [AC_MSG_RESULT(no)
    460    AC_MSG_WARN([uname is not correctly supported])
    461   ])
    462 
    463 #
    464 # check for GCC noreturn attribute
    465 #
    466 AX_GCC_FUNC_ATTRIBUTE([noreturn])
    467 
    468 #
    469 # check for GCC malloc attribute
    470 #
    471 AX_GCC_FUNC_ATTRIBUTE([malloc])
    472 
    473 AC_MSG_CHECKING([for extended malloc attributes])
    474 AC_COMPILE_IFELSE(
    475   [AC_LANG_PROGRAM(
    476      [[
    477        #include <stddef.h>
    478        #include <stdlib.h>
    479 	   __attribute__ ((malloc, malloc (free, 1))
    480 	   void * xmalloc(size_t sz) { return malloc(sz); }
    481      ]],
    482      [[
    483        void *p = xmalloc(8);
    484 	   free(p);
    485      ]])],
    486   [AC_MSG_RESULT(yes)
    487    AC_DEFINE([HAVE_MALLOC_EXT_ATTR], [1], [define if extended attributes for malloc are available])
    488   ],
    489   [AC_MSG_RESULT(no)])
    490 
    491 #
    492 # check for GCC returns_nonnull attribute
    493 #
    494 AX_GCC_FUNC_ATTRIBUTE([returns_nonnull])
    495 
    496 #
    497 # check for GCC returns_nonnull attribute
    498 #
    499 AX_GCC_FUNC_ATTRIBUTE([warn_unused_result])
    500 
    501 #
    502 # how to link math functions?
    503 #
    504 AC_SEARCH_LIBS([sqrt],[m])
    505 
    506 #
    507 # GeoIP support?
    508 #
    509 # Should be on by default if libmaxminddb exists.
    510 #
    511 # [pairwise: --enable-geoip --with-maxminddb=auto, --enable-geoip --with-maxminddb=yes, --disable-geoip]
    512 AC_ARG_ENABLE([geoip],
    513 	      [AS_HELP_STRING([--disable-geoip],
    514 			      [support GeoIP2 geolocation ACLs if available [default=yes]])],
    515 	      [], [enable_geoip="yes"])
    516 
    517 # [pairwise: skip]
    518 AC_ARG_WITH([maxminddb],
    519 	    [AS_HELP_STRING([--with-maxminddb=PATH],
    520 			    [Build with MaxMind GeoIP2 support (auto|yes|no|path) [default=auto]])],
    521 	    [], [with_maxminddb="auto"])
    522 
    523 AS_IF([test "$enable_geoip" = "yes"],
    524       [AS_CASE([$with_maxminddb],
    525 	       [no],[AC_MSG_ERROR([Use '--disable-geoip' to disable the GeoIP])],
    526 	       [auto],[PKG_CHECK_MODULES([MAXMINDDB], [libmaxminddb],
    527 					 [AC_DEFINE([HAVE_GEOIP2], [1], [Build with GeoIP2 support])
    528 					  PKG_CHECK_VAR([MAXMINDDB_PREFIX], [libmaxminddb], [prefix], [], [AC_MSG_ERROR([libmaxminddb prefix not found in pkg-config; set MAXMINDDB_PREFIX in the environment])])
    529 					 ],[:])],
    530 	       [yes],[PKG_CHECK_MODULES([MAXMINDDB], [libmaxminddb],
    531 					[AC_DEFINE([HAVE_GEOIP2], [1], [Build with GeoIP2 support])
    532 					 PKG_CHECK_VAR([MAXMINDDB_PREFIX], [libmaxminddb], [prefix], [], [AC_MSG_ERROR([libmaxminddb prefix not found in pkg-config; set MAXMINDDB_PREFIX in the environment])])
    533 					])],
    534 	       [ # default
    535 		   AX_SAVE_FLAGS([maxminddb])
    536 		   MAXMINDDB_CFLAGS="-I$with_maxminddb/include"
    537 		   MAXMINDDB_LIBS="-L$with_maxminddb/lib"
    538 		   CFLAGS="$CFLAGS $MAXMINDDB_CFLAGS"
    539 		   LIBS="$LIBS $MAXMINDDB_LIBS"
    540 		   AC_SEARCH_LIBS([MMDB_open], [maxminddb],
    541 				  [AC_DEFINE([HAVE_GEOIP2], [1], [Build with GeoIP2 support])
    542 				   MAXMINDDB_LIBS="$MAXMINDDB_LIBS $ac_cv_search_MMDB_open"
    543 				   AC_MSG_NOTICE([GeoIP2 default database path set to $with_maxminddb/share/GeoIP])
    544 				   AS_VAR_COPY([MAXMINDDB_PREFIX], [with_maxminddb])
    545 				  ],
    546 				  [AC_MSG_ERROR([GeoIP2 requested, but libmaxminddb not found])])
    547 		   AX_RESTORE_FLAGS([maxminddb])
    548 	       ])
    549        AC_ARG_VAR([MAXMINDDB_PREFIX], [value of prefix for MAXMINDDB, overriding pkg-config])
    550 ])
    551 
    552 AM_CONDITIONAL([HAVE_GEOIP2], [test -n "$MAXMINDDB_LIBS"])
    553 
    554 AC_SUBST([MAXMINDDB_CFLAGS])
    555 AC_SUBST([MAXMINDDB_LIBS])
    556 
    557 AX_PTHREAD
    558 
    559 LIBS="$PTHREAD_LIBS $LIBS"
    560 CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
    561 CC="$PTHREAD_CC"
    562 
    563 AC_MSG_CHECKING([for PTHREAD_MUTEX_ADAPTIVE_NP])
    564 AC_COMPILE_IFELSE(
    565   [AC_LANG_PROGRAM([[#include <pthread.h>]],
    566 		   [[(void)pthread_mutexattr_settype(&(pthread_mutexattr_t){ NULL }, PTHREAD_MUTEX_ADAPTIVE_NP);]])],
    567   [AC_MSG_RESULT([yes])
    568    AC_DEFINE([HAVE_PTHREAD_MUTEX_ADAPTIVE_NP], [1], [Define to 1 if PTHREAD_MUTEX_ADAPTIVE_NP is available])],
    569   [AC_MSG_RESULT([no])])
    570 
    571 AC_CHECK_FUNCS([pthread_attr_getstacksize pthread_attr_setstacksize pthread_barrier_init pthread_spin_init])
    572 
    573 AC_CHECK_HEADERS([sched.h])
    574 
    575 AC_SEARCH_LIBS([sched_yield],[rt])
    576 AC_CHECK_FUNCS([sched_yield pthread_yield pthread_yield_np])
    577 
    578 # Look for functions relating to thread naming
    579 AC_CHECK_FUNCS([pthread_setname_np pthread_set_name_np])
    580 AC_CHECK_HEADERS([pthread_np.h], [], [], [#include <pthread.h>])
    581 
    582 # libuv
    583 PKG_CHECK_MODULES([LIBUV], [libuv >= 1.37.0], [],
    584 		  [PKG_CHECK_MODULES([LIBUV], [libuv >= 1.34.0 libuv < 1.35.0], [],
    585 				     [AC_MSG_ERROR([libuv >= 1.34.0 (except 1.35.0 and 1.36.0) not found])])])
    586 
    587 PKG_CHECK_VERSION([LIBUV_VERSION], [libuv])
    588 
    589 AX_SAVE_FLAGS([libuv])
    590 CFLAGS="$CFLAGS $LIBUV_CFLAGS"
    591 LIBS="$LIBS $LIBUV_LIBS"
    592 
    593 # libuv recvmmsg support
    594 AC_CHECK_DECLS([UV_UDP_MMSG_FREE, UV_UDP_MMSG_CHUNK], [], [], [[#include <uv.h>]])
    595 AC_MSG_CHECKING([whether struct msghdr uses padding for alignment])
    596 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <sys/socket.h>],
    597 				   [const struct msghdr h = { .__pad1 = 0, .__pad2 = 0 };])],
    598 		  [AC_MSG_RESULT([yes])
    599 		   AC_DEFINE([HAVE_DECL_UV_UDP_RECVMMSG],
    600 			     [0], [Disable recvmmsg support on systems with MUSL glibc])],
    601 		  [AC_MSG_RESULT([no])
    602 		   AC_CHECK_DECLS([UV_UDP_RECVMMSG], [], [], [[#include <uv.h>]])])
    603 
    604 # libuv recverr support
    605 AC_CHECK_DECLS([UV_UDP_LINUX_RECVERR], [], [], [[#include <uv.h>]])
    606 
    607 AX_RESTORE_FLAGS([libuv])
    608 
    609 # [pairwise: --enable-doh --with-libnghttp2=auto, --enable-doh --with-libnghttp2=yes, --disable-doh]
    610 AC_ARG_ENABLE([doh],
    611 	      [AS_HELP_STRING([--disable-doh], [disable DNS over HTTPS, removes dependency on libnghttp2 (default is --enable-doh)])],
    612 	      [], [enable_doh=yes])
    613 
    614 # [pairwise: skip]
    615 AC_ARG_WITH([libnghttp2],
    616 	    [AS_HELP_STRING([--with-libnghttp2],
    617 			    [build with libnghttp2 library [yes|no|auto] (default is auto)])],
    618 	    [], [with_libnghttp2="auto"])
    619 
    620 AS_IF([test "$enable_doh" = "yes"],
    621       [AS_CASE([$with_libnghttp2],
    622 	       [no],[AC_MSG_ERROR([Use '--disable-doh' to disable DNS-over-HTTPS support])],
    623 	       [auto|yes],[PKG_CHECK_MODULES([LIBNGHTTP2], [libnghttp2 >= 1.6.0],
    624 					     [AC_DEFINE([HAVE_LIBNGHTTP2], [1], [Build with DNS-over-HTTPS support])],
    625 					     [AC_MSG_ERROR(m4_normalize([DNS-over-HTTPS support requested, but libnghttp2 not found.
    626 									 Either install libnghttp2 or use --disable-doh.]))])],
    627 	       [AC_MSG_ERROR([Specifying libnghttp2 installation path is not supported, adjust PKG_CONFIG_PATH instead])])])
    628 
    629 AM_CONDITIONAL([HAVE_LIBNGHTTP2], [test -n "$LIBNGHTTP2_LIBS"])
    630 
    631 
    632 #
    633 # flockfile is usually provided by pthreads
    634 #
    635 AC_CHECK_FUNCS([flockfile getc_unlocked])
    636 
    637 #
    638 # Look for sysconf or other ways to allow detection of the number of processors.
    639 #
    640 AC_CHECK_FUNCS([sysconf])
    641 AC_CHECK_FUNCS(sysconf sched_getaffinity cpuset_getaffinity)
    642 AC_CHECK_HEADERS([sys/cpuset.h], [], [],
    643 		 [$ac_includes_default
    644 		  #ifdef HAVE_SYS_PARAM_H
    645 		  # include <sys/param.h>
    646 		  #endif
    647 		 ])
    648 
    649 #
    650 # Do we want to use pthread rwlock?
    651 #
    652 # [pairwise: --enable-pthread-rwlock, --disable-pthread-rwlock]
    653 AC_ARG_ENABLE([pthread_rwlock],
    654 	      [AS_HELP_STRING([--enable-pthread-rwlock],
    655 			      [use pthread rwlock instead of internal rwlock implementation])],
    656 	      [], [enable_pthread_rwlock=no])
    657 
    658 AS_IF([test "$enable_pthread_rwlock" = "yes"],
    659       [AC_CHECK_FUNCS([pthread_rwlock_rdlock], [],
    660 		      [AC_MSG_ERROR([pthread_rwlock_rdlock requested but not found])])
    661        AC_DEFINE([USE_PTHREAD_RWLOCK],[1],[Define if you want to use pthread rwlock implementation])
    662       ])
    663 AM_CONDITIONAL([USE_ISC_RWLOCK], [test "$enable_pthread_rwlock" != "yes"])
    664 
    665 AC_CHECK_FUNCS_ONCE([arc4random])
    666 
    667 #
    668 # OpenSSL/LibreSSL is mandatory
    669 #
    670 PKG_CHECK_MODULES([OPENSSL], [libssl libcrypto], [PKG_CHECK_VERSION([OPENSSL_VERSION], [openssl])],
    671 		  [AX_CHECK_OPENSSL([:], [AC_MSG_FAILURE([OpenSSL/LibreSSL not found])])])
    672 
    673 AX_SAVE_FLAGS([openssl])
    674 
    675 CFLAGS="$OPENSSL_CFLAGS $CFLAGS"
    676 LIBS="$OPENSSL_LIBS $LIBS"
    677 
    678 AC_MSG_CHECKING([for OpenSSL >= 1.0.0 or LibreSSL >= 2.7.0])
    679 AC_COMPILE_IFELSE(
    680     [AC_LANG_PROGRAM([[#include <openssl/opensslv.h>]],
    681 		     [[#if (!defined(LIBRESSL_VERSION_NUMBER) && (OPENSSL_VERSION_NUMBER < 0x1000000fL)) || \\
    682 			   (defined(LIBRESSL_VERSION_NUMBER) && (LIBRESSL_VERSION_NUMBER < 0x02070000fL))
    683 		       #error OpenSSL >= 1.0.0 or LibreSSL >= 2.7.0 required
    684 		       #endif
    685 		      ]])],
    686     [AC_MSG_RESULT([yes])],
    687     [AC_MSG_FAILURE([not found])])
    688 
    689 #
    690 # Check for functions added in OpenSSL or LibreSSL
    691 #
    692 
    693 AC_CHECK_FUNCS([BIO_read_ex BIO_write_ex])
    694 AC_CHECK_FUNCS([BN_GENCB_new])
    695 AC_CHECK_FUNCS([CRYPTO_zalloc])
    696 AC_CHECK_FUNCS([ERR_get_error_all])
    697 AC_CHECK_FUNCS([EVP_CIPHER_CTX_new EVP_CIPHER_CTX_free])
    698 AC_CHECK_FUNCS([EVP_MD_CTX_new EVP_MD_CTX_free EVP_MD_CTX_reset EVP_MD_CTX_get0_md])
    699 AC_CHECK_FUNCS([EVP_PKEY_new_raw_private_key EVP_PKEY_eq])
    700 AC_CHECK_FUNCS([OPENSSL_init_ssl OPENSSL_init_crypto OPENSSL_cleanup])
    701 AC_CHECK_FUNCS([SSL_CTX_set_keylog_callback])
    702 AC_CHECK_FUNCS([SSL_CTX_set_min_proto_version])
    703 AC_CHECK_FUNCS([SSL_CTX_up_ref])
    704 AC_CHECK_FUNCS([SSL_read_ex SSL_peek_ex SSL_write_ex])
    705 AC_CHECK_FUNCS([SSL_CTX_set1_cert_store X509_STORE_up_ref])
    706 AC_CHECK_FUNCS([SSL_CTX_up_ref])
    707 AC_CHECK_FUNCS([SSL_SESSION_is_resumable])
    708 AC_CHECK_FUNCS([SSL_CTX_set_ciphersuites])
    709 
    710 #
    711 # Check for algorithm support in OpenSSL
    712 #
    713 
    714 AC_CHECK_FUNCS([EVP_DigestSignInit EVP_DigestVerifyInit], [:],
    715 	       [AC_MSG_FAILURE([EVP_DigestSignInit/EVP_DigestVerifyInit support in OpenSSL is mandatory.])])
    716 
    717 AC_MSG_CHECKING([for ECDSA P-256 support])
    718 AC_COMPILE_IFELSE(
    719     [AC_LANG_PROGRAM([[#include <openssl/evp.h>]],
    720 		     [[EVP_PKEY_CTX *kctx = EVP_PKEY_CTX_new_id(NID_X9_62_prime256v1, NULL);]])],
    721     [AC_MSG_RESULT([yes])],
    722     [AC_MSG_FAILURE([not found.  ECDSA P-256 support in OpenSSL is mandatory.])])
    723 
    724 AC_MSG_CHECKING([for ECDSA P-384 support])
    725 AC_COMPILE_IFELSE(
    726     [AC_LANG_PROGRAM([[#include <openssl/evp.h>]],
    727 		     [[EVP_PKEY_CTX *kctx = EVP_PKEY_CTX_new_id(NID_secp384r1, NULL);]])],
    728     [AC_MSG_RESULT([yes])],
    729     [AC_MSG_FAILURE([not found.  ECDSA P-384 support in OpenSSL is mandatory.])])
    730 
    731 AC_MSG_CHECKING([for Ed25519 support])
    732 AC_COMPILE_IFELSE(
    733     [AC_LANG_PROGRAM([[#include <openssl/evp.h>]],
    734 		     [[EVP_PKEY_CTX *kctx = EVP_PKEY_CTX_new_id(NID_ED25519, NULL);]])],
    735     [AC_DEFINE([HAVE_OPENSSL_ED25519], [1], [define if OpenSSL supports Ed25519])
    736      AC_MSG_RESULT([yes])],
    737     [AC_MSG_RESULT([no])])
    738 
    739 AC_MSG_CHECKING([for Ed448 support])
    740 AC_COMPILE_IFELSE(
    741     [AC_LANG_PROGRAM([[#include <openssl/evp.h>]],
    742 		     [[EVP_PKEY_CTX *kctx = EVP_PKEY_CTX_new_id(NID_ED448, NULL);]])],
    743     [AC_DEFINE([HAVE_OPENSSL_ED448], [1], [define if OpenSSL supports Ed448])
    744      AC_MSG_RESULT([yes])],
    745     [AC_MSG_RESULT([no])])
    746 
    747 #
    748 # Check for OpenSSL SHA-1 support
    749 #
    750 AC_CHECK_FUNCS([EVP_sha1], [:],
    751 	       [AC_MSG_FAILURE([SHA-1 support in OpenSSL is mandatory.])])
    752 
    753 #
    754 # Check for OpenSSL SHA-2 support
    755 #
    756 AC_CHECK_FUNCS([EVP_sha224 EVP_sha256 EVP_sha384 EVP_sha512], [:],
    757 	       [AC_MSG_FAILURE([SHA-2 support in OpenSSL is mandatory.])])
    758 
    759 #
    760 # Check for OpenSSL 1.1.x/LibreSSL functions
    761 #
    762 AC_CHECK_FUNCS([ECDSA_SIG_get0 EVP_PKEY_get0_EC_KEY])
    763 AC_CHECK_FUNCS([RSA_set0_key EVP_PKEY_get0_RSA])
    764 
    765 AC_CHECK_FUNCS([TLS_server_method TLS_client_method])
    766 
    767 #
    768 # Check whether FIPS mode is available and whether we should enable it
    769 #
    770 # FIPS is not included in pairwise testing as the relevant Docker image
    771 # does not support FIPS mode.
    772 #
    773 AC_CHECK_FUNCS(EVP_default_properties_enable_fips FIPS_mode)
    774 
    775 # [pairwise: skip]
    776 AC_ARG_ENABLE([fips-mode],
    777 	      [AS_HELP_STRING([--enable-fips-mode],
    778 			      [enable FIPS mode in OpenSSL library [default=no]])],
    779 	      [], [enable_fips_mode="no"])
    780 
    781 AC_MSG_CHECKING([whether to enable FIPS mode in OpenSSL library])
    782 AS_CASE([$enable_fips_mode],
    783 	[yes], [AC_MSG_RESULT([yes])
    784 	        AC_DEFINE([ENABLE_FIPS_MODE], [1], [Define to 1 if you want FIPS mode to be enabled])
    785 		AS_IF([test "x$ac_cv_func_FIPS_mode" != xyes -a "x$ac_cv_func_EVP_default_properties_enable_fips" != xyes],
    786 		      AC_MSG_FAILURE([OpenSSL FIPS mode requested but not available.]))],
    787 	[no], [AC_MSG_RESULT([no])])
    788 
    789 AX_RESTORE_FLAGS([openssl])
    790 
    791 AC_SUBST([OPENSSL_CFLAGS])
    792 AC_SUBST([OPENSSL_LIBS])
    793 
    794 AC_CHECK_FUNCS([clock_gettime])
    795 
    796 # [pairwise: --with-gssapi=yes, --with-gssapi=auto, --without-gssapi]
    797 AC_ARG_WITH([gssapi],
    798 	    [AS_HELP_STRING([--with-gssapi=[PATH|[/path/]krb5-config]],
    799 			   [Specify path for system-supplied GSSAPI
    800 				[default=auto]])],
    801 	    [], [with_gssapi="auto"])
    802 
    803 KRB5_CONFIG=
    804 AS_CASE([$with_gssapi],
    805 	[no],[AC_MSG_CHECKING([for GSSAPI support])
    806 	      AC_MSG_RESULT([no])],
    807 	[yes],[AC_PATH_PROG([KRB5_CONFIG], [krb5-config])
    808 	       AS_IF([test -z "$KRB5_CONFIG"],
    809 		     [AC_MSG_ERROR([krb5-config required but not found])])],
    810 	[auto],[AC_PATH_PROG([KRB5_CONFIG], [krb5-config])],
    811 	[*krb5-config*],[KRB5_CONFIG="$with_gssapi"],
    812 	[AC_MSG_ERROR([--with-gssapi requires yes|no|auto|/path/to/krb5-config])])
    813 
    814 GSSAPI_CFLAGS=
    815 GSSAPI_LIBS=
    816 KRB5_CFLAGS=
    817 KRB5_LIBS=
    818 AS_IF([test -n "$KRB5_CONFIG"],
    819       [AC_MSG_CHECKING([for gssapi libraries])
    820        AX_SAVE_FLAGS([gssapi])
    821        GSSAPI_CFLAGS=`"$KRB5_CONFIG" --cflags gssapi`
    822        GSSAPI_LIBS=`"$KRB5_CONFIG" --libs gssapi`
    823        CFLAGS="$CFLAGS $GSSAPI_CFLAGS"
    824        LIBS="$LIBS $GSSAPI_LIBS"
    825        AC_MSG_RESULT([$GSSAPI_CFLAGS $GSSAPI_LIBS])
    826        AC_CHECK_HEADERS([gssapi/gssapi.h], [],
    827 			[AC_CHECK_HEADERS([gssapi.h], [],
    828 					  [AC_MSG_ERROR([neither gssapi/gssapi.h nor gssapi.h found])])])
    829        AC_CHECK_HEADERS([gssapi/gssapi_krb5.h],
    830 			[AC_CHECK_HEADERS([gssapi_krb5.h], []
    831 					  [AC_MSG_ERROR([neither gssapi/gssapi_krb5.h nor gssapi_krb5.h found])])])
    832        AC_CHECK_FUNCS([gss_acquire_cred],[],
    833 		      [AC_MSG_ERROR([linking with $GSSAPI_LIBS does not work])])
    834        AX_RESTORE_FLAGS([gssapi])
    835 
    836        AC_MSG_CHECKING([for krb5 libraries])
    837        AX_SAVE_FLAGS([krb5])
    838        KRB5_CFLAGS=`"$KRB5_CONFIG" --cflags krb5`
    839        KRB5_LIBS=`$KRB5_CONFIG --libs krb5`
    840        CFLAGS="$CFLAGS $KRB5_CFLAGS"
    841        LIBS="$CFLAGS $KRB5_LIBS"
    842        AC_MSG_RESULT([$KRB5_CFLAGS $KRB5_LIBS])
    843        AC_CHECK_HEADERS([krb5/krb5.h], [],
    844 			[AC_CHECK_HEADERS([krb5.h], [],
    845 					  [AC_MSG_ERROR([neither krb5/krb5.h nor krb5 found])])])
    846        AC_CHECK_FUNCS([krb5_init_context], [],
    847 		      [AC_MSG_ERROR([linking with $KRB5_LIBS failed])])
    848        AX_RESTORE_FLAGS([krb5])
    849 
    850        AC_DEFINE([HAVE_GSSAPI], [1], [Define to 1 if you have the Kerberos Framework available])
    851        # kludge to silence compiler warnings which recommend use of GSS.framework on macOS
    852        AS_CASE([$host],[*-darwin*],[CFLAGS="$CFLAGS -Wno-deprecated-declarations"])])
    853 AM_CONDITIONAL([HAVE_GSSAPI], [test -n "$GSSAPI_LIBS"])
    854 AC_SUBST([GSSAPI_CFLAGS])
    855 AC_SUBST([GSSAPI_LIBS])
    856 AC_SUBST([KRB5_CFLAGS])
    857 AC_SUBST([KRB5_LIBS])
    858 
    859 #
    860 # was --with-lmdb specified?
    861 #
    862 
    863 # [pairwise: --with-lmdb=auto, --with-lmdb=yes, --without-lmdb]
    864 AC_ARG_WITH([lmdb],
    865 	    [AS_HELP_STRING([--with-lmdb=@<:@PATH@:>@],
    866 			    [use LMDB library @<:@default=auto@:>@, optionally specify the prefix for lmdb library])],
    867 	    [:],
    868 	    [with_lmdb="auto"])
    869 
    870 ac_lib_lmdb_found=no
    871 AS_CASE([$with_lmdb],
    872 	[no],[],
    873 	[auto|yes], [PKG_CHECK_MODULES([LMDB], [lmdb],
    874 				       [ac_lib_lmdb_found=yes],
    875 				       [for ac_lib_lmdb_path in /usr /usr/local /opt /opt/local; do
    876 						AX_LIB_LMDB([$ac_lib_lmdb_path],
    877 							    [ac_lib_lmdb_found=yes
    878 							     break])
    879 					done
    880 				       ])],
    881 	[AX_LIB_LMDB([$with_lmdb],[ac_lib_lmdb_found=yes])])
    882 
    883 # don't fail when in automatic mode
    884 AS_IF([test "$with_lmdb" = "auto" && test "$ac_lib_lmdb_found" = "no"],
    885       [with_lmdb=no])
    886 
    887 # hard fail when LMDB requested, but not found
    888 AS_IF([test "$with_lmdb" != "no" && test "$ac_lib_lmdb_found" != "yes"],
    889       [AC_MSG_ERROR([LMDB requested, but not found])])
    890 
    891 AS_IF([test "$ac_lib_lmdb_found" = "yes"],
    892       [AC_DEFINE([HAVE_LMDB], [1], [Use lmdb library])])
    893 
    894 AC_SUBST([LMDB_CFLAGS])
    895 AC_SUBST([LMDB_LIBS])
    896 AM_CONDITIONAL([HAVE_LMDB], [test -n "$LMDB_LIBS"])
    897 
    898 #
    899 # was --with-libxml2 specified?
    900 #
    901 # [pairwise: --with-libxml2=auto, --with-libxml2=yes, --without-libxml2]
    902 AC_ARG_WITH([libxml2],
    903 	    [AS_HELP_STRING([--with-libxml2],
    904 			    [build with libxml2 library [yes|no|auto] (default is auto)])],
    905 	    [], [with_libxml2="auto"])
    906 
    907 AS_CASE([$with_libxml2],
    908 	[no],[],
    909 	[auto],[PKG_CHECK_MODULES([LIBXML2], [libxml-2.0 >= 2.6.0],
    910 				  [AC_DEFINE([HAVE_LIBXML2], [1], [Use libxml2 library])],
    911 				  [:])],
    912 	[yes],[PKG_CHECK_MODULES([LIBXML2], [libxml-2.0 >= 2.6.0],
    913 				 [AC_DEFINE([HAVE_LIBXML2], [1], [Use libxml2 library])])],
    914 	[AC_MSG_ERROR([Specifying libxml2 installation path is not supported, adjust PKG_CONFIG_PATH instead])])
    915 
    916 AM_CONDITIONAL([HAVE_LIBXML2], [test -n "$LIBXML2_LIBS"])
    917 
    918 #
    919 # was --with-json-c specified?
    920 #
    921 # [pairwise: --with-json-c=detect, --with-json-c=yes, --without-json-c]
    922 AC_ARG_WITH([json-c],
    923 	    [AS_HELP_STRING([--with-json-c],
    924 			    [build with json-c library [yes|no|detect] (default is detect)])],
    925 	    [], [with_json_c="detect"])
    926 
    927 AS_CASE([$with_json_c],
    928 	[no],[],
    929 	[detect],[PKG_CHECK_MODULES([JSON_C], [json-c >= 0.11],
    930 				    [AC_DEFINE([HAVE_JSON_C], [1], [Use json-c library])],
    931 				    [:])],
    932 	[yes],[PKG_CHECK_MODULES([JSON_C], [json-c >= 0.11],
    933 				 [AC_DEFINE([HAVE_JSON_C], [1], [Use json-c library])])],
    934 	[AC_MSG_ERROR([Specifying json-c installation path is not supported, adjust PKG_CONFIG_PATH instead])]
    935        )
    936 
    937 AM_CONDITIONAL([HAVE_JSON_C], [test -n "$JSON_C_LIBS"])
    938 
    939 AC_SUBST([JSON_C_CFLAGS])
    940 AC_SUBST([JSON_C_LIBS])
    941 
    942 #
    943 # was --with-zlib specified?
    944 #
    945 # [pairwise: --with-zlib=auto, --with-zlib=yes, --without-zlib]
    946 AC_ARG_WITH([zlib],
    947 	    [AS_HELP_STRING([--with-zlib],
    948 			    [build with zlib for HTTP compression
    949 			     [default=yes]])],
    950 	    [], with_zlib="auto")
    951 
    952 AS_CASE([$with_zlib],
    953        [no],[],
    954        [auto],[PKG_CHECK_MODULES([ZLIB], [zlib],
    955 				 [AC_DEFINE([HAVE_ZLIB], [1], [Use zlib library])],
    956 				 [:])],
    957        [yes],[PKG_CHECK_MODULES([ZLIB], [zlib],
    958 				[AC_DEFINE([HAVE_ZLIB], [1], [Use zlib library])])],
    959        [AC_MSG_ERROR([Specifying zlib installation path is not supported, adjust PKG_CONFIG_PATH instead])])
    960 AC_SUBST([ZLIB_CFLAGS])
    961 AC_SUBST([ZLIB_LIBS])
    962 
    963 #
    964 # Check if the system supports glibc-compatible backtrace() function.
    965 #
    966 AC_CHECK_HEADERS([execinfo.h],
    967 		 [AC_SEARCH_LIBS([backtrace_symbols], [execinfo],
    968 				 [AC_CHECK_FUNCS([backtrace_symbols])])])
    969 
    970 #
    971 # We do the IPv6 compilation checking after libtool so that we can put
    972 # the right suffix on the files.
    973 #
    974 AC_MSG_CHECKING([for IPv6 structures])
    975 AC_COMPILE_IFELSE(
    976   [AC_LANG_PROGRAM(
    977      [[
    978        #include <sys/types.h>
    979        #include <sys/socket.h>
    980        #include <netinet/in.h>
    981      ]],
    982      [[
    983        struct sockaddr_in6 sin6;
    984        struct in6_addr in6;
    985        struct in6_pktinfo in6_pi;
    986        struct sockaddr_storage storage;
    987        in6 = in6addr_any;
    988        in6 = in6addr_loopback;
    989        sin6.sin6_scope_id = 0;
    990        return (0);
    991      ]])],
    992   [AC_MSG_RESULT([yes])],
    993   [AC_MSG_FAILURE([IPv6 support is mandatory])])
    994 
    995 #
    996 # Allow forcibly disabling TCP Fast Open support as autodetection might yield
    997 # confusing results on some systems (e.g. FreeBSD; see set_tcp_fastopen()
    998 # comment in lib/isc/socket.c).
    999 #
   1000 # [pairwise: --enable-tcp-fastopen, --disable-tcp-fastopen]
   1001 AC_ARG_ENABLE([tcp_fastopen],
   1002 	      [AS_HELP_STRING([--disable-tcp-fastopen],
   1003 			      [disable TCP Fast Open support [default=yes]])],
   1004 	      [], [enable_tcp_fastopen="yes"])
   1005 
   1006 AS_IF([test "$enable_tcp_fastopen" = "yes"],
   1007       [AC_DEFINE([ENABLE_TCP_FASTOPEN], [1], [define if you want TCP_FASTOPEN enabled if available])])
   1008 
   1009 #
   1010 # Check for some other useful functions that are not ever-present.
   1011 #
   1012 AC_CHECK_FUNCS([strlcpy strlcat strnstr])
   1013 
   1014 #
   1015 # Check for readline support
   1016 #
   1017 
   1018 # editline is not included in pairwise testing as the library
   1019 # is not present in the relevant Docker image.
   1020 #
   1021 # GNU Readline is not included in pairwise testing as the library
   1022 # in the relevant Docker image does not support pkg-config.
   1023 #
   1024 # [pairwise: --with-readline=auto, --with-readline=yes, --with-readline=libedit, --without-readline]
   1025 AC_ARG_WITH([readline],
   1026 	    [AS_HELP_STRING([--with-readline=yes|no|libedit|readline],
   1027 			    [specify readline library [default auto]])],
   1028 	    [], [with_readline="auto"])
   1029 
   1030 AS_CASE([$with_readline],
   1031 	[no],[],
   1032 	[auto|yes],
   1033 	[PKG_CHECK_MODULES([READLINE], [libedit],
   1034 			   [AC_DEFINE([HAVE_READLINE_LIBEDIT], [1], [Build with libedit support])],
   1035 			   [PKG_CHECK_MODULES([READLINE], [libeditline],
   1036 					      [AC_DEFINE([HAVE_READLINE_EDITLINE], [1], [Build with editline support.])],
   1037 					      [PKG_CHECK_MODULES([READLINE], [readline],
   1038 								 [AC_DEFINE([HAVE_READLINE_READLINE], [1], [Build with readline support.])],
   1039 								 [AS_IF([test "$with_readline" = "yes"],
   1040 									[AC_MSG_ERROR([readline support requested, but none of the libraries have been found.])])])])])],
   1041 	[libedit],
   1042 	[PKG_CHECK_MODULES([READLINE], [libedit],
   1043 			   [AC_DEFINE([HAVE_READLINE_LIBEDIT], [1], [Build with libedit support])])],
   1044 	[editline],
   1045 	[PKG_CHECK_MODULES([READLINE], [libeditline],
   1046 			   [AC_DEFINE([HAVE_READLINE_EDITLINE], [1], [Build with editline support])])],
   1047 	[readline],
   1048 	[PKG_CHECK_MODULES([READLINE], [readline],
   1049 			   [AC_DEFINE([HAVE_READLINE_READLINE], [1], [Build with readline support])])],
   1050 	[AC_MSG_ERROR([Unknown readline '$with_readline' library requested.])])
   1051 AM_CONDITIONAL([HAVE_READLINE], [test -n "$READLINE_LIBS"])
   1052 AC_SUBST([READLINE_CFLAGS])
   1053 AC_SUBST([READLINE_LIBS])
   1054 
   1055 #
   1056 # Security Stuff
   1057 #
   1058 # Note it is very recommended to *not* disable chroot(),
   1059 # this is only because chroot() was made obsolete by Posix.
   1060 #
   1061 # [pairwise: --enable-chroot, --disable-chroot]
   1062 AC_ARG_ENABLE(chroot, AS_HELP_STRING([--disable-chroot], [disable chroot]))
   1063 case "$enable_chroot" in
   1064 	yes|'')
   1065 		AC_CHECK_FUNCS(chroot)
   1066 		;;
   1067 	no)
   1068 		;;
   1069 esac
   1070 
   1071 AS_CASE([$host],
   1072 	[*-linux*],
   1073 	[PKG_CHECK_MODULES([LIBCAP], [libcap],
   1074 			   [AC_DEFINE([HAVE_LIBCAP], [1], [Define to 1 if libcap was found])])])
   1075 
   1076 case "$host" in
   1077 *-solaris*)
   1078 	AC_DEFINE(NEED_SECURE_DIRECTORY, 1,
   1079 		  [Define if connect does not honour the permission on the UNIX domain socket.])
   1080 	;;
   1081 esac
   1082 
   1083 #
   1084 # Time Zone Stuff
   1085 #
   1086 AC_CHECK_FUNCS([tzset])
   1087 
   1088 AC_MSG_CHECKING(for optarg declaration)
   1089 AC_COMPILE_IFELSE(
   1090   [AC_LANG_PROGRAM(
   1091      [[#include <unistd.h>]],
   1092      [[optarg = 0;]]
   1093    )],
   1094   [AC_MSG_RESULT(yes)],
   1095   [AC_MSG_RESULT(no)
   1096    GEN_NEED_OPTARG="-DNEED_OPTARG=1"
   1097    AC_DEFINE(NEED_OPTARG, 1, [Defined if extern char *optarg is not declared.])]
   1098 )
   1099 
   1100 #
   1101 # Check for nanoseconds in file stats
   1102 #
   1103 AC_MSG_CHECKING([for st_mtim.tv_nsec])
   1104 AC_COMPILE_IFELSE(
   1105   [AC_LANG_PROGRAM(
   1106      [[#include <sys/stat.h>]],
   1107      [[struct stat s;
   1108        return(s.st_mtim.tv_nsec);
   1109       ]])],
   1110   [AC_MSG_RESULT([yes])
   1111    AC_DEFINE([HAVE_STAT_NSEC], [1], [define if struct stat has st_mtim.tv_nsec field])],
   1112   [AC_MSG_RESULT([no])])
   1113 
   1114 #
   1115 # Check for if_nametoindex() for IPv6 scoped addresses support
   1116 #
   1117 AC_CHECK_FUNCS([if_nametoindex])
   1118 
   1119 AC_CHECK_HEADERS([uchar.h])
   1120 
   1121 #
   1122 # Check for __builtin_unreachable
   1123 #
   1124 AC_MSG_CHECKING([compiler support for __builtin_unreachable()])
   1125 AC_LINK_IFELSE(
   1126   [AC_LANG_PROGRAM(
   1127      [[]],
   1128      [[__builtin_unreachable();]]
   1129    )],
   1130   [AC_MSG_RESULT([yes])
   1131    AC_DEFINE([HAVE_BUILTIN_UNREACHABLE], [1], [define if the compiler supports __builtin_unreachable().])
   1132   ],
   1133   [AC_MSG_RESULT([no])
   1134   ])
   1135 
   1136 #
   1137 # Check for __builtin_clz
   1138 #
   1139 AC_MSG_CHECKING([compiler support for __builtin_clz])
   1140 AC_LINK_IFELSE(
   1141   [AC_LANG_PROGRAM(
   1142      [[]],
   1143      [[return (__builtin_clz(0xff) == 24 ? 1 : 0);]]
   1144    )],
   1145   [AC_MSG_RESULT([yes])
   1146    AC_DEFINE(HAVE_BUILTIN_CLZ, 1, [Define to 1 if the compiler supports __builtin_clz.])
   1147   ],
   1148   [AC_MSG_RESULT([no])]
   1149 )
   1150 
   1151 #
   1152 # Check for __builtin_*_overflow
   1153 #
   1154 AC_MSG_CHECKING([compiler support for __builtin_add_overflow()])
   1155 AC_LINK_IFELSE(
   1156   [AC_LANG_PROGRAM(
   1157      [[#include <limits.h>]],
   1158      [[return (__builtin_add_overflow((unsigned int)UINT_MAX, (unsigned int)UINT_MAX, &(unsigned int){ 0 }));]]
   1159    )],
   1160   [AC_MSG_RESULT([yes])
   1161    AC_DEFINE([HAVE_BUILTIN_ADD_OVERFLOW], [1], [define if the compiler supports __builtin_add_overflow().])
   1162   ],
   1163   [AC_MSG_RESULT([no])
   1164   ])
   1165 
   1166 AC_MSG_CHECKING([compiler support for __builtin_sub_overflow()])
   1167 AC_LINK_IFELSE(
   1168   [AC_LANG_PROGRAM(
   1169      [[#include <limits.h>]],
   1170      [[return (__builtin_sub_overflow((unsigned int)0, (unsigned int)UINT_MAX, &(unsigned int){ 0 }));]]
   1171    )],
   1172   [AC_MSG_RESULT([yes])
   1173    AC_DEFINE([HAVE_BUILTIN_SUB_OVERFLOW], [1], [define if the compiler supports __builtin_sub_overflow().])
   1174   ],
   1175   [AC_MSG_RESULT([no])
   1176   ])
   1177 
   1178 AC_MSG_CHECKING([compiler support for __builtin_mul_overflow()])
   1179 AC_LINK_IFELSE(
   1180   [AC_LANG_PROGRAM(
   1181      [[#include <limits.h>
   1182        #include <stdint.h>
   1183      ]],
   1184      [[return (__builtin_mul_overflow(UINT64_MAX, UINT64_MAX, &(uint64_t){ 0 }));]]
   1185    )],
   1186   [AC_MSG_RESULT([yes])
   1187    AC_DEFINE([HAVE_BUILTIN_MUL_OVERFLOW], [1], [define if the compiler supports __builtin_mul_overflow().])
   1188   ],
   1189   [AC_MSG_RESULT([no])
   1190   ])
   1191 
   1192 #
   1193 # Activate "rrset-order fixed" or not?
   1194 #
   1195 # [pairwise: --enable-fixed-rrset, --disable-fixed-rrset]
   1196 AC_ARG_ENABLE([fixed-rrset],
   1197 	      [AS_HELP_STRING([--enable-fixed-rrset],
   1198 			      [enable fixed rrset ordering [default=no]])],
   1199 	      [], [enable_fixed_rrset="no"])
   1200 AS_IF([test "$enable_fixed_rrset" = "yes"],
   1201       [AC_MSG_WARN([fixed rrset ordering is deprecated and will be removed in the future release])
   1202        AC_DEFINE([DNS_RDATASET_FIXED], [1], [Define to enable "rrset-order fixed" syntax.])])
   1203 
   1204 #
   1205 # Activate dnstap?
   1206 #
   1207 # [pairwise: --enable-dnstap, --disable-dnstap]
   1208 AC_ARG_ENABLE([dnstap],
   1209 	      [AS_HELP_STRING([--enable-dnstap],
   1210 			      [enable dnstap support
   1211 			       (requires fstrm, protobuf-c)])],
   1212 	      [], [enable_dnstap=no])
   1213 
   1214 AS_IF([test "$enable_dnstap" != "no"],
   1215       [PKG_CHECK_MODULES([DNSTAP], [libfstrm libprotobuf-c], [],
   1216 			 [AC_MSG_FAILURE([Required libraries (fstrm, protobuf-c) were not found, please install them.])])
   1217        AC_PATH_PROG([FSTRM_CAPTURE], [fstrm_capture])
   1218        AC_PATH_PROG([PROTOC_C], [protoc-c])
   1219        AS_IF([test -z "$PROTOC_C"],
   1220 	     [AC_MSG_ERROR([protoc-c compiler not found])])
   1221        AC_DEFINE([HAVE_DNSTAP], 1, [Define to 1 to enable dnstap support])
   1222       ])
   1223 
   1224 AC_SUBST([DNSTAP_CFLAGS])
   1225 AC_SUBST([DNSTAP_LIBS])
   1226 AM_CONDITIONAL([HAVE_DNSTAP], [test "$enable_dnstap" != "no"])
   1227 #
   1228 # The following sections deal with tools used for formatting
   1229 # the documentation.  They are all optional, unless you are
   1230 # a developer editing the documentation source.
   1231 #
   1232 
   1233 #
   1234 # Look for sphinx-build
   1235 #
   1236 AC_ARG_VAR([SPHINX_BUILD], [path to sphinx-build binary used to build the documentation])
   1237 AC_PATH_PROG([SPHINX_BUILD], [sphinx-build], [])
   1238 AM_CONDITIONAL([HAVE_SPHINX_BUILD], [test -n "$SPHINX_BUILD"])
   1239 
   1240 #
   1241 # Build the man pages only if we have prebuilt manpages or we can build them from RST sources
   1242 #
   1243 AM_CONDITIONAL([BUILD_MANPAGES], [test -e doc/man/named.conf.5in || test -n "$SPHINX_BUILD"])
   1244 
   1245 #
   1246 # Pull release date from changelog.rst file last modification date
   1247 # for reproducible builds
   1248 #
   1249 release_date=`date -u -r doc/arm/changelog.rst +%Y-%m-%d`
   1250 AC_SUBST([RELEASE_DATE], $release_date)
   1251 
   1252 #
   1253 # Look for Doxygen
   1254 #
   1255 AC_PATH_PROGS([DOXYGEN], [doxygen])
   1256 
   1257 AC_CONFIG_FILES([doc/doxygen/doxygen-input-filter],
   1258 		[chmod +x doc/doxygen/doxygen-input-filter])
   1259 
   1260 #
   1261 # Look for curl
   1262 #
   1263 
   1264 AC_PATH_PROG(CURL, curl, curl)
   1265 AC_SUBST(CURL)
   1266 
   1267 #
   1268 # Look for nc
   1269 #
   1270 
   1271 AC_PATH_PROGS(NC, nc, nc)
   1272 AC_SUBST(NC)
   1273 
   1274 #
   1275 # IDN support using libidn2
   1276 #
   1277 
   1278 LIBIDN2_CFLAGS=
   1279 LIBIDN2_LIBS=
   1280 
   1281 # [pairwise: --with-libidn2=yes, --without-libidn2]
   1282 AC_ARG_WITH([libidn2],
   1283 	    [AS_HELP_STRING([--with-libidn2[=PATH]], [enable IDN support using GNU libidn2 [yes|no(default)|path]])],
   1284 	    [with_libidn2="$withval"], [with_libidn2="no"])
   1285 AS_CASE([$with_libidn2],
   1286 	[yes],	[PKG_CHECK_MODULES([LIBIDN2], [libidn2],
   1287 				   [AC_DEFINE([HAVE_LIBIDN2], [1], [Define if libidn2 was found])])],
   1288 	[no],	[],
   1289 	[*],	[AX_SAVE_FLAGS([libidn2])
   1290 		 LIBIDN2_CFLAGS="-I$with_libidn2/include"
   1291 		 LIBIDN2_LIBS="-L$with_libidn2/lib"
   1292 		 CFLAGS="$CFLAGS $LIBIDN2_CFLAGS"
   1293 		 LIBS="$LIBS $LIBIDN2_LIBS"
   1294 		 AC_CHECK_HEADERS([idn2.h],
   1295 				  [],
   1296 				  [AC_MSG_ERROR([idn2.h not found])])
   1297 		 AC_SEARCH_LIBS([idn2_to_ascii_lz], [idn2],
   1298 				[LIBIDN2_LIBS="$LIBIDN2_LIBS $ac_cv_search_idn2_to_ascii_lz"
   1299 				 AC_DEFINE([HAVE_LIBIDN2], [1], [Define if libidn2 was found])],
   1300 				[AC_MSG_ERROR([libidn2 requested, but not found])])
   1301 		AX_RESTORE_FLAGS([libidn2])])
   1302 AC_SUBST([LIBIDN2_CFLAGS])
   1303 AC_SUBST([LIBIDN2_LIBS])
   1304 
   1305 #
   1306 # Check whether to build with cmocka unit testing framework
   1307 #
   1308 # [pairwise: --with-cmocka=detect, --with-cmocka=yes, --without-cmocka]
   1309 AC_ARG_WITH([cmocka],
   1310 	    [AS_HELP_STRING([--with-cmocka=detect],[enable CMocka based tests (default is detect)])],
   1311 	    [],[with_cmocka=detect])
   1312 
   1313 AS_CASE([$with_cmocka],
   1314 	[no],[],
   1315 	[detect],[PKG_CHECK_MODULES([CMOCKA], [cmocka >= 1.1.3],
   1316 				    [AC_DEFINE([HAVE_CMOCKA], [1], [Use CMocka])
   1317 				     with_cmocka=yes],[with_cmocka=no])],
   1318 	[yes],[PKG_CHECK_MODULES([CMOCKA], [cmocka >= 1.1.3],
   1319 				 [AC_DEFINE([HAVE_CMOCKA], [1], [Use CMocka])])],
   1320 	[AC_MSG_ERROR([Use PKG_CONFIG_PATH to specify path to CMocka library])]
   1321        )
   1322 AC_SUBST([CMOCKA_CFLAGS])
   1323 AC_SUBST([CMOCKA_LIBS])
   1324 
   1325 AM_CONDITIONAL([HAVE_CMOCKA], [test "$with_cmocka" = "yes"])
   1326 
   1327 #
   1328 # Compile with jemalloc (either provided as package or wired in the system on FreeBSD)
   1329 #
   1330 # [pairwise: --with-jemalloc=detect, --with-jemalloc=yes, --without-jemalloc]
   1331 AC_ARG_WITH([jemalloc],
   1332 	    [AS_HELP_STRING([--with-jemalloc=detect],[enable jemalloc memory allocator (default is detect)])],
   1333 	    [],[with_jemalloc=detect])
   1334 
   1335 AS_CASE([$with_jemalloc],
   1336 	[no],[],
   1337 	[yes],[AX_CHECK_JEMALLOC(
   1338 		 [AC_DEFINE([HAVE_JEMALLOC], [1], [Define to 1 if jemalloc is available])],
   1339 		 [AC_MSG_ERROR([jemalloc not found])])],
   1340 	[AX_CHECK_JEMALLOC(
   1341 	   [AC_DEFINE([HAVE_JEMALLOC], [1], [Define to 1 if jemalloc is available])
   1342 	    with_jemalloc=yes],
   1343 	   [AC_MSG_WARN([jemalloc not found; performance will be reduced])
   1344 	    with_jemalloc=no])])
   1345 
   1346 AS_IF([test "$with_jemalloc" = "no"],
   1347       [AS_CASE([$host],
   1348 	       [*-freebsd*],[AC_MSG_ERROR([You cannot compile without jemalloc; jemalloc is the system allocator on FreeBSD])])])
   1349 
   1350 AM_CONDITIONAL([HAVE_JEMALLOC], [test "$with_jemalloc" = "yes"])
   1351 
   1352 #
   1353 # Check memory leaks in external libraries
   1354 #
   1355 # [pairwise: --enable-leak-detection, --disable-leak-detection]
   1356 AC_ARG_ENABLE([leak-detection],
   1357 	      [AS_HELP_STRING([--enable-leak-detection],[enable the memory leak detection in external libraries (libxml2, libuv, OpenSSL) (disabled by default)])],
   1358 	      [],[enable_leak_detection=no])
   1359 AS_CASE([$enable_leak_detection],
   1360 	[yes],[AC_DEFINE([ENABLE_LEAK_DETECTION], [1], [Define to enable memory leak detection in external libraries])])
   1361 
   1362 #
   1363 # was --enable-querytrace or --enable-singletrace specified?
   1364 #
   1365 # [pairwise: --enable-singletrace --enable-querytrace, --disable-singletrace --enable-querytrace, --disable-singletrace --disable-querytrace]
   1366 AC_ARG_ENABLE([singletrace],
   1367 	      AS_HELP_STRING([--enable-singletrace],
   1368 			     [enable single-query trace logging
   1369 			      [default=no]]),
   1370 	      enable_singletrace="$enableval", enable_singletrace="no")
   1371 
   1372 AC_MSG_CHECKING([whether to enable single-query trace logging])
   1373 case "$enable_singletrace" in
   1374 yes)
   1375 	enable_querytrace=yes
   1376 	AC_MSG_RESULT(yes)
   1377 	AC_DEFINE(WANT_SINGLETRACE, 1, [Define to enable single-query tracing.])
   1378 	;;
   1379 no)
   1380 	AC_MSG_RESULT(no)
   1381 	;;
   1382 *)
   1383 	AC_MSG_ERROR("--enable-singletrace requires yes or no")
   1384 	;;
   1385 esac
   1386 
   1387 # [pairwise: skip]
   1388 AC_ARG_ENABLE(querytrace,
   1389 	      AS_HELP_STRING([--enable-querytrace],
   1390 			     [enable very verbose query trace logging
   1391 				[default=no]]),
   1392 	      enable_querytrace="$enableval",
   1393 	      enable_querytrace="$enable_singletrace")
   1394 
   1395 AC_MSG_CHECKING([whether to enable query trace logging])
   1396 case "$enable_querytrace" in
   1397 yes)
   1398 	AC_MSG_RESULT(yes)
   1399 	AC_DEFINE(WANT_QUERYTRACE, 1, [Define to enable very verbose query trace logging.])
   1400 	;;
   1401 no)
   1402        AS_IF([test "$enable_singletrace" = "yes"],
   1403 	     [AC_MSG_ERROR([--enable-singletrace requires --enable-querytrace])])
   1404 	AC_MSG_RESULT(no)
   1405 	;;
   1406 *)
   1407 	AC_MSG_ERROR(["--enable-querytrace requires yes or no (not $enable_querytrace)"])
   1408 	;;
   1409 esac
   1410 
   1411 #
   1412 # Was --disable-auto-validation specified?
   1413 #
   1414 
   1415 validation_default=auto
   1416 
   1417 # [pairwise: --enable-auto-validation, --disable-auto-validation]
   1418 AC_ARG_ENABLE(auto-validation,
   1419 	      AS_HELP_STRING([--enable-auto-validation],
   1420 			     [turn on DNSSEC validation by default, using the IANA root key [default=yes]]),
   1421 	      [:],[enable_auto_validation=yes])
   1422 AS_IF([test "$enable_auto_validation" = "no"],[validation_default=yes])
   1423 AC_DEFINE_UNQUOTED([VALIDATION_DEFAULT], ["$validation_default"], [the default value of dnssec-validation option])
   1424 
   1425 #
   1426 #
   1427 # Response policy rewriting using DNS Response Policy Service (DNSRPS)
   1428 # interface.
   1429 #
   1430 # DNSRPS can be compiled into BIND everywhere with a reasonably
   1431 # modern C compiler.  It is enabled on systems with dlopen() and librpz.so.
   1432 #
   1433 dnsrps_avail=yes
   1434 AC_MSG_CHECKING([for librpz __attribute__s])
   1435 AC_COMPILE_IFELSE(
   1436   [AC_LANG_PROGRAM(
   1437      [[]],
   1438      [[
   1439        extern void f(char *p __attribute__((unused)), ...)
   1440        __attribute__((format(printf,1,2))) __attribute__((__noreturn__));
   1441      ]])],
   1442   [
   1443     librpz_have_attr=yes
   1444     AC_DEFINE([LIBRPZ_HAVE_ATTR], [1], [have __attribute__s used in librpz.h])
   1445     AC_MSG_RESULT([yes])
   1446   ],[
   1447     librpz_have_attr=no
   1448     AC_MSG_RESULT([no])
   1449   ])
   1450 
   1451 # [pairwise: --enable-dnsrps --enable-dnsrps-dl, --disable-dnsrps]
   1452 AC_ARG_ENABLE([dnsrps-dl],
   1453 	      [AS_HELP_STRING([--enable-dnsrps-dl],
   1454 			      [DNS Response Policy Service delayed link
   1455 			       [default=yes]])],
   1456 	      [enable_dnsrps_dl="$enableval"], [enable_dnsrps_dl="yes"])
   1457 
   1458 AS_IF([test "$enable_dnsrps_dl" = "yes" -a "$with_dlopen" = "no"],
   1459       [AC_MSG_ERROR([DNS Response Policy Service delayed link requires dlopen to be enabled])])
   1460 
   1461 # [pairwise: skip]
   1462 AC_ARG_WITH([dnsrps-libname],
   1463 	    [AS_HELP_STRING([--with-dnsrps-libname],
   1464 			    [DNSRPS provider library name (librpz.so)])],
   1465 	    [librpz_name="$withval"], [librpz_name="librpz.so"])
   1466 
   1467 # [pairwise: skip]
   1468 AC_ARG_WITH([dnsrps-dir],
   1469 	    [AS_HELP_STRING([--with-dnsrps-dir],
   1470 			    [path to DNSRPS provider library])],
   1471 	    [librpz_path="$withval/$librpz_name"], [librpz_path="$librpz_name"])
   1472 AC_DEFINE_UNQUOTED([DNSRPS_LIBRPZ_PATH], ["$librpz_path"],
   1473 		   [dnsrps $librpz_name])
   1474 AS_IF([test "$enable_dnsrps_dl" = "yes"],
   1475       [
   1476 	dnsrps_lib_open=2
   1477       ],[
   1478 	dnsrps_lib_open=1
   1479 	# Add librpz.so to linked libraries if we are not using dlopen()
   1480 	AC_SEARCH_LIBS([librpz_client_create], [rpz], [],
   1481 		[dnsrps_lib_open=0
   1482 		 dnsrps_avail=no])
   1483       ])
   1484 AC_DEFINE_UNQUOTED([DNSRPS_LIB_OPEN], [$dnsrps_lib_open],
   1485 		   [0=no DNSRPS  1=static link  2=dlopen()])
   1486 
   1487 # [pairwise: skip]
   1488 AC_ARG_ENABLE([dnsrps],
   1489 	      AS_HELP_STRING([--enable-dnsrps],
   1490 			     [enable DNS Response Policy Service API]),
   1491 	      [enable_dnsrps=$enableval], [enable_dnsrps=no])
   1492 
   1493 AS_IF([test "$enable_dnsrps" != "no"],[
   1494 	AS_IF([test "$dnsrps_lib_open" = "0"],
   1495 	      [AC_MSG_ERROR([dlopen and librpz.so needed for DNSRPS])])
   1496 	AC_DEFINE([USE_DNSRPS], [1], [Enable DNS Response Policy Service API])
   1497       ])
   1498 
   1499 AM_CONDITIONAL([DNSRPS], [test "$enable_dnsrps" != "no"])
   1500 
   1501 AC_CHECK_HEADERS([glob.h])
   1502 
   1503 #
   1504 # Support for constructor and destructor attributes
   1505 #
   1506 AX_GCC_FUNC_ATTRIBUTE([constructor])
   1507 AX_GCC_FUNC_ATTRIBUTE([destructor])
   1508 
   1509 #
   1510 # Check whether to enable User Statically Defined Tracing.
   1511 #
   1512 # This is supported only on Linux now and requires SystemTap libraries.
   1513 #
   1514 # [pairwise: --enable-tracing=auto, --enable-tracing=yes, --disable-tracing]
   1515 AC_ARG_ENABLE([tracing],
   1516 	      [AS_HELP_STRING([--enable-tracing],
   1517 			      [enable User Statically Defined Tracing])],
   1518 	      [],
   1519 	      [enable_tracing=auto])
   1520 
   1521 AC_ARG_VAR([DTRACE], [path to dtrace binary used to build User Statically Defined Tracing probes])
   1522 AC_PATH_PROGS([DTRACE], [dtrace])
   1523 AC_CHECK_HEADERS([sys/sdt.h])
   1524 
   1525 AC_MSG_CHECKING([whether to enable User Statically Defined Tracing support (default is auto)])
   1526 AS_CASE([$enable_tracing],
   1527 	[auto],	[enable_tracing=yes
   1528 		 AS_IF([test "$ac_cv_header_sys_sdt_h" != "yes"], [enable_tracing=no])
   1529 		 AS_IF([test -z "$DTRACE"],[enable_tracing=no])
   1530 		 AC_COMPILE_IFELSE(
   1531 		   [AC_LANG_PROGRAM([[]],
   1532 				    [[#if !defined(__has_feature)
   1533 				      #define __has_feature(x) 0
   1534 				      #endif /* if !defined(__has_feature) */
   1535 				      #if __has_feature(address_sanitizer)
   1536 				      #define __SANITIZE_ADDRESS__ 1
   1537 				      #endif /* if __has_feature(address_sanitizer) */
   1538 				      #if defined(__SANITIZE_ADDRESS__)
   1539 				      #error Address Sanitizer enabled
   1540 				      #endif
   1541 				     ]])],
   1542 		   [],
   1543 		   [enable_tracing=no]
   1544 		 )])
   1545 AS_CASE([$enable_tracing],
   1546 	[yes], [AS_IF([test "$ac_cv_header_sys_sdt_h" != "yes"],
   1547 		      [AC_MSG_ERROR([sys/sdt.h header not found])])
   1548 		AS_IF([test -z "$DTRACE"],
   1549 		      [AC_MSG_ERROR([The dtrace command not found])])
   1550 		AC_MSG_RESULT([yes])],
   1551 	[DTRACE=""
   1552 	 AC_MSG_RESULT([no])])
   1553 
   1554 AS_CASE([$host],
   1555 	[*-linux*],[have_systemtap=true])
   1556 
   1557 AM_CONDITIONAL([HAVE_SYSTEMTAP], [test -n "$have_systemtap"])
   1558 AM_CONDITIONAL([HAVE_DTRACE], [test -n "$DTRACE"])
   1559 
   1560 # Use shim script if dtrace is not available
   1561 AS_IF([test -z "$DTRACE"],
   1562       [DTRACE='$(top_srcdir)/util/dtrace.sh'])
   1563 
   1564 AC_SUBST([DTRACE])
   1565 
   1566 #
   1567 # Which should be the default zone database, RBTDB or QPZONE?
   1568 # [pairwise: --with-zonedb=qp, --with-zonedb=rbt]
   1569 #
   1570 AC_ARG_WITH([zonedb],
   1571 	    [AS_HELP_STRING([--with-zonedb=detect],[specify default zone database type (default is "qpzone")])],
   1572 	    [],[with_zonedb=qp])
   1573 zonedb="qpzone"
   1574 AS_CASE([$with_zonedb],
   1575 	[RBT*|rbt*],[zonedb="rbt"],
   1576         [QP|qp],[],
   1577 	[AC_MSG_ERROR([Unknown zone database type])]
   1578        )
   1579 AC_DEFINE_UNQUOTED([ZONEDB_DEFAULT], ["$zonedb"], [Default zone database type])
   1580 
   1581 #
   1582 # Which should be the default zone database, RBTDB or QPCACHE?
   1583 # [pairwise: --with-cachedb=qp, --with-cachedb=rbt]
   1584 #
   1585 AC_ARG_WITH([cachedb],
   1586 	    [AS_HELP_STRING([--with-cachedb=detect],[specify default cache database type (default is "qpcache")])],
   1587 	    [],[with_cachedb=qp])
   1588 cachedb="qpcache"
   1589 AS_CASE([$with_cachedb],
   1590 	[RBT*|rbt*],[cachedb="rbt"],
   1591         [QP*|qp*],[],
   1592 	[AC_MSG_ERROR([Unknown cache database type])]
   1593        )
   1594 AC_DEFINE_UNQUOTED([CACHEDB_DEFAULT], ["$cachedb"], [Default cache database type])
   1595 
   1596 #
   1597 # In solaris 10, SMF can manage named service
   1598 #
   1599 LIBSCF_LIBS=
   1600 AC_CHECK_HEADER([libscf.h],
   1601 		[AC_CHECK_LIB([scf], [smf_enable_instance],
   1602 			      [AC_DEFINE([HAVE_LIBSCF], [1],
   1603 					 [Define to 1 if libscf was found])
   1604 			       LIBSCF_LIBS="-lscf"])])
   1605 AC_SUBST([LIBSCF_LIBS])
   1606 
   1607 #
   1608 # Files to configure.  These are listed here because we used to
   1609 # specify them as arguments to AC_OUTPUT.
   1610 #
   1611 
   1612 # Top
   1613 
   1614 AC_CONFIG_FILES([Makefile])
   1615 
   1616 # Binaries
   1617 
   1618 AC_CONFIG_FILES([bin/Makefile
   1619 		 bin/named/Makefile
   1620 		 bin/rndc/Makefile
   1621 		 bin/dig/Makefile
   1622 		 bin/delv/Makefile
   1623 		 bin/dnssec/Makefile
   1624 		 bin/tools/Makefile
   1625 		 bin/nsupdate/Makefile
   1626 		 bin/check/Makefile
   1627 		 bin/confgen/Makefile
   1628 		 bin/plugins/Makefile])
   1629 
   1630 # Libraries
   1631 
   1632 AC_CONFIG_FILES([lib/Makefile
   1633 		 lib/isc/Makefile
   1634 		 lib/dns/Makefile
   1635 		 lib/ns/Makefile
   1636 		 lib/isccfg/Makefile
   1637 		 lib/isccc/Makefile])
   1638 
   1639 # Documentation
   1640 
   1641 AC_CONFIG_FILES([doc/Makefile
   1642 		 doc/arm/Makefile
   1643 		 doc/man/Makefile
   1644 		 doc/misc/Makefile])
   1645 
   1646 # Unit tests and benchmarks
   1647 
   1648 AC_CONFIG_FILES([tests/Makefile
   1649 		 tests/bench/Makefile
   1650 		 tests/isc/Makefile
   1651 		 tests/dns/Makefile
   1652 		 tests/ns/Makefile
   1653 		 tests/isccfg/Makefile
   1654 		 tests/libtest/Makefile])
   1655 
   1656 AC_CONFIG_FILES([tests/unit-test-driver.sh],
   1657 		[chmod +x tests/unit-test-driver.sh])
   1658 
   1659 # System Tests
   1660 
   1661 AC_CONFIG_FILES([bin/tests/Makefile
   1662 		 bin/tests/system/Makefile
   1663 		 bin/tests/system/isctest/vars/.ac_vars/TOP_BUILDDIR
   1664 		 bin/tests/system/isctest/vars/.ac_vars/TOP_SRCDIR
   1665 		 bin/tests/system/isctest/vars/.ac_vars/FSTRM_CAPTURE
   1666 		 bin/tests/system/isctest/vars/.ac_vars/JQ
   1667 		 bin/tests/system/isctest/vars/.ac_vars/SHELL
   1668 		 bin/tests/system/isctest/vars/.ac_vars/PYTHON
   1669 		 bin/tests/system/isctest/vars/.ac_vars/PERL
   1670 		 bin/tests/system/isctest/vars/.ac_vars/CURL
   1671 		 bin/tests/system/isctest/vars/.ac_vars/NC
   1672 		 bin/tests/system/isctest/vars/.ac_vars/XMLLINT
   1673 		 bin/tests/system/isctest/vars/.ac_vars/XSLTPROC
   1674 		 bin/tests/system/isctest/vars/.ac_vars/PYTEST
   1675 		 bin/tests/system/dyndb/driver/Makefile
   1676 		 bin/tests/system/dlzexternal/driver/Makefile
   1677 		 bin/tests/system/hooks/driver/Makefile
   1678 		 bin/tests/system/rpz/testlib/Makefile
   1679                  ])
   1680 
   1681 AC_CONFIG_FILES([bin/tests/system/ifconfig.sh],
   1682 		[chmod +x bin/tests/system/ifconfig.sh])
   1683 AC_CONFIG_FILES([bin/tests/system/start.sh],
   1684 		[chmod +x bin/tests/system/start.sh])
   1685 AC_CONFIG_FILES([bin/tests/system/stop.sh],
   1686 		[chmod +x bin/tests/system/stop.sh])
   1687 
   1688 # Fuzz Tests
   1689 
   1690 AC_CONFIG_FILES([fuzz/Makefile])
   1691 
   1692 # Misc
   1693 
   1694 AC_CONFIG_FILES([util/check-make-install.sh])
   1695 
   1696 #
   1697 # Do it
   1698 #
   1699 
   1700 AC_OUTPUT
   1701 
   1702 # [pairwise: --enable-full-report, --disable-full-report]
   1703 AC_ARG_ENABLE(full-report,
   1704 	      AS_HELP_STRING([--enable-full-report],
   1705 			     [report values of all configure options]))
   1706 
   1707 report() {
   1708     echo "==============================================================================="
   1709     echo "Configuration summary:"
   1710     echo "-------------------------------------------------------------------------------"
   1711     echo "Optional features enabled:"
   1712     if test "yes" = "$with_jemalloc"; then
   1713 	echo "    Memory allocator: jemalloc"
   1714     fi
   1715     if test "yes" = "$enable_full_report" -o "rbt" = "$zonedb"; then
   1716             echo "    Default zone database type: $zonedb"
   1717     fi
   1718     if test "yes" = "$enable_full_report" -o "rbt" = "$zonedb"; then
   1719             echo "    Default cache database type: $cachedb"
   1720     fi
   1721     test "no" = "$enable_dnstap" || \
   1722 	    echo "    Allow 'dnstap' packet logging (--enable-dnstap)"
   1723     test -z "$MAXMINDDB_LIBS" || echo "    GeoIP2 access control (--enable-geoip)"
   1724     test -z "$GSSAPI_LIBS" || echo "    GSS-API (--with-gssapi)"
   1725 
   1726     # these lines are only printed if run with --enable-full-report
   1727     if test "yes" = "$enable_full_report"; then
   1728 	test -z "$LIBXML2_LIBS" || echo "    XML statistics (--with-libxml2)"
   1729 	test -z "$JSON_C_LIBS" || echo "    JSON statistics (--with-json-c): $JSON_C_CFLAGS $JSON_C_LIBS"
   1730 	test -z "$ZLIB_LIBS" || echo "    HTTP zlib compression (--with-zlib)"
   1731 	test -z "$LMDB_LIBS" || echo "    LMDB database to store configuration for 'addzone' zones (--with-lmdb)"
   1732 	test -z "$LIBIDN2_LIBS" || echo "    IDN support (--with-libidn2)"
   1733     fi
   1734 
   1735     test "yes" = "$enable_dnsrps" && \
   1736 	echo "    DNS Response Policy Service interface (--enable-dnsrps)"
   1737     test "yes" = "$enable_fixed_rrset" && \
   1738 	echo "    Allow 'fixed' rrset-order (--enable-fixed-rrset)"
   1739     test "yes" = "$enable_fips_mode" && \
   1740 	echo "    FIPS mode in OpenSSL (--enable-fips-mode)"
   1741 
   1742     test "yes" = "$enable_querytrace" && \
   1743 	echo "    Very verbose query trace logging (--enable-querytrace)"
   1744     test "yes" = "$enable_singletrace" && \
   1745 	echo "    Single-query trace logging (--enable-singletrace)"
   1746     test -z "$HAVE_CMOCKA" || echo "    CMocka Unit Testing Framework (--with-cmocka)"
   1747 
   1748     test "auto" = "$validation_default" && echo "    DNSSEC validation active by default (--enable-auto-validation)"
   1749 
   1750     echo "-------------------------------------------------------------------------------"
   1751     echo "    Library versions:"
   1752     echo "      OpenSSL:		$OPENSSL_VERSION"
   1753     echo "      libuv:		$LIBUV_VERSION"
   1754     echo "      Userspace-RCU:	$RCU_VERSION"
   1755     if test "no" != "$with_jemalloc"; then
   1756       echo "      jemalloc:		$JEMALLOC_VERSION"
   1757     fi
   1758     echo "-------------------------------------------------------------------------------"
   1759 
   1760     echo "Features disabled or unavailable on this platform:"
   1761     if test "no" = "$with_jemalloc"; then
   1762       echo "    Memory allocator: system"
   1763       echo
   1764       echo "    +------------------------------------------+"
   1765       echo "    |             ==== WARNING ====            |"
   1766       echo "    |                                          |"
   1767       echo "    | This is NOT a recommended configuration. |"
   1768       echo "    | Using the system memory allocator causes |"
   1769       echo "    | reduced performance and increased memory |"
   1770       echo "    | fragmentation. Installing the jemalloc   |"
   1771       echo "    | memory allocator (version >= 4.0.0) is   |"
   1772       echo "    | strongly recommended.                    |"
   1773       echo "    +------------------------------------------+"
   1774       echo
   1775     fi
   1776 
   1777     test "no" = "$enable_dnstap" && \
   1778 	    echo "    Allow 'dnstap' packet logging (--enable-dnstap)"
   1779     test -z "$MAXMINDDB_LIBS" && echo "    GeoIP2 access control (--enable-geoip)"
   1780     test -z "$GSSAPI_LIBS" && echo "    GSS-API (--with-gssapi)"
   1781 
   1782     test "no" = "$enable_dnsrps" && \
   1783 	echo "    DNS Response Policy Service interface (--enable-dnsrps)"
   1784 
   1785     test "yes" = "$enable_fixed_rrset" || \
   1786 	echo "    Allow 'fixed' rrset-order (--enable-fixed-rrset)"
   1787 
   1788     test "yes" = "$validation_default" && echo "    DNSSEC validation requires configuration (--enable-auto-validation)"
   1789 
   1790     test "yes" = "$enable_fips_mode" || \
   1791 	echo "    FIPS mode in OpenSSL (--enable-fips-mode)"
   1792 
   1793     test "yes" = "$enable_querytrace" || \
   1794 	echo "    Very verbose query trace logging (--enable-querytrace)"
   1795     test "yes" = "$enable_singletrace" || \
   1796 	echo "    Single-query trace logging (--enable-singletrace)"
   1797 
   1798     test "no" = "$with_cmocka" && echo "    CMocka Unit Testing Framework (--with-cmocka)"
   1799 
   1800     test -z "$LIBXML2_LIBS" && echo "    XML statistics (--with-libxml2)"
   1801     test -z "$JSON_C_LIBS" && echo "    JSON statistics (--with-json-c)"
   1802     test -z "$ZLIB_LIBS" && echo "    HTTP zlib compression (--with-zlib)"
   1803     test -z "$LMDB_LIBS" && echo "    LMDB database to store configuration for 'addzone' zones (--with-lmdb)"
   1804     test -z "$LIBIDN2_LIBS" && echo "    IDN support (--with-libidn2)"
   1805 
   1806     echo "-------------------------------------------------------------------------------"
   1807     echo "Configured paths:"
   1808     echo "    prefix: $prefix"
   1809     echo "    sysconfdir: $sysconfdir"
   1810     echo "    localstatedir: $localstatedir"
   1811     echo "-------------------------------------------------------------------------------"
   1812     echo "Compiler: $CC"
   1813     AS_IF([test "$GCC" = "yes"],
   1814 	  [$CC --version 2>&1 | sed 's/^/    /'],
   1815 	  [AS_CASE([$host],
   1816 		   [*-solaris*],[$CC -V 2>&1 | sed 's/^/    /'],
   1817 		   [$CC --version 2>&1 | sed 's/^/    /'])])
   1818     echo "CFLAGS: $STD_CFLAGS $CFLAGS"
   1819     echo "CPPFLAGS: $STD_CPPFLAGS $CPPFLAGS"
   1820     echo "LDFLAGS: $LDFLAGS"
   1821 
   1822     if test "X$ac_unrecognized_opts" != "X"; then
   1823 	echo "-------------------------------------------------------------------------------"
   1824 	echo "Unrecognized options:"
   1825 	echo "    $ac_unrecognized_opts"
   1826     fi
   1827 
   1828     if test "yes" != "$enable_full_report"; then
   1829 	echo "-------------------------------------------------------------------------------"
   1830 	echo "For more detail, use --enable-full-report."
   1831     fi
   1832     echo "==============================================================================="
   1833 }
   1834 
   1835 if test "yes" != "$silent"; then
   1836 	report
   1837 fi
   1838 
   1839 # Tell Emacs to edit this file in shell mode.
   1840 # Local Variables:
   1841 # mode: sh
   1842 # End:
   1843