configure.ac revision 1.1.1.12
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
710AC_MSG_CHECKING(for libuv)
711PKG_CHECK_MODULES([LIBUV], [libuv >= 1.0.0], [],
712		  [AC_MSG_ERROR([libuv 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# [pairwise: --enable-native-pkcs11 --with-dlopen, --disable-native-pkcs11 --with-dlopen, --disable-native-pkcs11 --without-dlopen]
943AC_ARG_ENABLE(native-pkcs11,
944	      AS_HELP_STRING([--enable-native-pkcs11],
945			     [use native PKCS11 for public-key crypto [default=no]]),
946	      [:], [enable_native_pkcs11="no"])
947
948AC_MSG_CHECKING([for PKCS11 for Public-Key Cryptography])
949AS_CASE([$enable_native_pkcs11],
950	[no],[AC_MSG_RESULT([no])],
951	[yes],[PKCS11_TOOLS=pkcs11
952	       PKCS11_TEST=pkcs11
953	       PKCS11_MANS='${pkcs11_man8_MANS}'
954	       CRYPTO=pkcs11
955	       AS_IF([$use_threads],
956		     [:],
957		     [AC_MSG_ERROR([PKCS11 requires threading support])])
958	       AC_MSG_RESULT([yes])
959	       AC_CHECK_FUNCS([getpassphrase])
960	      ])
961AC_SUBST([PKCS11_TEST])
962AC_SUBST([PKCS11_TOOLS])
963AC_SUBST([PKCS11_MANS])
964
965AC_SUBST([CRYPTO])
966AS_CASE([$CRYPTO],
967	[pkcs11],[AC_DEFINE([USE_PKCS11], [1], [define if PKCS11 is used for Public-Key Cryptography])],
968	[AC_DEFINE([USE_OPENSSL], [1], [define if OpenSSL is used for Public-Key Cryptography])])
969
970# preparation for automake
971# AM_CONDITIONAL([PKCS11_TOOLS], [test "$with_native_pkcs11" = "yes"])
972
973#
974# was --with-pkcs11 specified?
975#
976# [pairwise: skip]
977AC_ARG_WITH([pkcs11],
978	    [AS_HELP_STRING([--with-pkcs11[=PATH]],
979			    [Build with PKCS11 support [no|path] (PATH is for the PKCS11 provider)])],
980	    [:], [with_pkcs11="undefined"])
981
982AS_CASE([$with_pkcs11],
983	[yes|auto],[AC_MSG_ERROR([--with-pkcs11 needs explicit path to the PKCS11 library])],
984	[no|undefined],[with_pkcs11="undefined"])
985AC_DEFINE_UNQUOTED([PK11_LIB_LOCATION], ["$with_pkcs11"], [define the default PKCS11 library path])
986
987# for PKCS11 benchmarks
988
989have_clock_gt=no
990AC_CHECK_FUNC(clock_gettime,have_clock_gt=yes,)
991if test "no" = "$have_clock_gt"; then
992	AC_CHECK_LIB(rt,clock_gettime,have_clock_gt=rt,)
993fi
994
995if test "no" != "$have_clock_gt"; then
996	AC_DEFINE(HAVE_CLOCK_GETTIME, 1, [Define if clock_gettime is available.])
997fi
998
999if test "rt" = "$have_clock_gt"; then
1000	LIBS="-lrt $LIBS"
1001fi
1002
1003AC_MSG_CHECKING(for GSSAPI library)
1004
1005# [pairwise: --with-gssapi=yes, --with-gssapi=auto, --without-gssapi]
1006AC_ARG_WITH(gssapi,
1007	    AS_HELP_STRING([--with-gssapi=[PATH|[/path/]krb5-config]],
1008			   [Specify path for system-supplied GSSAPI
1009				[default=auto]]),
1010	    use_gssapi="$withval", use_gssapi="auto")
1011
1012# first try using krb5-config, if that does not work then fall back to "yes" method.
1013
1014case "$use_gssapi" in
1015*/krb5-config|krb5-config)
1016    AC_MSG_RESULT(trying $use_gssapi)
1017    if test krb5-config = "$use_gssapi"
1018    then
1019	AC_PATH_PROG(KRB5_CONFIG, $use_gssapi)
1020    else
1021	KRB5_CONFIG="$use_gssapi"
1022    fi
1023    gssapi_cflags=`$KRB5_CONFIG --cflags gssapi`
1024    gssapi_libs=`$KRB5_CONFIG --libs gssapi`
1025    krb5_cflags=`$KRB5_CONFIG --cflags krb5`
1026    krb5_libs=`$KRB5_CONFIG --libs krb5`
1027    saved_cppflags="$CPPFLAGS"
1028    CPPFLAGS="$gssapi_cflags $krb5_cflags $CPPFLAGS"
1029    AC_CHECK_HEADERS(gssapi.h gssapi/gssapi.h,
1030	[ISC_PLATFORM_GSSAPIHEADER="#define ISC_PLATFORM_GSSAPIHEADER <$ac_header>"])
1031    if test "" = "$ISC_PLATFORM_GSSAPIHEADER"; then
1032	AC_MSG_RESULT([krb5-config: gssapi.h not found])
1033	CPPFLAGS="$saved_cppflags"
1034	use_gssapi="yes"
1035    else
1036	AC_CHECK_HEADERS(krb5/krb5.h krb5.h,
1037	    [ISC_PLATFORM_KRB5HEADER="#define ISC_PLATFORM_KRB5HEADER <$ac_header>"])
1038	if test "" = "$ISC_PLATFORM_KRB5HEADER"; then
1039	    AC_MSG_RESULT([krb5-config: krb5.h not found])
1040	    CPPFLAGS="$saved_cppflags"
1041	    use_gssapi="yes"
1042	else
1043	    CPPFLAGS="$saved_cppflags"
1044	    saved_libs="$LIBS"
1045	    LIBS="$gssapi_libs $krb5_libs $LIBS"
1046	    AC_MSG_CHECKING([krb5-config linking as $LIBS])
1047	    AC_TRY_LINK( , [gss_acquire_cred();krb5_init_context()],
1048		gssapi_linked=yes, gssapi_linked=no)
1049	    case $gssapi_linked in
1050		yes) AC_MSG_RESULT([krb5-config: linked]);;
1051		no)  AC_MSG_RESULT([krb5-config: could not determine proper GSSAPI linkage])
1052		    use_gssapi="yes"
1053		    ;;
1054	    esac
1055	    LIBS=$saved_libs
1056	fi
1057    fi
1058    if test "yes" = "$use_gssapi"; then
1059	AC_MSG_CHECKING([for GSSAPI library, non krb5-config method])
1060    fi
1061    ;;
1062esac
1063
1064case "$host" in
1065*darwin*)
1066	if test "yes" = "$use_gssapi" -o "auto" = "$use_gssapi"
1067	then
1068		use_gssapi=framework
1069	fi
1070	;;
1071esac
1072
1073# gssapi is just the framework, we really require kerberos v5, so
1074# look for those headers (the gssapi headers must be there, too)
1075# The problem with this implementation is that it doesn't allow
1076# for the specification of gssapi and krb5 headers in different locations,
1077# which probably ought to be fixed although fixing might raise the issue of
1078# trying to build with incompatible versions of gssapi and krb5.
1079if test "yes" = "$use_gssapi" -o "auto" = "$use_gssapi"
1080then
1081	# first, deal with the obvious
1082	if test \( -f /usr/include/kerberosv5/krb5.h -o \
1083		   -f /usr/include/krb5/krb5.h -o \
1084		   -f /usr/include/krb5.h \)   -a \
1085		\( -f /usr/include/gssapi.h -o \
1086		   -f /usr/include/gssapi/gssapi.h \)
1087	then
1088		use_gssapi=/usr
1089	else
1090	    krb5dirs="/usr/local /usr/local/krb5 /usr/local/kerberosv5 /usr/local/kerberos /usr/pkg /usr/krb5 /usr/kerberosv5 /usr/kerberos /usr"
1091	    for d in $krb5dirs
1092	    do
1093		if test -f $d/include/gssapi/gssapi_krb5.h -o \
1094			-f $d/include/krb5.h
1095		then
1096			if test -f $d/include/gssapi/gssapi.h -o \
1097				-f $d/include/gssapi.h
1098			then
1099				use_gssapi=$d
1100				break
1101			fi
1102		fi
1103	    done
1104	    if test "auto" = "$use_gssapi"
1105	    then
1106		use_gssapi="no"
1107	    fi
1108	fi
1109fi
1110
1111case "$use_gssapi" in
1112	no)
1113		AC_MSG_RESULT(disabled)
1114		USE_GSSAPI=''
1115		;;
1116	yes)
1117		AC_MSG_ERROR([--with-gssapi must specify a path])
1118		;;
1119	*/krb5-config|krb5-config)
1120		USE_GSSAPI='-DGSSAPI'
1121		DST_GSSAPI_INC="$gssapi_cflags $krb5_cflags"
1122		DNS_GSSAPI_LIBS="$gssapi_libs $krb5_libs"
1123		;;
1124	framework)
1125		USE_GSSAPI='-DGSSAPI'
1126		ISC_PLATFORM_GSSAPIHEADER="#define ISC_PLATFORM_GSSAPIHEADER <Kerberos/Kerberos.h>"
1127		ISC_PLATFORM_KRB5HEADER="#define ISC_PLATFORM_KRB5HEADER <Kerberos/Kerberos.h>"
1128		DNS_GSSAPI_LIBS="-framework Kerberos"
1129		AC_MSG_RESULT(framework)
1130		;;
1131
1132	*)
1133		AC_MSG_RESULT(looking in $use_gssapi/lib)
1134		USE_GSSAPI='-DGSSAPI'
1135		saved_cppflags="$CPPFLAGS"
1136		CPPFLAGS="-I$use_gssapi/include $CPPFLAGS"
1137		AC_CHECK_HEADERS(gssapi.h gssapi/gssapi.h,
1138		    [ISC_PLATFORM_GSSAPIHEADER="#define ISC_PLATFORM_GSSAPIHEADER <$ac_header>"
1139		     gssapi_hack="#include <$ac_header>"])
1140
1141		if test "" = "$ISC_PLATFORM_GSSAPIHEADER"; then
1142		    AC_MSG_ERROR([gssapi.h not found])
1143		fi
1144
1145		AC_CHECK_HEADERS(gssapi_krb5.h gssapi/gssapi_krb5.h,
1146		    [ISC_PLATFORM_GSSAPI_KRB5_HEADER="#define ISC_PLATFORM_GSSAPI_KRB5_HEADER <$ac_header>"
1147		     gssapi_krb5_hack="#include <$ac_header>"])
1148
1149		AC_CHECK_HEADERS(krb5.h krb5/krb5.h kerberosv5/krb5.h,
1150		    [ISC_PLATFORM_KRB5HEADER="#define ISC_PLATFORM_KRB5HEADER <$ac_header>"
1151		    krb5_hack="#include <$ac_header>"])
1152
1153		if test "" = "$ISC_PLATFORM_KRB5HEADER"; then
1154		    AC_MSG_ERROR([krb5.h not found])
1155		fi
1156
1157		#
1158		# XXXDCL This probably doesn't work right on all systems.
1159		# It will need to be worked on as problems become evident.
1160		#
1161		# Essentially the problems here relate to two different
1162		# areas.  The first area is building with either KTH
1163		# or MIT Kerberos, particularly when both are present on
1164		# the machine.  The other is static versus dynamic linking.
1165		#
1166		# On the KTH vs MIT issue, Both have libkrb5 that can mess
1167		# up the works if one implementation ends up trying to
1168		# use the other's krb.  This is unfortunately a situation
1169		# that very easily arises.
1170		#
1171		# Dynamic linking when the dependency information is built
1172		# into MIT's libgssapi_krb5 or KTH's libgssapi magically makes
1173		# all such problems go away, but when that setup is not
1174		# present, because either the dynamic libraries lack
1175		# dependencies or static linking is being done, then the
1176		# problems start to show up.
1177		saved_libs="$LIBS"
1178		for TRY_LIBS in \
1179		    "-lgssapi_krb5" \
1180		    "-lgssapi_krb5 -lkrb5 -lk5crypto -lcom_err" \
1181		    "-lgssapi_krb5 -lkrb5 -lk5crypto -lcom_err -lresolv" \
1182		    "-lgssapi" \
1183		    "-lgssapi -lkrb5 -ldes -lcrypt -lasn1 -lroken -lcom_err" \
1184		    "-lgssapi -lkrb5 -lcrypt -lasn1 -lroken -lcom_err" \
1185		    "-lgssapi -lkrb5 -lgssapi_krb5 -lcrypt -lasn1 -lroken -lcom_err" \
1186		    "-lgssapi -lkrb5 -lhx509 -lcrypt -lasn1 -lroken -lcom_err" \
1187		    "-lgss -lkrb5"
1188		do
1189		    # Note that this does not include $saved_libs, because
1190		    # on FreeBSD machines this configure script has added
1191		    # -L/usr/local/lib to LIBS, which can make the
1192		    # -lgssapi_krb5 test succeed with shared libraries even
1193		    # when you are trying to build with KTH in /usr/lib.
1194		    if test "/usr" = "$use_gssapi"
1195		    then
1196			    LIBS="$TRY_LIBS $ISC_OPENSSL_LIBS"
1197		    else
1198			    LIBS="-L$use_gssapi/lib $TRY_LIBS $ISC_OPENSSL_LIBS"
1199		    fi
1200		    AC_MSG_CHECKING(linking as $TRY_LIBS)
1201		    AC_TRY_LINK([
1202#include <sys/types.h>
1203$gssapi_hack
1204$gssapi_krb5_hack
1205$krb5_hack
1206				] , [gss_acquire_cred(NULL, NULL, 0, NULL, 0, NULL, NULL, NULL);krb5_init_context(NULL);
1207#if defined(HAVE_GSSAPI_KRB5_H) || defined(HAVE_GSSAPI_GSSAPI_KRB5_H)
1208gsskrb5_register_acceptor_identity(NULL);
1209#endif],
1210				gssapi_linked=yes, gssapi_linked=no)
1211		    case $gssapi_linked in
1212		    yes) AC_MSG_RESULT(yes); break ;;
1213		    no)  AC_MSG_RESULT(no) ;;
1214		    esac
1215		done
1216
1217		CPPFLAGS="$saved_cppflags"
1218
1219		case $gssapi_linked in
1220		no) AC_MSG_ERROR(could not determine proper GSSAPI linkage) ;;
1221		esac
1222
1223		#
1224		# XXXDCL Major kludge.  Tries to cope with KTH in /usr/lib
1225		# but MIT in /usr/local/lib and trying to build with KTH.
1226		# /usr/local/lib can end up earlier on the link lines.
1227		# Like most kludges, this one is not only inelegant it
1228		# is also likely to be the wrong thing to do at least as
1229		# many times as it is the right thing.  Something better
1230		# needs to be done.
1231		#
1232		if test "/usr" = "$use_gssapi" -a \
1233			-f /usr/local/lib/libkrb5.a; then
1234		    FIX_KTH_VS_MIT=yes
1235		fi
1236
1237		case "$FIX_KTH_VS_MIT" in
1238		yes)
1239		    case "$enable_static_linking" in
1240		    yes) gssapi_lib_suffix=".a"  ;;
1241		    *)   gssapi_lib_suffix=".so" ;;
1242		    esac
1243
1244		    for lib in $LIBS; do
1245			case $lib in
1246			-L*)
1247			    ;;
1248			-l*)
1249			    new_lib=`echo $lib |
1250				     sed -e s%^-l%$use_gssapi/lib/lib% \
1251					 -e s%$%$gssapi_lib_suffix%`
1252			    NEW_LIBS="$NEW_LIBS $new_lib"
1253			    ;;
1254			*)
1255			   AC_MSG_ERROR([KTH vs MIT Kerberos confusion!])
1256			    ;;
1257			esac
1258		    done
1259		    LIBS="$NEW_LIBS"
1260		    ;;
1261		esac
1262
1263		DST_GSSAPI_INC="-I$use_gssapi/include"
1264		DNS_GSSAPI_LIBS="$LIBS"
1265
1266		AC_MSG_RESULT(using GSSAPI from $use_gssapi/lib and $use_gssapi/include)
1267		LIBS="$saved_libs"
1268		;;
1269esac
1270
1271AC_SUBST(ISC_PLATFORM_GSSAPIHEADER)
1272AC_SUBST(ISC_PLATFORM_GSSAPI_KRB5_HEADER)
1273AC_SUBST(ISC_PLATFORM_KRB5HEADER)
1274
1275AC_SUBST(USE_GSSAPI)
1276AC_SUBST(DST_GSSAPI_INC)
1277AC_SUBST(DNS_GSSAPI_LIBS)
1278DNS_CRYPTO_LIBS="$DNS_GSSAPI_LIBS"
1279
1280#
1281# Applications linking with libdns also need to link with these libraries.
1282#
1283
1284AC_SUBST(DNS_CRYPTO_LIBS)
1285
1286#
1287# was --with-lmdb specified?
1288#
1289AC_MSG_CHECKING(for lmdb library)
1290
1291# [pairwise: --with-lmdb=auto, --with-lmdb=yes, --without-lmdb]
1292AC_ARG_WITH(lmdb,
1293	    AS_HELP_STRING([--with-lmdb[=PATH]],
1294			   [build with LMDB library [yes|no|path]]),
1295    use_lmdb="$withval", use_lmdb="auto")
1296
1297have_lmdb=""
1298case "$use_lmdb" in
1299	no)
1300		LMDB_LIBS=""
1301		;;
1302	auto|yes)
1303		for d in /usr /usr/local /opt/local
1304		do
1305			if test -f "${d}/include/lmdb.h"
1306			then
1307				if test ${d} != /usr
1308				then
1309					LMDB_CFLAGS="-I ${d}/include"
1310					LMDB_LIBS="-L${d}/lib"
1311				fi
1312				have_lmdb="yes"
1313			fi
1314		done
1315		;;
1316	*)
1317		if test -f "${use_lmdb}/include/lmdb.h"
1318		then
1319			LMDB_CFLAGS="-I${use_lmdb}/include"
1320			LMDB_LIBS="-L${use_lmdb}/lib"
1321			have_lmdb="yes"
1322		else
1323			AC_MSG_ERROR([$use_lmdb/include/lmdb.h not found.])
1324		fi
1325		;;
1326esac
1327
1328if test "X${have_lmdb}" != "X"
1329then
1330	AC_MSG_RESULT(yes)
1331	AX_SAVE_FLAGS([lmdb])
1332	CFLAGS="$CFLAGS $LMDB_CFLAGS"
1333	LIBS="$LIBS $LMDB_LIBS"
1334	AC_SEARCH_LIBS([mdb_env_create], [lmdb], [],
1335		       [AC_MSG_ERROR([found lmdb include but not library.])
1336			have_lmdb=""])
1337	LMDB_LIBS="$LMDB_LIBS $ac_cv_search_mdb_env_create"
1338	AX_RESTORE_FLAGS([lmdb])
1339elif test "X$use_lmdb" = Xyes
1340then
1341	AC_MSG_ERROR([include/lmdb.h not found.])
1342else
1343	AC_MSG_RESULT(no)
1344fi
1345AC_SUBST([LMDB_CFLAGS])
1346AC_SUBST([LMDB_LIBS])
1347
1348NZD_TOOLS=""
1349NZDSRCS=
1350NZDTARGETS=
1351if test "X${have_lmdb}" != "X"
1352then
1353	AC_DEFINE(HAVE_LMDB, 1, [Define if lmdb was found])
1354	NZD_TOOLS="nzd"
1355	NZDSRCS='${NZDSRCS}'
1356	NZDTARGETS='${NZDTARGETS}'
1357	NZD_MANS='${nzd_man8_MANS}'
1358fi
1359AC_SUBST(NZD_TOOLS)
1360AC_SUBST(NZDSRCS)
1361AC_SUBST(NZDTARGETS)
1362AC_SUBST(NZD_MANS)
1363
1364#
1365# was --with-libxml2 specified?
1366#
1367# [pairwise: --with-libxml2=auto, --with-libxml2=yes, --without-libxml2]
1368AC_ARG_WITH([libxml2],
1369	    [AS_HELP_STRING([--with-libxml2],
1370			    [build with libxml2 library [yes|no|auto] (default is auto)])],
1371	    [], [with_libxml2="auto"])
1372
1373AS_CASE([$with_libxml2],
1374	[no],[],
1375	[auto],[PKG_CHECK_MODULES([LIBXML2], [libxml-2.0 >= 2.6.0],
1376				  [AC_DEFINE([HAVE_LIBXML2], [1], [Use libxml2 library])],
1377				  [:])],
1378	[yes],[PKG_CHECK_MODULES([LIBXML2], [libxml-2.0 >= 2.6.0],
1379				 [AC_DEFINE([HAVE_LIBXML2], [1], [Use libxml2 library])])],
1380	[AC_MSG_ERROR([Specifying libxml2 installation path is not supported, adjust PKG_CONFIG_PATH instead])])
1381
1382#
1383# DEPRECATED
1384#
1385# [pairwise: skip]
1386AC_ARG_WITH([libjson],
1387	    [AS_HELP_STRING([--with-libjson],
1388			    [deprecated, use --with-json-c])],
1389	    [AC_MSG_WARN([--with-libjson is DEPRECATED and will be removed in a future release, use --with-json-c instead])],
1390	    [with_libjson="detect"])
1391
1392#
1393# was --with-json-c specified?
1394#
1395# [pairwise: --with-json-c=detect, --with-json-c=yes, --without-json-c]
1396AC_ARG_WITH([json-c],
1397	    [AS_HELP_STRING([--with-json-c],
1398			    [build with json-c library [yes|no|detect] (default is detect)])],
1399	    [], [with_json_c="$with_libjson"])
1400
1401AS_CASE([$with_json_c],
1402	[no],[],
1403	[detect],[PKG_CHECK_MODULES([JSON_C], [json-c >= 0.11],
1404				    [AC_DEFINE([HAVE_JSON_C], [1], [Use json-c library])],
1405				    [:])],
1406	[yes],[PKG_CHECK_MODULES([JSON_C], [json-c >= 0.11],
1407				 [AC_DEFINE([HAVE_JSON_C], [1], [Use json-c library])])],
1408	[AC_MSG_ERROR([Specifying json-c installation path is not supported, adjust PKG_CONFIG_PATH instead])]
1409       )
1410
1411AC_SUBST([JSON_C_CFLAGS])
1412AC_SUBST([JSON_C_LIBS])
1413
1414# [pairwise: --with-zlib=auto, --with-zlib=yes, --without-zlib]
1415AC_ARG_WITH([zlib],
1416           [AS_HELP_STRING([--with-zlib],
1417                           [build with zlib for HTTP compression
1418                            [default=yes]])],
1419	   [], with_zlib="auto")
1420
1421AS_CASE([$with_zlib],
1422       [no],[],
1423       [auto],[PKG_CHECK_MODULES([ZLIB], [zlib],
1424                                 [AC_DEFINE([HAVE_ZLIB], [1], [Use zlib library])],
1425                                 [:])],
1426       [yes],[PKG_CHECK_MODULES([ZLIB], [zlib],
1427                                [AC_DEFINE([HAVE_ZLIB], [1], [Use zlib library])])],
1428       [AC_MSG_ERROR([Specifying zlib installation path is not supported, adjust PKG_CONFIG_PATH instead])])
1429AC_SUBST([ZLIB_CFLAGS])
1430AC_SUBST([ZLIB_LIBS])
1431
1432#
1433# In solaris 10, SMF can manage named service
1434#
1435AC_CHECK_LIB(scf, smf_enable_instance)
1436
1437#
1438# Additional compiler settings.
1439#
1440MKDEPCC="$CC"
1441
1442MKDEPCFLAGS="-M"
1443AS_CASE([$host],
1444	[*-solaris*],[
1445	    AS_IF([test "$GCC" != "yes"],
1446		  [MKDEPCFLAGS="-xM"])])
1447
1448AS_IF([test "$GCC" = "yes"],
1449      [STD_CWARNINGS="$STD_CWARNINGS -W -Wall -Wmissing-prototypes -Wcast-qual -Wwrite-strings -Wformat -Wpointer-arith -Wno-missing-field-initializers"]
1450      )
1451
1452AX_CHECK_COMPILE_FLAG([-fno-strict-aliasing],
1453		      [STD_CWARNINGS="$STD_CWARNINGS -fno-strict-aliasing"])
1454AX_CHECK_COMPILE_FLAG([-Werror -fno-delete-null-pointer-checks],
1455		      [STC_CWARNINGS="$STD_CWARNINGS -fno-delete-null-pointer-checks"])
1456AS_IF([test "$enable_warn_shadow" = "yes"],
1457      [AX_CHECK_COMPILE_FLAG([-Wshadow],
1458			     [STD_CWARNINGS="$STD_CWARNINGS -Wshadow"])])
1459AS_IF([test "$enable_warn_error" = "yes"],
1460      [AX_CHECK_COMPILE_FLAG([-Werror],
1461			     [STD_CWARNINGS="$STD_CWARNINGS -Werror"])])
1462
1463AC_SUBST([MKDEPCC])
1464AC_SUBST([MKDEPCFLAGS])
1465AC_SUBST([MKDEPPROG])
1466
1467#
1468# -lxnet buys us one big porting headache...  standards, gotta love 'em.
1469#
1470# AC_CHECK_LIB(xnet, socket, ,
1471#    AC_CHECK_LIB(socket, socket)
1472# )
1473#
1474# Use this for now, instead:
1475#
1476case "$host" in
1477	*-linux*)
1478		;;
1479	*)
1480		AC_CHECK_LIB(socket, socket)
1481		AC_CHECK_LIB(nsl, inet_addr)
1482		;;
1483esac
1484
1485#
1486# Work around Solaris's select() limitations.
1487#
1488case "$host" in
1489	*-solaris2.[[89]]|*-solaris2.1?)
1490	AC_DEFINE(FD_SETSIZE, 65536,
1491		  [Solaris hack to get select_large_fdset.])
1492	;;
1493esac
1494
1495#
1496# Purify support
1497#
1498AC_MSG_CHECKING(whether to use purify)
1499
1500# Purify is not included in pairwise testing as that tool is not present
1501# in the relevant Docker image.
1502#
1503# [pairwise: skip]
1504AC_ARG_WITH(purify,
1505	    AS_HELP_STRING([--with-purify[=PATH]],[use Rational purify]),
1506	    use_purify="$withval", use_purify="no")
1507
1508case "$use_purify" in
1509	no)
1510		;;
1511	yes)
1512		AC_PATH_PROG(purify_path, purify, purify)
1513		;;
1514	*)
1515		purify_path="$use_purify"
1516		;;
1517esac
1518
1519case "$use_purify" in
1520	no)
1521		AC_MSG_RESULT(no)
1522		PURIFY=""
1523		;;
1524	*)
1525		if test -f "$purify_path" || test purify = "$purify_path"; then
1526			AC_MSG_RESULT($purify_path)
1527			PURIFYFLAGS="`echo $PURIFYOPTIONS`"
1528			PURIFY="$purify_path $PURIFYFLAGS"
1529		else
1530			AC_MSG_ERROR([$purify_path not found.
1531
1532Please choose the proper path with the following command:
1533
1534    configure --with-purify=PATH
1535])
1536		fi
1537		;;
1538esac
1539
1540AC_SUBST(PURIFY)
1541
1542#
1543# Google/Great Performance Tools CPU Profiler
1544#
1545AC_MSG_CHECKING(whether to use gperftools profiler)
1546
1547# Google/Great Performance Tools CPU Profiler is not included in
1548# pairwise testing as that tool is not present in the relevant Docker
1549# image.
1550#
1551# [pairwise: skip]
1552AC_ARG_WITH(gperftools-profiler,
1553	    AS_HELP_STRING([--with-gperftools-profiler],
1554			   [use gperftools CPU profiler]),
1555	    use_profiler="$withval", use_profiler="no")
1556
1557case $use_profiler in
1558	yes)
1559		AC_MSG_RESULT(yes)
1560		AC_DEFINE([HAVE_GPERFTOOLS_PROFILER], 1,
1561		[Define to use gperftools CPU profiler.])
1562		LIBS="$LIBS -lprofiler"
1563		;;
1564	*)
1565		AC_MSG_RESULT(no)
1566		;;
1567esac
1568
1569#
1570# enable/disable dumping stack backtrace.  Also check if the system supports
1571# glibc-compatible backtrace() function.
1572#
1573# [pairwise: --enable-backtrace, --disable-backtrace]
1574AC_ARG_ENABLE([backtrace],
1575	      [AS_HELP_STRING([--enable-backtrace],
1576			      [log stack backtrace on abort [default=yes]])],
1577	      [], [enable_backtrace="yes"])
1578
1579AS_IF([test "$enable_backtrace" = "yes"],
1580      [AC_DEFINE([USE_BACKTRACE], [1], [define if we can use backtrace])
1581       AC_CHECK_LIB(execinfo,backtrace,EXILIBS=-lexecinfo,EXILIBS=)
1582       LIBS="$LIBS $EXILIBS"
1583       AC_LINK_IFELSE(
1584	 [AC_LANG_PROGRAM(
1585	    [[#include <execinfo.h>]],
1586	    [[return (backtrace((void **)0, 0));]]
1587	  )],
1588	 [AC_DEFINE([HAVE_LIBCTRACE], [1], [define if system have backtrace function])],
1589	 [AC_LINK_IFELSE(
1590	    [AC_LANG_PROGRAM(
1591	       [[#include <stddef.h>]],
1592	       [[return _Unwind_Backtrace(NULL, NULL);]]
1593	     )],
1594	    [AC_DEFINE([HAVE_UNWIND_BACKTRACE], [1], [define if the compiler supports _Unwind_Backtrace()])]
1595	  )]
1596       )])
1597
1598# [pairwise: --enable-symtable, --disable-symtable]
1599AC_ARG_ENABLE(symtable,
1600	      AS_HELP_STRING([--enable-symtable],
1601			     [use internal symbol table for backtrace
1602			      [all|minimal(default)|none]]),
1603		want_symtable="$enableval",  want_symtable="minimal")
1604case $want_symtable in
1605yes|all|minimal)     # "yes" is a hidden value equivalent to "minimal"
1606	if test "" = "$PERL"
1607	then
1608		AC_MSG_ERROR([Internal symbol table requires perl but no perl is found.
1609Install perl or explicitly disable the feature by --disable-symtable.])
1610	fi
1611	if test "yes" = "$use_libtool"; then
1612		AC_MSG_WARN([Internal symbol table does not work with libtool.  Disabling symbol table.])
1613	else
1614		# we generate the internal symbol table only for those systems
1615		# known to work to avoid unexpected build failure.  Also, warn
1616		# about unsupported systems when the feature is enabled
1617		#  manually.
1618		case $host_os in
1619		freebsd*|netbsd*|openbsd*|linux*|solaris*|darwin*)
1620			MKSYMTBL_PROGRAM="$PERL"
1621			if test "all" = "$want_symtable"; then
1622				ALWAYS_MAKE_SYMTABLE="yes"
1623			fi
1624			;;
1625		*)
1626			if test "yes" = "$want_symtable" -o "all" = "$want_symtable"
1627			then
1628				AC_MSG_WARN([this system is not known to generate internal symbol table safely; disabling it])
1629			fi
1630		esac
1631	fi
1632	;;
1633*)
1634	;;
1635esac
1636AC_SUBST(MKSYMTBL_PROGRAM)
1637AC_SUBST(ALWAYS_MAKE_SYMTABLE)
1638
1639#
1640# File name extension for static archive files, for those few places
1641# where they are treated differently from dynamic ones.
1642#
1643SA=a
1644
1645AC_SUBST(O)
1646AC_SUBST(A)
1647AC_SUBST(SA)
1648AC_SUBST(LIBTOOL_MKDEP_SED)
1649AC_SUBST(LIBTOOL_MODE_COMPILE)
1650AC_SUBST(LIBTOOL_MODE_INSTALL)
1651AC_SUBST(LIBTOOL_MODE_LINK)
1652AC_SUBST(LIBTOOL_MODE_UNINSTALL)
1653
1654BIND9_CO_RULE=".c.$O:"
1655AC_SUBST(BIND9_CO_RULE)
1656
1657#
1658# Here begins a very long section to determine the system's networking
1659# capabilities.  The order of the tests is significant.
1660#
1661
1662#
1663# We do the IPv6 compilation checking after libtool so that we can put
1664# the right suffix on the files.
1665#
1666AC_MSG_CHECKING([for IPv6 structures])
1667AC_COMPILE_IFELSE(
1668  [AC_LANG_PROGRAM(
1669     [[
1670       #include <sys/types.h>
1671       #include <sys/socket.h>
1672       #include <netinet/in.h>
1673     ]],
1674     [[
1675       struct sockaddr_in6 sin6;
1676       struct in6_addr in6;
1677       struct in6_pktinfo in6_pi;
1678       struct sockaddr_storage storage;
1679       in6 = in6addr_any;
1680       in6 = in6addr_loopback;
1681       sin6.sin6_scope_id = 0;
1682       return (0);
1683     ]])],
1684  [AC_MSG_RESULT([yes])],
1685  [AC_MSG_FAILURE([IPv6 support is mandatory])])
1686
1687#
1688# Allow forcibly disabling TCP Fast Open support as autodetection might yield
1689# confusing results on some systems (e.g. FreeBSD; see set_tcp_fastopen()
1690# comment in lib/isc/unix/socket.c).
1691#
1692# [pairwise: --enable-tcp-fastopen, --disable-tcp-fastopen]
1693AC_ARG_ENABLE([tcp_fastopen],
1694	      [AS_HELP_STRING([--disable-tcp-fastopen],
1695			      [disable TCP Fast Open support [default=yes]])],
1696	     [], [enable_tcp_fastopen="yes"])
1697
1698AS_IF([test "$enable_tcp_fastopen" = "yes"],
1699      [AC_DEFINE([ENABLE_TCP_FASTOPEN], [1], [define if you want TCP_FASTOPEN enabled if available])])
1700
1701#
1702# Check for some other useful functions that are not ever-present.
1703#
1704AC_CHECK_FUNCS([strlcpy strlcat])
1705
1706AC_SUBST(READLINE_LIB)
1707
1708# [pairwise: --with-readline=auto, --with-readline=yes, --without-readline]
1709AC_ARG_WITH(readline,
1710	    AS_HELP_STRING([--with-readline[=LIBSPEC]],
1711			   [specify readline library [default auto]]),
1712	    use_readline="$withval", use_readline="auto")
1713case "$use_readline" in
1714no)	;;
1715*)
1716	saved_LIBS="$LIBS"
1717	case "$use_readline" in
1718	yes|auto) try_readline="-ledit"; or_readline="-lreadline" ;;
1719	*) try_readline="$use_readline"
1720	esac
1721	for readline in "$try_readline" $or_readline
1722	do
1723		LIBS="$readline"
1724		AC_MSG_NOTICE(checking for readline with $readline)
1725		AC_CHECK_FUNCS(readline)
1726		if test "yes" = "$ac_cv_func_readline"
1727		then
1728			READLINE_LIB="$readline"
1729			break
1730		fi
1731		for lib in -lterminfo -ltermcap -lncurses -lcurses
1732		do
1733			AC_MSG_NOTICE(checking for readline with $readline $lib)
1734			unset ac_cv_func_readline
1735			LIBS="$readline $lib"
1736			AC_CHECK_FUNCS(readline)
1737			if test "yes" = "$ac_cv_func_readline"
1738			then
1739				READLINE_LIB="$readline $lib"
1740				break
1741			fi
1742		done
1743		if test "yes" = "$ac_cv_func_readline"
1744		then
1745			break
1746		fi
1747	done
1748	if test "auto" != "$use_readline" &&
1749	   test "X$READLINE_LIB" = "X"
1750	then
1751		AC_MSG_ERROR([The readline library was not found.])
1752	fi
1753	LIBS="$saved_LIBS"
1754	;;
1755esac
1756if test "yes" = "$ac_cv_func_readline"
1757then
1758	case "$READLINE_LIB" in
1759	*edit*)
1760		AC_CHECK_HEADERS(editline/readline.h)
1761		AC_CHECK_HEADERS(edit/readline/readline.h)
1762		AC_CHECK_HEADERS(edit/readline/history.h)
1763		;;
1764	esac
1765	AC_CHECK_HEADERS(readline/readline.h)
1766	AC_CHECK_HEADERS(readline/history.h)
1767fi
1768
1769AC_SUBST(DST_EXTRA_OBJS)
1770AC_SUBST(DST_EXTRA_SRCS)
1771
1772#
1773# Security Stuff
1774#
1775# Note it is very recommended to *not* disable chroot(),
1776# this is only because chroot() was made obsolete by Posix.
1777#
1778# [pairwise: --enable-chroot, --disable-chroot]
1779AC_ARG_ENABLE(chroot, AS_HELP_STRING([--disable-chroot], [disable chroot]))
1780case "$enable_chroot" in
1781	yes|'')
1782		AC_CHECK_FUNCS(chroot)
1783		;;
1784	no)
1785		;;
1786esac
1787
1788LIBCAP_LIBS=""
1789AC_MSG_CHECKING([whether to enable Linux capabilities])
1790
1791# [pairwise: --enable-linux-caps, --disable-linux-caps]
1792AC_ARG_ENABLE([linux-caps],
1793	      [AS_HELP_STRING([--disable-linux-caps],
1794			      [disable Linux capabilities])],
1795	      [],
1796	      [AS_CASE([$host],
1797		       [*-linux*],[enable_linux_caps=yes],
1798		       [enable_linux_caps=no])])
1799
1800AS_IF([test "$enable_linux_caps" = "yes"],
1801      [AC_MSG_RESULT([yes])
1802       AC_CHECK_HEADERS([sys/capability.h],
1803			[],
1804			[AC_MSG_ERROR(m4_normalize([sys/capability.h header is required for Linux capabilities support.
1805						    Either install libcap or use --disable-linux-caps.]))])
1806       AX_SAVE_FLAGS([cap])
1807       AC_SEARCH_LIBS([cap_set_proc], [cap],
1808		      [LIBCAP_LIBS="$ac_cv_search_cap_set_proc"],
1809		      [AC_MSG_ERROR(m4_normalize([libcap is required for Linux capabilities support.
1810						  Either install libcap or use --disable-linux-caps.]))])
1811       AX_RESTORE_FLAGS([cap])],
1812      [AC_MSG_RESULT([no])])
1813AC_SUBST([LIBCAP_LIBS])
1814
1815AC_CHECK_HEADERS(sys/un.h,
1816ISC_PLATFORM_HAVESYSUNH="#define ISC_PLATFORM_HAVESYSUNH 1"
1817,
1818ISC_PLATFORM_HAVESYSUNH="#undef ISC_PLATFORM_HAVESYSUNH"
1819)
1820AC_SUBST(ISC_PLATFORM_HAVESYSUNH)
1821
1822case "$host" in
1823*-solaris*)
1824	AC_DEFINE(NEED_SECURE_DIRECTORY, 1,
1825		  [Define if connect does not honour the permission on the UNIX domain socket.])
1826	;;
1827esac
1828
1829#
1830# Time Zone Stuff
1831#
1832AC_CHECK_FUNCS([tzset])
1833
1834AC_MSG_CHECKING(for optarg declaration)
1835AC_TRY_COMPILE([
1836#include <unistd.h>
1837],
1838[optarg = 0;],
1839[AC_MSG_RESULT(yes)],
1840[AC_MSG_RESULT(no)
1841GEN_NEED_OPTARG="-DNEED_OPTARG=1"
1842AC_DEFINE(NEED_OPTARG, 1, [Defined if extern char *optarg is not declared.])])
1843
1844#
1845# Check for nanoseconds in file stats
1846#
1847AC_MSG_CHECKING([for st_mtim.tv_nsec])
1848AC_COMPILE_IFELSE(
1849  [AC_LANG_PROGRAM(
1850     [[#include <sys/fcntl.h>]],
1851     [[struct stat s;
1852       return(s.st_mtim.tv_nsec);
1853      ]])],
1854   [AC_DEFINE([HAVE_STAT_NSEC], [1], [define if struct stat has st_mtim.tv_nsec field])])
1855
1856#
1857# Check for if_nametoindex() for IPv6 scoped addresses support
1858#
1859AC_CHECK_FUNCS([if_nametoindex])
1860
1861ISC_ATOMIC_LIBS=""
1862AC_CHECK_HEADERS(
1863  [stdatomic.h],
1864  [AC_MSG_CHECKING([for memory model aware atomic operations])
1865   AC_COMPILE_IFELSE(
1866     [AC_LANG_PROGRAM(
1867	[[#include <stdatomic.h>]],
1868	[[atomic_int_fast32_t val = 0; atomic_fetch_add_explicit(&val, 1, memory_order_relaxed);]]
1869      )],
1870     [AC_MSG_RESULT([stdatomic.h])
1871      AC_MSG_CHECKING([whether -latomic is needed for 64-bit stdatomic.h functions])
1872      AC_LINK_IFELSE(
1873	[AC_LANG_PROGRAM(
1874	   [[#include <stdatomic.h>]],
1875	   [[atomic_int_fast64_t val = 0; atomic_fetch_add_explicit(&val, 1, memory_order_relaxed);]]
1876	 )],
1877	[AC_MSG_RESULT([no])],
1878	[ISC_ATOMIC_LIBS="-latomic"
1879	 AX_SAVE_FLAGS([atomic])
1880	 LIBS="$LIBS $ISC_ATOMIC_LIBS"
1881	 AC_LINK_IFELSE(
1882	   [AC_LANG_PROGRAM(
1883	      [[#include <stdatomic.h>]],
1884	      [[atomic_int_fast64_t val = 0; atomic_fetch_add_explicit(&val, 1, memory_order_relaxed);]]
1885	    )],
1886	   [AC_MSG_RESULT([yes])],
1887	   [AC_MSG_FAILURE([libatomic needed, but linking with -latomic failed, please fix your toolchain.])])
1888	 AX_RESTORE_FLAGS([atomic])
1889	])
1890     ],
1891     [AC_MSG_FAILURE([stdatomic.h header found, but compilation failed, please fix your toolchain.])]
1892   )],
1893  [AC_MSG_CHECKING([for memory model aware atomic operations])
1894   AC_COMPILE_IFELSE(
1895     [AC_LANG_PROGRAM(
1896	[[#include <inttypes.h>]],
1897	[[int32_t val = 0; __atomic_fetch_add(&val, 1, __ATOMIC_RELAXED);]]
1898      )],
1899     [AC_MSG_RESULT([__atomic builtins])
1900      AC_DEFINE([HAVE___ATOMIC], [1], [define if __atomic builtins are not available])
1901      AC_MSG_CHECKING([whether -latomic is needed for 64-bit __atomic builtins])
1902      AC_LINK_IFELSE(
1903	[AC_LANG_PROGRAM(
1904	   [[#include <inttypes.h>]],
1905	   [[int64_t val = 0; __atomic_fetch_add(&val, 1, __ATOMIC_RELAXED);]]
1906	 )],
1907	[AC_MSG_RESULT([no])],
1908	[ISC_ATOMIC_LIBS="-latomic"
1909	 AX_SAVE_FLAGS([atomic])
1910	 LIBS="$LIBS $ISC_ATOMIC_LIBS"
1911	 AC_LINK_IFELSE(
1912	   [AC_LANG_PROGRAM(
1913	      [[#include <inttypes.h>]],
1914	      [[int64_t val = 0; __atomic_fetch_add(&val, 1, __ATOMIC_RELAXED);]]
1915	    )],
1916	   [AC_MSG_RESULT([yes])],
1917	   [AC_MSG_FAILURE([libatomic needed, but linking with -latomic failed, please fix your toolchain.])])
1918	 AX_RESTORE_FLAGS([atomic])
1919	])
1920     ],
1921     [AC_MSG_RESULT([__sync builtins])
1922     ])
1923  ])
1924LIBS="$LIBS $ISC_ATOMIC_LIBS"
1925
1926AC_CHECK_HEADERS([stdalign.h])
1927
1928AC_CHECK_HEADERS([uchar.h])
1929
1930#
1931# Check for __builtin_unreachable
1932#
1933AC_MSG_CHECKING([compiler support for __builtin_unreachable()])
1934AC_LINK_IFELSE(
1935  [AC_LANG_PROGRAM(
1936     [[]],
1937     [[__builtin_unreachable();]]
1938   )],
1939  [AC_MSG_RESULT([yes])
1940   AC_DEFINE([HAVE_BUILTIN_UNREACHABLE], [1], [define if the compiler supports __builtin_unreachable().])
1941  ],
1942  [AC_MSG_RESULT([no])
1943  ])
1944
1945#
1946# Check for __builtin_expect
1947#
1948AC_MSG_CHECKING([compiler support for __builtin_expect])
1949AC_TRY_LINK(, [
1950	return (__builtin_expect(1, 1) ? 1 : 0);
1951], [
1952	have_builtin_expect=yes
1953	AC_MSG_RESULT(yes)
1954], [
1955	have_builtin_expect=no
1956	AC_MSG_RESULT(no)
1957])
1958if test "yes" = "$have_builtin_expect"; then
1959	AC_DEFINE(HAVE_BUILTIN_EXPECT, 1, [Define to 1 if the compiler supports __builtin_expect.])
1960fi
1961
1962#
1963# Check for __builtin_clz
1964#
1965AC_MSG_CHECKING([compiler support for __builtin_clz])
1966AC_TRY_LINK(, [
1967	return (__builtin_clz(0xff) == 24 ? 1 : 0);
1968], [
1969	have_builtin_clz=yes
1970	AC_MSG_RESULT(yes)
1971], [
1972	have_builtin_clz=no
1973	AC_MSG_RESULT(no)
1974])
1975if test "yes" = "$have_builtin_clz"; then
1976	AC_DEFINE(HAVE_BUILTIN_CLZ, 1, [Define to 1 if the compiler supports __builtin_clz.])
1977fi
1978
1979#
1980# Activate "rrset-order fixed" or not?
1981#
1982# [pairwise: --enable-fixed-rrset, --disable-fixed-rrset]
1983AC_ARG_ENABLE(fixed-rrset,
1984	      AS_HELP_STRING([--enable-fixed-rrset],
1985			     [enable fixed rrset ordering [default=no]]),
1986	      enable_fixed="$enableval", enable_fixed="no")
1987case "$enable_fixed" in
1988	yes)
1989		AC_DEFINE(DNS_RDATASET_FIXED, 1,
1990			  [Define to enable "rrset-order fixed" syntax.])
1991		;;
1992	no)
1993		;;
1994	*)
1995		;;
1996esac
1997
1998#
1999# Activate dnstap?
2000#
2001# [pairwise: --enable-dnstap, --disable-dnstap]
2002AC_ARG_ENABLE(dnstap,
2003	      AS_HELP_STRING([--enable-dnstap],
2004			     [enable dnstap support
2005				(requires fstrm, protobuf-c)]),
2006	      use_dnstap=$enableval, use_dnstap=no)
2007
2008DNSTAP=
2009DNSTAPSRCS=
2010DNSTAPOBJS=
2011DNSTAPTARGETS=
2012if test "x$use_dnstap" != "xno"; then
2013
2014	# [pairwise: skip]
2015	AC_ARG_WITH([protobuf-c],
2016		    AS_HELP_STRING([--with-protobuf-c=path],
2017				   [Path where protobuf-c is installed, for dnstap]), [
2018	    # workaround for protobuf-c includes at old dir
2019	    # before protobuf-c-1.0.0
2020	    if test -f $withval/include/google/protobuf-c/protobuf-c.h
2021	    then
2022		PROTOBUF_C_CFLAGS="-I$withval/include/google"
2023	    else
2024		PROTOBUF_C_CFLAGS="-I$withval/include"
2025	    fi
2026	    PROTOBUF_C_LIBS="-L$withval/lib"
2027	    AC_PATH_PROG([PROTOC_C], [protoc-c], [],
2028			 [$PATH$PATH_SEPARATOR$withval/bin])
2029	], [
2030	    # workaround for protobuf-c includes at old dir
2031	    # before protobuf-c-1.0.0
2032	    if test -f /usr/include/google/protobuf-c/protobuf-c.h
2033	    then
2034		PROTOBUF_C_CFLAGS="-I/usr/include/google"
2035	    else
2036		if test -f /usr/local/include/google/protobuf-c/protobuf-c.h
2037		then
2038		    PROTOBUF_C_CFLAGS="-I/usr/local/include/google"
2039		    PROTOBUF_C_LIBS="-L/usr/local/lib"
2040		elif test -f /opt/local/include/google/protobuf-c/protobuf-c.h
2041		then
2042		    PROTOBUF_C_CFLAGS="-I/opt/local/include/google"
2043		    PROTOBUF_C_LIBS="-L/opt/local/lib"
2044		fi
2045	    fi
2046	    AC_PATH_PROG([PROTOC_C],[protoc-c])
2047	])
2048	if test -z "$PROTOC_C"; then
2049		AC_MSG_ERROR([The protoc-c program was not found.])
2050	fi
2051
2052	# [pairwise: skip]
2053	AC_ARG_WITH([libfstrm], AS_HELP_STRING([--with-libfstrm=path],
2054		    [Path where libfstrm is installed, for dnstap]), [
2055	    FSTRM_CFLAGS="-I$withval/include"
2056	    FSTRM_LIBS="-L$withval/lib"
2057	    AC_PATH_PROG([FSTRM_CAPTURE], [fstrm_capture], [], [$PATH$PATH_SEPARATOR$withval/bin])
2058	],[
2059	    for d in /usr /usr/local /opt/local
2060	    do
2061		if test -f "${d}/include/fstrm.h"
2062		then
2063		    if test ${d} != /usr
2064		    then
2065			FSTRM_CFLAGS="-I${d}/include"
2066			FSTRM_LIBS="-L${d}/lib"
2067		    fi
2068		    have_fstrm="$d"
2069		    break
2070		fi
2071	    done
2072	    if test -z "$have_fstrm"; then
2073		AC_PATH_PROG([FSTRM_CAPTURE], [fstrm_capture])
2074	    else
2075		AC_PATH_PROG([FSTRM_CAPTURE], [fstrm_capture], [], [$PATH$PATH_SEPARATOR$have_fstrm/bin])
2076	    fi
2077	])
2078	AX_SAVE_FLAGS([dnstap])
2079	CFLAGS="$CFLAGS $PROTOBUF_C_CFLAGS $FSTRM_CFLAGS"
2080	LIBS="$LDFLAGS $PROTOBUF_C_LIBS $FSTRM_LIBS"
2081
2082	AC_SEARCH_LIBS([fstrm_iothr_init], [fstrm], [],
2083		       AC_MSG_ERROR([The fstrm library was not found. Please install fstrm!]))
2084	FSTRM_LIBS="$FSTRM_LIBS $ac_cv_search_fstrm_iothr_init"
2085
2086	AC_SEARCH_LIBS([protobuf_c_message_pack], [protobuf-c], [],
2087		       AC_MSG_ERROR([The protobuf-c library was not found. Please install protobuf-c!]))
2088	PROTOBUF_C_LIBS="$PROTOBUF_C_LIBS $ac_cv_search_protobuf_c_message_pack"
2089
2090	AX_RESTORE_FLAGS([dnstap])
2091	AC_DEFINE(HAVE_DNSTAP, 1, [Define to 1 to enable dnstap support])
2092	DNSTAP=dnstap
2093	DNSTAPSRCS='${DNSTAPSRCS}'
2094	DNSTAPOBJS='${DNSTAPOBJS}'
2095	DNSTAPTARGETS='${DNSTAPTARGETS}'
2096	DNSTAP_MANS='${dnstap_man1_MANS}'
2097fi
2098AC_SUBST(DNSTAP)
2099AC_SUBST(DNSTAPSRCS)
2100AC_SUBST(DNSTAPOBJS)
2101AC_SUBST(DNSTAPTARGETS)
2102AC_SUBST(DNSTAP_MANS)
2103AC_SUBST([PROTOBUF_C_CFLAGS])
2104AC_SUBST([PROTOBUF_C_LIBS])
2105AC_SUBST([FSTRM_CFLAGS])
2106AC_SUBST([FSTRM_LIBS])
2107
2108#
2109#  The following sets up how non-blocking i/o is established.
2110#  cygwin and solaris 2.x (x<5) require special handling.
2111#
2112case "$host" in
2113*-cygwin*) AC_DEFINE(PORT_NONBLOCK, O_NDELAY);;
2114*-solaris2.[[01234]])
2115	AC_DEFINE(PORT_NONBLOCK, O_NONBLOCK)
2116	AC_DEFINE(USE_FIONBIO_IOCTL, 1,
2117		  [Defined if you need to use ioctl(FIONBIO) instead a fcntl call to make non-blocking.])
2118	;;
2119*) AC_DEFINE(PORT_NONBLOCK, O_NONBLOCK,
2120	     [Sets which flag to pass to open/fcntl to make non-blocking (O_NDELAY/O_NONBLOCK).])
2121	;;
2122esac
2123#
2124# Solaris 2.5.1 and earlier cannot bind() then connect() a TCP socket.
2125# This prevents the source address being set.
2126#
2127case "$host" in
2128*-solaris2.[[012345]]|*-solaris2.5.1)
2129	AC_DEFINE(BROKEN_TCP_BIND_BEFORE_CONNECT, 1,
2130		  [Define if you cannot bind() before connect() for TCP sockets.])
2131	;;
2132esac
2133#
2134# The following sections deal with tools used for formatting
2135# the documentation.  They are all optional, unless you are
2136# a developer editing the documentation source.
2137#
2138
2139#
2140# The following sections deal with tools used for formatting
2141# the documentation.  They are all optional, unless you are
2142# a developer editing the documentation source.
2143#
2144
2145#
2146# Look for sphinx-build
2147#
2148AC_ARG_VAR([SPHINX_BUILD], [path to sphinx-build binary used to build the documentation])
2149AC_PATH_PROG([SPHINX_BUILD], [sphinx-build], [:])
2150AM_CONDITIONAL([HAVE_SPHINX_BUILD], [test "$SPHINX_BUILD" != ":"])
2151
2152AC_PATH_PROG([XELATEX], [xelatex], [:])
2153AC_PATH_PROG([LATEXMK], [latexmk], [:])
2154AM_CONDITIONAL([HAVE_XELATEX], [test "$XELATEX" != ":" && test "$LATEXMK" != ":"])
2155
2156#
2157# Pull release date from CHANGES file last modification date
2158# for reproducible builds
2159#
2160release_date=`date -u -r CHANGES +%Y-%m-%d`
2161AC_SUBST([RELEASE_DATE], $release_date)
2162
2163# Don't build the documentation if the sphinx-build is not present
2164PDFTARGET=
2165HTMLTARGET=
2166MANSRCS=
2167AS_IF([test -n "$SPHINX_BUILD"],[
2168	  MANSRCS='$(MANPAGES_IN)'
2169	  HTMLTARGET='html dirhtml'
2170	  AC_PATH_PROGS([PDFLATEX], [pdflatex], [])
2171	  AC_PATH_PROGS([LATEXMK], [latexmk], [])
2172	  AS_IF([test -n "$PDFLATEX" && test -n "$LATEXMK"],[
2173		    PDFTARGET='pdf'
2174		])
2175      ])
2176AC_SUBST([HTMLTARGET])
2177AC_SUBST([PDFTARGET])
2178AC_SUBST([MANSRCS])
2179
2180#
2181# Look for Doxygen
2182#
2183AC_PATH_PROGS([DOXYGEN], [doxygen])
2184AC_SUBST(DOXYGEN)
2185
2186#
2187# Look for curl
2188#
2189
2190AC_PATH_PROG(CURL, curl, curl)
2191AC_SUBST(CURL)
2192
2193#
2194# Look for xsltproc
2195#
2196
2197AC_PATH_PROG(XSLTPROC, xsltproc, xsltproc)
2198AC_SUBST(XSLTPROC)
2199
2200#
2201# IDN support using libidn2
2202#
2203
2204LIBIDN2_CFLAGS=
2205LIBIDN2_LDFLAGS=
2206LIBIDN2_LIBS=
2207
2208# [pairwise: --with-libidn2=yes, --without-libidn2]
2209AC_ARG_WITH([libidn2],
2210	    [AS_HELP_STRING([--with-libidn2[=PATH]], [enable IDN support using GNU libidn2 [yes|no(default)|path]])],
2211	    [with_libidn2="$withval"], [with_libidn2="no"])
2212AS_CASE([$with_libidn2],
2213	[yes],	[PKG_CHECK_MODULES([LIBIDN2], [libidn2],
2214				   [AC_DEFINE([HAVE_LIBIDN2], [1], [Define if libidn2 was found])])],
2215	[no],	[],
2216	[*],	[AX_SAVE_FLAGS([libidn2])
2217		 LIBIDN2_CFLAGS="-I$with_libidn2/include"
2218		 LIBIDN2_LDFLAGS="-L$with_libidn2/lib"
2219		 CFLAGS="$LIBIDN2_CFLAGS $CFLAGS"
2220		 CPPFLAGS="$LIBIDN2_CFLAGS $CPPFLAGS"
2221		 LDFLAGS="$LIBIDN2_LDFLAGS $LDFLAGS"
2222		 AC_CHECK_HEADERS([idn2.h],
2223				  [],
2224				  [AC_MSG_ERROR([idn2.h not found])])
2225		 AC_SEARCH_LIBS([idn2_to_ascii_lz], [idn2],
2226				[LIBIDN2_LIBS="$ac_cv_search_idn2_to_ascii_lz"
2227				 AC_DEFINE([HAVE_LIBIDN2], [1], [Define if libidn2 was found])],
2228				[AC_MSG_ERROR([libidn2 requested, but not found])])
2229		AX_RESTORE_FLAGS([libidn2])])
2230AC_SUBST([LIBIDN2_CFLAGS])
2231AC_SUBST([LIBIDN2_LDFLAGS])
2232AC_SUBST([LIBIDN2_LIBS])
2233
2234#
2235# Check whether to build with cmocka unit testing framework
2236#
2237# [pairwise: --with-cmocka=detect, --with-cmocka=yes, --without-cmocka]
2238AC_ARG_WITH([cmocka],
2239	    [AS_HELP_STRING([--with-cmocka=detect],[enable CMocka based tests (default is detect)])],
2240	    [],[with_cmocka=detect])
2241
2242AS_CASE([$with_cmocka],
2243	[no],[],
2244	[detect],[PKG_CHECK_MODULES([CMOCKA], [cmocka >= 1.1.3],
2245				    [AC_DEFINE([HAVE_CMOCKA], [1], [Use CMocka])
2246				     with_cmocka=yes],[with_cmocka=no])],
2247	[yes],[PKG_CHECK_MODULES([CMOCKA], [cmocka >= 1.1.3],
2248				 [AC_DEFINE([HAVE_CMOCKA], [1], [Use CMocka])])],
2249	[AC_MSG_ERROR([Use PKG_CONFIG_PATH to specify path to CMocka library])]
2250       )
2251AC_SUBST([CMOCKA_CFLAGS])
2252AC_SUBST([CMOCKA_LIBS])
2253
2254AC_DEFINE([SKIPPED_TEST_EXIT_CODE], [0], [Exit code for skipped tests])
2255
2256#
2257# Check for kyua execution engine if CMocka was requested
2258# and bail out if execution engine was not found
2259#
2260AC_ARG_VAR([KYUA], [path to kyua execution engine])
2261AS_IF([test "$with_cmocka" != "no"],
2262      [AC_PATH_PROGS([KYUA], [kyua], [])
2263       AS_IF([test -z "$KYUA"],
2264             [AC_MSG_WARN([kyua test execution engine not found])],
2265             [UNITTESTS=tests])])
2266AC_SUBST([KYUA])
2267AC_SUBST([UNITTESTS])
2268
2269#
2270# Check for -Wl,--wrap= support
2271#
2272
2273LD_WRAP_TESTS=false
2274AC_MSG_CHECKING([for linker support for --wrap option])
2275AX_SAVE_FLAGS([wrap])
2276LDFLAGS="-Wl,--wrap,exit"
2277AC_LINK_IFELSE(
2278    [AC_LANG_PROGRAM([[#include <stdlib.h>
2279		       void __real_exit (int status);
2280		       void __wrap_exit (int status) { __real_exit (0); }
2281		      ]],
2282		     [[exit (1);]])],
2283    [LD_WRAP_TESTS=true
2284     AC_DEFINE([LD_WRAP], [1], [define if the linker supports --wrap option])
2285     AC_MSG_RESULT([yes])],
2286    [AC_MSG_RESULT([no])])
2287AX_RESTORE_FLAGS([wrap])
2288
2289AC_SUBST([LD_WRAP_TESTS])
2290
2291#
2292# Check for i18n
2293#
2294AC_CHECK_HEADERS(locale.h)
2295AC_CHECK_FUNCS(setlocale)
2296
2297#
2298# was --with-tuning specified?
2299#
2300# [pairwise: --with-tuning=small, --without-tuning]
2301AC_ARG_WITH([tuning],
2302	    AS_HELP_STRING([--with-tuning=ARG],
2303			   [Specify server tuning (default or small)]),
2304	    [],[with_tuning=no])
2305
2306AS_CASE([$with_tuning],
2307	[small],[AC_MSG_NOTICE(using small system tuning)],
2308	[AC_DEFINE(TUNE_LARGE, 1, [Define to use default system tuning.])
2309	 AC_MSG_NOTICE(using default system tuning)])
2310
2311#
2312# was --enable-querytrace specified?
2313#
2314# [pairwise: --enable-querytrace, --disable-querytrace]
2315AC_ARG_ENABLE(querytrace,
2316	      AS_HELP_STRING([--enable-querytrace],
2317			     [enable very verbose query trace logging
2318				[default=no]]),
2319	      want_querytrace="$enableval", want_querytrace="no")
2320
2321AC_MSG_CHECKING([whether to enable query trace logging])
2322case "$want_querytrace" in
2323yes)
2324	AC_MSG_RESULT(yes)
2325	AC_DEFINE(WANT_QUERYTRACE, 1, [Define to enable very verbose query trace logging.])
2326	;;
2327no)
2328	AC_MSG_RESULT(no)
2329	;;
2330*)
2331	AC_MSG_ERROR("--enable-querytrace requires yes or no")
2332	;;
2333esac
2334
2335#
2336# Was --disable-auto-validation specified?
2337#
2338
2339validation_default=auto
2340
2341# [pairwise: --enable-auto-validation, --disable-auto-validation]
2342AC_ARG_ENABLE(auto-validation,
2343	      AS_HELP_STRING([--enable-auto-validation],
2344			     [turn on DNSSEC validation by default, using the IANA root key [default=yes]]),
2345	      [:],[enable_auto_validation=yes])
2346AS_IF([test "$enable_auto_validation" = "no"],[validation_default=yes])
2347AC_DEFINE_UNQUOTED([VALIDATION_DEFAULT], ["$validation_default"], [the default value of dnssec-validation option])
2348
2349#
2350# Substitutions
2351#
2352AC_SUBST(BIND9_TOP_BUILDDIR)
2353BIND9_TOP_BUILDDIR=`pwd`
2354
2355AC_SUBST(BIND9_ISC_BUILDINCLUDE)
2356AC_SUBST(BIND9_ISCCC_BUILDINCLUDE)
2357AC_SUBST(BIND9_ISCCFG_BUILDINCLUDE)
2358AC_SUBST(BIND9_DNS_BUILDINCLUDE)
2359AC_SUBST(BIND9_NS_BUILDINCLUDE)
2360AC_SUBST(BIND9_BIND9_BUILDINCLUDE)
2361AC_SUBST(BIND9_IRS_BUILDINCLUDE)
2362if test "X$srcdir" != "X"; then
2363	BIND9_ISC_BUILDINCLUDE="-I${BIND9_TOP_BUILDDIR}/lib/isc/include"
2364	BIND9_ISCCC_BUILDINCLUDE="-I${BIND9_TOP_BUILDDIR}/lib/isccc/include"
2365	BIND9_ISCCFG_BUILDINCLUDE="-I${BIND9_TOP_BUILDDIR}/lib/isccfg/include"
2366	BIND9_DNS_BUILDINCLUDE="-I${BIND9_TOP_BUILDDIR}/lib/dns/include"
2367	BIND9_NS_BUILDINCLUDE="-I${BIND9_TOP_BUILDDIR}/lib/ns/include"
2368	BIND9_BIND9_BUILDINCLUDE="-I${BIND9_TOP_BUILDDIR}/lib/bind9/include"
2369	BIND9_IRS_BUILDINCLUDE="-I${BIND9_TOP_BUILDDIR}/lib/irs/include"
2370else
2371	BIND9_ISC_BUILDINCLUDE=""
2372	BIND9_ISCCC_BUILDINCLUDE=""
2373	BIND9_ISCCFG_BUILDINCLUDE=""
2374	BIND9_DNS_BUILDINCLUDE=""
2375	BIND9_NS_BUILDINCLUDE=""
2376	BIND9_BIND9_BUILDINCLUDE=""
2377	BIND9_IRS_BUILDINCLUDE=""
2378fi
2379
2380AC_SUBST_FILE(BIND9_MAKE_INCLUDES)
2381BIND9_MAKE_INCLUDES=$BIND9_TOP_BUILDDIR/make/includes
2382
2383AC_SUBST_FILE(BIND9_MAKE_RULES)
2384BIND9_MAKE_RULES=$BIND9_TOP_BUILDDIR/make/rules
2385
2386. "$srcdir/version"
2387BIND9_PRODUCT="PRODUCT=\"${PRODUCT}\""
2388AC_SUBST(BIND9_PRODUCT)
2389BIND9_DESCRIPTION="DESCRIPTION=\"${DESCRIPTION}\""
2390AC_SUBST(BIND9_DESCRIPTION)
2391BIND9_VERSION="${MAJORVER}.${MINORVER}${PATCHVER:+.}${PATCHVER}${RELEASETYPE}${RELEASEVER}${EXTENSIONS}"
2392AC_SUBST(BIND9_VERSION)
2393BIND9_MAJOR="MAJOR=${MAJORVER}.${MINORVER}"
2394AC_SUBST(BIND9_MAJOR)
2395BIND9_VERSIONSTRING="${PRODUCT} ${MAJORVER}.${MINORVER}${PATCHVER:+.}${PATCHVER}${RELEASETYPE}${RELEASEVER}${EXTENSIONS}${DESCRIPTION:+ }${DESCRIPTION}"
2396AC_SUBST(BIND9_VERSIONSTRING)
2397
2398BIND9_SRCID="SRCID=unset_id"
2399if test -f "${srcdir}/srcid"; then
2400	. "${srcdir}/srcid"
2401	BIND9_SRCID="SRCID=$SRCID"
2402elif test -d "${srcdir}/.git"; then
2403	BIND9_SRCID="SRCID="`(cd "${srcdir}";git rev-parse --short HEAD)`
2404fi
2405
2406AC_SUBST(BIND9_SRCID)
2407
2408if test -z "$ac_configure_args"; then
2409	BIND9_CONFIGARGS="defaults"
2410else
2411	for a in $ac_configure_args
2412	do
2413		BIND9_CONFIGARGS="$BIND9_CONFIGARGS $a"
2414	done
2415fi
2416BIND9_CONFIGARGS="`echo $BIND9_CONFIGARGS | sed 's/^ //'`"
2417BIND9_CONFIGARGS="CONFIGARGS=${BIND9_CONFIGARGS}"
2418AC_SUBST(BIND9_CONFIGARGS)
2419
2420AC_SUBST_FILE(LIBDNS_MAPAPI)
2421LIBDNS_MAPAPI="$srcdir/lib/dns/mapapi"
2422
2423#
2424# Configure any DLZ drivers.
2425#
2426# If config.dlz.in selects one or more DLZ drivers, it will set
2427# CONTRIB_DLZ to a non-empty value, which will be our clue to
2428# build DLZ drivers in contrib.
2429#
2430# This section has to come after the libtool stuff because it needs to
2431# know how to name the driver object files.
2432#
2433
2434CONTRIB_DLZ=""
2435DLZ_DRIVER_INCLUDES=""
2436DLZ_DRIVER_LIBS=""
2437DLZ_DRIVER_SRCS=""
2438DLZ_DRIVER_OBJS=""
2439DLZ_SYSTEM_TEST=""
2440DLZ_DRIVER_MYSQL_INCLUDES=""
2441DLZ_DRIVER_MYSQL_LIBS=""
2442
2443#
2444# Configure support for building a shared library object
2445#
2446# Even when libtool is available it can't always be relied upon
2447# to build an object that can be dlopen()'ed, but this is necessary
2448# for building the dlzexternal system test, so we'll try it the
2449# old-fashioned way.
2450#
2451SO="so"
2452SO_CFLAGS=""
2453SO_LDFLAGS=""
2454SO_LD=""
2455SO_TARGETS=""
2456SO_STRIP="cat"
2457
2458# [pairwise: skip]
2459AC_ARG_WITH([dlopen],
2460	    AS_HELP_STRING([--with-dlopen=ARG],
2461			   [support dynamically loadable DLZ and DYNDB drivers]),
2462	    [], [with_dlopen="auto"])
2463
2464
2465#
2466# If PIC is disabled, dlopen must also be
2467#
2468AS_IF([test "$pic_mode" = "no"],
2469      [AS_CASE([$with_dlopen],
2470	       [auto],[with_dlopen="no"],
2471	       [yes],[AC_MSG_ERROR([--with-dlopen requires PIC])])])
2472
2473AS_CASE([$with_dlopen],
2474	[auto|yes],[
2475	  # -fsanitize=thread hijacks dlopen and dlclose so use dlsym.
2476	  AC_SEARCH_LIBS([dlsym],[dl])
2477	  AC_CHECK_FUNCS([dlopen dlclose dlsym],
2478			 [with_dlopen="yes"],
2479			 [with_dlopen="no"])
2480	])
2481
2482AS_IF([test "$with_dlopen" = "yes"],
2483      [AS_CASE([$host],
2484	       [*-linux*|*-gnu*],[
2485		 LDFLAGS="${LDFLAGS} -Wl,--export-dynamic"
2486		 SO_CFLAGS="-fPIC"
2487		 SO_LDFLAGS=""
2488		 AS_IF([test "$use_libtool" = "yes"],[
2489			 SO_LDFLAGS="-Xcompiler -shared"
2490			 SO_LD="${CC}"
2491		       ],[
2492			 SO_LDFLAGS="-shared"
2493			 SO_LD="${CC}"
2494		       ])
2495	       ],
2496	       [*-freebsd*|*-openbsd*|*-netbsd*],[
2497		 LDFLAGS="${LDFLAGS} -Wl,-E"
2498		 SO_CFLAGS="-fpic"
2499		 AS_IF([test "$use_libtool" = "yes"],[
2500			 SO_LDFLAGS="-Xcompiler -shared"
2501			 SO_LD="${CC}"
2502		       ],[
2503			 SO_LDFLAGS="-shared"
2504			 SO_LD="${CC}"
2505		       ])
2506	       ],
2507	       [*-darwin*],[
2508		 SO_CFLAGS="-fPIC"
2509                 SO_LD="${CC}"
2510		 AS_IF([test "$use_libtool" = "yes"],[
2511			 SO_LDFLAGS="-Xcompiler -dynamiclib -undefined dynamic_lookup"
2512		       ],[
2513			 SO_LDFLAGS="-dynamiclib -undefined dynamic_lookup"
2514		       ])
2515	       ],
2516	       [*-solaris*],[
2517		 SO_CFLAGS="-KPIC"
2518		 SO_LDFLAGS="-G -z text"
2519		 SO_LD="ld"
2520	       ],
2521	       [ia64-hp-hpux*],[
2522		 SO_CFLAGS="+z"
2523	         SO_LDFLAGS="-b"
2524		 SO_LD="${CC}"
2525	       ],
2526	       [
2527		 SO_CFLAGS="-fPIC"
2528	       ])
2529       AS_IF([test "$GCC" = "yes"],[
2530	       SO_CFLAGS="-fPIC"
2531	       AS_IF([test -z "$SO_LD"],
2532		     [AS_IF([test "$use_libtool" = "yes"],[
2533			      SO_LDFLAGS="-Xcompiler -shared"
2534			      SO_LD="${CC}"
2535			    ],[
2536			      SO_LDFLAGS="-shared"
2537			      SO_LD="${CC}"
2538			    ])
2539		     ])
2540	     ])
2541       # If we still don't know how to make shared objects, don't make any.
2542       AS_IF([test -n "$SO_LD"],
2543	     [SO_TARGETS="\${SO_TARGETS}"
2544	      AC_DEFINE([ISC_DLZ_DLOPEN], [1],
2545			[Define to allow building of objects for dlopen().])
2546	     ])
2547      ])
2548
2549AS_IF([test "$with_dlopen" = "no" -a "$enable_native_pkcs11" = "yes"],
2550      [AC_MSG_ERROR([PKCS11 requires dlopen() support])])
2551
2552CFLAGS="$CFLAGS $SO_CFLAGS"
2553
2554AC_SUBST(SO)
2555AC_SUBST(SO_CFLAGS)
2556AC_SUBST(SO_LDFLAGS)
2557AC_SUBST(SO_LD)
2558AC_SUBST(SO_STRIP)
2559AC_SUBST(SO_TARGETS)
2560
2561#
2562# Response policy rewriting using DNS Response Policy Service (DNSRPS)
2563# interface.
2564#
2565# DNSRPS can be compiled into BIND everywhere with a reasonably
2566# modern C compiler.  It is enabled on systems with dlopen() and librpz.so.
2567#
2568dnsrps_avail=yes
2569AC_MSG_CHECKING([for librpz __attribute__s])
2570AC_COMPILE_IFELSE(
2571  [AC_LANG_PROGRAM(
2572     [[]],
2573     [[
2574       extern void f(char *p __attribute__((unused)), ...)
2575       __attribute__((format(printf,1,2))) __attribute__((__noreturn__));
2576     ]])],
2577  [
2578    librpz_have_attr=yes
2579    AC_DEFINE([LIBRPZ_HAVE_ATTR], [1], [have __attribute__s used in librpz.h])
2580    AC_MSG_RESULT([yes])
2581  ],[
2582    librpz_have_attr=no
2583    AC_MSG_RESULT([no])
2584  ])
2585
2586# DNSRPS is not included in pairwise testing as the librpz library is not
2587# present in the relevant Docker image.
2588#
2589# [pairwise: skip]
2590AC_ARG_ENABLE([dnsrps-dl],
2591	      [AS_HELP_STRING([--enable-dnsrps-dl],
2592			      [DNS Response Policy Service delayed link
2593			       [default=$librpz_dl]])],
2594	      [enable_librpz_dl="$enableval"], [enable_librpz_dl="$with_dlopen"])
2595
2596AS_IF([test "$enable_librpz_dl" = "yes" -a "$with_dlopen" = "no"],
2597      [AC_MSG_ERROR([DNS Response Policy Service delayed link requires dlopen to be enabled])])
2598
2599# [pairwise: skip]
2600AC_ARG_WITH([dnsrps-libname],
2601	    [AS_HELP_STRING([--with-dnsrps-libname],
2602			    [DNSRPS provider library name (librpz.so)])],
2603	    [librpz_name="$withval"], [librpz_name="librpz.so"])
2604
2605# [pairwise: skip]
2606AC_ARG_WITH([dnsrps-dir],
2607	    [AS_HELP_STRING([--with-dnsrps-dir],
2608			    [path to DNSRPS provider library])],
2609	    [librpz_path="$withval/$librpz_name"], [librpz_path="$librpz_name"])
2610AC_DEFINE_UNQUOTED([DNSRPS_LIBRPZ_PATH], ["$librpz_path"],
2611		   [dnsrps $librpz_name])
2612AS_IF([test "$enable_librpz_dl" = "yes"],
2613      [
2614	dnsrps_lib_open=2
2615      ],[
2616	dnsrps_lib_open=1
2617	# Add librpz.so to linked libraries if we are not using dlopen()
2618	AC_SEARCH_LIBS([librpz_client_create], [rpz], [],
2619		[dnsrps_lib_open=0
2620		 dnsrps_avail=no])
2621      ])
2622AC_DEFINE_UNQUOTED([DNSRPS_LIB_OPEN], [$dnsrps_lib_open],
2623		   [0=no DNSRPS  1=static link  2=dlopen()])
2624
2625# [pairwise: skip]
2626AC_ARG_ENABLE([dnsrps],
2627	      AS_HELP_STRING([--enable-dnsrps],
2628			     [enable DNS Response Policy Service API]),
2629	      [enable_dnsrps=$enableval], [enable_dnsrps=no])
2630
2631AS_IF([test "$enable_dnsrps" != "no"],[
2632	AS_IF([test "$dnsrps_avail" != "yes"],
2633	      [AC_MSG_ERROR([dlopen and librpz.so needed for DNSRPS])])
2634	AS_IF([test "$dnsrps_lib_open" = "0"],
2635	      [AC_MSG_ERROR([dlopen and librpz.so needed for DNSRPS])])
2636	AC_DEFINE([USE_DNSRPS], [1], [Enable DNS Response Policy Service API])
2637      ])
2638
2639sinclude(contrib/dlz/config.dlz.in)
2640AC_MSG_CHECKING(contributed DLZ drivers)
2641
2642#
2643# Support for constructor and destructor attributes
2644#
2645AX_GCC_FUNC_ATTRIBUTE([constructor])
2646AX_GCC_FUNC_ATTRIBUTE([destructor])
2647
2648if test -n "$CONTRIB_DLZ"
2649then
2650	AC_MSG_RESULT(yes)
2651	DLZ_DRIVER_RULES=contrib/dlz/drivers/rules
2652	AC_CONFIG_FILES([$DLZ_DRIVER_RULES
2653		contrib/dlz/modules/mysql/Makefile
2654		contrib/dlz/modules/mysqldyn/Makefile])
2655else
2656	AC_MSG_RESULT(no)
2657	DLZ_DRIVER_RULES=/dev/null
2658fi
2659
2660AC_SUBST(CONTRIB_DLZ)
2661AC_SUBST(DLZ_DRIVER_INCLUDES)
2662AC_SUBST(DLZ_DRIVER_LIBS)
2663AC_SUBST(DLZ_DRIVER_SRCS)
2664AC_SUBST(DLZ_DRIVER_OBJS)
2665AC_SUBST(DLZ_SYSTEM_TEST)
2666AC_SUBST(DLZ_DRIVER_MYSQL_INCLUDES)
2667AC_SUBST(DLZ_DRIVER_MYSQL_LIBS)
2668AC_SUBST_FILE(DLZ_DRIVER_RULES)
2669
2670if test "yes" = "$cross_compiling"; then
2671	if test -z "$BUILD_CC"; then
2672		AC_MSG_ERROR([BUILD_CC not set])
2673	fi
2674	BUILD_CFLAGS="$BUILD_CFLAGS"
2675	BUILD_CPPFLAGS="$BUILD_CPPFLAGS"
2676	BUILD_LDFLAGS="$BUILD_LDFLAGS"
2677	BUILD_LIBS="$BUILD_LIBS"
2678else
2679	BUILD_CC="$CC"
2680	BUILD_CFLAGS="$CFLAGS"
2681	BUILD_CPPFLAGS="$CPPFLAGS $GEN_NEED_OPTARG"
2682	BUILD_LDFLAGS="$LDFLAGS"
2683	BUILD_LIBS="$LIBS"
2684fi
2685
2686NEWFLAGS=""
2687for e in $BUILD_LDFLAGS ; do
2688    case $e in
2689	-L*)
2690	    case $host_os in
2691		netbsd*)
2692		    ee=`echo $e | sed -e 's%^-L%-Wl,-rpath,%'`
2693		    NEWFLAGS="$NEWFLAGS $e $ee"
2694		    ;;
2695		freebsd*)
2696		    ee=`echo $e | sed -e 's%^-L%-Wl,-rpath,%'`
2697		    NEWFLAGS="$NEWFLAGS $e $ee"
2698		    ;;
2699		solaris*)
2700		    ee=`echo $e | sed -e 's%^-L%-R%'`
2701		    NEWFLAGS="$NEWFLAGS $e $ee"
2702		    ;;
2703		*)
2704		    NEWFLAGS="$NEWFLAGS $e"
2705		    ;;
2706		esac
2707	    ;;
2708	*)
2709	    NEWFLAGS="$NEWFLAGS $e"
2710	    ;;
2711    esac
2712done
2713BUILD_LDFLAGS="$NEWFLAGS"
2714
2715NEWFLAGS=""
2716for e in $DNS_GSSAPI_LIBS ; do
2717    case $e in
2718	-L*)
2719	    case $host_os in
2720		netbsd*)
2721		    ee=`echo $e | sed -e 's%^-L%-Wl,-rpath,%'`
2722		    NEWFLAGS="$NEWFLAGS $e $ee"
2723		    ;;
2724		freebsd*)
2725		    ee=`echo $e | sed -e 's%^-L%-Wl,-rpath,%'`
2726		    NEWFLAGS="$NEWFLAGS $e $ee"
2727		    ;;
2728		solaris*)
2729		    ee=`echo $e | sed -e 's%^-L%-R%'`
2730		    NEWFLAGS="$NEWFLAGS $e $ee"
2731		    ;;
2732		*)
2733		    NEWFLAGS="$NEWFLAGS $e"
2734		    ;;
2735		esac
2736	    ;;
2737	*)
2738	    NEWFLAGS="$NEWFLAGS $e"
2739	    ;;
2740    esac
2741done
2742DNS_GSSAPI_LIBS="$NEWFLAGS"
2743
2744NEWFLAGS=""
2745for e in $ISC_OPENSSL_LIBS ; do
2746    case $e in
2747	-L*)
2748	    case $host_os in
2749		netbsd*)
2750		    ee=`echo $e | sed -e 's%^-L%-Wl,-rpath,%'`
2751		    NEWFLAGS="$NEWFLAGS $e $ee"
2752		    ;;
2753		freebsd*)
2754		    ee=`echo $e | sed -e 's%^-L%-Wl,-rpath,%'`
2755		    NEWFLAGS="$NEWFLAGS $e $ee"
2756		    ;;
2757		solaris*)
2758		    ee=`echo $e | sed -e 's%^-L%-R%'`
2759		    NEWFLAGS="$NEWFLAGS $e $ee"
2760		    ;;
2761		*)
2762		    NEWFLAGS="$NEWFLAGS $e"
2763		    ;;
2764		esac
2765	    ;;
2766	*)
2767	    NEWFLAGS="$NEWFLAGS $e"
2768	    ;;
2769    esac
2770done
2771ISC_OPENSSL_LIBS="$NEWFLAGS"
2772
2773NEWFLAGS=""
2774for e in $DNS_CRYPTO_LIBS ; do
2775    case $e in
2776	-L*)
2777	    case $host_os in
2778		netbsd*)
2779		    ee=`echo $e | sed -e 's%^-L%-Wl,-rpath,%'`
2780		    NEWFLAGS="$NEWFLAGS $e $ee"
2781		    ;;
2782		freebsd*)
2783		    ee=`echo $e | sed -e 's%^-L%-Wl,-rpath,%'`
2784		    NEWFLAGS="$NEWFLAGS $e $ee"
2785		    ;;
2786		solaris*)
2787		    ee=`echo $e | sed -e 's%^-L%-R%'`
2788		    NEWFLAGS="$NEWFLAGS $e $ee"
2789		    ;;
2790		*)
2791		    NEWFLAGS="$NEWFLAGS $e"
2792		    ;;
2793		esac
2794	    ;;
2795	*)
2796	    NEWFLAGS="$NEWFLAGS $e"
2797	    ;;
2798    esac
2799done
2800DNS_CRYPTO_LIBS="$NEWFLAGS"
2801
2802AC_SUBST(BUILD_CC)
2803AC_SUBST(BUILD_CFLAGS)
2804AC_SUBST(BUILD_CPPFLAGS)
2805AC_SUBST(BUILD_LDFLAGS)
2806AC_SUBST(BUILD_LIBS)
2807
2808#
2809# Commands to run at the end of config.status.
2810# Don't just put these into configure, it won't work right if somebody
2811# runs config.status directly (which autoconf allows).
2812#
2813
2814AC_CONFIG_COMMANDS(
2815	[chmod],
2816	[chmod a+x doc/doxygen/doxygen-input-filter])
2817
2818#
2819# Files to configure.  These are listed here because we used to
2820# specify them as arguments to AC_OUTPUT.  It's (now) ok to move these
2821# elsewhere if there's a good reason for doing so.
2822#
2823
2824AC_CONFIG_FILES([
2825	Makefile
2826	bin/Makefile
2827	bin/check/Makefile
2828	bin/confgen/Makefile
2829	bin/confgen/unix/Makefile
2830	bin/delv/Makefile
2831	bin/dig/Makefile
2832	bin/dnssec/Makefile
2833	bin/named/Makefile
2834	bin/named/unix/Makefile
2835	bin/nsupdate/Makefile
2836	bin/pkcs11/Makefile
2837	bin/plugins/Makefile
2838	bin/python/Makefile
2839	bin/python/dnssec-checkds.py
2840	bin/python/dnssec-coverage.py
2841	bin/python/dnssec-keymgr.py
2842	bin/python/isc/Makefile
2843	bin/python/isc/__init__.py
2844	bin/python/isc/checkds.py
2845	bin/python/isc/coverage.py
2846	bin/python/isc/dnskey.py
2847	bin/python/isc/eventlist.py
2848	bin/python/isc/keydict.py
2849	bin/python/isc/keyevent.py
2850	bin/python/isc/keymgr.py
2851	bin/python/isc/keyseries.py
2852	bin/python/isc/keyzone.py
2853	bin/python/isc/policy.py
2854	bin/python/isc/rndc.py
2855	bin/python/isc/tests/Makefile
2856	bin/python/isc/tests/dnskey_test.py
2857	bin/python/isc/tests/policy_test.py
2858	bin/python/isc/utils.py
2859	bin/rndc/Makefile
2860	bin/tests/Makefile
2861	bin/tests/headerdep_test.sh
2862	bin/tests/optional/Makefile
2863	bin/tests/pkcs11/Makefile
2864	bin/tests/pkcs11/benchmarks/Makefile
2865	bin/tests/system/Makefile
2866	bin/tests/system/conf.sh
2867	bin/tests/system/dlzexternal/Makefile
2868	bin/tests/system/dlzexternal/ns1/dlzs.conf
2869	bin/tests/system/dyndb/Makefile
2870	bin/tests/system/dyndb/driver/Makefile
2871	bin/tests/system/pipelined/Makefile
2872	bin/tests/system/rndc/Makefile
2873	bin/tests/system/rpz/Makefile
2874	bin/tests/system/rsabigexponent/Makefile
2875	bin/tests/system/tkey/Makefile
2876	bin/tools/Makefile
2877	contrib/scripts/check-secure-delegation.pl
2878	contrib/scripts/zone-edit.sh
2879	doc/Makefile
2880	doc/arm/Makefile
2881	doc/doxygen/Doxyfile
2882	doc/doxygen/Makefile
2883	doc/doxygen/doxygen-input-filter
2884	doc/man/Makefile
2885	doc/misc/Makefile
2886	fuzz/Makefile
2887	lib/Makefile
2888	lib/bind9/Makefile
2889	lib/bind9/include/Makefile
2890	lib/bind9/include/bind9/Makefile
2891	lib/dns/Makefile
2892	lib/dns/include/Makefile
2893	lib/dns/include/dns/Makefile
2894	lib/dns/include/dst/Makefile
2895	lib/dns/tests/Makefile
2896	lib/irs/Makefile
2897	lib/irs/include/Makefile
2898	lib/irs/include/irs/Makefile
2899	lib/irs/include/irs/netdb.h
2900	lib/irs/include/irs/platform.h
2901	lib/irs/tests/Makefile
2902	lib/isc/Makefile
2903	lib/isc/include/Makefile
2904	lib/isc/include/isc/Makefile
2905	lib/isc/include/isc/platform.h
2906	lib/isc/include/pk11/Makefile
2907	lib/isc/include/pkcs11/Makefile
2908	lib/isc/netmgr/Makefile
2909	lib/isc/pthreads/Makefile
2910	lib/isc/pthreads/include/Makefile
2911	lib/isc/pthreads/include/isc/Makefile
2912	lib/isc/tests/Makefile
2913	lib/isc/unix/Makefile
2914	lib/isc/unix/include/Makefile
2915	lib/isc/unix/include/isc/Makefile
2916	lib/isccc/Makefile
2917	lib/isccc/include/Makefile
2918	lib/isccc/include/isccc/Makefile
2919	lib/isccc/tests/Makefile
2920	lib/isccfg/Makefile
2921	lib/isccfg/include/Makefile
2922	lib/isccfg/include/isccfg/Makefile
2923	lib/isccfg/tests/Makefile
2924	lib/ns/Makefile
2925	lib/ns/include/Makefile
2926	lib/ns/include/ns/Makefile
2927	lib/ns/tests/Makefile
2928	make/Makefile
2929	make/mkdep
2930	unit/unittest.sh
2931	util/check-make-install
2932])
2933
2934#
2935# Do it
2936#
2937
2938AC_OUTPUT
2939
2940#
2941# Now that the Makefiles exist we can ensure that everything is rebuilt.
2942#
2943# [pairwise: --with-make-clean, --without-make-clean]
2944AC_ARG_WITH(make-clean,
2945	    AS_HELP_STRING([--with-make-clean],
2946			   [run "make clean" at end of configure [yes|no]]),
2947    make_clean="$withval", make_clean="yes")
2948case "$make_clean" in
2949yes)
2950	if test "yes" != "$no_create"
2951	then
2952		if test "yes" = "$silent"
2953		then
2954			make clean > /dev/null
2955		else
2956			make clean
2957		fi
2958	fi
2959	;;
2960esac
2961
2962# [pairwise: --enable-full-report, --disable-full-report]
2963AC_ARG_ENABLE(full-report,
2964	      AS_HELP_STRING([--enable-full-report],
2965			     [report values of all configure options]))
2966
2967report() {
2968    echo "==============================================================================="
2969    echo "Configuration summary:"
2970    echo "-------------------------------------------------------------------------------"
2971    echo "Optional features enabled:"
2972    if test "yes" = "$enable_full_report" -o "standard" = "$with_locktype"; then
2973	echo "    Mutex lock type: $with_locktype"
2974    fi
2975    test "small" = "$with_tuning" && echo "    Small-system tuning (--with-tuning)"
2976    test "no" = "$use_dnstap" || \
2977	    echo "    Allow 'dnstap' packet logging (--enable-dnstap)"
2978    test -z "$MAXMINDDB_LIBS" || echo "    GeoIP2 access control (--enable-geoip)"
2979    test "no" = "$use_gssapi" || echo "    GSS-API (--with-gssapi)"
2980
2981    # these lines are only printed if run with --enable-full-report
2982    if test "yes" = "$enable_full_report"; then
2983	test "no" = "$found_ipv6" || echo "    IPv6 support (--enable-ipv6)"
2984	test "X$PYTHON" = "X" || echo "    Python tools (--with-python)"
2985	test "X$LIBXML2_LIBS" = "X" || echo "    XML statistics (--with-libxml2)"
2986	test "X$JSON_C_LIBS" = "X" || echo "    JSON statistics (--with-json-c): $JSON_C_CFLAGS $JSON_C_LIBS"
2987	test "X$ZLIB_LIBS" = "X" || echo "    HTTP zlib compression (--with-zlib)"
2988	test "X$NZD_TOOLS" = "X" || echo "    LMDB database to store configuration for 'addzone' zones (--with-lmdb)"
2989	test "no" = "$with_libidn2" || echo "    IDN support (--with-libidn2)"
2990    fi
2991
2992    test "yes" = "$enable_dnsrps" && \
2993	echo "    DNS Response Policy Service interface (--enable-dnsrps)"
2994    test "yes" = "$enable_fixed" && \
2995	echo "    Allow 'fixed' rrset-order (--enable-fixed-rrset)"
2996    test "yes" = "$enable_backtrace" && \
2997	echo "    Print backtrace on crash (--enable-backtrace)"
2998    test "minimal" = "$want_symtable" && \
2999	echo "    Use symbol table for backtrace, named only (--enable-symtable)"
3000    test "yes" = "$want_symtable" -o "all" = "$want_symtable" && \
3001	echo "    Use symbol table for backtrace, all binaries (--enable-symtable=all)"
3002    test "no" = "$use_libtool" || echo "    Use GNU libtool (--with-libtool)"
3003    test "yes" = "$want_querytrace" && \
3004	echo "    Very verbose query trace logging (--enable-querytrace)"
3005    test "no" = "$with_cmocka" || echo "    CMocka Unit Testing Framework (--with-cmocka)"
3006
3007    test "auto" = "$validation_default" && echo "    DNSSEC validation active by default (--enable-auto-validation)"
3008
3009    test "$CRYPTO" = "pkcs11" && (
3010	echo "    Using PKCS#11 for Public-Key Cryptography (--with-native-pkcs11)"
3011	echo "    PKCS#11 module (--with-pkcs11): $with_pkcs11"
3012	echo "    +--------------------------------------------+"
3013	echo "    |             ==== WARNING ====              |"
3014	echo "    |                                            |"
3015	echo "    | The use of native PKCS#11 for Public-Key   |"
3016	echo "    | Cryptography in BIND 9 has been deprecated |"
3017	echo "    | in favor of OpenSSL engine_pkcs11 from the |"
3018	echo "    | OpenSC project. The --with-native-pkcs11   |"
3019	echo "    | configuration option will be removed from  |"
3020	echo "    | the next major BIND 9 release. The option  |"
3021	echo "    | to use the engine_pkcs11 OpenSSL engine is |"
3022	echo "    | already available in BIND 9; please see    |"
3023	echo "    | the ARM section on PKCS#11 for details.    |"
3024	echo "    +--------------------------------------------+"
3025    )
3026
3027    dlz_enabled=no
3028
3029    echo "    Dynamically loadable zone (DLZ) drivers:"
3030    AS_IF([test "$use_dlz_bdb" != "no"],
3031	  [AS_ECHO(["        Berkeley DB (--with-dlz-bdb)"])
3032	   dlz_enabled=yes])
3033    AS_IF([test "$use_dlz_ldap" != "no"],
3034	  [AS_ECHO(["        LDAP (--with-dlz-ldap)"])
3035	   dlz_enabled=yes])
3036    AS_IF([test "$use_dlz_mysql" != "no"],
3037	  [AS_ECHO(["        MySQL (--with-dlz-mysql)"])
3038	   dlz_enabled=yes])
3039    AS_IF([test "$use_dlz_odbc" != "no"],
3040	  [AS_ECHO(["        ODBC (--with-dlz-odbc)"])
3041	   dlz_enabled=yes])
3042    AS_IF([test "$use_dlz_postgres" != "no"],
3043	  [AS_ECHO(["        Postgres (--with-dlz-postgres)"])
3044	   dlz_enabled=yes])
3045    AS_IF([test "$use_dlz_filesystem" != "no"],
3046	  [AS_ECHO(["        Filesystem (--with-dlz-filesystem)"])
3047	   dlz_enabled=yes])
3048    AS_IF([test "$use_dlz_stub" != "no"],
3049	  [AS_ECHO(["        Stub (--with-dlz-stub)"])
3050	   dlz_enabled=yes])
3051
3052    AS_IF([test "$dlz_enabled" = "no"],
3053	  [AS_ECHO(["        None"])],
3054	  [AS_ECHO(["    +--------------------------------------------------------+"])
3055	   AS_ECHO(["    |             ==== DEPRECATION WARNING ====              |"])
3056	   AS_ECHO(["    +--------------------------------------------------------+"])
3057	   AS_ECHO(["    | Old-style DLZ drivers have been deprecated in favor of |"])
3058	   AS_ECHO(["    | DLZ modules. The DLZ drivers configuration option will |"])
3059	   AS_ECHO(["    | be removed from the next major BIND 9 release.         |"])
3060	   AS_ECHO(["    |                                                        |"])
3061	   AS_ECHO(["    | The option to use the DLZ modules is already available |"])
3062	   AS_ECHO(["    | in BIND 9; please see the ARM section on DLZ modules.  |"])
3063	   AS_ECHO(["    +--------------------------------------------------------+"])
3064	  ])
3065
3066    echo "-------------------------------------------------------------------------------"
3067
3068    echo "Features disabled or unavailable on this platform:"
3069    test "no" = "$found_ipv6" && echo "    IPv6 support (--enable-ipv6)"
3070    test "small" = "$with_tuning" || echo "    Small-system tuning (--with-tuning)"
3071
3072    test "no" = "$use_dnstap" && \
3073	    echo "    Allow 'dnstap' packet logging (--enable-dnstap)"
3074    test -z "$MAXMINDDB_LIBS" && echo "    GeoIP2 access control (--enable-geoip)"
3075    test "no" = "$use_gssapi" && echo "    GSS-API (--with-gssapi)"
3076
3077    test "no" = "$enable_dnsrps" && \
3078	echo "    DNS Response Policy Service interface (--enable-dnsrps)"
3079
3080    test "yes" = "$enable_fixed" || \
3081	echo "    Allow 'fixed' rrset-order (--enable-fixed-rrset)"
3082
3083    test "yes" = "$validation_default" && echo "    DNSSEC validation requires configuration (--enablee-auto-validation)"
3084
3085    test "$CRYPTO" = "pkcs11" || (
3086	echo "    Using PKCS#11 for Public-Key Cryptography (--with-native-pkcs11)"
3087    )
3088
3089    test "yes" = "$enable_backtrace" || \
3090	echo "    Print backtrace on crash (--enable-backtrace)"
3091    test "yes" = "$want_querytrace" || \
3092	echo "    Very verbose query trace logging (--enable-querytrace)"
3093
3094    test "yes" = "$use_libtool" || echo "    Use GNU libtool (--with-libtool)"
3095    test "no" = "$with_cmocka" && echo "    CMocka Unit Testing Framework (--with-cmocka)"
3096
3097    test "X$PYTHON" = "X" && echo "    Python tools (--with-python)"
3098    test "X$LIBXML2_LIBS" = "X" && echo "    XML statistics (--with-libxml2)"
3099    test "X$JSON_C_LIBS" = "X" && echo "    JSON statistics (--with-json-c)"
3100    test "X$ZLIB_LIBS" = "X" && echo "    HTTP zlib compression (--with-zlib)"
3101    test "X$NZD_TOOLS" = "X" && echo "    LMDB database to store configuration for 'addzone' zones (--with-lmdb)"
3102    test "no" = "$with_libidn2" && echo "    IDN support (--with-libidn2)"
3103
3104    echo "-------------------------------------------------------------------------------"
3105    echo "Configured paths:"
3106    echo "    prefix: $prefix"
3107    echo "    sysconfdir: $sysconfdir"
3108    echo "    localstatedir: $localstatedir"
3109    echo "-------------------------------------------------------------------------------"
3110    echo "Compiler: $CC"
3111    AS_IF([test "$GCC" = "yes"],
3112	  [$CC --version 2>&1 | sed 's/^/    /'],
3113	  [AS_CASE([$host],
3114		   [*-solaris*],[$CC -V 2>&1 | sed 's/^/    /'],
3115		   [$CC --version 2>&1 | sed 's/^/    /'])])
3116
3117    if test "X$ac_unrecognized_opts" != "X"; then
3118	echo "Unrecognized options:"
3119	echo "    $ac_unrecognized_opts"
3120    fi
3121
3122    if test "yes" != "$enable_full_report"; then
3123	echo "-------------------------------------------------------------------------------"
3124	echo "For more detail, use --enable-full-report."
3125    fi
3126    echo "==============================================================================="
3127}
3128
3129if test "yes" != "$silent"; then
3130	report
3131fi
3132
3133# Tell Emacs to edit this file in shell mode.
3134# Local Variables:
3135# mode: sh
3136# End:
3137