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
12AC_INIT(BIND, [9.16], [https://gitlab.isc.org/isc-projects/bind9/-/issues/new?issuable_template=Bug], [], [https://www.isc.org/downloads/])
13AC_PREREQ([2.60])
14
15#
16# Enable maintainer mode by default, but allow to disable it in the CI
17#
18AM_MAINTAINER_MODE([enable])
19
20AC_CONFIG_HEADER(config.h)
21AC_CONFIG_MACRO_DIR([m4])
22
23AC_CANONICAL_HOST
24
25#
26# Enable system extensions to C and POSIX
27#
28AC_USE_SYSTEM_EXTENSIONS
29
30#
31# Enable large file support
32#
33AC_SYS_LARGEFILE
34AC_FUNC_FSEEKO
35
36LFS_CFLAGS=`getconf LFS_CFLAGS 2>/dev/null`
37LFS_LDFLAGS=`getconf LFS_LDFLAGS 2>/dev/null`
38LFS_LIBS=`getconf LFS_LIBS 2>/dev/null`
39
40AC_SUBST([LFS_CFLAGS])
41AC_SUBST([LFS_LDFLAGS])
42AC_SUBST([LFS_LIBS])
43
44# Enable RFC 3542 APIs on macOS
45AC_DEFINE([__APPLE_USE_RFC_3542], [1], [Select RFC3542 IPv6 API on macOS])
46
47AC_PROG_MAKE_SET
48
49AC_PROG_LIBTOOL
50AC_PROG_INSTALL
51AC_PROG_LN_S
52AX_POSIX_SHELL
53AC_PROG_MKDIR_P
54
55AC_SUBST(STD_CINCLUDES)
56AC_SUBST(STD_CDEFINES)
57AC_SUBST(STD_CWARNINGS)
58AC_SUBST(CCOPT)
59AC_SUBST(CCNOOPT)
60AC_SUBST(BACKTRACECFLAGS)
61
62#
63# Use pkg-config
64#
65
66PKG_PROG_PKG_CONFIG
67AS_IF([test -z "$PKG_CONFIG"],
68      [AC_MSG_ERROR([The pkg-config script could not be found or is too old.])])
69
70# [pairwise: --enable-buffer-useinline, --disable-buffer-useinline]
71AC_ARG_ENABLE(buffer_useinline,
72	      AS_HELP_STRING([--enable-buffer-useinline],
73		             [define ISC_BUFFER_USEINLINE when compiling
74				[default=yes]]),
75	      if test yes = "${enable}"
76	      then
77		      AC_DEFINE([ISC_BUFFER_USEINLINE], [1],
78			        [Define if you want to use inline buffers])
79	      fi,
80	      AC_DEFINE([ISC_BUFFER_USEINLINE], [1]))
81
82# [pairwise: --enable-warn-shadow, --disable-warn-shadow]
83AC_ARG_ENABLE([warn_shadow],
84	      [AS_HELP_STRING([--enable-warn-shadow],
85			      [turn on -Wshadow when compiling])])
86
87# [pairwise: --enable-warn-error, --disable-warn-error]
88AC_ARG_ENABLE([warn_error],
89	      [AS_HELP_STRING([--enable-warn-error],
90			      [turn on -Werror when compiling])])
91
92# [pairwise: --enable-developer, --disable-developer]
93AC_ARG_ENABLE([developer],
94	      [AS_HELP_STRING([--enable-developer],
95			      [enable developer build settings])])
96
97XTARGETS=
98AS_IF([test "$enable_developer" = "yes"],
99      [STD_CDEFINES="$STD_CDEFINES -DISC_MEM_DEFAULTFILL=1 -DISC_LIST_CHECKINIT=1"
100       test "${enable_fixed_rrset+set}" = set || enable_fixed_rrset=yes
101       test "${enable_querytrace+set}" = set || enable_querytrace=yes
102       test "${with_cmocka+set}" = set || with_cmocka=yes
103       test "${with_dlz_filesystem+set}" = set || with_dlz_filesystem=yes
104       test "${enable_symtable+set}" = set || enable_symtable=all
105       test "${enable_warn_error+set}" = set || enable_warn_error=yes
106       test "${enable_warn_shadow+set}" = set || enable_warn_shadow=yes
107       test "${with_zlib+set}" = set || with_zlib=yes
108       XTARGETS='${XTARGETS}'
109       ])
110AC_SUBST([XTARGETS])
111
112# Fuzzing is not included in pairwise testing as fuzzing tools are
113# not present in the relevant Docker image.
114#
115# [pairwise: skip]
116AC_ARG_ENABLE([fuzzing],
117	      [AS_HELP_STRING([--enable-fuzzing=<afl|libfuzzer>],
118			      [Enable fuzzing using American Fuzzy Lop or libFuzzer (default=no)])],
119	      [],
120	      [enable_fuzzing=no])
121
122AC_MSG_CHECKING([whether to enable fuzzing mode])
123AS_CASE([$enable_fuzzing],
124	[no],[AC_MSG_RESULT([no])],
125	[afl],[
126	  AC_MSG_RESULT([using AFL])
127	  AC_DEFINE([ENABLE_AFL], [1],
128		    [Define to enable American Fuzzy Lop test harness])
129	  CFLAGS="$CFLAGS -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION=1"
130	  LIBS="$LIBS -lpthread"],
131	[libfuzzer],[
132	  AC_MSG_RESULT([using libFuzzer])
133	  CFLAGS="$CFLAGS -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION=1 -fsanitize=fuzzer,address,undefined"
134	  LDFLAGS="$LDFLAGS -fsanitize=fuzzer,address,undefined"],
135	[*],[AC_MSG_ERROR([You need to explicitly select the fuzzer])])
136
137AS_IF([test "$enable_fuzzing" = "afl"],
138      [AC_MSG_CHECKING("for AFL enabled compiler")
139       AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
140					  [#ifndef __AFL_COMPILER
141					   #error AFL compiler required
142					   #endif
143					  ])],
144			 [AC_MSG_RESULT([yes])],
145			 [AC_MSG_ERROR([set CC=afl-<gcc|clang> when --enable-fuzzing=afl is used])])
146      ])
147
148# [pairwise: --enable-mutex-atomics, --disable-mutex-atomics]
149AC_ARG_ENABLE(mutex_atomics,
150	      AS_HELP_STRING([--enable-mutex-atomics],
151		             [emulate atomics by mutex-locked variables, useful for debugging
152				[default=no]]),
153	      [],
154	      [enable_mutex_atomics=no])
155
156AC_MSG_CHECKING([whether to emulate atomics with mutexes])
157case "$enable_mutex_atomics" in
158yes)
159        AC_MSG_RESULT(yes)
160        AC_DEFINE(ISC_MUTEX_ATOMICS, 1, [Define to emulate atomic variables with mutexes.])
161        ;;
162no)
163        AC_MSG_RESULT(no)
164        ;;
165*)
166        AC_MSG_ERROR("--enable-mutex-atomics requires yes or no")
167        ;;
168esac
169
170#
171# Make very sure that these are the first files processed by
172# config.status, since we use the processed output as the input for
173# AC_SUBST_FILE() substitutions in other files.
174#
175AC_CONFIG_FILES([make/rules make/includes])
176
177AC_PATH_PROG(AR, ar)
178ARFLAGS="cruv"
179AC_SUBST(AR)
180AC_SUBST(ARFLAGS)
181
182# The POSIX ln(1) program.  Non-POSIX systems may substitute
183# "copy" or something.
184LN=ln
185AC_SUBST(LN)
186
187case "$AR" in
188	"")
189		AC_MSG_ERROR([
190ar program not found.  Please fix your PATH to include the directory in
191which ar resides, or set AR in the environment with the full path to ar.
192])
193
194		;;
195esac
196
197#
198# Look for w3m
199#
200AC_PATH_PROGS(W3M, w3m, w3m)
201AC_SUBST(W3M)
202
203#
204# Look for pandoc
205#
206AC_PATH_PROG(PANDOC, pandoc, pandoc)
207AC_SUBST(PANDOC)
208
209#
210# Perl is optional; it is used only by some of the system test scripts.
211# Note: the backtrace feature (see below) uses perl to build the symbol table,
212# but it still compiles without perl, in which case an empty table will be used.
213#
214AC_PATH_PROGS(PERL, perl5 perl)
215AC_SUBST(PERL)
216
217#
218# Python is also optional but required by default so that dnssec-keymgr gets
219# installed unless explicitly prevented by the user using --without-python.
220#
221testminvers='import sys
222if (sys.version_info < (2,7)) or (sys.version_info < (3,2) and sys.version_info >= (3,0)):
223   exit(1)'
224
225testargparse='try: import argparse
226except: exit(1)'
227
228testply='try: import ply
229except: exit(1)'
230
231testsetup='try: from distutils.core import setup
232except: exit(1)'
233
234default_with_python="python python3 python3.8 python3.7 python3.6 python3.5 python3.4 python3.3 python3.2 python2 python2.7"
235
236AC_ARG_VAR([PYTHON], [path to python executable])
237
238# [pairwise: --with-python, --without-python]
239AC_ARG_WITH([python],
240	    AS_HELP_STRING([--with-python=PATH],
241			   [specify path to Python interpreter]),
242	    [], [with_python=$default_with_python])
243
244# [pairwise: skip]
245AC_ARG_WITH([python-install-dir],
246	    AS_HELP_STRING([--with-python-install-dir=PATH],
247			   [installation directory for Python modules]),
248	    [], with_python_install_dir="")
249
250AS_IF([test "$with_python" = "yes"],
251      [with_python=$default_with_python])
252
253AS_IF([test "$with_python" = "no"],
254      [AC_MSG_CHECKING([for Python support])
255       unset PYTHON
256       AC_MSG_RESULT([disabled])],
257      [for p in $with_python
258       do
259	 AS_CASE([$p],
260		 [/*],[PYTHON="$p"])
261
262	 AC_PATH_PROG([PYTHON], [$p])
263	 # Do not cache the result of the check from the previous line.  If the
264	 # first found Python interpreter has missing module dependencies and
265	 # the result of the above check is cached, subsequent module checks
266	 # will erroneously keep on using the cached path to the first found
267	 # Python interpreter instead of different ones.
268	 unset ac_cv_path_PYTHON
269
270	 AS_IF([test -z "$PYTHON"], [continue])
271
272	 AC_MSG_CHECKING([if $PYTHON is python2 version >= 2.7 or python3 version >= 3.2])
273	 AS_IF(["$PYTHON" -c "$testminvers" 2>/dev/null],
274	       [AC_MSG_RESULT([yes])],
275	       [AC_MSG_RESULT([no])
276		unset PYTHON
277		continue])
278
279	 AC_MSG_CHECKING([Python module 'argparse'])
280	 AS_IF(["$PYTHON" -c "$testargparse" 2>/dev/null],
281	       [AC_MSG_RESULT([yes])],
282	       [AC_MSG_RESULT([no])
283		unset PYTHON
284		continue])
285
286	 AC_MSG_CHECKING([Python module 'ply'])
287	 AS_IF(["$PYTHON" -c "$testply" 2>/dev/null],
288	       [AC_MSG_RESULT([yes])],
289	       [AC_MSG_RESULT([no])
290		unset PYTHON
291		continue])
292
293	 AC_MSG_CHECKING([Python module 'distutils.core setup'])
294	 AS_IF(["$PYTHON" -c "$testsetup" 2>/dev/null],
295	       [AC_MSG_RESULT([yes])],
296	       [AC_MSG_RESULT([no])
297		unset PYTHON
298		continue])
299
300	 # Stop looking any further once we find a Python interpreter
301	 # satisfying all requirements.
302	 break
303       done
304
305       AS_IF([test "X$PYTHON" = "X"],
306	     [AC_MSG_CHECKING([for Python support])
307	      AC_MSG_RESULT([no])
308	      AC_MSG_ERROR([m4_normalize(
309				[Python >= 2.7 or >= 3.2 and the PLY package
310                                 are required for dnssec-keymgr and other
311                                 Python-based tools. PLY may be
312                                 available from your OS package manager
313                                 as python-ply or python3-ply; it can also
314                                 be installed via pip. To build without
315                                 Python/PLY, use --without-python.]
316			    )])])])
317
318PYTHON_TOOLS=''
319CHECKDS=''
320COVERAGE=''
321KEYMGR=''
322AS_IF([test "X$PYTHON" != "X"],
323      [PYTHON_TOOLS=python
324       CHECKDS=checkdstool
325       COVERAGE=coverage
326       KEYMGR=keymgr
327       PYTHON_INSTALL_DIR="$with_python_install_dir"
328       AS_IF([test -n "$with_python_install_dir"],
329	     [PYTHON_INSTALL_LIB="--install-lib=$with_python_install_dir"])])
330AC_SUBST(CHECKDS)
331AC_SUBST(COVERAGE)
332AC_SUBST(KEYMGR)
333AC_SUBST(PYTHON_TOOLS)
334AC_SUBST(PYTHON_INSTALL_DIR)
335AC_SUBST(PYTHON_INSTALL_LIB)
336
337#
338# expanded_sysconfdir is needed for replacement in the python utilities
339#
340expanded_sysconfdir=`eval echo $sysconfdir`
341AC_SUBST(expanded_sysconfdir)
342
343#
344# Make sure INSTALL uses an absolute path, else it will be wrong in all
345# Makefiles, since they use make/rules.in and INSTALL will be adjusted by
346# configure based on the location of the file where it is substituted.
347# Since in BIND9 INSTALL is only substituted into make/rules.in, an immediate
348# subdirectory of install-sh, This relative path will be wrong for all
349# directories more than one level down from install-sh.
350#
351case "$INSTALL" in
352	/*)
353		;;
354	*)
355		#
356		# Not all systems have dirname.
357		#
358		changequote({, })
359		ac_dir="`echo $INSTALL | sed 's%/[^/]*$%%'`"
360		changequote([, ])
361
362		ac_prog="`echo $INSTALL | sed 's%.*/%%'`"
363		test "X$ac_dir" = "X$ac_prog" && ac_dir=.
364		test -d "$ac_dir" && ac_dir="`(cd \"$ac_dir\" && pwd)`"
365		INSTALL="$ac_dir/$ac_prog"
366		;;
367esac
368
369AC_PATH_PROGS([PYTEST], [pytest-3 py.test-3 pytest py.test pytest-pypy], [])
370AS_IF([test -z "$PYTEST"],
371      [AC_MSG_WARN([pytest not found, some system tests will be skipped])])
372AC_SUBST([PYTEST])
373
374
375AC_PROG_CC
376AC_PROG_CC_C99
377
378#
379# Using Solaris linker with gcc on Solaris breaks Thread Local Storage
380#
381AS_CASE([$host],
382	[*-solaris*],[
383	    AS_IF([test "$GCC" = "yes"],
384		  [LDFLAGS="$LDFLAGS -zrelax=transtls"
385		   AC_MSG_WARN([When using GNU C Compiler on Solaris, -zrelax=transtls linker flag is used to fix bug in Thread Local Storage])
386		  ])
387	],
388	[*-darwin*],[LDFLAGS="$LDFLAGS -Wl,-flat_namespace"])
389
390#
391# CCNOOPT defaults to -O0 on gcc and disables optimization when is last
392#
393if test "X$CCNOOPT" = "X" -a "X$GCC" = "Xyes"; then
394	CCNOOPT="-O0"
395fi
396
397AC_HEADER_STDC
398
399AC_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,,,
400[$ac_includes_default
401#ifdef HAVE_SYS_PARAM_H
402# include <sys/param.h>
403#endif
404#ifdef HAVE_SYS_SOCKET_H
405# include <sys/socket.h>
406#endif
407])
408
409#
410# Check for thread local storage
411#
412AC_CHECK_HEADERS([threads.h],
413		 [
414		     AC_MSG_CHECKING([for C11 Thread-Local Storage using thread_local])
415		     AC_COMPILE_IFELSE(
416			 [AC_LANG_PROGRAM(
417			      [
418				  #include <threads.h>
419			      ],[
420				  static thread_local int tls = 0;
421				  return (tls);
422			      ])
423			 ],[
424			     AC_MSG_RESULT([yes])
425			     AC_DEFINE([HAVE_THREAD_LOCAL],[1],[Define if thread_local keyword is available])
426			     AC_DEFINE([HAVE_TLS],[1],[Define if Thread-Local Storage is available])
427			 ],[
428			     AC_MSG_ERROR([Thread Local Storage support required, update your toolchain to build BIND 9])
429			 ])
430		 ],[
431		     AC_MSG_CHECKING([for Thread-Local Storage using __thread])
432		     AC_COMPILE_IFELSE(
433			 [AC_LANG_PROGRAM(
434			      [
435			      ],[
436				  static __thread int tls = 0;
437				  return (tls);
438			      ])
439			 ],[
440			     AC_MSG_RESULT([yes])
441			     AC_DEFINE([HAVE___THREAD],[1],[Define if __thread keyword is available])
442			     AC_DEFINE([HAVE_TLS],[1],[Define if Thread-Local Storage is available])
443			 ],[
444			     AC_MSG_ERROR([Thread Local Storage support required, update your toolchain to build BIND 9])
445			 ])
446		 ])
447
448AC_C_CONST
449AC_C_INLINE
450AC_C_VOLATILE
451AC_C_FLEXIBLE_ARRAY_MEMBER
452
453#
454# Check for yield support on ARM processors
455#
456AS_CASE([$host],
457	[arm*],
458	[AC_MSG_CHECKING([for yield instruction support])
459	 AC_COMPILE_IFELSE(
460	     [AC_LANG_PROGRAM([[]],
461			     [[__asm__ __volatile__ ("yield")]])],
462	     [AC_MSG_RESULT([yes])
463	      AC_DEFINE([HAVE_ARM_YIELD], [1],
464			[define if the ARM yield instruction is available])],
465	     [AC_MSG_RESULT([no])])])
466
467#
468# Check for pause support on SPARC processors
469#
470AS_CASE([$host],
471	[sparc*],
472	[AC_MSG_CHECKING([for pause instruction support])
473	 AC_COMPILE_IFELSE(
474	     [AC_LANG_PROGRAM([[]],
475			     [[__asm__ __volatile__ ("pause")]])],
476	     [AC_MSG_RESULT([yes])
477	      AC_DEFINE([HAVE_SPARC_PAUSE], [1],
478			[define if the SPARC pause instruction is available])],
479	     [AC_MSG_RESULT([no])])])
480
481AC_CHECK_FUNCS([sysctlbyname])
482
483#
484# Check for the existence of mmap to enable the fast format zones
485#
486AC_CHECK_FUNCS(mmap)
487
488#
489# Older versions of HP/UX don't define seteuid() and setegid()
490#
491AC_CHECK_FUNCS(seteuid setresuid)
492AC_CHECK_FUNCS(setegid setresgid)
493
494AC_TYPE_SIZE_T
495AC_TYPE_SSIZE_T
496AC_TYPE_UINTPTR_T
497
498AC_HEADER_TIME
499
500#
501# check for uname library routine
502#
503AC_MSG_CHECKING([for uname])
504AC_COMPILE_IFELSE(
505  [AC_LANG_PROGRAM(
506     [[#include <sys/utsname.h>
507       #include <stdio.h>
508      ]],
509     [[
510       struct utsname uts;
511       uname(&uts);
512       printf("running on %s %s %s for %s\n",
513	      uts.sysname, uts.release, uts.version, uts.machine);
514     ]])],
515  [AC_MSG_RESULT(yes)
516   AC_DEFINE([HAVE_UNAME], [1], [define if uname is available])
517  ],
518  [AC_MSG_RESULT(no)
519   AC_MSG_WARN([uname is not correctly supported])
520  ])
521
522#
523# check for GCC noreturn attribute
524#
525AC_MSG_CHECKING(for GCC noreturn attribute)
526AC_TRY_COMPILE([],[void foo() __attribute__((noreturn));],
527	[AC_MSG_RESULT(yes)
528		ISC_PLATFORM_NORETURN_PRE="#define ISC_PLATFORM_NORETURN_PRE"
529		ISC_PLATFORM_NORETURN_POST="#define ISC_PLATFORM_NORETURN_POST __attribute__((noreturn))"],
530	[AC_MSG_RESULT(no)
531		ISC_PLATFORM_NORETURN_PRE="#define ISC_PLATFORM_NORETURN_PRE"
532		ISC_PLATFORM_NORETURN_POST="#define ISC_PLATFORM_NORETURN_POST"])
533AC_SUBST(ISC_PLATFORM_NORETURN_PRE)
534AC_SUBST(ISC_PLATFORM_NORETURN_POST)
535
536#
537# check for GCC malloc attribute
538#
539AX_GCC_FUNC_ATTRIBUTE([malloc])
540
541AC_MSG_CHECKING([for extended malloc attributes])
542AC_COMPILE_IFELSE(
543  [AC_LANG_PROGRAM(
544     [[
545       #include <stddef.h>
546       #include <stdlib.h>
547       __attribute__ ((malloc, malloc (free, 1))
548       void * xmalloc(size_t sz) { return malloc(sz); }
549     ]],
550     [[
551       void *p = xmalloc(8);
552       free(p);
553     ]])],
554  [AC_MSG_RESULT(yes)
555   AC_DEFINE([HAVE_MALLOC_EXT_ATTR], [1], [define if extended attributes for malloc are available])
556  ],
557  [AC_MSG_RESULT(no)])
558
559#
560# check for GCC returns_nonnull attribute
561#
562AX_GCC_FUNC_ATTRIBUTE([returns_nonnull])
563
564#
565# check if we have kqueue
566#
567# [pairwise: --enable-kqueue, --disable-kqueue]
568AC_ARG_ENABLE([kqueue],
569	      [AS_HELP_STRING([--enable-kqueue],
570			      [use BSD kqueue when available [default=yes]])],
571	      [], enable_kqueue="yes")
572
573AS_IF([test "$enable_kqueue" = "yes"],
574      [AC_CHECK_FUNCS([kqueue])])
575
576#
577# check if we have epoll.  Linux kernel 2.4 has epoll_create() which fails,
578# so we need to try running the code, not just test its existence.
579#
580# [pairwise: --enable-epoll, --disable-epoll]
581AC_ARG_ENABLE([epoll],
582	      [AS_HELP_STRING([--enable-epoll],
583			      [use Linux epoll when available [default=auto]])],
584	      [], [enable_epoll="yes"])
585
586AS_IF([test "$enable_epoll" = "yes"],
587      [AC_CHECK_FUNCS([epoll_create1])])
588
589#
590# check if we support /dev/poll
591#
592# [pairwise: --enable-devpoll, --disable-devpoll]
593AC_ARG_ENABLE([devpoll],
594	      [AS_HELP_STRING([--enable-devpoll],
595			      [use /dev/poll when available [default=yes]])],
596	      [], [enable_devpoll="yes"])
597AS_IF([test "$enable_devpoll" = "yes"],
598      [AC_CHECK_HEADERS([sys/devpoll.h devpoll.h])])
599
600#
601# Find the machine's endian flavor.
602#
603AC_C_BIGENDIAN
604
605#
606# GeoIP support?
607#
608# Should be on by default if libmaxminddb exists.
609#
610# [pairwise: skip]
611AC_ARG_WITH([geoip2],
612	    [AS_HELP_STRING([--with-geoip2],
613			    [deprecated, use --with-maxminddb])],
614	    [AC_MSG_WARN([--with-geoip2 is DEPRECATED and will be removed in a future release, use --with-maxminddb instead])],
615	    [with_geoip2="auto"])
616
617# [pairwise: --enable-geoip --with-maxminddb=auto, --enable-geoip --with-maxminddb=yes, --disable-geoip]
618AC_ARG_ENABLE([geoip],
619	      [AS_HELP_STRING([--disable-geoip],
620			      [support GeoIP2 geolocation ACLs if available [default=yes]])],
621	      [], [enable_geoip="yes"])
622
623# [pairwise: skip]
624AC_ARG_WITH([maxminddb],
625	    [AS_HELP_STRING([--with-maxminddb=PATH],
626			    [Build with MaxMind GeoIP2 support (auto|yes|no|path) [default=auto]])],
627	    [], [with_maxminddb="$with_geoip2"])
628
629GEOIP2LINKSRCS=
630GEOIP2LINKOBJS=
631AS_IF([test "$enable_geoip" = "yes"],
632      [AS_CASE([$with_maxminddb],
633	       [no],[AC_MSG_ERROR([Use '--disable-geoip' to disable the GeoIP])],
634	       [auto],[PKG_CHECK_MODULES([MAXMINDDB], [libmaxminddb],
635					 [AC_DEFINE([HAVE_GEOIP2], [1], [Build with GeoIP2 support])
636					  PKG_CHECK_VAR([MAXMINDDB_PREFIX], [libmaxminddb], [prefix], [], [AC_MSG_ERROR([libmaxminddb prefix not found in pkg-config; set MAXMINDDB_PREFIX in the environment])])
637					  GEOIP2LINKSRCS='${GEOIP2LINKSRCS}'
638					  GEOIP2LINKOBJS='${GEOIP2LINKOBJS}'
639					 ],[:])],
640	       [yes],[PKG_CHECK_MODULES([MAXMINDDB], [libmaxminddb],
641					[AC_DEFINE([HAVE_GEOIP2], [1], [Build with GeoIP2 support])
642					 PKG_CHECK_VAR([MAXMINDDB_PREFIX], [libmaxminddb], [prefix], [], [AC_MSG_ERROR([libmaxminddb prefix not found in pkg-config; set MAXMINDDB_PREFIX in the environment])])
643					 GEOIP2LINKSRCS='${GEOIP2LINKSRCS}'
644					 GEOIP2LINKOBJS='${GEOIP2LINKOBJS}'
645					])],
646	       [ # default
647		   AX_SAVE_FLAGS([maxminddb])
648		   MAXMINDDB_CFLAGS="-I$with_maxminddb/include"
649		   MAXMINDDB_LIBS="-L$with_maxminddb/lib"
650		   CFLAGS="$CFLAGS $MAXMINDDB_CFLAGS"
651		   LDFLAGS="$LDFLAGS $MAXMINDDB_LIBS"
652		   AC_SEARCH_LIBS([MMDB_open], [maxminddb],
653				  [AC_DEFINE([HAVE_GEOIP2], [1], [Build with GeoIP2 support])
654				   GEOIP2LINKSRCS='${GEOIP2LINKSRCS}'
655				   GEOIP2LINKOBJS='${GEOIP2LINKOBJS}'
656				   MAXMINDDB_LIBS="$MAXMINDDB_LIBS $ac_cv_search_MMDB_open"
657				   AC_MSG_NOTICE([GeoIP2 default database path set to $with_maxminddb/share/GeoIP])
658				   AS_VAR_COPY([MAXMINDDB_PREFIX], [$with_maxminddb])
659				  ],
660				  [AC_MSG_ERROR([GeoIP2 requested, but libmaxminddb not found])])
661		   AX_RESTORE_FLAGS([maxminddb])
662	       ])
663       AC_ARG_VAR([MAXMINDDB_PREFIX], [value of prefix for MAXMINDDB, overriding pkg-config])
664])
665
666AC_SUBST([MAXMINDDB_CFLAGS])
667AC_SUBST([MAXMINDDB_LIBS])
668AC_SUBST([GEOIP2LINKSRCS])
669AC_SUBST([GEOIP2LINKOBJS])
670
671#
672# Do we have arc4random(), etc ?
673#
674AC_CHECK_FUNCS(arc4random arc4random_buf arc4random_uniform getrandom)
675
676AX_PTHREAD
677
678LIBS="$PTHREAD_LIBS $LIBS"
679CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
680CC="$PTHREAD_CC"
681
682AC_CHECK_FUNCS([pthread_attr_getstacksize pthread_attr_setstacksize])
683
684# [pairwise: --with-locktype=adaptive, --with-locktype=standard]
685AC_ARG_WITH([locktype],
686	    AS_HELP_STRING([--with-locktype=ARG],
687			   [Specify mutex lock type
688			    (adaptive or standard)]),
689	    [], [with_locktype="adaptive"])
690
691AS_CASE([$with_locktype],
692	[adaptive],[
693	  AC_MSG_CHECKING([for PTHREAD_MUTEX_ADAPTIVE_NP])
694	  AC_COMPILE_IFELSE(
695	    [AC_LANG_PROGRAM(
696	       [[
697		 #ifndef _GNU_SOURCE
698		 #define _GNU_SOURCE
699		 #endif
700		 #include <pthread.h>
701	       ]],
702	       [[
703		 return (PTHREAD_MUTEX_ADAPTIVE_NP);
704	       ]]
705	     )],
706	    [AC_MSG_RESULT([using adaptive lock type])
707	     AC_DEFINE([HAVE_PTHREAD_MUTEX_ADAPTIVE_NP], 1,
708		       [Support for PTHREAD_MUTEX_ADAPTIVE_NP]) ],
709	    [AC_MSG_RESULT([using standard lock type])]
710	  )],
711	[standard],[AC_MSG_RESULT([using standard lock type])],
712	[AC_MSG_ERROR([You must specify "adaptive" or "standard" for --with-locktype.])]
713       )
714
715AC_CHECK_HEADERS([sched.h])
716
717AC_SEARCH_LIBS([sched_yield],[rt])
718AC_CHECK_FUNCS([sched_yield pthread_yield pthread_yield_np])
719
720# Look for functions relating to thread naming
721AC_CHECK_FUNCS([pthread_setname_np pthread_set_name_np])
722AC_CHECK_HEADERS([pthread_np.h], [], [], [#include <pthread.h>])
723
724# libuv
725AC_MSG_CHECKING(for libuv)
726PKG_CHECK_MODULES([LIBUV], [libuv >= 1.0.0], [],
727		  [AC_MSG_ERROR([libuv not found])])
728
729# libuv recvmmsg support
730AC_CHECK_DECLS([UV_UDP_MMSG_FREE, UV_UDP_MMSG_CHUNK], [], [], [[#include <uv.h>]])
731AC_MSG_CHECKING([whether struct msghdr uses padding for alignment])
732AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <sys/socket.h>],
733				   [const struct msghdr h = { .__pad1 = 0, .__pad2 = 0 };])],
734		  [AC_MSG_RESULT([yes])
735		   AC_DEFINE([HAVE_DECL_UV_UDP_RECVMMSG],
736			     [0], [Disable recvmmsg support on systems with MUSL glibc])],
737		  [AC_MSG_RESULT([no])
738		   AC_CHECK_DECLS([UV_UDP_RECVMMSG], [], [], [[#include <uv.h>]])])
739
740#
741# flockfile is usually provided by pthreads
742#
743AC_CHECK_FUNCS([flockfile getc_unlocked])
744
745#
746# Look for sysconf to allow detection of the number of processors.
747#
748AC_CHECK_FUNCS([sysconf])
749
750AC_SUBST(ALWAYS_DEFINES)
751
752AC_MSG_CHECKING(for libtool)
753
754# [pairwise: --with-libtool, --without-libtool]
755AC_ARG_WITH(libtool, AS_HELP_STRING([--with-libtool], [use GNU libtool]),
756	    use_libtool="$withval", use_libtool="no")
757NO_LIBTOOL_ISCLIBS=
758NO_LIBTOOL_DNSLIBS=
759case $use_libtool in
760	yes)
761		AC_MSG_RESULT(yes)
762		AM_PROG_LIBTOOL
763		O=lo
764		A=la
765		LIBTOOL_MKDEP_SED='s;\.o;\.lo;'
766		LIBTOOL_MODE_COMPILE='--mode=compile'
767		LIBTOOL_MODE_INSTALL='--mode=install'
768		LIBTOOL_MODE_LINK='--mode=link'
769		LIBTOOL_MODE_UNINSTALL='--mode=uninstall'
770		INSTALL_LIBRARY='${INSTALL_PROGRAM}'
771		AC_DEFINE([USE_LIBTOOL],[1],[Define if libtool is used for compilation])
772		;;
773	*)
774		AC_MSG_RESULT(no)
775		O=o
776		A=a
777		LIBTOOL=
778		AC_SUBST(LIBTOOL)
779		LIBTOOL_MKDEP_SED=
780		LIBTOOL_MODE_COMPILE=
781		LIBTOOL_MODE_INSTALL=
782		LIBTOOL_MODE_LINK=
783		LIBTOOL_MODE_UNINSTALL=
784		INSTALL_LIBRARY='${INSTALL_DATA}'
785		NO_LIBTOOL_ISCLIBS='${NO_LIBTOOL_ISCLIBS}'
786		NO_LIBTOOL_DNSLIBS='${NO_LIBTOOL_DNSLIBS}'
787		;;
788esac
789AC_SUBST(INSTALL_LIBRARY)
790AC_SUBST(NO_LIBTOOL_ISCLIBS)
791AC_SUBST(NO_LIBTOOL_DNSLIBS)
792
793#
794# Do we want to use pthread rwlock?
795#
796# [pairwise: --enable-pthread-rwlock, --disable-pthread-rwlock]
797AC_ARG_ENABLE([pthread_rwlock],
798	      [AS_HELP_STRING([--enable-pthread-rwlock],
799			      [use pthread rwlock instead of internal rwlock implementation])],
800	      [], [enable_pthread_rwlock=no])
801
802AS_IF([test "$enable_pthread_rwlock" = "yes"],
803      [AC_CHECK_FUNCS([pthread_rwlock_rdlock], [],
804		      [AC_MSG_ERROR([pthread_rwlock_rdlock requested but not found])])
805       AC_DEFINE([USE_PTHREAD_RWLOCK],[1],[Define if you want to use pthread rwlock implementation])
806      ])
807
808CRYPTO=OpenSSL
809
810#
811# OpenSSL/LibreSSL is mandatory
812#
813PKG_CHECK_MODULES([OPENSSL], [libssl libcrypto], [],
814		  [AX_CHECK_OPENSSL([:],[AC_MSG_FAILURE([OpenSSL/LibreSSL not found])])])
815
816AX_SAVE_FLAGS([openssl])
817
818#
819# This maintenance branch of BIND 9 does not support new OpenSSL APIs
820# introduced in version 3.0.0.  Suppress compiler warnings about using
821# functions deprecated in newer OpenSSL versions as they will not be
822# addressed in BIND 9.16.
823#
824OPENSSL_CFLAGS="$OPENSSL_CFLAGS -DOPENSSL_SUPPRESS_DEPRECATED"
825
826CFLAGS="$CFLAGS $OPENSSL_CFLAGS"
827LIBS="$LIBS $OPENSSL_LIBS"
828
829AC_MSG_CHECKING([for OpenSSL >= 1.0.0 or LibreSSL >= 2.7.0])
830AC_COMPILE_IFELSE(
831    [AC_LANG_PROGRAM([[#include <openssl/opensslv.h>]],
832		     [[#if (!defined(LIBRESSL_VERSION_NUMBER) && (OPENSSL_VERSION_NUMBER < 0x1000000fL)) || \\
833			   (defined(LIBRESSL_VERSION_NUMBER) && (LIBRESSL_VERSION_NUMBER < 0x02070000fL))
834		       #error OpenSSL >= 1.0.0 or LibreSSL >= 2.7.0 required
835		       #endif
836		      ]])],
837    [AC_MSG_RESULT([yes])],
838    [AC_MSG_FAILURE([not found])])
839
840#
841# Check for functions added in OpenSSL or LibreSSL
842#
843
844AC_CHECK_FUNCS([OPENSSL_init_ssl OPENSSL_init_crypto OPENSSL_cleanup])
845AC_CHECK_FUNCS([CRYPTO_zalloc])
846AC_CHECK_FUNCS([EVP_CIPHER_CTX_new EVP_CIPHER_CTX_free])
847AC_CHECK_FUNCS([EVP_MD_CTX_new EVP_MD_CTX_free EVP_MD_CTX_reset])
848AC_CHECK_FUNCS([HMAC_CTX_new HMAC_CTX_free HMAC_CTX_reset HMAC_CTX_get_md])
849AC_CHECK_FUNCS([SSL_read_ex SSL_peek_ex SSL_write_ex])
850AC_CHECK_FUNCS([BIO_read_ex BIO_write_ex])
851AC_CHECK_FUNCS([BN_GENCB_new])
852AC_CHECK_FUNCS([SSL_CTX_up_ref])
853AC_CHECK_FUNCS([SSL_CTX_set_min_proto_version])
854
855#
856# Check for algorithm support in OpenSSL
857#
858
859AC_CHECK_FUNCS([ECDSA_sign ECDSA_verify], [:],
860	       [AC_MSG_FAILURE([ECDSA support in OpenSSL is mandatory.])])
861
862AC_MSG_CHECKING([for ECDSA P-256 support])
863AC_COMPILE_IFELSE(
864    [AC_LANG_PROGRAM([[#include <openssl/evp.h>
865		       #include <openssl/ec.h>]],
866		     [[EC_KEY *key = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1);]])],
867    [AC_MSG_RESULT([yes])],
868    [AC_MSG_FAILURE([not found.  ECDSA P-256 support in OpenSSL is mandatory.])])
869
870AC_MSG_CHECKING([for ECDSA P-384 support])
871AC_COMPILE_IFELSE(
872    [AC_LANG_PROGRAM([[#include <openssl/evp.h>
873		       #include <openssl/ec.h>]],
874		     [[EC_KEY *key = EC_KEY_new_by_curve_name(NID_secp384r1);]])],
875    [AC_MSG_RESULT([yes])],
876    [AC_MSG_FAILURE([not found.  ECDSA P-384 support in OpenSSL is mandatory.])])
877
878AC_MSG_CHECKING([for Ed25519 support])
879AC_COMPILE_IFELSE(
880    [AC_LANG_PROGRAM([[#include <openssl/evp.h>
881		       #include <openssl/ec.h>]],
882		     [[EC_KEY *key = EC_KEY_new_by_curve_name(NID_ED25519);]])],
883    [AC_DEFINE([HAVE_OPENSSL_ED25519], [1], [define if OpenSSL supports Ed25519])
884     AC_MSG_RESULT([yes])],
885    [AC_MSG_RESULT([no])])
886
887AC_MSG_CHECKING([for Ed448 support])
888AC_COMPILE_IFELSE(
889    [AC_LANG_PROGRAM([[#include <openssl/evp.h>
890		       #include <openssl/ec.h>]],
891		     [[EC_KEY *key = EC_KEY_new_by_curve_name(NID_ED448);]])],
892    [AC_DEFINE([HAVE_OPENSSL_ED448], [1], [define if OpenSSL supports Ed448])
893     AC_MSG_RESULT([yes])],
894    [AC_MSG_RESULT([no])])
895
896#
897# Check for OpenSSL SHA-1 support
898#
899AC_CHECK_FUNCS([EVP_sha1], [:],
900	       [AC_MSG_FAILURE([SHA-1 support in OpenSSL is mandatory.])])
901
902#
903# Check for OpenSSL SHA-2 support
904#
905AC_CHECK_FUNCS([EVP_sha224 EVP_sha256 EVP_sha384 EVP_sha512], [:],
906	       [AC_MSG_FAILURE([SHA-2 support in OpenSSL is mandatory.])])
907
908#
909# Check for OpenSSL AES support
910#
911AC_CHECK_FUNCS([EVP_aes_128_ecb EVP_aes_192_ecb EVP_aes_256_ecb], [:],
912	       [AC_MSG_FAILURE([AES support in OpenSSL is mandatory.])])
913
914#
915# Check for OpenSSL 1.1.x/LibreSSL functions
916#
917AC_CHECK_FUNCS([DH_get0_key ECDSA_SIG_get0 RSA_set0_key])
918
919AC_CHECK_FUNCS([TLS_server_method TLS_client_method])
920
921#
922# Check whether FIPS mode is available and whether we should enable it
923#
924# FIPS is not included in pairwise testing as the relevant Docker image
925# does not support FIPS mode.
926#
927# [pairwise: skip]
928AC_ARG_ENABLE([fips-mode],
929	      [AS_HELP_STRING([--enable-fips-mode],
930			      [enable FIPS mode in OpenSSL library [default=no]])],
931	      [], [enable_fips_mode="no"])
932
933AC_MSG_CHECKING([whether to enable FIPS mode in OpenSSL library])
934AS_CASE([$enable_fips_mode],
935	[yes], [AC_MSG_RESULT([yes])
936		AC_CHECK_FUNCS([FIPS_mode],
937			       [], [AC_MSG_FAILURE([OpenSSL FIPS mode requested but not available.])])],
938	[no], [AC_MSG_RESULT([no])])
939
940AX_RESTORE_FLAGS([openssl])
941
942AC_SUBST([OPENSSL_CFLAGS])
943AC_SUBST([OPENSSL_LIBS])
944
945PKCS11_TOOLS=
946PKCS11_TEST=
947PKCS11_MANS=
948#
949# was --enable-native-pkcs11 specified?
950#
951# [pairwise: --enable-native-pkcs11 --with-dlopen, --disable-native-pkcs11 --with-dlopen, --disable-native-pkcs11 --without-dlopen]
952AC_ARG_ENABLE(native-pkcs11,
953	      AS_HELP_STRING([--enable-native-pkcs11],
954			     [use native PKCS11 for public-key crypto [default=no]]),
955	      [:], [enable_native_pkcs11="no"])
956
957AC_MSG_CHECKING([for PKCS11 for Public-Key Cryptography])
958AS_CASE([$enable_native_pkcs11],
959	[no],[AC_MSG_RESULT([no])],
960	[yes],[PKCS11_TOOLS=pkcs11
961	       PKCS11_TEST=pkcs11
962	       PKCS11_MANS='${pkcs11_man8_MANS}'
963	       CRYPTO=pkcs11
964	       AS_IF([$use_threads],
965		     [:],
966		     [AC_MSG_ERROR([PKCS11 requires threading support])])
967	       AC_MSG_RESULT([yes])
968	       AC_CHECK_FUNCS([getpassphrase])
969	      ])
970AC_SUBST([PKCS11_TEST])
971AC_SUBST([PKCS11_TOOLS])
972AC_SUBST([PKCS11_MANS])
973
974AC_SUBST([CRYPTO])
975AS_CASE([$CRYPTO],
976	[pkcs11],[AC_DEFINE([USE_PKCS11], [1], [define if PKCS11 is used for Public-Key Cryptography])],
977	[AC_DEFINE([USE_OPENSSL], [1], [define if OpenSSL is used for Public-Key Cryptography])])
978
979# preparation for automake
980# AM_CONDITIONAL([PKCS11_TOOLS], [test "$with_native_pkcs11" = "yes"])
981
982#
983# was --with-pkcs11 specified?
984#
985# [pairwise: skip]
986AC_ARG_WITH([pkcs11],
987	    [AS_HELP_STRING([--with-pkcs11[=PATH]],
988			    [Build with PKCS11 support [no|path] (PATH is for the PKCS11 provider)])],
989	    [:], [with_pkcs11="undefined"])
990
991AS_CASE([$with_pkcs11],
992	[yes|auto],[AC_MSG_ERROR([--with-pkcs11 needs explicit path to the PKCS11 library])],
993	[no|undefined],[with_pkcs11="undefined"])
994AC_DEFINE_UNQUOTED([PK11_LIB_LOCATION], ["$with_pkcs11"], [define the default PKCS11 library path])
995
996# for PKCS11 benchmarks
997
998have_clock_gt=no
999AC_CHECK_FUNC(clock_gettime,have_clock_gt=yes,)
1000if test "no" = "$have_clock_gt"; then
1001	AC_CHECK_LIB(rt,clock_gettime,have_clock_gt=rt,)
1002fi
1003
1004if test "no" != "$have_clock_gt"; then
1005	AC_DEFINE(HAVE_CLOCK_GETTIME, 1, [Define if clock_gettime is available.])
1006fi
1007
1008if test "rt" = "$have_clock_gt"; then
1009	LIBS="-lrt $LIBS"
1010fi
1011
1012AC_MSG_CHECKING(for GSSAPI library)
1013
1014# [pairwise: --with-gssapi=yes, --with-gssapi=auto, --without-gssapi]
1015AC_ARG_WITH(gssapi,
1016	    AS_HELP_STRING([--with-gssapi=[PATH|[/path/]krb5-config]],
1017			   [Specify path for system-supplied GSSAPI
1018				[default=auto]]),
1019	    use_gssapi="$withval", use_gssapi="auto")
1020
1021# first try using krb5-config, if that does not work then fall back to "yes" method.
1022
1023case "$use_gssapi" in
1024*/krb5-config|krb5-config)
1025    AC_MSG_RESULT(trying $use_gssapi)
1026    if test krb5-config = "$use_gssapi"
1027    then
1028	AC_PATH_PROG(KRB5_CONFIG, $use_gssapi)
1029    else
1030	KRB5_CONFIG="$use_gssapi"
1031    fi
1032    gssapi_cflags=`$KRB5_CONFIG --cflags gssapi`
1033    gssapi_libs=`$KRB5_CONFIG --libs gssapi`
1034    krb5_cflags=`$KRB5_CONFIG --cflags krb5`
1035    krb5_libs=`$KRB5_CONFIG --libs krb5`
1036    saved_cppflags="$CPPFLAGS"
1037    CPPFLAGS="$gssapi_cflags $krb5_cflags $CPPFLAGS"
1038    AC_CHECK_HEADERS(gssapi.h gssapi/gssapi.h,
1039	[ISC_PLATFORM_GSSAPIHEADER="#define ISC_PLATFORM_GSSAPIHEADER <$ac_header>"])
1040    if test "" = "$ISC_PLATFORM_GSSAPIHEADER"; then
1041	AC_MSG_RESULT([krb5-config: gssapi.h not found])
1042	CPPFLAGS="$saved_cppflags"
1043	use_gssapi="yes"
1044    else
1045	AC_CHECK_HEADERS(krb5/krb5.h krb5.h,
1046	    [ISC_PLATFORM_KRB5HEADER="#define ISC_PLATFORM_KRB5HEADER <$ac_header>"])
1047	if test "" = "$ISC_PLATFORM_KRB5HEADER"; then
1048	    AC_MSG_RESULT([krb5-config: krb5.h not found])
1049	    CPPFLAGS="$saved_cppflags"
1050	    use_gssapi="yes"
1051	else
1052	    CPPFLAGS="$saved_cppflags"
1053	    saved_libs="$LIBS"
1054	    LIBS="$gssapi_libs $krb5_libs $LIBS"
1055	    AC_MSG_CHECKING([krb5-config linking as $LIBS])
1056	    AC_TRY_LINK( , [gss_acquire_cred();krb5_init_context()],
1057		gssapi_linked=yes, gssapi_linked=no)
1058	    case $gssapi_linked in
1059		yes) AC_MSG_RESULT([krb5-config: linked]);;
1060		no)  AC_MSG_RESULT([krb5-config: could not determine proper GSSAPI linkage])
1061		    use_gssapi="yes"
1062		    ;;
1063	    esac
1064	    LIBS=$saved_libs
1065	fi
1066    fi
1067    if test "yes" = "$use_gssapi"; then
1068	AC_MSG_CHECKING([for GSSAPI library, non krb5-config method])
1069    fi
1070    ;;
1071esac
1072
1073case "$host" in
1074*darwin*)
1075	if test "yes" = "$use_gssapi" -o "auto" = "$use_gssapi"
1076	then
1077		use_gssapi=framework
1078	fi
1079	;;
1080esac
1081
1082# gssapi is just the framework, we really require kerberos v5, so
1083# look for those headers (the gssapi headers must be there, too)
1084# The problem with this implementation is that it doesn't allow
1085# for the specification of gssapi and krb5 headers in different locations,
1086# which probably ought to be fixed although fixing might raise the issue of
1087# trying to build with incompatible versions of gssapi and krb5.
1088if test "yes" = "$use_gssapi" -o "auto" = "$use_gssapi"
1089then
1090	# first, deal with the obvious
1091	if test \( -f /usr/include/kerberosv5/krb5.h -o \
1092		   -f /usr/include/krb5/krb5.h -o \
1093		   -f /usr/include/krb5.h \)   -a \
1094		\( -f /usr/include/gssapi.h -o \
1095		   -f /usr/include/gssapi/gssapi.h \)
1096	then
1097		use_gssapi=/usr
1098	else
1099	    krb5dirs="/usr/local /usr/local/krb5 /usr/local/kerberosv5 /usr/local/kerberos /usr/pkg /usr/krb5 /usr/kerberosv5 /usr/kerberos /usr"
1100	    for d in $krb5dirs
1101	    do
1102		if test -f $d/include/gssapi/gssapi_krb5.h -o \
1103			-f $d/include/krb5.h
1104		then
1105			if test -f $d/include/gssapi/gssapi.h -o \
1106				-f $d/include/gssapi.h
1107			then
1108				use_gssapi=$d
1109				break
1110			fi
1111		fi
1112	    done
1113	    if test "auto" = "$use_gssapi"
1114	    then
1115		use_gssapi="no"
1116	    fi
1117	fi
1118fi
1119
1120case "$use_gssapi" in
1121	no)
1122		AC_MSG_RESULT(disabled)
1123		USE_GSSAPI=''
1124		;;
1125	yes)
1126		AC_MSG_ERROR([--with-gssapi must specify a path])
1127		;;
1128	*/krb5-config|krb5-config)
1129		USE_GSSAPI='-DGSSAPI'
1130		DST_GSSAPI_INC="$gssapi_cflags $krb5_cflags"
1131		DNS_GSSAPI_LIBS="$gssapi_libs $krb5_libs"
1132		;;
1133	framework)
1134		USE_GSSAPI='-DGSSAPI'
1135		ISC_PLATFORM_GSSAPIHEADER="#define ISC_PLATFORM_GSSAPIHEADER <Kerberos/Kerberos.h>"
1136		ISC_PLATFORM_KRB5HEADER="#define ISC_PLATFORM_KRB5HEADER <Kerberos/Kerberos.h>"
1137		DNS_GSSAPI_LIBS="-framework Kerberos"
1138		AC_MSG_RESULT(framework)
1139		;;
1140
1141	*)
1142		AC_MSG_RESULT(looking in $use_gssapi/lib)
1143		USE_GSSAPI='-DGSSAPI'
1144		saved_cppflags="$CPPFLAGS"
1145		CPPFLAGS="-I$use_gssapi/include $CPPFLAGS"
1146		AC_CHECK_HEADERS(gssapi.h gssapi/gssapi.h,
1147		    [ISC_PLATFORM_GSSAPIHEADER="#define ISC_PLATFORM_GSSAPIHEADER <$ac_header>"
1148		     gssapi_hack="#include <$ac_header>"])
1149
1150		if test "" = "$ISC_PLATFORM_GSSAPIHEADER"; then
1151		    AC_MSG_ERROR([gssapi.h not found])
1152		fi
1153
1154		AC_CHECK_HEADERS(gssapi_krb5.h gssapi/gssapi_krb5.h,
1155		    [ISC_PLATFORM_GSSAPI_KRB5_HEADER="#define ISC_PLATFORM_GSSAPI_KRB5_HEADER <$ac_header>"
1156		     gssapi_krb5_hack="#include <$ac_header>"])
1157
1158		AC_CHECK_HEADERS(krb5.h krb5/krb5.h kerberosv5/krb5.h,
1159		    [ISC_PLATFORM_KRB5HEADER="#define ISC_PLATFORM_KRB5HEADER <$ac_header>"
1160		    krb5_hack="#include <$ac_header>"])
1161
1162		if test "" = "$ISC_PLATFORM_KRB5HEADER"; then
1163		    AC_MSG_ERROR([krb5.h not found])
1164		fi
1165
1166		#
1167		# XXXDCL This probably doesn't work right on all systems.
1168		# It will need to be worked on as problems become evident.
1169		#
1170		# Essentially the problems here relate to two different
1171		# areas.  The first area is building with either KTH
1172		# or MIT Kerberos, particularly when both are present on
1173		# the machine.  The other is static versus dynamic linking.
1174		#
1175		# On the KTH vs MIT issue, Both have libkrb5 that can mess
1176		# up the works if one implementation ends up trying to
1177		# use the other's krb.  This is unfortunately a situation
1178		# that very easily arises.
1179		#
1180		# Dynamic linking when the dependency information is built
1181		# into MIT's libgssapi_krb5 or KTH's libgssapi magically makes
1182		# all such problems go away, but when that setup is not
1183		# present, because either the dynamic libraries lack
1184		# dependencies or static linking is being done, then the
1185		# problems start to show up.
1186		saved_libs="$LIBS"
1187		for TRY_LIBS in \
1188		    "-lgssapi_krb5" \
1189		    "-lgssapi_krb5 -lkrb5 -lk5crypto -lcom_err" \
1190		    "-lgssapi_krb5 -lkrb5 -lk5crypto -lcom_err -lresolv" \
1191		    "-lgssapi" \
1192		    "-lgssapi -lkrb5 -ldes -lcrypt -lasn1 -lroken -lcom_err" \
1193		    "-lgssapi -lkrb5 -lcrypt -lasn1 -lroken -lcom_err" \
1194		    "-lgssapi -lkrb5 -lgssapi_krb5 -lcrypt -lasn1 -lroken -lcom_err" \
1195		    "-lgssapi -lkrb5 -lhx509 -lcrypt -lasn1 -lroken -lcom_err" \
1196		    "-lgss -lkrb5"
1197		do
1198		    # Note that this does not include $saved_libs, because
1199		    # on FreeBSD machines this configure script has added
1200		    # -L/usr/local/lib to LIBS, which can make the
1201		    # -lgssapi_krb5 test succeed with shared libraries even
1202		    # when you are trying to build with KTH in /usr/lib.
1203		    if test "/usr" = "$use_gssapi"
1204		    then
1205			    LIBS="$TRY_LIBS $ISC_OPENSSL_LIBS"
1206		    else
1207			    LIBS="-L$use_gssapi/lib $TRY_LIBS $ISC_OPENSSL_LIBS"
1208		    fi
1209		    AC_MSG_CHECKING(linking as $TRY_LIBS)
1210		    AC_TRY_LINK([
1211#include <sys/types.h>
1212$gssapi_hack
1213$gssapi_krb5_hack
1214$krb5_hack
1215				] , [gss_acquire_cred(NULL, NULL, 0, NULL, 0, NULL, NULL, NULL);krb5_init_context(NULL);
1216#if defined(HAVE_GSSAPI_KRB5_H) || defined(HAVE_GSSAPI_GSSAPI_KRB5_H)
1217gsskrb5_register_acceptor_identity(NULL);
1218#endif],
1219				gssapi_linked=yes, gssapi_linked=no)
1220		    case $gssapi_linked in
1221		    yes) AC_MSG_RESULT(yes); break ;;
1222		    no)  AC_MSG_RESULT(no) ;;
1223		    esac
1224		done
1225
1226		CPPFLAGS="$saved_cppflags"
1227
1228		case $gssapi_linked in
1229		no) AC_MSG_ERROR(could not determine proper GSSAPI linkage) ;;
1230		esac
1231
1232		#
1233		# XXXDCL Major kludge.  Tries to cope with KTH in /usr/lib
1234		# but MIT in /usr/local/lib and trying to build with KTH.
1235		# /usr/local/lib can end up earlier on the link lines.
1236		# Like most kludges, this one is not only inelegant it
1237		# is also likely to be the wrong thing to do at least as
1238		# many times as it is the right thing.  Something better
1239		# needs to be done.
1240		#
1241		if test "/usr" = "$use_gssapi" -a \
1242			-f /usr/local/lib/libkrb5.a; then
1243		    FIX_KTH_VS_MIT=yes
1244		fi
1245
1246		case "$FIX_KTH_VS_MIT" in
1247		yes)
1248		    case "$enable_static_linking" in
1249		    yes) gssapi_lib_suffix=".a"  ;;
1250		    *)   gssapi_lib_suffix=".so" ;;
1251		    esac
1252
1253		    for lib in $LIBS; do
1254			case $lib in
1255			-L*)
1256			    ;;
1257			-l*)
1258			    new_lib=`echo $lib |
1259				     sed -e s%^-l%$use_gssapi/lib/lib% \
1260					 -e s%$%$gssapi_lib_suffix%`
1261			    NEW_LIBS="$NEW_LIBS $new_lib"
1262			    ;;
1263			*)
1264			   AC_MSG_ERROR([KTH vs MIT Kerberos confusion!])
1265			    ;;
1266			esac
1267		    done
1268		    LIBS="$NEW_LIBS"
1269		    ;;
1270		esac
1271
1272		DST_GSSAPI_INC="-I$use_gssapi/include"
1273		DNS_GSSAPI_LIBS="$LIBS"
1274
1275		AC_MSG_RESULT(using GSSAPI from $use_gssapi/lib and $use_gssapi/include)
1276		LIBS="$saved_libs"
1277		;;
1278esac
1279
1280AC_SUBST(ISC_PLATFORM_GSSAPIHEADER)
1281AC_SUBST(ISC_PLATFORM_GSSAPI_KRB5_HEADER)
1282AC_SUBST(ISC_PLATFORM_KRB5HEADER)
1283
1284AC_SUBST(USE_GSSAPI)
1285AC_SUBST(DST_GSSAPI_INC)
1286AC_SUBST(DNS_GSSAPI_LIBS)
1287DNS_CRYPTO_LIBS="$DNS_GSSAPI_LIBS"
1288
1289#
1290# Applications linking with libdns also need to link with these libraries.
1291#
1292
1293AC_SUBST(DNS_CRYPTO_LIBS)
1294
1295#
1296# was --with-lmdb specified?
1297#
1298AC_MSG_CHECKING(for lmdb library)
1299
1300# [pairwise: --with-lmdb=auto, --with-lmdb=yes, --without-lmdb]
1301AC_ARG_WITH(lmdb,
1302	    AS_HELP_STRING([--with-lmdb[=PATH]],
1303			   [build with LMDB library [yes|no|path]]),
1304    use_lmdb="$withval", use_lmdb="auto")
1305
1306have_lmdb=""
1307case "$use_lmdb" in
1308	no)
1309		LMDB_LIBS=""
1310		;;
1311	auto|yes)
1312		for d in /usr /usr/local /opt/local
1313		do
1314			if test -f "${d}/include/lmdb.h"
1315			then
1316				if test ${d} != /usr
1317				then
1318					LMDB_CFLAGS="-I ${d}/include"
1319					LMDB_LIBS="-L${d}/lib"
1320				fi
1321				have_lmdb="yes"
1322			fi
1323		done
1324		;;
1325	*)
1326		if test -f "${use_lmdb}/include/lmdb.h"
1327		then
1328			LMDB_CFLAGS="-I${use_lmdb}/include"
1329			LMDB_LIBS="-L${use_lmdb}/lib"
1330			have_lmdb="yes"
1331		else
1332			AC_MSG_ERROR([$use_lmdb/include/lmdb.h not found.])
1333		fi
1334		;;
1335esac
1336
1337if test "X${have_lmdb}" != "X"
1338then
1339	AC_MSG_RESULT(yes)
1340	AX_SAVE_FLAGS([lmdb])
1341	CFLAGS="$CFLAGS $LMDB_CFLAGS"
1342	LIBS="$LIBS $LMDB_LIBS"
1343	AC_SEARCH_LIBS([mdb_env_create], [lmdb], [],
1344		       [AC_MSG_ERROR([found lmdb include but not library.])
1345			have_lmdb=""])
1346	LMDB_LIBS="$LMDB_LIBS $ac_cv_search_mdb_env_create"
1347	AX_RESTORE_FLAGS([lmdb])
1348elif test "X$use_lmdb" = Xyes
1349then
1350	AC_MSG_ERROR([include/lmdb.h not found.])
1351else
1352	AC_MSG_RESULT(no)
1353fi
1354AC_SUBST([LMDB_CFLAGS])
1355AC_SUBST([LMDB_LIBS])
1356
1357NZD_TOOLS=""
1358NZDSRCS=
1359NZDTARGETS=
1360if test "X${have_lmdb}" != "X"
1361then
1362	AC_DEFINE(HAVE_LMDB, 1, [Define if lmdb was found])
1363	NZD_TOOLS="nzd"
1364	NZDSRCS='${NZDSRCS}'
1365	NZDTARGETS='${NZDTARGETS}'
1366	NZD_MANS='${nzd_man8_MANS}'
1367fi
1368AC_SUBST(NZD_TOOLS)
1369AC_SUBST(NZDSRCS)
1370AC_SUBST(NZDTARGETS)
1371AC_SUBST(NZD_MANS)
1372
1373#
1374# was --with-libxml2 specified?
1375#
1376# [pairwise: --with-libxml2=auto, --with-libxml2=yes, --without-libxml2]
1377AC_ARG_WITH([libxml2],
1378	    [AS_HELP_STRING([--with-libxml2],
1379			    [build with libxml2 library [yes|no|auto] (default is auto)])],
1380	    [], [with_libxml2="auto"])
1381
1382AS_CASE([$with_libxml2],
1383	[no],[],
1384	[auto],[PKG_CHECK_MODULES([LIBXML2], [libxml-2.0 >= 2.6.0],
1385				  [AC_DEFINE([HAVE_LIBXML2], [1], [Use libxml2 library])],
1386				  [:])],
1387	[yes],[PKG_CHECK_MODULES([LIBXML2], [libxml-2.0 >= 2.6.0],
1388				 [AC_DEFINE([HAVE_LIBXML2], [1], [Use libxml2 library])])],
1389	[AC_MSG_ERROR([Specifying libxml2 installation path is not supported, adjust PKG_CONFIG_PATH instead])])
1390
1391#
1392# DEPRECATED
1393#
1394# [pairwise: skip]
1395AC_ARG_WITH([libjson],
1396	    [AS_HELP_STRING([--with-libjson],
1397			    [deprecated, use --with-json-c])],
1398	    [AC_MSG_WARN([--with-libjson is DEPRECATED and will be removed in a future release, use --with-json-c instead])],
1399	    [with_libjson="detect"])
1400
1401#
1402# was --with-json-c specified?
1403#
1404# [pairwise: --with-json-c=detect, --with-json-c=yes, --without-json-c]
1405AC_ARG_WITH([json-c],
1406	    [AS_HELP_STRING([--with-json-c],
1407			    [build with json-c library [yes|no|detect] (default is detect)])],
1408	    [], [with_json_c="$with_libjson"])
1409
1410AS_CASE([$with_json_c],
1411	[no],[],
1412	[detect],[PKG_CHECK_MODULES([JSON_C], [json-c >= 0.11],
1413				    [AC_DEFINE([HAVE_JSON_C], [1], [Use json-c library])],
1414				    [:])],
1415	[yes],[PKG_CHECK_MODULES([JSON_C], [json-c >= 0.11],
1416				 [AC_DEFINE([HAVE_JSON_C], [1], [Use json-c library])])],
1417	[AC_MSG_ERROR([Specifying json-c installation path is not supported, adjust PKG_CONFIG_PATH instead])]
1418       )
1419
1420AC_SUBST([JSON_C_CFLAGS])
1421AC_SUBST([JSON_C_LIBS])
1422
1423# [pairwise: --with-zlib=auto, --with-zlib=yes, --without-zlib]
1424AC_ARG_WITH([zlib],
1425           [AS_HELP_STRING([--with-zlib],
1426                           [build with zlib for HTTP compression
1427                            [default=yes]])],
1428	   [], with_zlib="auto")
1429
1430AS_CASE([$with_zlib],
1431       [no],[],
1432       [auto],[PKG_CHECK_MODULES([ZLIB], [zlib],
1433                                 [AC_DEFINE([HAVE_ZLIB], [1], [Use zlib library])],
1434                                 [:])],
1435       [yes],[PKG_CHECK_MODULES([ZLIB], [zlib],
1436                                [AC_DEFINE([HAVE_ZLIB], [1], [Use zlib library])])],
1437       [AC_MSG_ERROR([Specifying zlib installation path is not supported, adjust PKG_CONFIG_PATH instead])])
1438AC_SUBST([ZLIB_CFLAGS])
1439AC_SUBST([ZLIB_LIBS])
1440
1441#
1442# In solaris 10, SMF can manage named service
1443#
1444AC_CHECK_LIB(scf, smf_enable_instance)
1445
1446#
1447# Additional compiler settings.
1448#
1449MKDEPCC="$CC"
1450
1451MKDEPCFLAGS="-M"
1452AS_CASE([$host],
1453	[*-solaris*],[
1454	    AS_IF([test "$GCC" != "yes"],
1455		  [MKDEPCFLAGS="-xM"])])
1456
1457AS_IF([test "$GCC" = "yes"],
1458      [STD_CWARNINGS="$STD_CWARNINGS -W -Wall -Wmissing-prototypes -Wcast-qual -Wwrite-strings -Wformat -Wpointer-arith -Wno-missing-field-initializers"]
1459      )
1460
1461AX_CHECK_COMPILE_FLAG([-fno-strict-aliasing],
1462		      [STD_CWARNINGS="$STD_CWARNINGS -fno-strict-aliasing"])
1463AX_CHECK_COMPILE_FLAG([-Werror -fno-delete-null-pointer-checks],
1464		      [STC_CWARNINGS="$STD_CWARNINGS -fno-delete-null-pointer-checks"])
1465AS_IF([test "$enable_warn_shadow" = "yes"],
1466      [AX_CHECK_COMPILE_FLAG([-Wshadow],
1467			     [STD_CWARNINGS="$STD_CWARNINGS -Wshadow"])])
1468AS_IF([test "$enable_warn_error" = "yes"],
1469      [AX_CHECK_COMPILE_FLAG([-Werror],
1470			     [STD_CWARNINGS="$STD_CWARNINGS -Werror"])])
1471
1472AC_SUBST([MKDEPCC])
1473AC_SUBST([MKDEPCFLAGS])
1474AC_SUBST([MKDEPPROG])
1475
1476#
1477# -lxnet buys us one big porting headache...  standards, gotta love 'em.
1478#
1479# AC_CHECK_LIB(xnet, socket, ,
1480#    AC_CHECK_LIB(socket, socket)
1481# )
1482#
1483# Use this for now, instead:
1484#
1485case "$host" in
1486	*-linux*)
1487		;;
1488	*)
1489		AC_CHECK_LIB(socket, socket)
1490		AC_CHECK_LIB(nsl, inet_addr)
1491		;;
1492esac
1493
1494#
1495# Work around Solaris's select() limitations.
1496#
1497case "$host" in
1498	*-solaris2.[[89]]|*-solaris2.1?)
1499	AC_DEFINE(FD_SETSIZE, 65536,
1500		  [Solaris hack to get select_large_fdset.])
1501	;;
1502esac
1503
1504#
1505# Purify support
1506#
1507AC_MSG_CHECKING(whether to use purify)
1508
1509# Purify is not included in pairwise testing as that tool is not present
1510# in the relevant Docker image.
1511#
1512# [pairwise: skip]
1513AC_ARG_WITH(purify,
1514	    AS_HELP_STRING([--with-purify[=PATH]],[use Rational purify]),
1515	    use_purify="$withval", use_purify="no")
1516
1517case "$use_purify" in
1518	no)
1519		;;
1520	yes)
1521		AC_PATH_PROG(purify_path, purify, purify)
1522		;;
1523	*)
1524		purify_path="$use_purify"
1525		;;
1526esac
1527
1528case "$use_purify" in
1529	no)
1530		AC_MSG_RESULT(no)
1531		PURIFY=""
1532		;;
1533	*)
1534		if test -f "$purify_path" || test purify = "$purify_path"; then
1535			AC_MSG_RESULT($purify_path)
1536			PURIFYFLAGS="`echo $PURIFYOPTIONS`"
1537			PURIFY="$purify_path $PURIFYFLAGS"
1538		else
1539			AC_MSG_ERROR([$purify_path not found.
1540
1541Please choose the proper path with the following command:
1542
1543    configure --with-purify=PATH
1544])
1545		fi
1546		;;
1547esac
1548
1549AC_SUBST(PURIFY)
1550
1551#
1552# Google/Great Performance Tools CPU Profiler
1553#
1554AC_MSG_CHECKING(whether to use gperftools profiler)
1555
1556# Google/Great Performance Tools CPU Profiler is not included in
1557# pairwise testing as that tool is not present in the relevant Docker
1558# image.
1559#
1560# [pairwise: skip]
1561AC_ARG_WITH(gperftools-profiler,
1562	    AS_HELP_STRING([--with-gperftools-profiler],
1563			   [use gperftools CPU profiler]),
1564	    use_profiler="$withval", use_profiler="no")
1565
1566case $use_profiler in
1567	yes)
1568		AC_MSG_RESULT(yes)
1569		AC_DEFINE([HAVE_GPERFTOOLS_PROFILER], 1,
1570		[Define to use gperftools CPU profiler.])
1571		LIBS="$LIBS -lprofiler"
1572		;;
1573	*)
1574		AC_MSG_RESULT(no)
1575		;;
1576esac
1577
1578#
1579# enable/disable dumping stack backtrace.  Also check if the system supports
1580# glibc-compatible backtrace() function.
1581#
1582# [pairwise: --enable-backtrace, --disable-backtrace]
1583AC_ARG_ENABLE([backtrace],
1584	      [AS_HELP_STRING([--enable-backtrace],
1585			      [log stack backtrace on abort [default=yes]])],
1586	      [], [enable_backtrace="yes"])
1587
1588AS_IF([test "$enable_backtrace" = "yes"],
1589      [AC_DEFINE([USE_BACKTRACE], [1], [define if we can use backtrace])
1590       AC_CHECK_LIB(execinfo,backtrace,EXILIBS=-lexecinfo,EXILIBS=)
1591       LIBS="$LIBS $EXILIBS"
1592       AC_LINK_IFELSE(
1593	 [AC_LANG_PROGRAM(
1594	    [[#include <execinfo.h>]],
1595	    [[return (backtrace((void **)0, 0));]]
1596	  )],
1597	 [AC_DEFINE([HAVE_LIBCTRACE], [1], [define if system have backtrace function])],
1598	 [AC_LINK_IFELSE(
1599	    [AC_LANG_PROGRAM(
1600	       [[#include <stddef.h>]],
1601	       [[return _Unwind_Backtrace(NULL, NULL);]]
1602	     )],
1603	    [AC_DEFINE([HAVE_UNWIND_BACKTRACE], [1], [define if the compiler supports _Unwind_Backtrace()])]
1604	  )]
1605       )])
1606
1607# [pairwise: --enable-symtable, --disable-symtable]
1608AC_ARG_ENABLE(symtable,
1609	      AS_HELP_STRING([--enable-symtable],
1610			     [use internal symbol table for backtrace
1611			      [all|minimal(default)|none]]),
1612		want_symtable="$enableval",  want_symtable="minimal")
1613case $want_symtable in
1614yes|all|minimal)     # "yes" is a hidden value equivalent to "minimal"
1615	if test "" = "$PERL"
1616	then
1617		AC_MSG_ERROR([Internal symbol table requires perl but no perl is found.
1618Install perl or explicitly disable the feature by --disable-symtable.])
1619	fi
1620	if test "yes" = "$use_libtool"; then
1621		AC_MSG_WARN([Internal symbol table does not work with libtool.  Disabling symbol table.])
1622	else
1623		# we generate the internal symbol table only for those systems
1624		# known to work to avoid unexpected build failure.  Also, warn
1625		# about unsupported systems when the feature is enabled
1626		#  manually.
1627		case $host_os in
1628		freebsd*|netbsd*|openbsd*|linux*|solaris*|darwin*)
1629			MKSYMTBL_PROGRAM="$PERL"
1630			if test "all" = "$want_symtable"; then
1631				ALWAYS_MAKE_SYMTABLE="yes"
1632			fi
1633			;;
1634		*)
1635			if test "yes" = "$want_symtable" -o "all" = "$want_symtable"
1636			then
1637				AC_MSG_WARN([this system is not known to generate internal symbol table safely; disabling it])
1638			fi
1639		esac
1640	fi
1641	;;
1642*)
1643	;;
1644esac
1645AC_SUBST(MKSYMTBL_PROGRAM)
1646AC_SUBST(ALWAYS_MAKE_SYMTABLE)
1647
1648#
1649# File name extension for static archive files, for those few places
1650# where they are treated differently from dynamic ones.
1651#
1652SA=a
1653
1654AC_SUBST(O)
1655AC_SUBST(A)
1656AC_SUBST(SA)
1657AC_SUBST(LIBTOOL_MKDEP_SED)
1658AC_SUBST(LIBTOOL_MODE_COMPILE)
1659AC_SUBST(LIBTOOL_MODE_INSTALL)
1660AC_SUBST(LIBTOOL_MODE_LINK)
1661AC_SUBST(LIBTOOL_MODE_UNINSTALL)
1662
1663BIND9_CO_RULE=".c.$O:"
1664AC_SUBST(BIND9_CO_RULE)
1665
1666#
1667# Here begins a very long section to determine the system's networking
1668# capabilities.  The order of the tests is significant.
1669#
1670
1671#
1672# We do the IPv6 compilation checking after libtool so that we can put
1673# the right suffix on the files.
1674#
1675AC_MSG_CHECKING([for IPv6 structures])
1676AC_COMPILE_IFELSE(
1677  [AC_LANG_PROGRAM(
1678     [[
1679       #include <sys/types.h>
1680       #include <sys/socket.h>
1681       #include <netinet/in.h>
1682     ]],
1683     [[
1684       struct sockaddr_in6 sin6;
1685       struct in6_addr in6;
1686       struct in6_pktinfo in6_pi;
1687       struct sockaddr_storage storage;
1688       in6 = in6addr_any;
1689       in6 = in6addr_loopback;
1690       sin6.sin6_scope_id = 0;
1691       return (0);
1692     ]])],
1693  [AC_MSG_RESULT([yes])],
1694  [AC_MSG_FAILURE([IPv6 support is mandatory])])
1695
1696#
1697# Allow forcibly disabling TCP Fast Open support as autodetection might yield
1698# confusing results on some systems (e.g. FreeBSD; see set_tcp_fastopen()
1699# comment in lib/isc/unix/socket.c).
1700#
1701# [pairwise: --enable-tcp-fastopen, --disable-tcp-fastopen]
1702AC_ARG_ENABLE([tcp_fastopen],
1703	      [AS_HELP_STRING([--disable-tcp-fastopen],
1704			      [disable TCP Fast Open support [default=yes]])],
1705	     [], [enable_tcp_fastopen="yes"])
1706
1707AS_IF([test "$enable_tcp_fastopen" = "yes"],
1708      [AC_DEFINE([ENABLE_TCP_FASTOPEN], [1], [define if you want TCP_FASTOPEN enabled if available])])
1709
1710#
1711# Check for some other useful functions that are not ever-present.
1712#
1713AC_CHECK_FUNCS([strlcpy strlcat])
1714
1715AC_SUBST(READLINE_LIB)
1716
1717# [pairwise: --with-readline=auto, --with-readline=yes, --without-readline]
1718AC_ARG_WITH(readline,
1719	    AS_HELP_STRING([--with-readline[=LIBSPEC]],
1720			   [specify readline library [default auto]]),
1721	    use_readline="$withval", use_readline="auto")
1722case "$use_readline" in
1723no)	;;
1724*)
1725	saved_LIBS="$LIBS"
1726	case "$use_readline" in
1727	yes|auto) try_readline="-ledit"; or_readline="-lreadline" ;;
1728	*) try_readline="$use_readline"
1729	esac
1730	for readline in "$try_readline" $or_readline
1731	do
1732		LIBS="$readline"
1733		AC_MSG_NOTICE(checking for readline with $readline)
1734		AC_CHECK_FUNCS(readline)
1735		if test "yes" = "$ac_cv_func_readline"
1736		then
1737			READLINE_LIB="$readline"
1738			break
1739		fi
1740		for lib in -lterminfo -ltermcap -lncurses -lcurses
1741		do
1742			AC_MSG_NOTICE(checking for readline with $readline $lib)
1743			unset ac_cv_func_readline
1744			LIBS="$readline $lib"
1745			AC_CHECK_FUNCS(readline)
1746			if test "yes" = "$ac_cv_func_readline"
1747			then
1748				READLINE_LIB="$readline $lib"
1749				break
1750			fi
1751		done
1752		if test "yes" = "$ac_cv_func_readline"
1753		then
1754			break
1755		fi
1756	done
1757	if test "auto" != "$use_readline" &&
1758	   test "X$READLINE_LIB" = "X"
1759	then
1760		AC_MSG_ERROR([The readline library was not found.])
1761	fi
1762	LIBS="$saved_LIBS"
1763	;;
1764esac
1765if test "yes" = "$ac_cv_func_readline"
1766then
1767	case "$READLINE_LIB" in
1768	*edit*)
1769		AC_CHECK_HEADERS(editline/readline.h)
1770		AC_CHECK_HEADERS(edit/readline/readline.h)
1771		AC_CHECK_HEADERS(edit/readline/history.h)
1772		;;
1773	esac
1774	AC_CHECK_HEADERS(readline/readline.h)
1775	AC_CHECK_HEADERS(readline/history.h)
1776fi
1777
1778AC_SUBST(DST_EXTRA_OBJS)
1779AC_SUBST(DST_EXTRA_SRCS)
1780
1781#
1782# Security Stuff
1783#
1784# Note it is very recommended to *not* disable chroot(),
1785# this is only because chroot() was made obsolete by Posix.
1786#
1787# [pairwise: --enable-chroot, --disable-chroot]
1788AC_ARG_ENABLE(chroot, AS_HELP_STRING([--disable-chroot], [disable chroot]))
1789case "$enable_chroot" in
1790	yes|'')
1791		AC_CHECK_FUNCS(chroot)
1792		;;
1793	no)
1794		;;
1795esac
1796
1797LIBCAP_LIBS=""
1798AC_MSG_CHECKING([whether to enable Linux capabilities])
1799
1800# [pairwise: --enable-linux-caps, --disable-linux-caps]
1801AC_ARG_ENABLE([linux-caps],
1802	      [AS_HELP_STRING([--disable-linux-caps],
1803			      [disable Linux capabilities])],
1804	      [],
1805	      [AS_CASE([$host],
1806		       [*-linux*],[enable_linux_caps=yes],
1807		       [enable_linux_caps=no])])
1808
1809AS_IF([test "$enable_linux_caps" = "yes"],
1810      [AC_MSG_RESULT([yes])
1811       AC_CHECK_HEADERS([sys/capability.h],
1812			[],
1813			[AC_MSG_ERROR(m4_normalize([sys/capability.h header is required for Linux capabilities support.
1814						    Either install libcap or use --disable-linux-caps.]))])
1815       AX_SAVE_FLAGS([cap])
1816       AC_SEARCH_LIBS([cap_set_proc], [cap],
1817		      [LIBCAP_LIBS="$ac_cv_search_cap_set_proc"],
1818		      [AC_MSG_ERROR(m4_normalize([libcap is required for Linux capabilities support.
1819						  Either install libcap or use --disable-linux-caps.]))])
1820       AX_RESTORE_FLAGS([cap])],
1821      [AC_MSG_RESULT([no])])
1822AC_SUBST([LIBCAP_LIBS])
1823
1824AC_CHECK_HEADERS(sys/un.h,
1825ISC_PLATFORM_HAVESYSUNH="#define ISC_PLATFORM_HAVESYSUNH 1"
1826,
1827ISC_PLATFORM_HAVESYSUNH="#undef ISC_PLATFORM_HAVESYSUNH"
1828)
1829AC_SUBST(ISC_PLATFORM_HAVESYSUNH)
1830
1831case "$host" in
1832*-solaris*)
1833	AC_DEFINE(NEED_SECURE_DIRECTORY, 1,
1834		  [Define if connect does not honour the permission on the UNIX domain socket.])
1835	;;
1836esac
1837
1838#
1839# Time Zone Stuff
1840#
1841AC_CHECK_FUNCS([tzset])
1842
1843AC_MSG_CHECKING(for optarg declaration)
1844AC_TRY_COMPILE([
1845#include <unistd.h>
1846],
1847[optarg = 0;],
1848[AC_MSG_RESULT(yes)],
1849[AC_MSG_RESULT(no)
1850GEN_NEED_OPTARG="-DNEED_OPTARG=1"
1851AC_DEFINE(NEED_OPTARG, 1, [Defined if extern char *optarg is not declared.])])
1852
1853#
1854# Check for nanoseconds in file stats
1855#
1856AC_MSG_CHECKING([for st_mtim.tv_nsec])
1857AC_COMPILE_IFELSE(
1858  [AC_LANG_PROGRAM(
1859     [[#include <sys/fcntl.h>]],
1860     [[struct stat s;
1861       return(s.st_mtim.tv_nsec);
1862      ]])],
1863   [AC_DEFINE([HAVE_STAT_NSEC], [1], [define if struct stat has st_mtim.tv_nsec field])])
1864
1865#
1866# Check for if_nametoindex() for IPv6 scoped addresses support
1867#
1868AC_CHECK_FUNCS([if_nametoindex])
1869
1870ISC_ATOMIC_LIBS=""
1871AC_CHECK_HEADERS(
1872  [stdatomic.h],
1873  [AC_MSG_CHECKING([for memory model aware atomic operations])
1874   AC_COMPILE_IFELSE(
1875     [AC_LANG_PROGRAM(
1876	[[#include <stdatomic.h>]],
1877	[[atomic_int_fast32_t val = 0; atomic_fetch_add_explicit(&val, 1, memory_order_relaxed);]]
1878      )],
1879     [AC_MSG_RESULT([stdatomic.h])
1880      AC_MSG_CHECKING([whether -latomic is needed for 64-bit stdatomic.h functions])
1881      AC_LINK_IFELSE(
1882	[AC_LANG_PROGRAM(
1883	   [[#include <stdatomic.h>]],
1884	   [[atomic_int_fast64_t val = 0; atomic_fetch_add_explicit(&val, 1, memory_order_relaxed);]]
1885	 )],
1886	[AC_MSG_RESULT([no])],
1887	[ISC_ATOMIC_LIBS="-latomic"
1888	 AX_SAVE_FLAGS([atomic])
1889	 LIBS="$LIBS $ISC_ATOMIC_LIBS"
1890	 AC_LINK_IFELSE(
1891	   [AC_LANG_PROGRAM(
1892	      [[#include <stdatomic.h>]],
1893	      [[atomic_int_fast64_t val = 0; atomic_fetch_add_explicit(&val, 1, memory_order_relaxed);]]
1894	    )],
1895	   [AC_MSG_RESULT([yes])],
1896	   [AC_MSG_FAILURE([libatomic needed, but linking with -latomic failed, please fix your toolchain.])])
1897	 AX_RESTORE_FLAGS([atomic])
1898	])
1899     ],
1900     [AC_MSG_FAILURE([stdatomic.h header found, but compilation failed, please fix your toolchain.])]
1901   )],
1902  [AC_MSG_CHECKING([for memory model aware atomic operations])
1903   AC_COMPILE_IFELSE(
1904     [AC_LANG_PROGRAM(
1905	[[#include <inttypes.h>]],
1906	[[int32_t val = 0; __atomic_fetch_add(&val, 1, __ATOMIC_RELAXED);]]
1907      )],
1908     [AC_MSG_RESULT([__atomic builtins])
1909      AC_DEFINE([HAVE___ATOMIC], [1], [define if __atomic builtins are not available])
1910      AC_MSG_CHECKING([whether -latomic is needed for 64-bit __atomic builtins])
1911      AC_LINK_IFELSE(
1912	[AC_LANG_PROGRAM(
1913	   [[#include <inttypes.h>]],
1914	   [[int64_t val = 0; __atomic_fetch_add(&val, 1, __ATOMIC_RELAXED);]]
1915	 )],
1916	[AC_MSG_RESULT([no])],
1917	[ISC_ATOMIC_LIBS="-latomic"
1918	 AX_SAVE_FLAGS([atomic])
1919	 LIBS="$LIBS $ISC_ATOMIC_LIBS"
1920	 AC_LINK_IFELSE(
1921	   [AC_LANG_PROGRAM(
1922	      [[#include <inttypes.h>]],
1923	      [[int64_t val = 0; __atomic_fetch_add(&val, 1, __ATOMIC_RELAXED);]]
1924	    )],
1925	   [AC_MSG_RESULT([yes])],
1926	   [AC_MSG_FAILURE([libatomic needed, but linking with -latomic failed, please fix your toolchain.])])
1927	 AX_RESTORE_FLAGS([atomic])
1928	])
1929     ],
1930     [AC_MSG_RESULT([__sync builtins])
1931     ])
1932  ])
1933LIBS="$LIBS $ISC_ATOMIC_LIBS"
1934
1935AC_CHECK_HEADERS([stdalign.h])
1936
1937AC_CHECK_HEADERS([uchar.h])
1938
1939#
1940# Check for __builtin_unreachable
1941#
1942AC_MSG_CHECKING([compiler support for __builtin_unreachable()])
1943AC_LINK_IFELSE(
1944  [AC_LANG_PROGRAM(
1945     [[]],
1946     [[__builtin_unreachable();]]
1947   )],
1948  [AC_MSG_RESULT([yes])
1949   AC_DEFINE([HAVE_BUILTIN_UNREACHABLE], [1], [define if the compiler supports __builtin_unreachable().])
1950  ],
1951  [AC_MSG_RESULT([no])
1952  ])
1953
1954#
1955# Check for __builtin_expect
1956#
1957AC_MSG_CHECKING([compiler support for __builtin_expect])
1958AC_TRY_LINK(, [
1959	return (__builtin_expect(1, 1) ? 1 : 0);
1960], [
1961	have_builtin_expect=yes
1962	AC_MSG_RESULT(yes)
1963], [
1964	have_builtin_expect=no
1965	AC_MSG_RESULT(no)
1966])
1967if test "yes" = "$have_builtin_expect"; then
1968	AC_DEFINE(HAVE_BUILTIN_EXPECT, 1, [Define to 1 if the compiler supports __builtin_expect.])
1969fi
1970
1971#
1972# Check for __builtin_clz
1973#
1974AC_MSG_CHECKING([compiler support for __builtin_clz])
1975AC_TRY_LINK(, [
1976	return (__builtin_clz(0xff) == 24 ? 1 : 0);
1977], [
1978	have_builtin_clz=yes
1979	AC_MSG_RESULT(yes)
1980], [
1981	have_builtin_clz=no
1982	AC_MSG_RESULT(no)
1983])
1984if test "yes" = "$have_builtin_clz"; then
1985	AC_DEFINE(HAVE_BUILTIN_CLZ, 1, [Define to 1 if the compiler supports __builtin_clz.])
1986fi
1987
1988#
1989# Activate "rrset-order fixed" or not?
1990#
1991# [pairwise: --enable-fixed-rrset, --disable-fixed-rrset]
1992AC_ARG_ENABLE(fixed-rrset,
1993	      AS_HELP_STRING([--enable-fixed-rrset],
1994			     [enable fixed rrset ordering [default=no]]),
1995	      enable_fixed="$enableval", enable_fixed="no")
1996case "$enable_fixed" in
1997	yes)
1998		AC_DEFINE(DNS_RDATASET_FIXED, 1,
1999			  [Define to enable "rrset-order fixed" syntax.])
2000		;;
2001	no)
2002		;;
2003	*)
2004		;;
2005esac
2006
2007#
2008# Activate dnstap?
2009#
2010# [pairwise: --enable-dnstap, --disable-dnstap]
2011AC_ARG_ENABLE(dnstap,
2012	      AS_HELP_STRING([--enable-dnstap],
2013			     [enable dnstap support
2014				(requires fstrm, protobuf-c)]),
2015	      use_dnstap=$enableval, use_dnstap=no)
2016
2017DNSTAP=
2018DNSTAPSRCS=
2019DNSTAPOBJS=
2020DNSTAPTARGETS=
2021if test "x$use_dnstap" != "xno"; then
2022
2023	# [pairwise: skip]
2024	AC_ARG_WITH([protobuf-c],
2025		    AS_HELP_STRING([--with-protobuf-c=path],
2026				   [Path where protobuf-c is installed, for dnstap]), [
2027	    # workaround for protobuf-c includes at old dir
2028	    # before protobuf-c-1.0.0
2029	    if test -f $withval/include/google/protobuf-c/protobuf-c.h
2030	    then
2031		PROTOBUF_C_CFLAGS="-I$withval/include/google"
2032	    else
2033		PROTOBUF_C_CFLAGS="-I$withval/include"
2034	    fi
2035	    PROTOBUF_C_LIBS="-L$withval/lib"
2036	    AC_PATH_PROG([PROTOC_C], [protoc-c], [],
2037			 [$PATH$PATH_SEPARATOR$withval/bin])
2038	], [
2039	    # workaround for protobuf-c includes at old dir
2040	    # before protobuf-c-1.0.0
2041	    if test -f /usr/include/google/protobuf-c/protobuf-c.h
2042	    then
2043		PROTOBUF_C_CFLAGS="-I/usr/include/google"
2044	    else
2045		if test -f /usr/local/include/google/protobuf-c/protobuf-c.h
2046		then
2047		    PROTOBUF_C_CFLAGS="-I/usr/local/include/google"
2048		    PROTOBUF_C_LIBS="-L/usr/local/lib"
2049		elif test -f /opt/local/include/google/protobuf-c/protobuf-c.h
2050		then
2051		    PROTOBUF_C_CFLAGS="-I/opt/local/include/google"
2052		    PROTOBUF_C_LIBS="-L/opt/local/lib"
2053		fi
2054	    fi
2055	    AC_PATH_PROG([PROTOC_C],[protoc-c])
2056	])
2057	if test -z "$PROTOC_C"; then
2058		AC_MSG_ERROR([The protoc-c program was not found.])
2059	fi
2060
2061	# [pairwise: skip]
2062	AC_ARG_WITH([libfstrm], AS_HELP_STRING([--with-libfstrm=path],
2063		    [Path where libfstrm is installed, for dnstap]), [
2064	    FSTRM_CFLAGS="-I$withval/include"
2065	    FSTRM_LIBS="-L$withval/lib"
2066	    AC_PATH_PROG([FSTRM_CAPTURE], [fstrm_capture], [], [$PATH$PATH_SEPARATOR$withval/bin])
2067	],[
2068	    for d in /usr /usr/local /opt/local
2069	    do
2070		if test -f "${d}/include/fstrm.h"
2071		then
2072		    if test ${d} != /usr
2073		    then
2074			FSTRM_CFLAGS="-I${d}/include"
2075			FSTRM_LIBS="-L${d}/lib"
2076		    fi
2077		    have_fstrm="$d"
2078		    break
2079		fi
2080	    done
2081	    if test -z "$have_fstrm"; then
2082		AC_PATH_PROG([FSTRM_CAPTURE], [fstrm_capture])
2083	    else
2084		AC_PATH_PROG([FSTRM_CAPTURE], [fstrm_capture], [], [$PATH$PATH_SEPARATOR$have_fstrm/bin])
2085	    fi
2086	])
2087	AX_SAVE_FLAGS([dnstap])
2088	CFLAGS="$CFLAGS $PROTOBUF_C_CFLAGS $FSTRM_CFLAGS"
2089	LIBS="$LDFLAGS $PROTOBUF_C_LIBS $FSTRM_LIBS"
2090
2091	AC_SEARCH_LIBS([fstrm_iothr_init], [fstrm], [],
2092		       AC_MSG_ERROR([The fstrm library was not found. Please install fstrm!]))
2093	FSTRM_LIBS="$FSTRM_LIBS $ac_cv_search_fstrm_iothr_init"
2094
2095	AC_SEARCH_LIBS([protobuf_c_message_pack], [protobuf-c], [],
2096		       AC_MSG_ERROR([The protobuf-c library was not found. Please install protobuf-c!]))
2097	PROTOBUF_C_LIBS="$PROTOBUF_C_LIBS $ac_cv_search_protobuf_c_message_pack"
2098
2099	AX_RESTORE_FLAGS([dnstap])
2100	AC_DEFINE(HAVE_DNSTAP, 1, [Define to 1 to enable dnstap support])
2101	DNSTAP=dnstap
2102	DNSTAPSRCS='${DNSTAPSRCS}'
2103	DNSTAPOBJS='${DNSTAPOBJS}'
2104	DNSTAPTARGETS='${DNSTAPTARGETS}'
2105	DNSTAP_MANS='${dnstap_man1_MANS}'
2106fi
2107AC_SUBST(DNSTAP)
2108AC_SUBST(DNSTAPSRCS)
2109AC_SUBST(DNSTAPOBJS)
2110AC_SUBST(DNSTAPTARGETS)
2111AC_SUBST(DNSTAP_MANS)
2112AC_SUBST([PROTOBUF_C_CFLAGS])
2113AC_SUBST([PROTOBUF_C_LIBS])
2114AC_SUBST([FSTRM_CFLAGS])
2115AC_SUBST([FSTRM_LIBS])
2116
2117#
2118#  The following sets up how non-blocking i/o is established.
2119#  cygwin and solaris 2.x (x<5) require special handling.
2120#
2121case "$host" in
2122*-cygwin*) AC_DEFINE(PORT_NONBLOCK, O_NDELAY);;
2123*-solaris2.[[01234]])
2124	AC_DEFINE(PORT_NONBLOCK, O_NONBLOCK)
2125	AC_DEFINE(USE_FIONBIO_IOCTL, 1,
2126		  [Defined if you need to use ioctl(FIONBIO) instead a fcntl call to make non-blocking.])
2127	;;
2128*) AC_DEFINE(PORT_NONBLOCK, O_NONBLOCK,
2129	     [Sets which flag to pass to open/fcntl to make non-blocking (O_NDELAY/O_NONBLOCK).])
2130	;;
2131esac
2132#
2133# Solaris 2.5.1 and earlier cannot bind() then connect() a TCP socket.
2134# This prevents the source address being set.
2135#
2136case "$host" in
2137*-solaris2.[[012345]]|*-solaris2.5.1)
2138	AC_DEFINE(BROKEN_TCP_BIND_BEFORE_CONNECT, 1,
2139		  [Define if you cannot bind() before connect() for TCP sockets.])
2140	;;
2141esac
2142#
2143# The following sections deal with tools used for formatting
2144# the documentation.  They are all optional, unless you are
2145# a developer editing the documentation source.
2146#
2147
2148#
2149# The following sections deal with tools used for formatting
2150# the documentation.  They are all optional, unless you are
2151# a developer editing the documentation source.
2152#
2153
2154#
2155# Look for sphinx-build
2156#
2157AC_ARG_VAR([SPHINX_BUILD], [path to sphinx-build binary used to build the documentation])
2158AC_PATH_PROG([SPHINX_BUILD], [sphinx-build], [:])
2159AM_CONDITIONAL([HAVE_SPHINX_BUILD], [test "$SPHINX_BUILD" != ":"])
2160
2161AC_PATH_PROG([XELATEX], [xelatex], [:])
2162AC_PATH_PROG([LATEXMK], [latexmk], [:])
2163AM_CONDITIONAL([HAVE_XELATEX], [test "$XELATEX" != ":" && test "$LATEXMK" != ":"])
2164
2165#
2166# Pull release date from CHANGES file last modification date
2167# for reproducible builds
2168#
2169release_date=`date -u -r CHANGES +%Y-%m-%d`
2170AC_SUBST([RELEASE_DATE], $release_date)
2171
2172# Don't build the documentation if the sphinx-build is not present
2173PDFTARGET=
2174HTMLTARGET=
2175MANSRCS=
2176AS_IF([test -n "$SPHINX_BUILD"],[
2177	  MANSRCS='$(MANPAGES_IN)'
2178	  HTMLTARGET='html dirhtml'
2179	  AC_PATH_PROGS([PDFLATEX], [pdflatex], [])
2180	  AC_PATH_PROGS([LATEXMK], [latexmk], [])
2181	  AS_IF([test -n "$PDFLATEX" && test -n "$LATEXMK"],[
2182		    PDFTARGET='pdf'
2183		])
2184      ])
2185AC_SUBST([HTMLTARGET])
2186AC_SUBST([PDFTARGET])
2187AC_SUBST([MANSRCS])
2188
2189#
2190# Look for Doxygen
2191#
2192AC_PATH_PROGS([DOXYGEN], [doxygen])
2193AC_SUBST(DOXYGEN)
2194
2195#
2196# Look for curl
2197#
2198
2199AC_PATH_PROG(CURL, curl, curl)
2200AC_SUBST(CURL)
2201
2202#
2203# Look for xsltproc
2204#
2205
2206AC_PATH_PROG(XSLTPROC, xsltproc, xsltproc)
2207AC_SUBST(XSLTPROC)
2208
2209#
2210# IDN support using libidn2
2211#
2212
2213LIBIDN2_CFLAGS=
2214LIBIDN2_LDFLAGS=
2215LIBIDN2_LIBS=
2216
2217# [pairwise: --with-libidn2=yes, --without-libidn2]
2218AC_ARG_WITH([libidn2],
2219	    [AS_HELP_STRING([--with-libidn2[=PATH]], [enable IDN support using GNU libidn2 [yes|no(default)|path]])],
2220	    [with_libidn2="$withval"], [with_libidn2="no"])
2221AS_CASE([$with_libidn2],
2222	[yes],	[PKG_CHECK_MODULES([LIBIDN2], [libidn2],
2223				   [AC_DEFINE([HAVE_LIBIDN2], [1], [Define if libidn2 was found])])],
2224	[no],	[],
2225	[*],	[AX_SAVE_FLAGS([libidn2])
2226		 LIBIDN2_CFLAGS="-I$with_libidn2/include"
2227		 LIBIDN2_LDFLAGS="-L$with_libidn2/lib"
2228		 CFLAGS="$LIBIDN2_CFLAGS $CFLAGS"
2229		 CPPFLAGS="$LIBIDN2_CFLAGS $CPPFLAGS"
2230		 LDFLAGS="$LIBIDN2_LDFLAGS $LDFLAGS"
2231		 AC_CHECK_HEADERS([idn2.h],
2232				  [],
2233				  [AC_MSG_ERROR([idn2.h not found])])
2234		 AC_SEARCH_LIBS([idn2_to_ascii_lz], [idn2],
2235				[LIBIDN2_LIBS="$ac_cv_search_idn2_to_ascii_lz"
2236				 AC_DEFINE([HAVE_LIBIDN2], [1], [Define if libidn2 was found])],
2237				[AC_MSG_ERROR([libidn2 requested, but not found])])
2238		AX_RESTORE_FLAGS([libidn2])])
2239AC_SUBST([LIBIDN2_CFLAGS])
2240AC_SUBST([LIBIDN2_LDFLAGS])
2241AC_SUBST([LIBIDN2_LIBS])
2242
2243#
2244# Check whether to build with cmocka unit testing framework
2245#
2246# [pairwise: --with-cmocka=detect, --with-cmocka=yes, --without-cmocka]
2247AC_ARG_WITH([cmocka],
2248	    [AS_HELP_STRING([--with-cmocka=detect],[enable CMocka based tests (default is detect)])],
2249	    [],[with_cmocka=detect])
2250
2251AS_CASE([$with_cmocka],
2252	[no],[],
2253	[detect],[PKG_CHECK_MODULES([CMOCKA], [cmocka >= 1.1.3],
2254				    [AC_DEFINE([HAVE_CMOCKA], [1], [Use CMocka])
2255				     with_cmocka=yes],[with_cmocka=no])],
2256	[yes],[PKG_CHECK_MODULES([CMOCKA], [cmocka >= 1.1.3],
2257				 [AC_DEFINE([HAVE_CMOCKA], [1], [Use CMocka])])],
2258	[AC_MSG_ERROR([Use PKG_CONFIG_PATH to specify path to CMocka library])]
2259       )
2260AC_SUBST([CMOCKA_CFLAGS])
2261AC_SUBST([CMOCKA_LIBS])
2262
2263AC_DEFINE([SKIPPED_TEST_EXIT_CODE], [0], [Exit code for skipped tests])
2264
2265#
2266# Check for kyua execution engine if CMocka was requested
2267# and bail out if execution engine was not found
2268#
2269AC_ARG_VAR([KYUA], [path to kyua execution engine])
2270AS_IF([test "$with_cmocka" != "no"],
2271      [AC_PATH_PROGS([KYUA], [kyua], [])
2272       AS_IF([test -z "$KYUA"],
2273             [AC_MSG_WARN([kyua test execution engine not found])],
2274             [UNITTESTS=tests])])
2275AC_SUBST([KYUA])
2276AC_SUBST([UNITTESTS])
2277
2278#
2279# Check for -Wl,--wrap= support
2280#
2281
2282LD_WRAP_TESTS=false
2283AC_MSG_CHECKING([for linker support for --wrap option])
2284AX_SAVE_FLAGS([wrap])
2285LDFLAGS="-Wl,--wrap,exit"
2286AC_LINK_IFELSE(
2287    [AC_LANG_PROGRAM([[#include <stdlib.h>
2288		       void __real_exit (int status);
2289		       void __wrap_exit (int status) { __real_exit (0); }
2290		      ]],
2291		     [[exit (1);]])],
2292    [LD_WRAP_TESTS=true
2293     AC_DEFINE([LD_WRAP], [1], [define if the linker supports --wrap option])
2294     AC_MSG_RESULT([yes])],
2295    [AC_MSG_RESULT([no])])
2296AX_RESTORE_FLAGS([wrap])
2297
2298AC_SUBST([LD_WRAP_TESTS])
2299
2300#
2301# Check for i18n
2302#
2303AC_CHECK_HEADERS(locale.h)
2304AC_CHECK_FUNCS(setlocale)
2305
2306#
2307# was --with-tuning specified?
2308#
2309# [pairwise: --with-tuning=small, --without-tuning]
2310AC_ARG_WITH([tuning],
2311	    AS_HELP_STRING([--with-tuning=ARG],
2312			   [Specify server tuning (default or small)]),
2313	    [],[with_tuning=no])
2314
2315AS_CASE([$with_tuning],
2316	[small],[AC_MSG_NOTICE(using small system tuning)],
2317	[AC_DEFINE(TUNE_LARGE, 1, [Define to use default system tuning.])
2318	 AC_MSG_NOTICE(using default system tuning)])
2319
2320#
2321# was --enable-querytrace specified?
2322#
2323# [pairwise: --enable-querytrace, --disable-querytrace]
2324AC_ARG_ENABLE(querytrace,
2325	      AS_HELP_STRING([--enable-querytrace],
2326			     [enable very verbose query trace logging
2327				[default=no]]),
2328	      want_querytrace="$enableval", want_querytrace="no")
2329
2330AC_MSG_CHECKING([whether to enable query trace logging])
2331case "$want_querytrace" in
2332yes)
2333	AC_MSG_RESULT(yes)
2334	AC_DEFINE(WANT_QUERYTRACE, 1, [Define to enable very verbose query trace logging.])
2335	;;
2336no)
2337	AC_MSG_RESULT(no)
2338	;;
2339*)
2340	AC_MSG_ERROR("--enable-querytrace requires yes or no")
2341	;;
2342esac
2343
2344#
2345# Was --disable-auto-validation specified?
2346#
2347
2348validation_default=auto
2349
2350# [pairwise: --enable-auto-validation, --disable-auto-validation]
2351AC_ARG_ENABLE(auto-validation,
2352	      AS_HELP_STRING([--enable-auto-validation],
2353			     [turn on DNSSEC validation by default, using the IANA root key [default=yes]]),
2354	      [:],[enable_auto_validation=yes])
2355AS_IF([test "$enable_auto_validation" = "no"],[validation_default=yes])
2356AC_DEFINE_UNQUOTED([VALIDATION_DEFAULT], ["$validation_default"], [the default value of dnssec-validation option])
2357
2358#
2359# Substitutions
2360#
2361AC_SUBST(BIND9_TOP_BUILDDIR)
2362BIND9_TOP_BUILDDIR=`pwd`
2363
2364AC_SUBST(BIND9_ISC_BUILDINCLUDE)
2365AC_SUBST(BIND9_ISCCC_BUILDINCLUDE)
2366AC_SUBST(BIND9_ISCCFG_BUILDINCLUDE)
2367AC_SUBST(BIND9_DNS_BUILDINCLUDE)
2368AC_SUBST(BIND9_NS_BUILDINCLUDE)
2369AC_SUBST(BIND9_BIND9_BUILDINCLUDE)
2370AC_SUBST(BIND9_IRS_BUILDINCLUDE)
2371if test "X$srcdir" != "X"; then
2372	BIND9_ISC_BUILDINCLUDE="-I${BIND9_TOP_BUILDDIR}/lib/isc/include"
2373	BIND9_ISCCC_BUILDINCLUDE="-I${BIND9_TOP_BUILDDIR}/lib/isccc/include"
2374	BIND9_ISCCFG_BUILDINCLUDE="-I${BIND9_TOP_BUILDDIR}/lib/isccfg/include"
2375	BIND9_DNS_BUILDINCLUDE="-I${BIND9_TOP_BUILDDIR}/lib/dns/include"
2376	BIND9_NS_BUILDINCLUDE="-I${BIND9_TOP_BUILDDIR}/lib/ns/include"
2377	BIND9_BIND9_BUILDINCLUDE="-I${BIND9_TOP_BUILDDIR}/lib/bind9/include"
2378	BIND9_IRS_BUILDINCLUDE="-I${BIND9_TOP_BUILDDIR}/lib/irs/include"
2379else
2380	BIND9_ISC_BUILDINCLUDE=""
2381	BIND9_ISCCC_BUILDINCLUDE=""
2382	BIND9_ISCCFG_BUILDINCLUDE=""
2383	BIND9_DNS_BUILDINCLUDE=""
2384	BIND9_NS_BUILDINCLUDE=""
2385	BIND9_BIND9_BUILDINCLUDE=""
2386	BIND9_IRS_BUILDINCLUDE=""
2387fi
2388
2389AC_SUBST_FILE(BIND9_MAKE_INCLUDES)
2390BIND9_MAKE_INCLUDES=$BIND9_TOP_BUILDDIR/make/includes
2391
2392AC_SUBST_FILE(BIND9_MAKE_RULES)
2393BIND9_MAKE_RULES=$BIND9_TOP_BUILDDIR/make/rules
2394
2395. "$srcdir/version"
2396BIND9_PRODUCT="PRODUCT=\"${PRODUCT}\""
2397AC_SUBST(BIND9_PRODUCT)
2398BIND9_DESCRIPTION="DESCRIPTION=\"${DESCRIPTION}\""
2399AC_SUBST(BIND9_DESCRIPTION)
2400BIND9_VERSION="${MAJORVER}.${MINORVER}${PATCHVER:+.}${PATCHVER}${RELEASETYPE}${RELEASEVER}${EXTENSIONS}"
2401AC_SUBST(BIND9_VERSION)
2402BIND9_MAJOR="MAJOR=${MAJORVER}.${MINORVER}"
2403AC_SUBST(BIND9_MAJOR)
2404BIND9_VERSIONSTRING="${PRODUCT} ${MAJORVER}.${MINORVER}${PATCHVER:+.}${PATCHVER}${RELEASETYPE}${RELEASEVER}${EXTENSIONS}${DESCRIPTION:+ }${DESCRIPTION}"
2405AC_SUBST(BIND9_VERSIONSTRING)
2406
2407BIND9_SRCID="SRCID=unset_id"
2408if test -f "${srcdir}/srcid"; then
2409	. "${srcdir}/srcid"
2410	BIND9_SRCID="SRCID=$SRCID"
2411elif test -d "${srcdir}/.git"; then
2412	BIND9_SRCID="SRCID="`(cd "${srcdir}";git rev-parse --short HEAD)`
2413fi
2414
2415AC_SUBST(BIND9_SRCID)
2416
2417if test -z "$ac_configure_args"; then
2418	BIND9_CONFIGARGS="defaults"
2419else
2420	for a in $ac_configure_args
2421	do
2422		BIND9_CONFIGARGS="$BIND9_CONFIGARGS $a"
2423	done
2424fi
2425BIND9_CONFIGARGS="`echo $BIND9_CONFIGARGS | sed 's/^ //'`"
2426BIND9_CONFIGARGS="CONFIGARGS=${BIND9_CONFIGARGS}"
2427AC_SUBST(BIND9_CONFIGARGS)
2428
2429AC_SUBST_FILE(LIBDNS_MAPAPI)
2430LIBDNS_MAPAPI="$srcdir/lib/dns/mapapi"
2431
2432#
2433# Configure any DLZ drivers.
2434#
2435# If config.dlz.in selects one or more DLZ drivers, it will set
2436# CONTRIB_DLZ to a non-empty value, which will be our clue to
2437# build DLZ drivers in contrib.
2438#
2439# This section has to come after the libtool stuff because it needs to
2440# know how to name the driver object files.
2441#
2442
2443CONTRIB_DLZ=""
2444DLZ_DRIVER_INCLUDES=""
2445DLZ_DRIVER_LIBS=""
2446DLZ_DRIVER_SRCS=""
2447DLZ_DRIVER_OBJS=""
2448DLZ_SYSTEM_TEST=""
2449DLZ_DRIVER_MYSQL_INCLUDES=""
2450DLZ_DRIVER_MYSQL_LIBS=""
2451
2452#
2453# Configure support for building a shared library object
2454#
2455# Even when libtool is available it can't always be relied upon
2456# to build an object that can be dlopen()'ed, but this is necessary
2457# for building the dlzexternal system test, so we'll try it the
2458# old-fashioned way.
2459#
2460SO="so"
2461SO_CFLAGS=""
2462SO_LDFLAGS=""
2463SO_LD=""
2464SO_TARGETS=""
2465SO_STRIP="cat"
2466
2467# [pairwise: skip]
2468AC_ARG_WITH([dlopen],
2469	    AS_HELP_STRING([--with-dlopen=ARG],
2470			   [support dynamically loadable DLZ and DYNDB drivers]),
2471	    [], [with_dlopen="auto"])
2472
2473
2474#
2475# If PIC is disabled, dlopen must also be
2476#
2477AS_IF([test "$pic_mode" = "no"],
2478      [AS_CASE([$with_dlopen],
2479	       [auto],[with_dlopen="no"],
2480	       [yes],[AC_MSG_ERROR([--with-dlopen requires PIC])])])
2481
2482AS_CASE([$with_dlopen],
2483	[auto|yes],[
2484	  # -fsanitize=thread hijacks dlopen and dlclose so use dlsym.
2485	  AC_SEARCH_LIBS([dlsym],[dl])
2486	  AC_CHECK_FUNCS([dlopen dlclose dlsym],
2487			 [with_dlopen="yes"],
2488			 [with_dlopen="no"])
2489	])
2490
2491AS_IF([test "$with_dlopen" = "yes"],
2492      [AS_CASE([$host],
2493	       [*-linux*|*-gnu*],[
2494		 LDFLAGS="${LDFLAGS} -Wl,--export-dynamic"
2495		 SO_CFLAGS="-fPIC"
2496		 SO_LDFLAGS=""
2497		 AS_IF([test "$use_libtool" = "yes"],[
2498			 SO_LDFLAGS="-Xcompiler -shared"
2499			 SO_LD="${CC}"
2500		       ],[
2501			 SO_LDFLAGS="-shared"
2502			 SO_LD="${CC}"
2503		       ])
2504	       ],
2505	       [*-freebsd*|*-openbsd*|*-netbsd*],[
2506		 LDFLAGS="${LDFLAGS} -Wl,-E"
2507		 SO_CFLAGS="-fpic"
2508		 AS_IF([test "$use_libtool" = "yes"],[
2509			 SO_LDFLAGS="-Xcompiler -shared"
2510			 SO_LD="${CC}"
2511		       ],[
2512			 SO_LDFLAGS="-shared"
2513			 SO_LD="${CC}"
2514		       ])
2515	       ],
2516	       [*-darwin*],[
2517		 SO_CFLAGS="-fPIC"
2518                 SO_LD="${CC}"
2519		 AS_IF([test "$use_libtool" = "yes"],[
2520			 SO_LDFLAGS="-Xcompiler -dynamiclib -undefined dynamic_lookup"
2521		       ],[
2522			 SO_LDFLAGS="-dynamiclib -undefined dynamic_lookup"
2523		       ])
2524	       ],
2525	       [*-solaris*],[
2526		 SO_CFLAGS="-KPIC"
2527		 SO_LDFLAGS="-G -z text"
2528		 SO_LD="ld"
2529	       ],
2530	       [ia64-hp-hpux*],[
2531		 SO_CFLAGS="+z"
2532	         SO_LDFLAGS="-b"
2533		 SO_LD="${CC}"
2534	       ],
2535	       [
2536		 SO_CFLAGS="-fPIC"
2537	       ])
2538       AS_IF([test "$GCC" = "yes"],[
2539	       SO_CFLAGS="-fPIC"
2540	       AS_IF([test -z "$SO_LD"],
2541		     [AS_IF([test "$use_libtool" = "yes"],[
2542			      SO_LDFLAGS="-Xcompiler -shared"
2543			      SO_LD="${CC}"
2544			    ],[
2545			      SO_LDFLAGS="-shared"
2546			      SO_LD="${CC}"
2547			    ])
2548		     ])
2549	     ])
2550       # If we still don't know how to make shared objects, don't make any.
2551       AS_IF([test -n "$SO_LD"],
2552	     [SO_TARGETS="\${SO_TARGETS}"
2553	      AC_DEFINE([ISC_DLZ_DLOPEN], [1],
2554			[Define to allow building of objects for dlopen().])
2555	     ])
2556      ])
2557
2558AS_IF([test "$with_dlopen" = "no" -a "$enable_native_pkcs11" = "yes"],
2559      [AC_MSG_ERROR([PKCS11 requires dlopen() support])])
2560
2561CFLAGS="$CFLAGS $SO_CFLAGS"
2562
2563AC_SUBST(SO)
2564AC_SUBST(SO_CFLAGS)
2565AC_SUBST(SO_LDFLAGS)
2566AC_SUBST(SO_LD)
2567AC_SUBST(SO_STRIP)
2568AC_SUBST(SO_TARGETS)
2569
2570#
2571# Response policy rewriting using DNS Response Policy Service (DNSRPS)
2572# interface.
2573#
2574# DNSRPS can be compiled into BIND everywhere with a reasonably
2575# modern C compiler.  It is enabled on systems with dlopen() and librpz.so.
2576#
2577dnsrps_avail=yes
2578AC_MSG_CHECKING([for librpz __attribute__s])
2579AC_COMPILE_IFELSE(
2580  [AC_LANG_PROGRAM(
2581     [[]],
2582     [[
2583       extern void f(char *p __attribute__((unused)), ...)
2584       __attribute__((format(printf,1,2))) __attribute__((__noreturn__));
2585     ]])],
2586  [
2587    librpz_have_attr=yes
2588    AC_DEFINE([LIBRPZ_HAVE_ATTR], [1], [have __attribute__s used in librpz.h])
2589    AC_MSG_RESULT([yes])
2590  ],[
2591    librpz_have_attr=no
2592    AC_MSG_RESULT([no])
2593  ])
2594
2595# DNSRPS is not included in pairwise testing as the librpz library is not
2596# present in the relevant Docker image.
2597#
2598# [pairwise: skip]
2599AC_ARG_ENABLE([dnsrps-dl],
2600	      [AS_HELP_STRING([--enable-dnsrps-dl],
2601			      [DNS Response Policy Service delayed link
2602			       [default=$librpz_dl]])],
2603	      [enable_librpz_dl="$enableval"], [enable_librpz_dl="$with_dlopen"])
2604
2605AS_IF([test "$enable_librpz_dl" = "yes" -a "$with_dlopen" = "no"],
2606      [AC_MSG_ERROR([DNS Response Policy Service delayed link requires dlopen to be enabled])])
2607
2608# [pairwise: skip]
2609AC_ARG_WITH([dnsrps-libname],
2610	    [AS_HELP_STRING([--with-dnsrps-libname],
2611			    [DNSRPS provider library name (librpz.so)])],
2612	    [librpz_name="$withval"], [librpz_name="librpz.so"])
2613
2614# [pairwise: skip]
2615AC_ARG_WITH([dnsrps-dir],
2616	    [AS_HELP_STRING([--with-dnsrps-dir],
2617			    [path to DNSRPS provider library])],
2618	    [librpz_path="$withval/$librpz_name"], [librpz_path="$librpz_name"])
2619AC_DEFINE_UNQUOTED([DNSRPS_LIBRPZ_PATH], ["$librpz_path"],
2620		   [dnsrps $librpz_name])
2621AS_IF([test "$enable_librpz_dl" = "yes"],
2622      [
2623	dnsrps_lib_open=2
2624      ],[
2625	dnsrps_lib_open=1
2626	# Add librpz.so to linked libraries if we are not using dlopen()
2627	AC_SEARCH_LIBS([librpz_client_create], [rpz], [],
2628		[dnsrps_lib_open=0
2629		 dnsrps_avail=no])
2630      ])
2631AC_DEFINE_UNQUOTED([DNSRPS_LIB_OPEN], [$dnsrps_lib_open],
2632		   [0=no DNSRPS  1=static link  2=dlopen()])
2633
2634# [pairwise: skip]
2635AC_ARG_ENABLE([dnsrps],
2636	      AS_HELP_STRING([--enable-dnsrps],
2637			     [enable DNS Response Policy Service API]),
2638	      [enable_dnsrps=$enableval], [enable_dnsrps=no])
2639
2640AS_IF([test "$enable_dnsrps" != "no"],[
2641	AS_IF([test "$dnsrps_avail" != "yes"],
2642	      [AC_MSG_ERROR([dlopen and librpz.so needed for DNSRPS])])
2643	AS_IF([test "$dnsrps_lib_open" = "0"],
2644	      [AC_MSG_ERROR([dlopen and librpz.so needed for DNSRPS])])
2645	AC_DEFINE([USE_DNSRPS], [1], [Enable DNS Response Policy Service API])
2646      ])
2647
2648sinclude(contrib/dlz/config.dlz.in)
2649AC_MSG_CHECKING(contributed DLZ drivers)
2650
2651#
2652# Support for constructor and destructor attributes
2653#
2654AX_GCC_FUNC_ATTRIBUTE([constructor])
2655AX_GCC_FUNC_ATTRIBUTE([destructor])
2656
2657if test -n "$CONTRIB_DLZ"
2658then
2659	AC_MSG_RESULT(yes)
2660	DLZ_DRIVER_RULES=contrib/dlz/drivers/rules
2661	AC_CONFIG_FILES([$DLZ_DRIVER_RULES
2662		contrib/dlz/modules/mysql/Makefile
2663		contrib/dlz/modules/mysqldyn/Makefile])
2664else
2665	AC_MSG_RESULT(no)
2666	DLZ_DRIVER_RULES=/dev/null
2667fi
2668
2669AC_SUBST(CONTRIB_DLZ)
2670AC_SUBST(DLZ_DRIVER_INCLUDES)
2671AC_SUBST(DLZ_DRIVER_LIBS)
2672AC_SUBST(DLZ_DRIVER_SRCS)
2673AC_SUBST(DLZ_DRIVER_OBJS)
2674AC_SUBST(DLZ_SYSTEM_TEST)
2675AC_SUBST(DLZ_DRIVER_MYSQL_INCLUDES)
2676AC_SUBST(DLZ_DRIVER_MYSQL_LIBS)
2677AC_SUBST_FILE(DLZ_DRIVER_RULES)
2678
2679if test "yes" = "$cross_compiling"; then
2680	if test -z "$BUILD_CC"; then
2681		AC_MSG_ERROR([BUILD_CC not set])
2682	fi
2683	BUILD_CFLAGS="$BUILD_CFLAGS"
2684	BUILD_CPPFLAGS="$BUILD_CPPFLAGS"
2685	BUILD_LDFLAGS="$BUILD_LDFLAGS"
2686	BUILD_LIBS="$BUILD_LIBS"
2687else
2688	BUILD_CC="$CC"
2689	BUILD_CFLAGS="$CFLAGS"
2690	BUILD_CPPFLAGS="$CPPFLAGS $GEN_NEED_OPTARG"
2691	BUILD_LDFLAGS="$LDFLAGS"
2692	BUILD_LIBS="$LIBS"
2693fi
2694
2695NEWFLAGS=""
2696for e in $BUILD_LDFLAGS ; do
2697    case $e in
2698	-L*)
2699	    case $host_os in
2700		netbsd*)
2701		    ee=`echo $e | sed -e 's%^-L%-Wl,-rpath,%'`
2702		    NEWFLAGS="$NEWFLAGS $e $ee"
2703		    ;;
2704		freebsd*)
2705		    ee=`echo $e | sed -e 's%^-L%-Wl,-rpath,%'`
2706		    NEWFLAGS="$NEWFLAGS $e $ee"
2707		    ;;
2708		solaris*)
2709		    ee=`echo $e | sed -e 's%^-L%-R%'`
2710		    NEWFLAGS="$NEWFLAGS $e $ee"
2711		    ;;
2712		*)
2713		    NEWFLAGS="$NEWFLAGS $e"
2714		    ;;
2715		esac
2716	    ;;
2717	*)
2718	    NEWFLAGS="$NEWFLAGS $e"
2719	    ;;
2720    esac
2721done
2722BUILD_LDFLAGS="$NEWFLAGS"
2723
2724NEWFLAGS=""
2725for e in $DNS_GSSAPI_LIBS ; do
2726    case $e in
2727	-L*)
2728	    case $host_os in
2729		netbsd*)
2730		    ee=`echo $e | sed -e 's%^-L%-Wl,-rpath,%'`
2731		    NEWFLAGS="$NEWFLAGS $e $ee"
2732		    ;;
2733		freebsd*)
2734		    ee=`echo $e | sed -e 's%^-L%-Wl,-rpath,%'`
2735		    NEWFLAGS="$NEWFLAGS $e $ee"
2736		    ;;
2737		solaris*)
2738		    ee=`echo $e | sed -e 's%^-L%-R%'`
2739		    NEWFLAGS="$NEWFLAGS $e $ee"
2740		    ;;
2741		*)
2742		    NEWFLAGS="$NEWFLAGS $e"
2743		    ;;
2744		esac
2745	    ;;
2746	*)
2747	    NEWFLAGS="$NEWFLAGS $e"
2748	    ;;
2749    esac
2750done
2751DNS_GSSAPI_LIBS="$NEWFLAGS"
2752
2753NEWFLAGS=""
2754for e in $ISC_OPENSSL_LIBS ; do
2755    case $e in
2756	-L*)
2757	    case $host_os in
2758		netbsd*)
2759		    ee=`echo $e | sed -e 's%^-L%-Wl,-rpath,%'`
2760		    NEWFLAGS="$NEWFLAGS $e $ee"
2761		    ;;
2762		freebsd*)
2763		    ee=`echo $e | sed -e 's%^-L%-Wl,-rpath,%'`
2764		    NEWFLAGS="$NEWFLAGS $e $ee"
2765		    ;;
2766		solaris*)
2767		    ee=`echo $e | sed -e 's%^-L%-R%'`
2768		    NEWFLAGS="$NEWFLAGS $e $ee"
2769		    ;;
2770		*)
2771		    NEWFLAGS="$NEWFLAGS $e"
2772		    ;;
2773		esac
2774	    ;;
2775	*)
2776	    NEWFLAGS="$NEWFLAGS $e"
2777	    ;;
2778    esac
2779done
2780ISC_OPENSSL_LIBS="$NEWFLAGS"
2781
2782NEWFLAGS=""
2783for e in $DNS_CRYPTO_LIBS ; do
2784    case $e in
2785	-L*)
2786	    case $host_os in
2787		netbsd*)
2788		    ee=`echo $e | sed -e 's%^-L%-Wl,-rpath,%'`
2789		    NEWFLAGS="$NEWFLAGS $e $ee"
2790		    ;;
2791		freebsd*)
2792		    ee=`echo $e | sed -e 's%^-L%-Wl,-rpath,%'`
2793		    NEWFLAGS="$NEWFLAGS $e $ee"
2794		    ;;
2795		solaris*)
2796		    ee=`echo $e | sed -e 's%^-L%-R%'`
2797		    NEWFLAGS="$NEWFLAGS $e $ee"
2798		    ;;
2799		*)
2800		    NEWFLAGS="$NEWFLAGS $e"
2801		    ;;
2802		esac
2803	    ;;
2804	*)
2805	    NEWFLAGS="$NEWFLAGS $e"
2806	    ;;
2807    esac
2808done
2809DNS_CRYPTO_LIBS="$NEWFLAGS"
2810
2811AC_SUBST(BUILD_CC)
2812AC_SUBST(BUILD_CFLAGS)
2813AC_SUBST(BUILD_CPPFLAGS)
2814AC_SUBST(BUILD_LDFLAGS)
2815AC_SUBST(BUILD_LIBS)
2816
2817#
2818# Commands to run at the end of config.status.
2819# Don't just put these into configure, it won't work right if somebody
2820# runs config.status directly (which autoconf allows).
2821#
2822
2823AC_CONFIG_COMMANDS(
2824	[chmod],
2825	[chmod a+x doc/doxygen/doxygen-input-filter])
2826
2827#
2828# Files to configure.  These are listed here because we used to
2829# specify them as arguments to AC_OUTPUT.  It's (now) ok to move these
2830# elsewhere if there's a good reason for doing so.
2831#
2832
2833AC_CONFIG_FILES([
2834	Makefile
2835	bin/Makefile
2836	bin/check/Makefile
2837	bin/confgen/Makefile
2838	bin/confgen/unix/Makefile
2839	bin/delv/Makefile
2840	bin/dig/Makefile
2841	bin/dnssec/Makefile
2842	bin/named/Makefile
2843	bin/named/unix/Makefile
2844	bin/nsupdate/Makefile
2845	bin/pkcs11/Makefile
2846	bin/plugins/Makefile
2847	bin/python/Makefile
2848	bin/python/dnssec-checkds.py
2849	bin/python/dnssec-coverage.py
2850	bin/python/dnssec-keymgr.py
2851	bin/python/isc/Makefile
2852	bin/python/isc/__init__.py
2853	bin/python/isc/checkds.py
2854	bin/python/isc/coverage.py
2855	bin/python/isc/dnskey.py
2856	bin/python/isc/eventlist.py
2857	bin/python/isc/keydict.py
2858	bin/python/isc/keyevent.py
2859	bin/python/isc/keymgr.py
2860	bin/python/isc/keyseries.py
2861	bin/python/isc/keyzone.py
2862	bin/python/isc/policy.py
2863	bin/python/isc/rndc.py
2864	bin/python/isc/tests/Makefile
2865	bin/python/isc/tests/dnskey_test.py
2866	bin/python/isc/tests/policy_test.py
2867	bin/python/isc/utils.py
2868	bin/rndc/Makefile
2869	bin/tests/Makefile
2870	bin/tests/headerdep_test.sh
2871	bin/tests/optional/Makefile
2872	bin/tests/pkcs11/Makefile
2873	bin/tests/pkcs11/benchmarks/Makefile
2874	bin/tests/system/Makefile
2875	bin/tests/system/conf.sh
2876	bin/tests/system/dlzexternal/Makefile
2877	bin/tests/system/dlzexternal/ns1/dlzs.conf
2878	bin/tests/system/dyndb/Makefile
2879	bin/tests/system/dyndb/driver/Makefile
2880	bin/tests/system/pipelined/Makefile
2881	bin/tests/system/rndc/Makefile
2882	bin/tests/system/rpz/Makefile
2883	bin/tests/system/rsabigexponent/Makefile
2884	bin/tests/system/tkey/Makefile
2885	bin/tools/Makefile
2886	contrib/scripts/check-secure-delegation.pl
2887	contrib/scripts/zone-edit.sh
2888	doc/Makefile
2889	doc/arm/Makefile
2890	doc/doxygen/Doxyfile
2891	doc/doxygen/Makefile
2892	doc/doxygen/doxygen-input-filter
2893	doc/man/Makefile
2894	doc/misc/Makefile
2895	fuzz/Makefile
2896	lib/Makefile
2897	lib/bind9/Makefile
2898	lib/bind9/include/Makefile
2899	lib/bind9/include/bind9/Makefile
2900	lib/dns/Makefile
2901	lib/dns/include/Makefile
2902	lib/dns/include/dns/Makefile
2903	lib/dns/include/dst/Makefile
2904	lib/dns/tests/Makefile
2905	lib/irs/Makefile
2906	lib/irs/include/Makefile
2907	lib/irs/include/irs/Makefile
2908	lib/irs/include/irs/netdb.h
2909	lib/irs/include/irs/platform.h
2910	lib/irs/tests/Makefile
2911	lib/isc/Makefile
2912	lib/isc/include/Makefile
2913	lib/isc/include/isc/Makefile
2914	lib/isc/include/isc/platform.h
2915	lib/isc/include/pk11/Makefile
2916	lib/isc/include/pkcs11/Makefile
2917	lib/isc/netmgr/Makefile
2918	lib/isc/pthreads/Makefile
2919	lib/isc/pthreads/include/Makefile
2920	lib/isc/pthreads/include/isc/Makefile
2921	lib/isc/tests/Makefile
2922	lib/isc/unix/Makefile
2923	lib/isc/unix/include/Makefile
2924	lib/isc/unix/include/isc/Makefile
2925	lib/isccc/Makefile
2926	lib/isccc/include/Makefile
2927	lib/isccc/include/isccc/Makefile
2928	lib/isccc/tests/Makefile
2929	lib/isccfg/Makefile
2930	lib/isccfg/include/Makefile
2931	lib/isccfg/include/isccfg/Makefile
2932	lib/isccfg/tests/Makefile
2933	lib/ns/Makefile
2934	lib/ns/include/Makefile
2935	lib/ns/include/ns/Makefile
2936	lib/ns/tests/Makefile
2937	make/Makefile
2938	make/mkdep
2939	unit/unittest.sh
2940	util/check-make-install
2941])
2942
2943#
2944# Do it
2945#
2946
2947AC_OUTPUT
2948
2949#
2950# Now that the Makefiles exist we can ensure that everything is rebuilt.
2951#
2952# [pairwise: --with-make-clean, --without-make-clean]
2953AC_ARG_WITH(make-clean,
2954	    AS_HELP_STRING([--with-make-clean],
2955			   [run "make clean" at end of configure [yes|no]]),
2956    make_clean="$withval", make_clean="yes")
2957case "$make_clean" in
2958yes)
2959	if test "yes" != "$no_create"
2960	then
2961		if test "yes" = "$silent"
2962		then
2963			make clean > /dev/null
2964		else
2965			make clean
2966		fi
2967	fi
2968	;;
2969esac
2970
2971# [pairwise: --enable-full-report, --disable-full-report]
2972AC_ARG_ENABLE(full-report,
2973	      AS_HELP_STRING([--enable-full-report],
2974			     [report values of all configure options]))
2975
2976report() {
2977    echo "==============================================================================="
2978    echo "Configuration summary:"
2979    echo "-------------------------------------------------------------------------------"
2980    echo "Optional features enabled:"
2981    if test "yes" = "$enable_full_report" -o "standard" = "$with_locktype"; then
2982	echo "    Mutex lock type: $with_locktype"
2983    fi
2984    test "small" = "$with_tuning" && echo "    Small-system tuning (--with-tuning)"
2985    test "no" = "$use_dnstap" || \
2986	    echo "    Allow 'dnstap' packet logging (--enable-dnstap)"
2987    test -z "$MAXMINDDB_LIBS" || echo "    GeoIP2 access control (--enable-geoip)"
2988    test "no" = "$use_gssapi" || echo "    GSS-API (--with-gssapi)"
2989
2990    # these lines are only printed if run with --enable-full-report
2991    if test "yes" = "$enable_full_report"; then
2992	test "no" = "$found_ipv6" || echo "    IPv6 support (--enable-ipv6)"
2993	test "X$PYTHON" = "X" || echo "    Python tools (--with-python)"
2994	test "X$LIBXML2_LIBS" = "X" || echo "    XML statistics (--with-libxml2)"
2995	test "X$JSON_C_LIBS" = "X" || echo "    JSON statistics (--with-json-c): $JSON_C_CFLAGS $JSON_C_LIBS"
2996	test "X$ZLIB_LIBS" = "X" || echo "    HTTP zlib compression (--with-zlib)"
2997	test "X$NZD_TOOLS" = "X" || echo "    LMDB database to store configuration for 'addzone' zones (--with-lmdb)"
2998	test "no" = "$with_libidn2" || echo "    IDN support (--with-libidn2)"
2999    fi
3000
3001    test "yes" = "$enable_dnsrps" && \
3002	echo "    DNS Response Policy Service interface (--enable-dnsrps)"
3003    test "yes" = "$enable_fixed" && \
3004	echo "    Allow 'fixed' rrset-order (--enable-fixed-rrset)"
3005    test "yes" = "$enable_backtrace" && \
3006	echo "    Print backtrace on crash (--enable-backtrace)"
3007    test "minimal" = "$want_symtable" && \
3008	echo "    Use symbol table for backtrace, named only (--enable-symtable)"
3009    test "yes" = "$want_symtable" -o "all" = "$want_symtable" && \
3010	echo "    Use symbol table for backtrace, all binaries (--enable-symtable=all)"
3011    test "no" = "$use_libtool" || echo "    Use GNU libtool (--with-libtool)"
3012    test "yes" = "$want_querytrace" && \
3013	echo "    Very verbose query trace logging (--enable-querytrace)"
3014    test "no" = "$with_cmocka" || echo "    CMocka Unit Testing Framework (--with-cmocka)"
3015
3016    test "auto" = "$validation_default" && echo "    DNSSEC validation active by default (--enable-auto-validation)"
3017
3018    test "$CRYPTO" = "pkcs11" && (
3019	echo "    Using PKCS#11 for Public-Key Cryptography (--with-native-pkcs11)"
3020	echo "    PKCS#11 module (--with-pkcs11): $with_pkcs11"
3021	echo "    +--------------------------------------------+"
3022	echo "    |             ==== WARNING ====              |"
3023	echo "    |                                            |"
3024	echo "    | The use of native PKCS#11 for Public-Key   |"
3025	echo "    | Cryptography in BIND 9 has been deprecated |"
3026	echo "    | in favor of OpenSSL engine_pkcs11 from the |"
3027	echo "    | OpenSC project. The --with-native-pkcs11   |"
3028	echo "    | configuration option will be removed from  |"
3029	echo "    | the next major BIND 9 release. The option  |"
3030	echo "    | to use the engine_pkcs11 OpenSSL engine is |"
3031	echo "    | already available in BIND 9; please see    |"
3032	echo "    | the ARM section on PKCS#11 for details.    |"
3033	echo "    +--------------------------------------------+"
3034    )
3035
3036    dlz_enabled=no
3037
3038    echo "    Dynamically loadable zone (DLZ) drivers:"
3039    AS_IF([test "$use_dlz_bdb" != "no"],
3040	  [AS_ECHO(["        Berkeley DB (--with-dlz-bdb)"])
3041	   dlz_enabled=yes])
3042    AS_IF([test "$use_dlz_ldap" != "no"],
3043	  [AS_ECHO(["        LDAP (--with-dlz-ldap)"])
3044	   dlz_enabled=yes])
3045    AS_IF([test "$use_dlz_mysql" != "no"],
3046	  [AS_ECHO(["        MySQL (--with-dlz-mysql)"])
3047	   dlz_enabled=yes])
3048    AS_IF([test "$use_dlz_odbc" != "no"],
3049	  [AS_ECHO(["        ODBC (--with-dlz-odbc)"])
3050	   dlz_enabled=yes])
3051    AS_IF([test "$use_dlz_postgres" != "no"],
3052	  [AS_ECHO(["        Postgres (--with-dlz-postgres)"])
3053	   dlz_enabled=yes])
3054    AS_IF([test "$use_dlz_filesystem" != "no"],
3055	  [AS_ECHO(["        Filesystem (--with-dlz-filesystem)"])
3056	   dlz_enabled=yes])
3057    AS_IF([test "$use_dlz_stub" != "no"],
3058	  [AS_ECHO(["        Stub (--with-dlz-stub)"])
3059	   dlz_enabled=yes])
3060
3061    AS_IF([test "$dlz_enabled" = "no"],
3062	  [AS_ECHO(["        None"])],
3063	  [AS_ECHO(["    +--------------------------------------------------------+"])
3064	   AS_ECHO(["    |             ==== DEPRECATION WARNING ====              |"])
3065	   AS_ECHO(["    +--------------------------------------------------------+"])
3066	   AS_ECHO(["    | Old-style DLZ drivers have been deprecated in favor of |"])
3067	   AS_ECHO(["    | DLZ modules. The DLZ drivers configuration option will |"])
3068	   AS_ECHO(["    | be removed from the next major BIND 9 release.         |"])
3069	   AS_ECHO(["    |                                                        |"])
3070	   AS_ECHO(["    | The option to use the DLZ modules is already available |"])
3071	   AS_ECHO(["    | in BIND 9; please see the ARM section on DLZ modules.  |"])
3072	   AS_ECHO(["    +--------------------------------------------------------+"])
3073	  ])
3074
3075    echo "-------------------------------------------------------------------------------"
3076
3077    echo "Features disabled or unavailable on this platform:"
3078    test "no" = "$found_ipv6" && echo "    IPv6 support (--enable-ipv6)"
3079    test "small" = "$with_tuning" || echo "    Small-system tuning (--with-tuning)"
3080
3081    test "no" = "$use_dnstap" && \
3082	    echo "    Allow 'dnstap' packet logging (--enable-dnstap)"
3083    test -z "$MAXMINDDB_LIBS" && echo "    GeoIP2 access control (--enable-geoip)"
3084    test "no" = "$use_gssapi" && echo "    GSS-API (--with-gssapi)"
3085
3086    test "no" = "$enable_dnsrps" && \
3087	echo "    DNS Response Policy Service interface (--enable-dnsrps)"
3088
3089    test "yes" = "$enable_fixed" || \
3090	echo "    Allow 'fixed' rrset-order (--enable-fixed-rrset)"
3091
3092    test "yes" = "$validation_default" && echo "    DNSSEC validation requires configuration (--enablee-auto-validation)"
3093
3094    test "$CRYPTO" = "pkcs11" || (
3095	echo "    Using PKCS#11 for Public-Key Cryptography (--with-native-pkcs11)"
3096    )
3097
3098    test "yes" = "$enable_backtrace" || \
3099	echo "    Print backtrace on crash (--enable-backtrace)"
3100    test "yes" = "$want_querytrace" || \
3101	echo "    Very verbose query trace logging (--enable-querytrace)"
3102
3103    test "yes" = "$use_libtool" || echo "    Use GNU libtool (--with-libtool)"
3104    test "no" = "$with_cmocka" && echo "    CMocka Unit Testing Framework (--with-cmocka)"
3105
3106    test "X$PYTHON" = "X" && echo "    Python tools (--with-python)"
3107    test "X$LIBXML2_LIBS" = "X" && echo "    XML statistics (--with-libxml2)"
3108    test "X$JSON_C_LIBS" = "X" && echo "    JSON statistics (--with-json-c)"
3109    test "X$ZLIB_LIBS" = "X" && echo "    HTTP zlib compression (--with-zlib)"
3110    test "X$NZD_TOOLS" = "X" && echo "    LMDB database to store configuration for 'addzone' zones (--with-lmdb)"
3111    test "no" = "$with_libidn2" && echo "    IDN support (--with-libidn2)"
3112
3113    echo "-------------------------------------------------------------------------------"
3114    echo "Configured paths:"
3115    echo "    prefix: $prefix"
3116    echo "    sysconfdir: $sysconfdir"
3117    echo "    localstatedir: $localstatedir"
3118    echo "-------------------------------------------------------------------------------"
3119    echo "Compiler: $CC"
3120    AS_IF([test "$GCC" = "yes"],
3121	  [$CC --version 2>&1 | sed 's/^/    /'],
3122	  [AS_CASE([$host],
3123		   [*-solaris*],[$CC -V 2>&1 | sed 's/^/    /'],
3124		   [$CC --version 2>&1 | sed 's/^/    /'])])
3125
3126    if test "X$ac_unrecognized_opts" != "X"; then
3127	echo "Unrecognized options:"
3128	echo "    $ac_unrecognized_opts"
3129    fi
3130
3131    if test "yes" != "$enable_full_report"; then
3132	echo "-------------------------------------------------------------------------------"
3133	echo "For more detail, use --enable-full-report."
3134    fi
3135    echo "==============================================================================="
3136}
3137
3138if test "yes" != "$silent"; then
3139	report
3140fi
3141
3142# Tell Emacs to edit this file in shell mode.
3143# Local Variables:
3144# mode: sh
3145# End:
3146