configure.ac 86.4 KB
Newer Older
1
# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
Tinderbox User's avatar
Tinderbox User committed
2
#
3 4 5
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 7 8
#
# See the COPYRIGHT file distributed with this work for additional
# information regarding copyright ownership.
9

10
AC_INIT(BIND, [9.15], [info@isc.org], [], [https://www.isc.org/downloads/BIND/])
11
AC_PREREQ([2.60])
Bob Halley's avatar
Bob Halley committed
12

13 14 15 16 17
#
# Enable maintainer mode by default, but allow to disable it in the CI
#
AM_MAINTAINER_MODE([enable])

Bob Halley's avatar
Bob Halley committed
18
AC_CONFIG_HEADER(config.h)
Ondřej Surý's avatar
Ondřej Surý committed
19
AC_CONFIG_MACRO_DIR([m4])
Bob Halley's avatar
Bob Halley committed
20 21

AC_CANONICAL_HOST
22 23 24 25

#
# Enable system extensions to C and POSIX
#
26 27
AC_USE_SYSTEM_EXTENSIONS

28 29 30 31 32 33
#
# Enable large file support
#
AC_SYS_LARGEFILE
AC_FUNC_FSEEKO

34 35 36 37 38 39 40 41
LFS_CFLAGS=`getconf LFS_CFLAGS 2>/dev/null`
LFS_LDFLAGS=`getconf LFS_LDFLAGS 2>/dev/null`
LFS_LIBS=`getconf LFS_LIBS 2>/dev/null`

AC_SUBST([LFS_CFLAGS])
AC_SUBST([LFS_LDFLAGS])
AC_SUBST([LFS_LIBS])

42 43
# Enable RFC 3542 APIs on macOS
AC_DEFINE([__APPLE_USE_RFC_3542], [1], [Select RFC3542 IPv6 API on macOS])
Bob Halley's avatar
Bob Halley committed
44

45
AC_PROG_MAKE_SET
46

47
AC_PROG_LIBTOOL
48
AC_PROG_INSTALL
49
AC_PROG_LN_S
50
AX_POSIX_SHELL
51 52 53 54

AC_SUBST(STD_CINCLUDES)
AC_SUBST(STD_CDEFINES)
AC_SUBST(STD_CWARNINGS)
55
AC_SUBST(CCOPT)
Evan Hunt's avatar
Evan Hunt committed
56
AC_SUBST(CCNOOPT)
Mark Andrews's avatar
Mark Andrews committed
57
AC_SUBST(BACKTRACECFLAGS)
58

59 60 61 62 63 64
#
# Use pkg-config
#

PKG_PROG_PKG_CONFIG

65 66 67 68
AC_ARG_ENABLE(buffer_useinline,
	      AS_HELP_STRING([--enable-buffer-useinline],
		             [define ISC_BUFFER_USEINLINE when compiling
				[default=yes]]),
69 70 71 72 73 74 75
	      if test yes = "${enable}"
	      then
		      AC_DEFINE([ISC_BUFFER_USEINLINE], [1],
			        [Define if you want to use inline buffers])
	      fi,
	      AC_DEFINE([ISC_BUFFER_USEINLINE], [1]))

76 77 78
AC_ARG_ENABLE([warn_shadow],
	      [AS_HELP_STRING([--enable-warn-shadow],
			      [turn on -Wshadow when compiling])])
79

80 81 82 83 84 85 86
AC_ARG_ENABLE([warn_error],
	      [AS_HELP_STRING([--enable-warn-error],
			      [turn on -Werror when compiling])])

AC_ARG_ENABLE([developer],
	      [AS_HELP_STRING([--enable-developer],
			      [enable developer build settings])])
87

88
XTARGETS=
89 90 91 92 93 94 95 96 97 98 99 100 101
AS_IF([test "$enable_developer" = "yes"],
      [STD_CDEFINES="$STD_CDEFINES -DISC_MEM_DEFAULTFILL=1 -DISC_LIST_CHECKINIT=1"
       test "${enable_fixed_rrset+set}" = set || enable_fixed_rrset=yes
       test "${enable_querytrace+set}" = set || enable_querytrace=yes
       test "${with_cmocka+set}" = set || with_cmocka=yes
       test "${with_dlz_filesystem+set}" = set || with_dlz_filesystem=yes
       test "${enable_symtable+set}" = set || enable_symtable=all
       test "${enable_warn_error+set}" = set || enable_warn_error=yes
       test "${enable_warn_shadow+set}" = set || enable_warn_shadow=yes
       test "${with_zlib+set}" = set || with_zlib=yes
       XTARGETS='${XTARGETS}'
       ])
AC_SUBST([XTARGETS])
102

103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
AC_ARG_ENABLE([fuzzing],
	      [AS_HELP_STRING([--enable-fuzzing=<afl|libfuzzer>],
			      [Enable fuzzing using American Fuzzy Lop or libFuzzer (default=no)])],
	      [],
	      [enable_fuzzing=no])

AC_MSG_CHECKING([whether to enable fuzzing mode])
AS_CASE([$enable_fuzzing],
	[no],[AC_MSG_RESULT([no])],
	[afl],[
	  AC_MSG_RESULT([using AFL])
	  AC_DEFINE([ENABLE_AFL], [1],
		    [Define to enable American Fuzzy Lop test harness])
	  CFLAGS="$CFLAGS -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION=1"
	  LIBS="$LIBS -lpthread"],
	[libfuzzer],[
	  AC_MSG_RESULT([using libFuzzer])
	  CFLAGS="$CFLAGS -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION=1 -fsanitize=fuzzer,address,undefined"
	  LDFLAGS="$LDFLAGS -fsanitize=fuzzer,address,undefined"],
	[*],[AC_MSG_ERROR([You need to explicitly select the fuzzer])])

AS_IF([test "$enable_fuzzing" = "afl"],
      [AC_MSG_CHECKING("for AFL enabled compiler")
       AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
					  [#ifndef __AFL_COMPILER
					   #error AFL compiler required
					   #endif
					  ])],
			 [AC_MSG_RESULT([yes])],
			 [AC_MSG_ERROR([set CC=afl-<gcc|clang> when --enable-fuzzing=afl is used])])
      ])
134

135 136 137
#
# Make very sure that these are the first files processed by
# config.status, since we use the processed output as the input for
Francis Dupont's avatar
Francis Dupont committed
138
# AC_SUBST_FILE() substitutions in other files.
139 140 141
#
AC_CONFIG_FILES([make/rules make/includes])

David Lawrence's avatar
David Lawrence committed
142 143 144 145 146
AC_PATH_PROG(AR, ar)
ARFLAGS="cruv"
AC_SUBST(AR)
AC_SUBST(ARFLAGS)

147 148 149 150 151
# The POSIX ln(1) program.  Non-POSIX systems may substitute
# "copy" or something.
LN=ln
AC_SUBST(LN)

152 153 154 155 156 157 158 159 160 161
case "$AR" in
	"")
		AC_MSG_ERROR([
ar program not found.  Please fix your PATH to include the directory in
which ar resides, or set AR in the environment with the full path to ar.
])

		;;
esac

Bob Halley's avatar
Bob Halley committed
162 163 164
#
# Etags.
#
165
AC_PATH_PROGS(ETAGS, etags emacs-etags)
Andreas Gustafsson's avatar
Andreas Gustafsson committed
166

Bob Halley's avatar
Bob Halley committed
167 168 169 170 171 172 173 174 175 176 177 178 179
#
# Some systems, e.g. RH7, have the Exuberant Ctags etags instead of
# GNU emacs etags, and it requires the -L flag.
#
if test "X$ETAGS" != "X"; then
	AC_MSG_CHECKING(for Exuberant Ctags etags)
	if $ETAGS --version 2>&1 | grep 'Exuberant Ctags' >/dev/null 2>&1; then
		AC_MSG_RESULT(yes)
		ETAGS="$ETAGS -L"
	else
		AC_MSG_RESULT(no)
	fi
fi
180 181
AC_SUBST(ETAGS)

182 183
#
# Perl is optional; it is used only by some of the system test scripts.
184 185
# Note: the backtrace feature (see below) uses perl to build the symbol table,
# but it still compiles without perl, in which case an empty table will be used.
186 187 188 189
#
AC_PATH_PROGS(PERL, perl5 perl)
AC_SUBST(PERL)

190
#
191 192
# Python is also optional but required by default so that dnssec-keymgr gets
# installed unless explicitly prevented by the user using --without-python.
193
#
194 195 196
testminvers='import sys
if (sys.version_info < (2,7)) or (sys.version_info < (3,2) and sys.version_info >= (3,0)):
   exit(1)'
Evan Hunt's avatar
Evan Hunt committed
197 198 199 200

testargparse='try: import argparse
except: exit(1)'

201
testply='try: import ply
Evan Hunt's avatar
Evan Hunt committed
202
except: exit(1)'
Evan Hunt's avatar
Evan Hunt committed
203

204 205
default_with_python="python python3 python3.7 python3.6 python3.5 python3.4 python3.3 python3.2 python2 python2.7"

206 207 208
AC_ARG_WITH([python],
	    AS_HELP_STRING([--with-python=PATH],
			   [specify path to Python interpreter]),
209
	    [], [with_python=$default_with_python])
210 211 212 213 214
AC_ARG_WITH([python-install-dir],
	    AS_HELP_STRING([--with-python-install-dir=PATH],
			   [installation directory for Python modules]),
	    [], with_python_install_dir="")

215 216 217
AS_IF([test "$with_python" = "yes"],
      [with_python=$default_with_python])

218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264
AS_IF([test "$with_python" = "no"],
      [AC_MSG_CHECKING([for Python support])
       AC_MSG_RESULT([disabled])],
      [for p in $with_python
       do
	 AS_CASE([$p],
		 [/*],[PYTHON="$p"])

	 AC_PATH_PROG([PYTHON], [$p])
	 # Do not cache the result of the check from the previous line.  If the
	 # first found Python interpreter has missing module dependencies and
	 # the result of the above check is cached, subsequent module checks
	 # will erroneously keep on using the cached path to the first found
	 # Python interpreter instead of different ones.
	 unset ac_cv_path_PYTHON

	 AS_IF([test -z "$PYTHON"], [continue])

	 AC_MSG_CHECKING([if $PYTHON is python2 version >= 2.7 or python3 version >= 3.2])
	 AS_IF(["$PYTHON" -c "$testminvers" 2>/dev/null],
	       [AC_MSG_RESULT([yes])],
	       [AC_MSG_RESULT([no])
		unset PYTHON
		continue])

	 AC_MSG_CHECKING([Python module 'argparse'])
	 AS_IF(["$PYTHON" -c "$testargparse" 2>/dev/null],
	       [AC_MSG_RESULT([yes])],
	       [AC_MSG_RESULT([no])
		unset PYTHON
		continue])

	 AC_MSG_CHECKING([Python module 'ply'])
	 AS_IF(["$PYTHON" -c "$testply" 2>/dev/null],
	       [AC_MSG_RESULT([yes])],
	       [AC_MSG_RESULT([no])
		unset PYTHON
		continue])

	 # Stop looking any further once we find a Python interpreter
	 # satisfying all requirements.
	 break
       done

       AS_IF([test "X$PYTHON" = "X"],
	     [AC_MSG_CHECKING([for Python support])
	      AC_MSG_RESULT([no])
265 266 267 268 269 270 271
	      AC_MSG_ERROR([m4_normalize(
				[Python >= 2.7 or >= 3.2 and the PLY package
                                 are required for dnssec-keymgr and other
                                 Python-based tools. PLY may be
                                 available from your OS package manager
                                 as python-ply or python3-ply; it can also
                                 be installed via pip. To build without
272
                                 Python/PLY, use --without-python.]
273
			    )])])])
274 275

PYTHON_TOOLS=''
276
CHECKDS=''
Evan Hunt's avatar
Evan Hunt committed
277
COVERAGE=''
Evan Hunt's avatar
Evan Hunt committed
278
KEYMGR=''
279 280 281 282 283 284 285 286
AS_IF([test "X$PYTHON" != "X"],
      [PYTHON_TOOLS=python
       CHECKDS=checkds
       COVERAGE=coverage
       KEYMGR=keymgr
       PYTHON_INSTALL_DIR="$with_python_install_dir"
       AS_IF([test -n "$with_python_install_dir"],
	     [PYTHON_INSTALL_LIB="--install-lib=$with_python_install_dir"])])
287
AC_SUBST(CHECKDS)
Evan Hunt's avatar
Evan Hunt committed
288
AC_SUBST(COVERAGE)
Evan Hunt's avatar
Evan Hunt committed
289
AC_SUBST(KEYMGR)
290
AC_SUBST(PYTHON_TOOLS)
291 292
AC_SUBST(PYTHON_INSTALL_DIR)
AC_SUBST(PYTHON_INSTALL_LIB)
293

294
#
295
# expanded_sysconfdir is needed for replacement in the python utilities
296
#
Evan Hunt's avatar
Evan Hunt committed
297 298
expanded_sysconfdir=`eval echo $sysconfdir`
AC_SUBST(expanded_sysconfdir)
299

300 301 302 303 304 305 306 307
#
# Make sure INSTALL uses an absolute path, else it will be wrong in all
# Makefiles, since they use make/rules.in and INSTALL will be adjusted by
# configure based on the location of the file where it is substituted.
# Since in BIND9 INSTALL is only substituted into make/rules.in, an immediate
# subdirectory of install-sh, This relative path will be wrong for all
# directories more than one level down from install-sh.
#
308 309
case "$INSTALL" in
	/*)
310 311 312 313 314 315 316 317 318 319
		;;
	*)
		#
		# Not all systems have dirname.
		#
		changequote({, })
		ac_dir="`echo $INSTALL | sed 's%/[^/]*$%%'`"
		changequote([, ])

		ac_prog="`echo $INSTALL | sed 's%.*/%%'`"
320
		test "X$ac_dir" = "X$ac_prog" && ac_dir=.
321 322 323
		test -d "$ac_dir" && ac_dir="`(cd \"$ac_dir\" && pwd)`"
		INSTALL="$ac_dir/$ac_prog"
		;;
324 325
esac

326
AC_PROG_CC
327
AC_PROG_CC_C99
328

329 330 331 332 333 334 335 336 337 338 339
#
# Using Solaris linker with gcc on Solaris breaks Thread Local Storage
#
AS_CASE([$host],
	[*-solaris*],[
	    AS_IF([test "$GCC" = "yes"],
		  [LDFLAGS="$LDFLAGS -zrelax=transtls"
		   AC_MSG_WARN([When using GNU C Compiler on Solaris, -zrelax=transtls linker flag is used to fix bug in Thread Local Storage])
		  ])
	])

Evan Hunt's avatar
Evan Hunt committed
340 341 342 343 344 345 346
#
# CCNOOPT defaults to -O0 on gcc and disables optimization when is last
#
if test "X$CCNOOPT" = "X" -a "X$GCC" = "Xyes"; then
	CCNOOPT="-O0"
fi

347 348
AC_HEADER_STDC

Mark Andrews's avatar
Mark Andrews committed
349
AC_CHECK_HEADERS(fcntl.h regex.h sys/time.h unistd.h sys/mman.h sys/sockio.h sys/select.h sys/param.h sys/sysctl.h net/if6.h sys/socket.h net/route.h linux/netlink.h linux/rtnetlink.h,,,
350 351 352 353
[$ac_includes_default
#ifdef HAVE_SYS_PARAM_H
# include <sys/param.h>
#endif
354 355 356
#ifdef HAVE_SYS_SOCKET_H
# include <sys/socket.h>
#endif
357
])
358

359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397
#
# Check for thread local storage
#
AC_CHECK_HEADERS([threads.h],
		 [
		     AC_MSG_CHECKING([for C11 Thread-Local Storage using thread_local])
		     AC_COMPILE_IFELSE(
			 [AC_LANG_PROGRAM(
			      [
				  #include <threads.h>
			      ],[
				  static thread_local int tls = 0;
				  return (tls);
			      ])
			 ],[
			     AC_MSG_RESULT([yes])
			     AC_DEFINE([HAVE_THREAD_LOCAL],[1],[Define if thread_local keyword is available])
			     AC_DEFINE([HAVE_TLS],[1],[Define if Thread-Local Storage is available])
			 ],[
			     AC_MSG_RESULT([no])
			 ])
		 ],[
		     AC_MSG_CHECKING([for Thread-Local Storage using __thread])
		     AC_COMPILE_IFELSE(
			 [AC_LANG_PROGRAM(
			      [
			      ],[
				  static __thread int tls = 0;
				  return (tls);
			      ])
			 ],[
			     AC_MSG_RESULT([yes])
			     AC_DEFINE([HAVE___THREAD],[1],[Define if __thread keyword is available])
			     AC_DEFINE([HAVE_TLS],[1],[Define if Thread-Local Storage is available])
			 ],[
			     AC_MSG_RESULT([no])
			 ])
		 ])

398 399
AC_C_CONST
AC_C_INLINE
400
AC_C_VOLATILE
401
AC_C_FLEXIBLE_ARRAY_MEMBER
402

403 404 405 406
#
# Check for yield support on ARM processors
#
AS_CASE([$host],
407 408 409 410 411 412 413 414 415
	[arm*],
	[AC_MSG_CHECKING([for yield instruction support])
	 AC_COMPILE_IFELSE(
	     [AC_LANG_PROGRAM([[]],
			     [[__asm__ __volatile__ ("yield")]])],
	     [AC_MSG_RESULT([yes])
	      AC_DEFINE([HAVE_ARM_YIELD], [1],
			[define if the ARM yield instruction is available])],
	     [AC_MSG_RESULT([no])])])
416

417 418
AC_CHECK_FUNCS([sysctlbyname])

Evan Hunt's avatar
Evan Hunt committed
419 420 421 422 423
#
# Check for the existence of mmap to enable the fast format zones
#
AC_CHECK_FUNCS(mmap)

424 425 426 427 428 429
#
# Older versions of HP/UX don't define seteuid() and setegid()
#
AC_CHECK_FUNCS(seteuid setresuid)
AC_CHECK_FUNCS(setegid setresgid)

430
AC_TYPE_SIZE_T
431 432 433
AC_TYPE_SSIZE_T
AC_TYPE_UINTPTR_T

434 435
AC_HEADER_TIME

436 437 438
#
# check for uname library routine
#
439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456
AC_MSG_CHECKING([for uname])
AC_COMPILE_IFELSE(
  [AC_LANG_PROGRAM(
     [[#include <sys/utsname.h>
       #include <stdio.h>
      ]],
     [[
       struct utsname uts;
       uname(&uts);
       printf("running on %s %s %s for %s\n",
	      uts.sysname, uts.release, uts.version, uts.machine);
     ]])],
  [AC_MSG_RESULT(yes)
   AC_DEFINE([HAVE_UNAME], [1], [define if uname is available])
  ],
  [AC_MSG_RESULT(no)
   AC_MSG_WARN([uname is not correctly supported])
  ])
457

Francis Dupont's avatar
Francis Dupont committed
458 459 460 461 462 463 464 465 466 467
#
# check for GCC noreturn attribute
#
AC_MSG_CHECKING(for GCC noreturn attribute)
AC_TRY_COMPILE([],[void foo() __attribute__((noreturn));],
	[AC_MSG_RESULT(yes)
		ISC_PLATFORM_NORETURN_PRE="#define ISC_PLATFORM_NORETURN_PRE"
		ISC_PLATFORM_NORETURN_POST="#define ISC_PLATFORM_NORETURN_POST __attribute__((noreturn))"],
	[AC_MSG_RESULT(no)
		ISC_PLATFORM_NORETURN_PRE="#define ISC_PLATFORM_NORETURN_PRE"
468
		ISC_PLATFORM_NORETURN_POST="#define ISC_PLATFORM_NORETURN_POST"])
Francis Dupont's avatar
Francis Dupont committed
469 470 471
AC_SUBST(ISC_PLATFORM_NORETURN_PRE)
AC_SUBST(ISC_PLATFORM_NORETURN_POST)

472 473 474
#
# check if we have kqueue
#
475 476 477 478 479 480 481
AC_ARG_ENABLE([kqueue],
	      [AS_HELP_STRING([--enable-kqueue],
			      [use BSD kqueue when available [default=yes]])],
	      [], enable_kqueue="yes")

AS_IF([test "$enable_kqueue" = "yes"],
      [AC_CHECK_FUNCS([kqueue])])
482 483

#
484 485
# check if we have epoll.  Linux kernel 2.4 has epoll_create() which fails,
# so we need to try running the code, not just test its existence.
486
#
487 488 489 490 491 492 493
AC_ARG_ENABLE([epoll],
	      [AS_HELP_STRING([--enable-epoll],
			      [use Linux epoll when available [default=auto]])],
	      [], [enable_epoll="yes"])

AS_IF([test "$enable_epoll" = "yes"],
      [AC_CHECK_FUNCS([epoll_create1])])
494 495 496 497

#
# check if we support /dev/poll
#
498 499 500 501 502 503
AC_ARG_ENABLE([devpoll],
	      [AS_HELP_STRING([--enable-devpoll],
			      [use /dev/poll when available [default=yes]])],
	      [], [enable_devpoll="yes"])
AS_IF([test "$enable_devpoll" = "yes"],
      [AC_CHECK_HEADERS([sys/devpoll.h devpoll.h])])
504

505 506 507 508 509
#
# Find the machine's endian flavor.
#
AC_C_BIGENDIAN

Michael Graff's avatar
Michael Graff committed
510
#
Evan Hunt's avatar
Evan Hunt committed
511
# GeoIP support?
Michael Graff's avatar
Michael Graff committed
512
#
513
geoip2_default="auto"
Evan Hunt's avatar
Evan Hunt committed
514
AC_ARG_WITH(geoip,
515
	    AS_HELP_STRING([--with-geoip=PATH],
516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572
			   [Build with legacy GeoIP support (yes|no|path)]),
                           [
                            use_geoip="$withval"
                            geoip2_default="no"
                           ],
                           [use_geoip="no"])
AC_ARG_WITH([geoip2],
	    [AS_HELP_STRING([--with-geoip2=PATH],
			    [Build with MaxMind GeoIP2 support (auto|yes|no|path) [default=$geoip2_default]])],
	    [], with_geoip2="$geoip2_default")

# --with-geoip2 should be turned on by default if the library exists.
#
# --with-geoip is not on by default, but can be turned on if the library
# exists. if it is turned on, --with-geoip2 is suppressed.
#
# specifying both --with-geoip and --with-geoip2 is an error.
AS_IF([test "no" != "$with_geoip2" && test "no" != "$use_geoip"],
      [AC_MSG_ERROR([--with-geoip and --with-geoip2 are incompatible])])

GEOIP2LINKSRCS=
GEOIP2LINKOBJS=
AS_CASE([$with_geoip2],
	[no],[],
	[auto],[PKG_CHECK_MODULES([MAXMINDDB], [libmaxminddb],
				      [AC_DEFINE([HAVE_GEOIP2], [1], [Build with GeoIP2 support])
				       PKG_CHECK_VAR([MAXMINDDB_PREFIX], [libmaxminddb], [prefix], [], [AC_MSG_ERROR([libmaxminddb prefix not found in pkg-config; set MAXMINDDB_PREFIX in the environment])])
				       GEOIP2LINKSRCS='${GEOIP2LINKSRCS}'
				       GEOIP2LINKOBJS='${GEOIP2LINKOBJS}'
				      ],[:])],
	[yes],[PKG_CHECK_MODULES([MAXMINDDB], [libmaxminddb],
				      [AC_DEFINE([HAVE_GEOIP2], [1], [Build with GeoIP2 support])
				       PKG_CHECK_VAR([MAXMINDDB_PREFIX], [libmaxminddb], [prefix], [], [AC_MSG_ERROR([libmaxminddb prefix not found in pkg-config; set MAXMINDDB_PREFIX in the environment])])
				       GEOIP2LINKSRCS='${GEOIP2LINKSRCS}'
				       GEOIP2LINKOBJS='${GEOIP2LINKOBJS}'
				      ])],
	[ # default
	    AX_SAVE_FLAGS([geoip2])
	    MAXMINDDB_CFLAGS="-I$with_geoip2/include"
	    MAXMINDDB_LIBS="-L$with_geoip2/libs"
	    CFLAGS="$CFLAGS $MAXMINDDB_CFLAGS"
	    LDFLAGS="$LDFLAGS $MAXMINDDB_LIBS"
	    AC_SEARCH_LIBS([MMDB_open], [maxminddb],
			   [AC_DEFINE([HAVE_GEOIP2], [1], [Build with GeoIP2 support])
			    GEOIP2LINKSRCS='${GEOIP2LINKSRCS}'
			    GEOIP2LINKOBJS='${GEOIP2LINKOBJS}'
			    MAXMINDDB_LIBS="$MAXMINDDB_LIBS $ac_cv_search_mmdb_open"
			    AC_MSG_NOTICE([GeoIP2 default database path set to $with_geoip2/share/GeoIP])
			    AS_VAR_COPY([MAXMINDDB_PREFIX], [$with_geoip2])
			   ],
			   [AC_MSG_ERROR([GeoIP2 requested, but libmaxminddb not found])])
	])
AC_ARG_VAR([MAXMINDDB_PREFIX], [value of prefix for MAXMINDDB, overriding pkg-config])
AC_SUBST([MAXMINDDB_CFLAGS])
AC_SUBST([MAXMINDDB_LIBS])
AC_SUBST([GEOIP2LINKSRCS])
AC_SUBST([GEOIP2LINKOBJS])
Michael Graff's avatar
Michael Graff committed
573

574 575
GEOIPLINKSRCS=
GEOIPLINKOBJS=
576
if test "yes" = "$use_geoip"
577
then
578
	for d in /usr /usr/local /opt/local
579
	do
Evan Hunt's avatar
Evan Hunt committed
580
		if test -f $d/include/GeoIP.h
581
		then
Evan Hunt's avatar
Evan Hunt committed
582
			use_geoip=$d
583 584 585 586
			break
		fi
	done
fi
Evan Hunt's avatar
Evan Hunt committed
587 588 589

case "$use_geoip" in
	no|'')
590
		;;
591
	*)
Evan Hunt's avatar
Evan Hunt committed
592
		if test -d "$use_geoip" -o -L "$use_geoip"
593
		then
Evan Hunt's avatar
Evan Hunt committed
594 595
			CFLAGS="$CFLAGS -I$use_geoip/include"
			CPPFLAGS="$CPPFLAGS -I$use_geoip/include"
596
			LIBS="$LIBS -L$use_geoip/lib"
Evan Hunt's avatar
Evan Hunt committed
597 598 599 600
			case "$host_os" in
				netbsd*|openbsd*|solaris*)
					LIBS="$LIBS -Wl,-rpath=$use_geoip/lib"
					;;
601
			esac
602
		elif test "yes" = "$use_geoip"
603
		then
Evan Hunt's avatar
Evan Hunt committed
604 605 606
			AC_MSG_ERROR([GeoIP path not found])
		else
			AC_MSG_ERROR([GeoIP path $use_geoip does not exist])
607
		fi
Evan Hunt's avatar
Evan Hunt committed
608 609 610
		AC_CHECK_HEADER(GeoIP.h, [],
			[AC_MSG_ERROR([GeoIP header file not found])]
		)
611 612
		AC_SEARCH_LIBS(GeoIP_id_by_addr_gl, GeoIP, [],
			[AC_MSG_ERROR([suitable GeoIP library not found])]
Evan Hunt's avatar
Evan Hunt committed
613 614 615 616
		)
		AC_SEARCH_LIBS(fabsf, m, [],
			[AC_MSG_ERROR([Math library not found])]
		)
617
		AC_DEFINE(HAVE_GEOIP, 1, Build with GeoIP support)
Evan Hunt's avatar
Evan Hunt committed
618 619 620 621
		GEOIPLINKSRCS='${GEOIPLINKSRCS}'
		GEOIPLINKOBJS='${GEOIPLINKOBJS}'
		AC_MSG_CHECKING([for GeoIP support])
		AC_MSG_RESULT([yes])
622

Evan Hunt's avatar
Evan Hunt committed
623 624 625 626 627 628 629 630 631 632 633
		AC_MSG_CHECKING([for GeoIP Country IPv6 support])
		AC_COMPILE_IFELSE(
			[AC_LANG_PROGRAM([
				#include <GeoIP.h>
				#include <netinet/in.h>
			], [
				struct in6_addr in6;
				GeoIP_country_name_by_ipnum_v6(NULL, in6);
			])],
			[
				AC_MSG_RESULT([yes])
634
				AC_DEFINE(HAVE_GEOIP_V6, 1, Build with GeoIP Country IPv6 support)
Evan Hunt's avatar
Evan Hunt committed
635 636 637
			],
			[AC_MSG_RESULT([no])]
		)
638

Evan Hunt's avatar
Evan Hunt committed
639 640 641 642 643 644 645 646
		AC_MSG_CHECKING([for GeoIP City IPv6 support])
		AC_COMPILE_IFELSE(
			[AC_LANG_PROGRAM([
				#include <GeoIP.h>
				#include <GeoIPCity.h>
				#include <netinet/in.h>
			], [
				struct in6_addr in6;
647
				int i = GEOIP_CITY_EDITION_REV0_V6;
Evan Hunt's avatar
Evan Hunt committed
648 649 650 651
				GeoIP_record_by_ipnum_v6(NULL, in6);
			])],
			[
				AC_MSG_RESULT([yes])
652
				AC_DEFINE(HAVE_GEOIP_CITY_V6, 1, Build with GeoIP City IPv6 support)
Evan Hunt's avatar
Evan Hunt committed
653 654
			],
			[AC_MSG_RESULT([no])]
655
		)
Evan Hunt's avatar
Evan Hunt committed
656
		;;
657
esac
Evan Hunt's avatar
Evan Hunt committed
658 659
AC_SUBST(GEOIPLINKSRCS)
AC_SUBST(GEOIPLINKOBJS)
660

Francis Dupont's avatar
Francis Dupont committed
661
#
662
# Do we have arc4random(), etc ?
Francis Dupont's avatar
Francis Dupont committed
663
#
664
AC_CHECK_FUNCS(arc4random arc4random_buf arc4random_uniform getrandom)
Francis Dupont's avatar
Francis Dupont committed
665

666
AX_PTHREAD
Francis Dupont's avatar
Francis Dupont committed
667

668 669 670
LIBS="$PTHREAD_LIBS $LIBS"
CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
CC="$PTHREAD_CC"
Evan Hunt's avatar
Evan Hunt committed
671

672
AC_CHECK_FUNCS([pthread_attr_getstacksize pthread_attr_setstacksize])
Witold Krecicki's avatar
Witold Krecicki committed
673

674
AC_ARG_WITH([locktype],
Witold Krecicki's avatar
Witold Krecicki committed
675 676
	    AS_HELP_STRING([--with-locktype=ARG],
			   [Specify mutex lock type
677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707
			    (adaptive or standard)]),
	    [], [with_locktype="adaptive"])

AS_CASE([$with_locktype],
	[adaptive],[
	  AC_MSG_CHECKING([for PTHREAD_MUTEX_ADAPTIVE_NP])
	  AC_COMPILE_IFELSE(
	    [AC_LANG_PROGRAM(
	       [[
		 #ifndef _GNU_SOURCE
		 #define _GNU_SOURCE
		 #endif
		 #include <pthread.h>
	       ]],
	       [[
		 return (PTHREAD_MUTEX_ADAPTIVE_NP);
	       ]]
	     )],
	    [AC_MSG_RESULT([using adaptive lock type])
	     AC_DEFINE([HAVE_PTHREAD_MUTEX_ADAPTIVE_NP], 1,
		       [Support for PTHREAD_MUTEX_ADAPTIVE_NP]) ],
	    [AC_MSG_RESULT([using standard lock type])]
	  )],
	[standard],[AC_MSG_RESULT([using standard lock type])],
	[AC_MSG_ERROR([You must specify "adaptive" or "standard" for --with-locktype.])]
       )

AC_CHECK_HEADERS([sched.h])

AC_SEARCH_LIBS([sched_yield],[rt])
AC_CHECK_FUNCS([sched_yield pthread_yield pthread_yield_np])
Witold Krecicki's avatar
Witold Krecicki committed
708

Witold Krecicki's avatar
Witold Krecicki committed
709 710 711 712
AC_CHECK_HEADERS([sys/cpuset.h])
AC_CHECK_HEADERS([sys/procset.h])
AC_CHECK_FUNCS([pthread_setaffinity_np cpuset_setaffinity processor_bind sched_setaffinity])

Witold Krecicki's avatar
Witold Krecicki committed
713
# Look for functions relating to thread naming
714
AC_CHECK_FUNCS([pthread_setname_np pthread_set_name_np])
Witold Krecicki's avatar
Witold Krecicki committed
715 716
AC_CHECK_HEADERS([pthread_np.h], [], [], [#include <pthread.h>])

717 718 719 720 721
#
# flockfile is usually provided by pthreads
#
AC_CHECK_FUNCS([flockfile getc_unlocked])

Witold Krecicki's avatar
Witold Krecicki committed
722 723 724
#
# Look for sysconf to allow detection of the number of processors.
#
725
AC_CHECK_FUNCS([sysconf])
726

Ondřej Surý's avatar
Ondřej Surý committed
727
AC_SUBST(ALWAYS_DEFINES)
Ondřej Surý's avatar
Ondřej Surý committed
728

Ondřej Surý's avatar
Ondřej Surý committed
729 730 731
AC_MSG_CHECKING(for libtool)
AC_ARG_WITH(libtool, AS_HELP_STRING([--with-libtool], [use GNU libtool]),
	    use_libtool="$withval", use_libtool="no")
732

Ondřej Surý's avatar
Ondřej Surý committed
733
case $use_libtool in
734
	yes)
Ondřej Surý's avatar
Ondřej Surý committed
735 736 737 738 739
		AC_MSG_RESULT(yes)
		AM_PROG_LIBTOOL
		O=lo
		A=la
		LIBTOOL_MKDEP_SED='s;\.o;\.lo;'
740 741 742 743
		LIBTOOL_MODE_COMPILE='--mode=compile'
		LIBTOOL_MODE_INSTALL='--mode=install'
		LIBTOOL_MODE_LINK='--mode=link'
		LIBTOOL_MODE_UNINSTALL='--mode=uninstall'
Ondřej Surý's avatar
Ondřej Surý committed
744
		INSTALL_LIBRARY='${INSTALL_PROGRAM}'
745 746
		;;
	*)
Ondřej Surý's avatar
Ondřej Surý committed
747 748 749 750 751 752 753 754 755 756 757
		AC_MSG_RESULT(no)
		O=o
		A=a
		LIBTOOL=
		AC_SUBST(LIBTOOL)
		LIBTOOL_MKDEP_SED=
		LIBTOOL_MODE_COMPILE=
		LIBTOOL_MODE_INSTALL=
		LIBTOOL_MODE_LINK=
		LIBTOOL_MODE_UNINSTALL=
		INSTALL_LIBRARY='${INSTALL_DATA}'
758
		;;
Ondřej Surý's avatar
Ondřej Surý committed
759 760
esac
AC_SUBST(INSTALL_LIBRARY)
761

762 763 764 765 766 767 768 769 770 771 772 773 774
#
# Do we want to use pthread rwlock? (useful for ThreadSanitizer)
#
AC_ARG_ENABLE([pthread_rwlock],
	      [AS_HELP_STRING([--enable-pthread-rwlock],
			      [use pthread rwlock instead of internal rwlock implementation (EXPERIMENTAL)])],
	      [], [enable_pthread_rwlock=no])

AS_IF([test "$enable_pthread_rwlock" = "yes"],
      [AC_CHECK_FUNCS([pthread_rwlock_rdlock], [],
		      [AC_MSG_ERROR([pthread_rwlock_rdlock requested but not found])])
       AC_DEFINE([USE_PTHREAD_RWLOCK],[1],[Define if you want to use pthread rwlock implementation])
      ])
775

776 777 778
AS_IF([test "$enable_pthread_rwlock" = "yes" -a "$enable_developer" != "yes"],
      [AC_MSG_ERROR([pthread rwlock is not meant used in production and the developer mode must be enabled])])

Ondřej Surý's avatar
Ondřej Surý committed
779
CRYPTO=OpenSSL
780

Ondřej Surý's avatar
Ondřej Surý committed
781
#
782
# OpenSSL/LibreSSL is mandatory
Ondřej Surý's avatar
Ondřej Surý committed
783
#
784 785
PKG_CHECK_MODULES([OPENSSL], [libcrypto], [],
		  [AX_CHECK_OPENSSL([:],[AC_MSG_FAILURE([OpenSSL/LibreSSL not found])])])
Ondřej Surý's avatar
Ondřej Surý committed
786

787 788
AX_SAVE_FLAGS([openssl])

789
CFLAGS="$CFLAGS $OPENSSL_CFLAGS"
Ondřej Surý's avatar
Ondřej Surý committed
790 791 792 793 794 795 796 797 798 799 800 801
LIBS="$LIBS $OPENSSL_LIBS"

AC_MSG_CHECKING([for OpenSSL >= 1.0.0 or LibreSSL])
AC_COMPILE_IFELSE(
    [AC_LANG_PROGRAM([[#include <openssl/opensslv.h>]],
		     [[#if !defined(LIBRESSL_VERSION_NUMBER) && (OPENSSL_VERSION_NUMBER < 0x1000000fL)
		       #error OpenSSL >= 1.0.0 or LibreSSL required
		       #endif
		      ]])],
    [AC_MSG_RESULT([yes])],
    [AC_MSG_FAILURE([not found])])

802 803 804 805 806 807 808 809 810
#
# Check for functions added in OpenSSL or LibreSSL
#

AC_CHECK_FUNCS([CRYPTO_zalloc])
AC_CHECK_FUNCS([EVP_CIPHER_CTX_new EVP_CIPHER_CTX_free])
AC_CHECK_FUNCS([EVP_MD_CTX_new EVP_MD_CTX_free EVP_MD_CTX_reset])
AC_CHECK_FUNCS([HMAC_CTX_new HMAC_CTX_free HMAC_CTX_reset HMAC_CTX_get_md])

Ondřej Surý's avatar
Ondřej Surý committed
811 812 813 814 815 816 817 818 819
#
# Check for algorithm support in OpenSSL
#

AC_CHECK_FUNCS([ECDSA_sign ECDSA_verify], [:],
	       [AC_MSG_FAILURE([ECDSA support in OpenSSL is mandatory.])])

AC_MSG_CHECKING([for ECDSA P-256 support])
AC_COMPILE_IFELSE(
820 821 822
    [AC_LANG_PROGRAM([[#include <openssl/evp.h>
		       #include <openssl/ec.h>]],
		     [[EC_KEY *key = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1);]])],
Ondřej Surý's avatar
Ondřej Surý committed
823 824 825 826 827
    [AC_MSG_RESULT([yes])],
    [AC_MSG_FAILURE([not found.  ECDSA P-256 support in OpenSSL is mandatory.])])

AC_MSG_CHECKING([for ECDSA P-384 support])
AC_COMPILE_IFELSE(
828 829 830
    [AC_LANG_PROGRAM([[#include <openssl/evp.h>
		       #include <openssl/ec.h>]],
		     [[EC_KEY *key = EC_KEY_new_by_curve_name(NID_secp384r1);]])],
Ondřej Surý's avatar
Ondřej Surý committed
831 832 833 834 835
    [AC_MSG_RESULT([yes])],
    [AC_MSG_FAILURE([not found.  ECDSA P-384 support in OpenSSL is mandatory.])])

AC_MSG_CHECKING([for Ed25519 support])
AC_COMPILE_IFELSE(
836 837 838
    [AC_LANG_PROGRAM([[#include <openssl/evp.h>
		       #include <openssl/ec.h>]],
		     [[EC_KEY *key = EC_KEY_new_by_curve_name(NID_ED25519);]])],
Ondřej Surý's avatar
Ondřej Surý committed
839 840 841
    [AC_DEFINE([HAVE_OPENSSL_ED25519], [1], [define if OpenSSL supports Ed25519])
     AC_MSG_RESULT([yes])],
    [AC_MSG_RESULT([no])])
842

Ondřej Surý's avatar
Ondřej Surý committed
843
AC_MSG_CHECKING([for Ed448 support])
Mark Andrews's avatar
Mark Andrews committed
844 845 846 847 848 849 850
AC_COMPILE_IFELSE(
    [AC_LANG_PROGRAM([[#include <openssl/evp.h>
		       #include <openssl/ec.h>]],
		     [[EC_KEY *key = EC_KEY_new_by_curve_name(NID_ED448);]])],
    [AC_DEFINE([HAVE_OPENSSL_ED448], [1], [define if OpenSSL supports Ed448])
     AC_MSG_RESULT([yes])],
    [AC_MSG_RESULT([no])])
851

Ondřej Surý's avatar
Ondřej Surý committed
852 853 854 855 856
#
# Check for OpenSSL SHA-1 support
#
AC_CHECK_FUNCS([EVP_sha1], [:],
	       [AC_MSG_FAILURE([SHA-1 support in OpenSSL is mandatory.])])
857

Ondřej Surý's avatar
Ondřej Surý committed
858 859 860 861 862
#
# Check for OpenSSL SHA-2 support
#
AC_CHECK_FUNCS([EVP_sha224 EVP_sha256 EVP_sha384 EVP_sha512], [:],
	       [AC_MSG_FAILURE([SHA-2 support in OpenSSL is mandatory.])])
863

Ondřej Surý's avatar
Ondřej Surý committed
864 865 866 867 868
#
# Check for OpenSSL AES support
#
AC_CHECK_FUNCS([EVP_aes_128_ecb EVP_aes_192_ecb EVP_aes_256_ecb], [:],
	       [AC_MSG_FAILURE([AES support in OpenSSL is mandatory.])])
869

Evan Hunt's avatar
Evan Hunt committed
870
#
Ondřej Surý's avatar
Ondřej Surý committed
871
# Check for OpenSSL 1.1.x/LibreSSL functions
Evan Hunt's avatar
Evan Hunt committed
872
#
873
AC_CHECK_FUNCS([DH_get0_key ECDSA_SIG_get0 RSA_set0_key])
874

875 876 877 878 879 880 881 882 883 884 885 886 887 888 889
#
# Check whether FIPS mode is available and whether we should enable it
#
AC_ARG_ENABLE([fips-mode],
	      [AS_HELP_STRING([--enable-fips-mode],
			      [enable FIPS mode in OpenSSL library [default=no]])],
	      [], [enable_fips_mode="no"])

AC_MSG_CHECKING([whether to enable FIPS mode in OpenSSL library])
AS_CASE([$enable_fips_mode],
	[yes], [AC_MSG_RESULT([yes])
		AC_CHECK_FUNCS([FIPS_mode],
			       [], [AC_MSG_FAILURE([OpenSSL FIPS mode requested but not available.])])],
	[no], [AC_MSG_RESULT([no])])

890
AX_RESTORE_FLAGS([openssl])
891

892
AC_SUBST([OPENSSL_CFLAGS])
Ondřej Surý's avatar
Ondřej Surý committed
893
AC_SUBST([OPENSSL_LIBS])
894 895

#
Ondřej Surý's avatar
Ondřej Surý committed
896
# Client Cookie algorithm choice
897
#
Ondřej Surý's avatar
Ondřej Surý committed
898 899 900 901 902 903 904 905 906 907 908 909 910 911 912
AC_ARG_WITH([cc-alg],
	    [AS_HELP_STRING([--with-cc-alg=ALG],
			   [choose the algorithm for Client Cookie
			    [aes|sha1|sha256] (default is aes)])],
	    [:], [with_cc_alg="aes"])

AC_MSG_CHECKING([for the algorithm for Client Cookie])
AS_CASE([$with_cc_alg],
	[sha1|SHA1],[AC_MSG_RESULT([sha1])
		     AC_DEFINE([HMAC_SHA1_CC], [1], [Use HMAC-SHA1 for Client Cookie generation])],
	[sha256|SHA256],[AC_MSG_RESULT([sha256])
			 AC_DEFINE([HMAC_SHA256_CC], [1], [Use HMAC-SHA256 for Client Cookie generation])],
	[aes|AES|auto],[AC_MSG_RESULT([aes])
		       AC_DEFINE([AES_CC], [1], [Use AES for Client Cookie generation])],
	[AC_MSG_ERROR([Invalid $with_cc_alg algorithm for Client Cookie])])
913

914

Ondřej Surý's avatar
Ondřej Surý committed
915
PKCS11_TOOLS=
916
PKCS11_TEST=
917
#
Ondřej Surý's avatar
Ondřej Surý committed
918
# was --enable-native-pkcs11 specified?
919
#
Ondřej Surý's avatar
Ondřej Surý committed
920 921 922 923 924 925 926 927 928
AC_ARG_ENABLE(native-pkcs11,
	      AS_HELP_STRING([--enable-native-pkcs11],
			     [use native PKCS11 for public-key crypto [default=no]]),
	      [:], [enable_native_pkcs11="no"])

AC_MSG_CHECKING([for PKCS11 for Public-Key Cryptography])
AS_CASE([$enable_native_pkcs11],
	[no],[AC_MSG_RESULT([no])],
	[yes],[PKCS11_TOOLS=pkcs11
929
	       PKCS11_TEST=pkcs11
Ondřej Surý's avatar
Ondřej Surý committed
930 931 932 933 934 935
	       CRYPTO=pkcs11
	       AS_IF([$use_threads],
		     [:],
		     [AC_MSG_ERROR([PKCS11 requires threading support])])
	       AC_MSG_RESULT([yes])
	       AC_CHECK_FUNCS([getpassphrase])
936 937
	      ])
AC_SUBST([PKCS11_TEST])
Ondřej Surý's avatar
Ondřej Surý committed
938 939 940 941 942 943 944 945
AC_SUBST([PKCS11_TOOLS])

AS_CASE([$CRYPTO],
	[pkcs11],[AC_DEFINE([USE_PKCS11], [1], [define if PKCS11 is used for Public-Key Cryptography])],
	[AC_DEFINE([USE_OPENSSL], [1], [define if OpenSSL is used for Public-Key Cryptography])])

# preparation for automake
# AM_CONDITIONAL([PKCS11_TOOLS], [test "$with_native_pkcs11" = "yes"])
946

947
#
Ondřej Surý's avatar
Ondřej Surý committed
948
# was --with-pkcs11 specified?
949
#
Ondřej Surý's avatar
Ondřej Surý committed
950 951 952 953
AC_ARG_WITH([pkcs11],
	    [AS_HELP_STRING([--with-pkcs11[=PATH]],
			    [Build with PKCS11 support [no|path] (PATH is for the PKCS11 provider)])],
	    [:], [with_pkcs11="undefined"])
954

Ondřej Surý's avatar
Ondřej Surý committed
955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979
AS_CASE([$with_pkcs11],
	[yes|auto],[AC_MSG_ERROR([--with-pkcs11 needs explicit path to the PKCS11 library])],
	[no|undefined],[with_pkcs11="undefined"])
AC_DEFINE_UNQUOTED([PK11_LIB_LOCATION], ["$with_pkcs11"], [define the default PKCS11 library path])

# for PKCS11 benchmarks

have_clock_gt=no
AC_CHECK_FUNC(clock_gettime,have_clock_gt=yes,)
if test "no" = "$have_clock_gt"; then
	AC_CHECK_LIB(rt,clock_gettime,have_clock_gt=rt,)
fi

if test "no" != "$have_clock_gt"; then
	AC_DEFINE(HAVE_CLOCK_GETTIME, 1, [Define if clock_gettime is available.])
fi

if test "rt" = "$have_clock_gt"; then
	LIBS="-lrt $LIBS"
fi

AC_MSG_CHECKING(for GSSAPI library)
AC_ARG_WITH(gssapi,
	    AS_HELP_STRING([--with-gssapi=[PATH|[/path/]krb5-config]],
			   [Specify path for system-supplied GSSAPI
980 981
				[default=auto]]),
	    use_gssapi="$withval", use_gssapi="auto")
Ondřej Surý's avatar
Ondřej Surý committed
982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010

# first try using krb5-config, if that does not work then fall back to "yes" method.

case "$use_gssapi" in
*/krb5-config|krb5-config)
    AC_MSG_RESULT(trying $use_gssapi)
    if test krb5-config = "$use_gssapi"
    then
	AC_PATH_PROG(KRB5_CONFIG, $use_gssapi)
    else
	KRB5_CONFIG="$use_gssapi"
    fi
    gssapi_cflags=`$KRB5_CONFIG --cflags gssapi`
    gssapi_libs=`$KRB5_CONFIG --libs gssapi`
    saved_cppflags="$CPPFLAGS"
    CPPFLAGS="$gssapi_cflags $CPPFLAGS"
    AC_CHECK_HEADERS(gssapi.h gssapi/gssapi.h,
	[ISC_PLATFORM_GSSAPIHEADER="#define ISC_PLATFORM_GSSAPIHEADER <$ac_header>"])
    if test "" = "$ISC_PLATFORM_GSSAPIHEADER"; then
	AC_MSG_RESULT([krb5-config: gssapi.h not found])
	CPPFLAGS="$saved_cppflags"
	use_gssapi="yes"
    else
	AC_CHECK_HEADERS(krb5/krb5.h krb5.h,
	    [ISC_PLATFORM_KRB5HEADER="#define ISC_PLATFORM_KRB5HEADER <$ac_header>"])
	if test "" = "$ISC_PLATFORM_KRB5HEADER"; then
	    AC_MSG_RESULT([krb5-config: krb5.h not found])
	    CPPFLAGS="$saved_cppflags"
	    use_gssapi="yes"
1011
	else
Ondřej Surý's avatar
Ondřej Surý committed
1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024
	    CPPFLAGS="$saved_cppflags"
	    saved_libs="$LIBS"
	    LIBS=$gssapi_libs
	    AC_MSG_CHECKING([krb5-config linking as $LIBS])
	    AC_TRY_LINK( , [gss_acquire_cred();krb5_init_context()],
		gssapi_linked=yes, gssapi_linked=no)
	    case $gssapi_linked in
		yes) AC_MSG_RESULT([krb5-config: linked]);;
		no)  AC_MSG_RESULT([krb5-config: could not determine proper GSSAPI linkage])
		    use_gssapi="yes"
		    ;;
	    esac
	    LIBS=$saved_libs
1025
	fi
Ondřej Surý's avatar
Ondřej Surý committed
1026 1027 1028 1029 1030 1031 1032 1033 1034
    fi
    if test "yes" = "$use_gssapi"; then
	AC_MSG_CHECKING([for GSSAPI library, non krb5-config method])
    fi
    ;;
esac

case "$host" in
*darwin*)
1035
	if test "yes" = "$use_gssapi" -o "auto" = "$use_gssapi"
Ondřej Surý's avatar
Ondřej Surý committed
1036 1037 1038 1039
	then
		use_gssapi=framework
	fi
	;;
1040
esac
1041

Ondřej Surý's avatar
Ondřej Surý committed
1042 1043 1044 1045 1046 1047
# gssapi is just the framework, we really require kerberos v5, so
# look for those headers (the gssapi headers must be there, too)
# The problem with this implementation is that it doesn't allow
# for the specification of gssapi and krb5 headers in different locations,
# which probably ought to be fixed although fixing might raise the issue of
# trying to build with incompatible versions of gssapi and krb5.
1048
if test "yes" = "$use_gssapi" -o "auto" = "$use_gssapi"
Evan Hunt's avatar
Evan Hunt committed
1049
then
Ondřej Surý's avatar
Ondřej Surý committed
1050 1051 1052 1053 1054 1055
	# first, deal with the obvious
	if test \( -f /usr/include/kerberosv5/krb5.h -o \
		   -f /usr/include/krb5/krb5.h -o \
		   -f /usr/include/krb5.h \)   -a \
		\( -f /usr/include/gssapi.h -o \
		   -f /usr/include/gssapi/gssapi.h \)
Evan Hunt's avatar
Evan Hunt committed
1056
	then
Ondřej Surý's avatar
Ondřej Surý committed
1057
		use_gssapi=/usr
Evan Hunt's avatar
Evan Hunt committed
1058
	else
Ondřej Surý's avatar
Ondřej Surý committed
1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072
	    krb5dirs="/usr/local /usr/local/krb5 /usr/local/kerberosv5 /usr/local/kerberos /usr/pkg /usr/krb5 /usr/kerberosv5 /usr/kerberos /usr"
	    for d in $krb5dirs
	    do
		if test -f $d/include/gssapi/gssapi_krb5.h -o \
			-f $d/include/krb5.h
		then
			if test -f $d/include/gssapi/gssapi.h -o \
				-f $d/include/gssapi.h
			then
				use_gssapi=$d
				break
			fi
		fi
	    done
1073 1074 1075 1076
	    if test "auto" = "$use_gssapi"
	    then
		use_gssapi="no"
	    fi
Evan Hunt's avatar
Evan Hunt committed
1077 1078
	fi
fi
1079

Ondřej Surý's avatar
Ondřej Surý committed
1080
case "$use_gssapi" in
Evan Hunt's avatar
Evan Hunt committed
1081
	no)
Ondřej Surý's avatar
Ondřej Surý committed
1082 1083
		AC_MSG_RESULT(disabled)
		USE_GSSAPI=''
1084
		;;
Ondřej Surý's avatar
Ondřej Surý committed
1085 1086
	yes)
		AC_MSG_ERROR([--with-gssapi must specify a path])
1087
		;;
Ondřej Surý's avatar
Ondřej Surý committed
1088 1089 1090 1091
	*/krb5-config|krb5-config)
		USE_GSSAPI='-DGSSAPI'
		DST_GSSAPI_INC="$gssapi_cflags"
		DNS_GSSAPI_LIBS="$gssapi_libs"
1092
		;;
Ondřej Surý's avatar
Ondřej Surý committed
1093 1094 1095 1096 1097 1098
	framework)
		USE_GSSAPI='-DGSSAPI'
		ISC_PLATFORM_GSSAPIHEADER="#define ISC_PLATFORM_GSSAPIHEADER <Kerberos/Kerberos.h>"
		ISC_PLATFORM_KRB5HEADER="#define ISC_PLATFORM_KRB5HEADER <Kerberos/Kerberos.h>"
		DNS_GSSAPI_LIBS="-framework Kerberos"
		AC_MSG_RESULT(framework)
Evan Hunt's avatar
Evan Hunt committed
1099
		;;
1100

1101
	*)
Ondřej Surý's avatar
Ondřej Surý committed
1102 1103 1104 1105 1106 1107 1108
		AC_MSG_RESULT(looking in $use_gssapi/lib)
		USE_GSSAPI='-DGSSAPI'
		saved_cppflags="$CPPFLAGS"
		CPPFLAGS="-I$use_gssapi/include $CPPFLAGS"
		AC_CHECK_HEADERS(gssapi.h gssapi/gssapi.h,
		    [ISC_PLATFORM_GSSAPIHEADER="#define ISC_PLATFORM_GSSAPIHEADER <$ac_header>"
		     gssapi_hack="#include <$ac_header>"])
1109

Ondřej Surý's avatar
Ondřej Surý committed
1110 1111 1112
		if test "" = "$ISC_PLATFORM_GSSAPIHEADER"; then
		    AC_MSG_ERROR([gssapi.h not found])
		fi
1113

Ondřej Surý's avatar
Ondřej Surý committed
1114 1115 1116
		AC_CHECK_HEADERS(gssapi_krb5.h gssapi/gssapi_krb5.h,
		    [ISC_PLATFORM_GSSAPI_KRB5_HEADER="#define ISC_PLATFORM_GSSAPI_KRB5_HEADER <$ac_header>"
		     gssapi_krb5_hack="#include <$ac_header>"])
Andreas Gustafsson's avatar
Andreas Gustafsson committed
1117

Ondřej Surý's avatar
Ondřej Surý committed
1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189
		AC_CHECK_HEADERS(krb5.h krb5/krb5.h kerberosv5/krb5.h,
		    [ISC_PLATFORM_KRB5HEADER="#define ISC_PLATFORM_KRB5HEADER <$ac_header>"
		    krb5_hack="#include <$ac_header>"])

		if test "" = "$ISC_PLATFORM_KRB5HEADER"; then
		    AC_MSG_ERROR([krb5.h not found])
		fi

		#
		# XXXDCL This probably doesn't work right on all systems.
		# It will need to be worked on as problems become evident.
		#
		# Essentially the problems here relate to two different
		# areas.  The first area is building with either KTH
		# or MIT Kerberos, particularly when both are present on
		# the machine.  The other is static versus dynamic linking.
		#
		# On the KTH vs MIT issue, Both have libkrb5 that can mess
		# up the works if one implementation ends up trying to
		# use the other's krb.  This is unfortunately a situation
		# that very easily arises.
		#
		# Dynamic linking when the dependency information is built
		# into MIT's libgssapi_krb5 or KTH's libgssapi magically makes
		# all such problems go away, but when that setup is not
		# present, because either the dynamic libraries lack
		# dependencies or static linking is being done, then the
		# problems start to show up.
		saved_libs="$LIBS"
		for TRY_LIBS in \
		    "-lgssapi_krb5" \
		    "-lgssapi_krb5 -lkrb5 -lk5crypto -lcom_err" \
		    "-lgssapi_krb5 -lkrb5 -lk5crypto -lcom_err -lresolv" \
		    "-lgssapi" \
		    "-lgssapi -lkrb5 -ldes -lcrypt -lasn1 -lroken -lcom_err" \
		    "-lgssapi -lkrb5 -lcrypt -lasn1 -lroken -lcom_err" \
		    "-lgssapi -lkrb5 -lgssapi_krb5 -lcrypt -lasn1 -lroken -lcom_err" \
		    "-lgssapi -lkrb5 -lhx509 -lcrypt -lasn1 -lroken -lcom_err" \
		    "-lgss -lkrb5"
		do
		    # Note that this does not include $saved_libs, because
		    # on FreeBSD machines this configure script has added
		    # -L/usr/local/lib to LIBS, which can make the
		    # -lgssapi_krb5 test succeed with shared libraries even
		    # when you are trying to build with KTH in /usr/lib.
		    if test "/usr" = "$use_gssapi"
		    then
			    LIBS="$TRY_LIBS $ISC_OPENSSL_LIBS"
		    else
			    LIBS="-L$use_gssapi/lib $TRY_LIBS $ISC_OPENSSL_LIBS"
		    fi
		    AC_MSG_CHECKING(linking as $TRY_LIBS)
		    AC_TRY_LINK([
#include <sys/types.h>
$gssapi_hack
$gssapi_krb5_hack
$krb5_hack
				] , [gss_acquire_cred(NULL, NULL, 0, NULL, 0, NULL, NULL, NULL);krb5_init_context(NULL);
#if defined(HAVE_GSSAPI_KRB5_H) || defined(HAVE_GSSAPI_GSSAPI_KRB5_H)
gsskrb5_register_acceptor_identity(NULL);
#endif],
				gssapi_linked=yes, gssapi_linked=no)
		    case $gssapi_linked in
		    yes) AC_MSG_RESULT(yes); break ;;
		    no)  AC_MSG_RESULT(no) ;;
		    esac
		done

		CPPFLAGS="$saved_cppflags"

		case $gssapi_linked in
		no) AC_MSG_ERROR(could not determine proper GSSAPI linkage) ;;
1190
		esac
Ondřej Surý's avatar
Ondřej Surý committed
1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222

		#
		# XXXDCL Major kludge.  Tries to cope with KTH in /usr/lib
		# but MIT in /usr/local/lib and trying to build with KTH.
		# /usr/local/lib can end up earlier on the link lines.
		# Like most kludges, this one is not only inelegant it
		# is also likely to be the wrong thing to do at least as
		# many times as it is the right thing.  Something better
		# needs to be done.
		#
		if test "/usr" = "$use_gssapi" -a \
			-f /usr/local/lib/libkrb5.a; then
		    FIX_KTH_VS_MIT=yes
		fi

		case "$FIX_KTH_VS_MIT" in
		yes)
		    case "$enable_static_linking" in
		    yes) gssapi_lib_suffix=".a"  ;;
		    *)   gssapi_lib_suffix=".so" ;;
		    esac

		    for lib in $LIBS; do
			case $lib in
			-L*)
			    ;;
			-l*)
			    new_lib=`echo $lib |
				     sed -e s%^-l%$use_gssapi/lib/lib% \
					 -e s%$%$gssapi_lib_suffix%`
			    NEW_LIBS="$NEW_LIBS $new_lib"
			    ;;
1223
			*)
Ondřej Surý's avatar
Ondřej Surý committed
1224 1225
			   AC_MSG_ERROR([KTH vs MIT Kerberos confusion!])
			    ;;
1226
			esac
Ondřej Surý's avatar
Ondřej Surý committed
1227 1228 1229
		    done
		    LIBS="$NEW_LIBS"
		    ;;
1230
		esac
Ondřej Surý's avatar
Ondřej Surý committed
1231 1232 1233 1234 1235 1236

		DST_GSSAPI_INC="-I$use_gssapi/include"
		DNS_GSSAPI_LIBS="$LIBS"

		AC_MSG_RESULT(using GSSAPI from $use_gssapi/lib and $use_gssapi/include)
		LIBS="$saved_libs"
Evan Hunt's avatar
Evan Hunt committed
1237 1238
		;;
esac
1239

Ondřej Surý's avatar
Ondřej Surý committed
1240 1241 1242 1243
AC_SUBST(ISC_PLATFORM_HAVEGSSAPI)
AC_SUBST(ISC_PLATFORM_GSSAPIHEADER)
AC_SUBST(ISC_PLATFORM_GSSAPI_KRB5_HEADER)
AC_SUBST(ISC_PLATFORM_KRB5HEADER)
Andreas Gustafsson's avatar
Andreas Gustafsson committed
1244

Ondřej Surý's avatar
Ondřej Surý committed
1245 1246 1247 1248
AC_SUBST(USE_GSSAPI)
AC_SUBST(DST_GSSAPI_INC)
AC_SUBST(DNS_GSSAPI_LIBS)
DNS_CRYPTO_LIBS="$DNS_GSSAPI_LIBS"
1249

Ondřej Surý's avatar
Ondřej Surý committed
1250 1251 1252
#
# Applications linking with libdns also need to link with these libraries.
#
1253

Ondřej Surý's avatar
Ondřej Surý committed
1254
AC_SUBST(DNS_CRYPTO_LIBS)
Francis Dupont's avatar
Francis Dupont committed
1255

1256 1257 1258 1259 1260
#
# was --with-lmdb specified?
#
AC_MSG_CHECKING(for lmdb library)
AC_ARG_WITH(lmdb,
1261 1262
	    AS_HELP_STRING([--with-lmdb[=PATH]],
			   [build with LMDB library [yes|no|path]]),
1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 127