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