configure.ac 55.3 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 11 12 13 14 15 16
#
# Defining the version in m4 requires a bit of dancing around,
# so the strings are properly concatenated, as you can't use
# a shell variable in AC_INIT()
#
m4_define([bind_VERSION_MAJOR], 9)dnl
m4_define([bind_VERSION_MINOR], 17)dnl
17
m4_define([bind_VERSION_PATCH], 3)dnl
18
m4_define([bind_VERSION_EXTRA], )dnl
19
m4_define([bind_DESCRIPTION], [(Development Release)])dnl
20
m4_define([bind_SRCID], [m4_esyscmd_s([git rev-parse --short HEAD | cut -b1-7])])dnl
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
m4_define([bind_PKG_VERSION], [[bind_VERSION_MAJOR.bind_VERSION_MINOR.bind_VERSION_PATCH]bind_VERSION_EXTRA])dnl

#
# Autoconf initialization
#
AC_INIT([BIND], bind_PKG_VERSION, [info@isc.org], [], [https://www.isc.org/downloads/])
AC_PREREQ(2.60)

AC_DEFINE([PACKAGE_VERSION_MAJOR], ["][bind_VERSION_MAJOR]["], [BIND 9 Major part of the version])
AC_DEFINE([PACKAGE_VERSION_MINOR], ["][bind_VERSION_MINOR]["], [BIND 9 Minor part of the version])
AC_DEFINE([PACKAGE_VERSION_PATCH], ["][bind_VERSION_PATCH]["], [BIND 9 Patch part of the version])
AC_DEFINE([PACKAGE_VERSION_EXTRA], ["][bind_VERSION_EXTRA]["], [BIND 9 Extra part of the version])
AC_DEFINE([PACKAGE_DESCRIPTION], [m4_ifnblank(bind_DESCRIPTION, [" ]bind_DESCRIPTION["], [])], [An extra string to print after PACKAGE_STRING])
AC_DEFINE([PACKAGE_SRCID], ["][bind_SRCID]["], [A short hash from git])

# This value should be increased whenever changing the structure of
# any object that will appear in a type 'map' master file (which
# contains a working memory image of an RBT database), as loading 
# an incorrect memory image produces an inconsistent and probably
# nonfunctional database.  These structures include but are not
# necessarily limited to dns_masterrawheader, rbtdb_file_header,
# rbt_file_header, dns_rbtdb, dns_rbt, dns_rbtnode, rdatasetheader.
#
# Err on the side of caution: if anything in the RBTDB is changed,
# bump the value.  Making map files unreadable protects the system
# from instability; it's a feature not a bug.
#
# Whenever releasing a new major release of BIND9, set this value
# back to 1.0 when releasing the first alpha.  Map files are *never*
# compatible across major releases.
AC_DEFINE([MAPAPI], ["2.0"], [BIND 9 MAPAPI Version])

bind_CONFIGARGS="${ac_configure_args:-default}"
AC_DEFINE_UNQUOTED([PACKAGE_CONFIGARGS], ["$bind_CONFIGARGS"], [Either 'defaults' or used ./configure options])

AC_DEFINE([PACKAGE_BUILDER], ["make"], [make or Visual Studio])

AC_CONFIG_SRCDIR([bin/named/main.c])
Michal Nowak's avatar
Michal Nowak committed
59
AM_INIT_AUTOMAKE([1.9 tar-pax foreign subdir-objects dist-xz no-dist-gzip -Wall -Werror])
60
AM_SILENT_RULES([yes])
61
AM_EXTRA_RECURSIVE_TARGETS([test unit doc])
62 63 64

AC_CONFIG_HEADERS([config.h])
AC_CONFIG_MACRO_DIR([m4])
Bob Halley's avatar
Bob Halley committed
65

66
#
67
# Enable maintainer mode by default only when building from git repository
68
#
69
AM_MAINTAINER_MODE([m4_ifset([bind_SRCID],[enable],[disable])])
70

71 72
# Set the library versions
# https://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html
Bob Halley's avatar
Bob Halley committed
73

74 75 76 77 78 79 80
AX_BIND9_LIB_VERSION([bind9])
AX_BIND9_LIB_VERSION([dns])
AX_BIND9_LIB_VERSION([irs])
AX_BIND9_LIB_VERSION([isc])
AX_BIND9_LIB_VERSION([isccc])
AX_BIND9_LIB_VERSION([isccfg])
AX_BIND9_LIB_VERSION([ns])
81 82 83 84

#
# Enable system extensions to C and POSIX
#
85
AC_USE_SYSTEM_EXTENSIONS
86 87 88 89 90 91 92 93 94 95 96 97
AC_CANONICAL_HOST

#
# Compiler compatibility flags
#
AC_PROG_CC_C99
AC_PROG_CPP_WERROR

#
# Find the machine's endian flavor.
#
AC_C_BIGENDIAN
98

99 100 101 102 103 104
#
# Enable large file support
#
AC_SYS_LARGEFILE
AC_FUNC_FSEEKO

105 106
# 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
107

108
AC_PROG_MAKE_SET
109

110 111 112
# Checks for programs.
m4_ifdef([AM_PROG_AR], [AM_PROG_AR]) # call AM_PROG_AR only if available

Michał Kępień's avatar
Michał Kępień committed
113
AC_PATH_PROG([LIBTOOL], [libtool])
114 115
AS_IF([test -z "$LIBTOOL"],
      [AC_MSG_ERROR([The libtool script could not be found.])])
116
AC_PROG_INSTALL
117
AC_PROG_LN_S
118
AX_POSIX_SHELL
119
AC_PROG_MKDIR_P
120

121
# Initialize libtool
122 123 124 125
LT_INIT([disable-static dlopen pic-only])

AS_IF([test $enable_static != "no"],
      [AC_MSG_ERROR([Static linking is not supported as it disables dlopen() and certain security features (e.g. RELRO, ASLR)])])
126 127 128 129

LT_CONFIG_LTDL_DIR([libltdl])
LTDL_INIT([recursive])
AC_CONFIG_FILES([libltdl/Makefile])
130

131
#
132
# Set the default CFLAGS and CPPFLAGS
133
#
134
STD_CFLAGS="-Wall -Wextra -Wwrite-strings -Wcast-qual -Wpointer-arith -Wno-missing-field-initializers -Wformat -Wshadow"
135

136 137
# These should be always errors
STD_CFLAGS="$STD_CFLAGS -Werror=implicit-function-declaration -Werror=missing-prototypes -Werror=format-security -Werror=parentheses -Werror=implicit -Werror=strict-prototypes"
138

139 140
# Fortify the sources by default
STD_CPPFLAGS="-D_FORTIFY_SOURCE=2"
141

142 143 144 145 146
#
# Additional compiler settings.
#
AX_CHECK_COMPILE_FLAG([-fno-strict-aliasing],
		      [STD_CFLAGS="$STD_CFLAGS -fno-strict-aliasing"])
147 148
# Clang only issues a warning so use -Werror to force a error.
AX_CHECK_COMPILE_FLAG([-Werror -fno-delete-null-pointer-checks],
149 150 151
		      [STD_CFLAGS="$STD_CFLAGS -fno-delete-null-pointer-checks"])
AX_CHECK_COMPILE_FLAG([-fdiagnostics-show-option],
		      [STD_CFLAGS="$STD_CFLAGS -fdiagnostics-show-option"])
152

153 154 155 156
#
# Change defaults for developers if not explicity set.
# Needs to be before the option is tested.
#
157 158 159
AC_ARG_ENABLE([developer],
	      [AS_HELP_STRING([--enable-developer],
			      [enable developer build settings])])
160

161
AS_IF([test "$enable_developer" = "yes"],
162
      [STD_CPPFLAGS="$STD_CPPFLAGS -DISC_MEM_DEFAULTFILL=1 -DISC_LIST_CHECKINIT=1"
163 164 165 166 167
       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 "${with_zlib+set}" = set || with_zlib=yes
168
       test "${enable_warn_error+set}" = set || enable_warn_error=yes
169
       ])
170 171 172 173

AC_SUBST([STD_CFLAGS])
AC_SUBST([STD_CPPFLAGS])

174 175 176 177 178 179 180
AC_ARG_ENABLE([warn_error],
	      [AS_HELP_STRING([--enable-warn-error],
			      [turn on -Werror when compiling])],
	      [],[enable_warn_error=no])
AS_IF([test "$enable_warn_error" = "yes"],
      [STD_CFLAGS="$STD_CFLAGS -Werror"])

181 182 183 184 185 186 187 188 189 190
#
# Use pkg-config
#

PKG_PROG_PKG_CONFIG
AS_IF([test -z "$PKG_CONFIG"],
      [AC_MSG_ERROR([The pkg-config script could not be found or is too old.])])

AC_ARG_ENABLE(buffer_useinline,
	      AS_HELP_STRING([--enable-buffer-useinline],
191
			     [define ISC_BUFFER_USEINLINE when compiling
192 193 194 195
				[default=yes]]),
	      if test yes = "${enable}"
	      then
		      AC_DEFINE([ISC_BUFFER_USEINLINE], [1],
196
				[Define if you want to use inline buffers])
197 198
	      fi,
	      AC_DEFINE([ISC_BUFFER_USEINLINE], [1]))
199

200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230
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])])
      ])
231

232 233
AC_ARG_ENABLE(mutex_atomics,
	      AS_HELP_STRING([--enable-mutex-atomics],
234
			     [emulate atomics by mutex-locked variables, useful for debugging
235 236 237 238 239 240 241
				[default=no]]),
	      [],
	      [enable_mutex_atomics=no])

AC_MSG_CHECKING([whether to emulate atomics with mutexes])
case "$enable_mutex_atomics" in
yes)
242 243 244
	AC_MSG_RESULT(yes)
	AC_DEFINE(ISC_MUTEX_ATOMICS, 1, [Define to emulate atomic variables with mutexes.])
	;;
245
no)
246 247
	AC_MSG_RESULT(no)
	;;
248
*)
249 250
	AC_MSG_ERROR("--enable-mutex-atomics requires yes or no")
	;;
251 252
esac

253 254 255
#
# Perl is optional; it is used only by some of the system test scripts.
#
256 257 258
AC_PATH_PROGS([PERL], [perl5 perl])
AC_SUBST([PERL])
AM_CONDITIONAL([HAVE_PERL], [test -n "$PERL"])
259

260 261 262
AX_PERL_MODULE([Digest::HMAC])
AM_CONDITIONAL([HAVE_PERLMOD_DIGEST_HMAC],
	       [test "$HAVE_PERLMOD_DIGEST__HMAC" = "yes"])
263

264 265 266
AX_PERL_MODULE([File::Fetch])
AM_CONDITIONAL([HAVE_PERLMOD_FILE_FETCH],
	       [test "$HAVE_PERLMOD_FILE__FETCH" = "yes"])
267

268 269 270
AX_PERL_MODULE([Net::DNS])
AM_CONDITIONAL([HAVE_PERLMOD_NET_DNS],
	       [test "$HAVE_PERLMOD_NET__DNS" = "yes"])
271

272 273 274
AX_PERL_MODULE([Net::DNS::Nameserver])
AM_CONDITIONAL([HAVE_PERLMOD_NET_DNS_NAMESERVER],
	       [test "$HAVE_PERLMOD_NET__DNS__NAMESERVER" = "yes"])
275

276 277 278
AX_PERL_MODULE([Time::HiRes])
AM_CONDITIONAL([HAVE_PERLMOD_TIME_HIRES],
	       [test "$HAVE_PERLMOD_TIME__HIRES" = "yes"])
279

280 281 282 283 284
#
# Python is optional, it is used only by some of the system test scripts.
#
AM_PATH_PYTHON([3.4], [], [:])
AM_CONDITIONAL([HAVE_PYTHON], [test "$PYTHON" != ":"])
285

286
AC_PATH_PROGS([PYTEST], [pytest-3 py.test-3 pytest pytest-pypy], [])
Ondřej Surý's avatar
Ondřej Surý committed
287 288 289
AS_IF([test -z "$PYTEST"],
      [AC_MSG_WARN([pytest not found, some system tests will be skipped])])
AC_SUBST([PYTEST])
290
AM_CONDITIONAL([HAVE_PYTEST], [test -n "$PYTEST"])
Ondřej Surý's avatar
Ondřej Surý committed
291

292 293
AX_PYTHON_MODULE([dns])
AM_CONDITIONAL([HAVE_PYMOD_DNS], [test "$HAVE_PYMOD_DNS" = "yes"])
294

295
#
296
# xsltproc is optional, it is used only by system test scripts.
297
#
298
AC_PATH_PROG([XSLTPROC], [xsltproc])
299

300 301 302 303 304 305 306 307 308 309 310
#
# 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])
		  ])
	])

311 312
AC_HEADER_STDC

313 314 315 316 317 318 319 320 321
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], [], [],
		 [$ac_includes_default
		  #ifdef HAVE_SYS_PARAM_H
		  # include <sys/param.h>
		  #endif
		  #ifdef HAVE_SYS_SOCKET_H
		  # include <sys/socket.h>
		  #endif
		 ])
322

323 324 325
#
# Check for thread local storage
#
326 327 328 329
AC_CHECK_HEADERS([threads.h])
AX_TLS([AS_IF([test "$ac_cv_tls" != "thread_local"],
	      [AC_DEFINE_UNQUOTED([thread_local], [$ac_cv_tls], [Define if the compiler uses a different keyword than thread_local for TLS variables])])],
       [AC_MSG_ERROR([Thread Local Storage support required, update your toolchain to build BIND 9])])
330

331 332
AC_C_CONST
AC_C_INLINE
333
AC_C_VOLATILE
334

335 336 337 338
#
# Check for yield support on ARM processors
#
AS_CASE([$host],
339 340 341 342 343 344 345 346 347
	[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])])])
348

349 350 351 352 353 354 355 356 357 358 359 360 361 362
#
# Check for pause support on SPARC processors
#
AS_CASE([$host],
	[sparc*],
	[AC_MSG_CHECKING([for pause instruction support])
	 AC_COMPILE_IFELSE(
	     [AC_LANG_PROGRAM([[]],
			     [[__asm__ __volatile__ ("pause")]])],
	     [AC_MSG_RESULT([yes])
	      AC_DEFINE([HAVE_SPARC_PAUSE], [1],
			[define if the SPARC pause instruction is available])],
	     [AC_MSG_RESULT([no])])])

363 364
AC_CHECK_FUNCS([sysctlbyname])

Evan Hunt's avatar
Evan Hunt committed
365 366 367 368 369
#
# Check for the existence of mmap to enable the fast format zones
#
AC_CHECK_FUNCS(mmap)

370 371 372
#
# Older versions of HP/UX don't define seteuid() and setegid()
#
373 374
AC_CHECK_FUNCS([seteuid setresuid])
AC_CHECK_FUNCS([setegid setresgid])
375

376
AC_TYPE_SIZE_T
377 378 379
AC_TYPE_SSIZE_T
AC_TYPE_UINTPTR_T

380 381
AC_HEADER_TIME

382 383 384
#
# check for uname library routine
#
385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402
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])
  ])
403

Francis Dupont's avatar
Francis Dupont committed
404 405 406
#
# check for GCC noreturn attribute
#
407
AX_GCC_FUNC_ATTRIBUTE([noreturn])
Francis Dupont's avatar
Francis Dupont committed
408

409 410 411
#
# check if we have kqueue
#
412 413 414 415 416 417 418
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])])
419 420

#
421 422
# 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.
423
#
424 425 426 427 428 429 430
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])])
431 432 433 434

#
# check if we support /dev/poll
#
435 436 437 438 439 440
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])])
441

Michael Graff's avatar
Michael Graff committed
442
#
Evan Hunt's avatar
Evan Hunt committed
443
# GeoIP support?
Michael Graff's avatar
Michael Graff committed
444
#
445 446 447 448 449 450 451 452 453
# Should be on by default if libmaxminddb exists.
#
AC_ARG_ENABLE([geoip],
	      [AS_HELP_STRING([--disable-geoip],
			      [support GeoIP2 geolocation ACLs if available [default=yes]])],
	      [], [enable_geoip="yes"])

AC_ARG_WITH([maxminddb],
	    [AS_HELP_STRING([--with-maxminddb=PATH],
454
			    [Build with MaxMind GeoIP2 support (auto|yes|no|path) [default=auto]])],
455
	    [], [with_maxminddb="auto"])
456

457 458 459 460 461 462 463 464 465 466 467 468 469 470
AS_IF([test "$enable_geoip" = "yes"],
      [AS_CASE([$with_maxminddb],
	       [no],[AC_MSG_ERROR([Use '--disable-geoip' to disable the GeoIP])],
	       [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])])
					 ],[:])],
	       [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])])
					])],
	       [ # default
		   AX_SAVE_FLAGS([maxminddb])
		   MAXMINDDB_CFLAGS="-I$with_maxminddb/include"
471
		   MAXMINDDB_LIBS="-L$with_maxminddb/lib"
472
		   CFLAGS="$CFLAGS $MAXMINDDB_CFLAGS"
473
		   LIBS="$LIBS $MAXMINDDB_LIBS"
474 475 476 477 478 479 480
		   AC_SEARCH_LIBS([MMDB_open], [maxminddb],
				  [AC_DEFINE([HAVE_GEOIP2], [1], [Build with GeoIP2 support])
				   MAXMINDDB_LIBS="$MAXMINDDB_LIBS $ac_cv_search_mmdb_open"
				   AC_MSG_NOTICE([GeoIP2 default database path set to $with_maxminddb/share/GeoIP])
				   AS_VAR_COPY([MAXMINDDB_PREFIX], [$with_maxminddb])
				  ],
				  [AC_MSG_ERROR([GeoIP2 requested, but libmaxminddb not found])])
481
		   AX_RESTORE_FLAGS([maxminddb])
482 483 484 485
	       ])
       AC_ARG_VAR([MAXMINDDB_PREFIX], [value of prefix for MAXMINDDB, overriding pkg-config])
])

486 487
AM_CONDITIONAL([HAVE_GEOIP2], [test -n "$MAXMINDDB_LIBS"])

488 489
AC_SUBST([MAXMINDDB_CFLAGS])
AC_SUBST([MAXMINDDB_LIBS])
Francis Dupont's avatar
Francis Dupont committed
490

491
AX_PTHREAD
Francis Dupont's avatar
Francis Dupont committed
492

493 494 495
LIBS="$PTHREAD_LIBS $LIBS"
CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
CC="$PTHREAD_CC"
Evan Hunt's avatar
Evan Hunt committed
496

497
AC_CHECK_FUNCS([pthread_attr_getstacksize pthread_attr_setstacksize])
Witold Krecicki's avatar
Witold Krecicki committed
498

499
AC_ARG_WITH([locktype],
Witold Krecicki's avatar
Witold Krecicki committed
500 501
	    AS_HELP_STRING([--with-locktype=ARG],
			   [Specify mutex lock type
502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532
			    (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
533

Witold Krecicki's avatar
Witold Krecicki committed
534 535 536 537
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
538
# Look for functions relating to thread naming
539
AC_CHECK_FUNCS([pthread_setname_np pthread_set_name_np])
Witold Krecicki's avatar
Witold Krecicki committed
540 541
AC_CHECK_HEADERS([pthread_np.h], [], [], [#include <pthread.h>])

542
# libuv
543
AC_MSG_CHECKING([for libuv])
544 545 546 547 548 549 550
PKG_CHECK_MODULES([LIBUV], [libuv >= 1.0.0], [],
		  [AC_MSG_ERROR([libuv not found])])
AX_SAVE_FLAGS([libuv])

CFLAGS="$CFLAGS $LIBUV_CFLAGS"
LIBS="$LIBS $LIBUV_LIBS"

551 552
# Those functions are only provided in newer versions of libuv, we'll be emulating them
# for now
553
AC_CHECK_FUNCS([uv_handle_get_data uv_handle_set_data uv_import])
554
AX_RESTORE_FLAGS([libuv])
555

556 557 558 559 560
#
# flockfile is usually provided by pthreads
#
AC_CHECK_FUNCS([flockfile getc_unlocked])

Witold Krecicki's avatar
Witold Krecicki committed
561 562 563
#
# Look for sysconf to allow detection of the number of processors.
#
564
AC_CHECK_FUNCS([sysconf])
565

566
#
567
# Do we want to use pthread rwlock?
568 569
#
AC_ARG_ENABLE([pthread_rwlock],
570 571 572
	      [AS_HELP_STRING([--enable-pthread-rwlock],
			      [use pthread rwlock instead of internal rwlock implementation])],
	      [], [enable_pthread_rwlock=no])
573 574 575 576 577 578

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])
      ])
579

Ondřej Surý's avatar
Ondřej Surý committed
580
CRYPTO=OpenSSL
581

Ondřej Surý's avatar
Ondřej Surý committed
582
#
583
# OpenSSL/LibreSSL is mandatory
Ondřej Surý's avatar
Ondřej Surý committed
584
#
585 586
PKG_CHECK_MODULES([OPENSSL], [libcrypto], [],
		  [AX_CHECK_OPENSSL([:],[AC_MSG_FAILURE([OpenSSL/LibreSSL not found])])])
Ondřej Surý's avatar
Ondřej Surý committed
587

588 589
AX_SAVE_FLAGS([openssl])

590
CFLAGS="$CFLAGS $OPENSSL_CFLAGS"
Ondřej Surý's avatar
Ondřej Surý committed
591 592 593 594 595 596 597 598 599 600 601 602
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])])

603 604 605 606 607 608 609 610 611
#
# 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
612 613 614 615 616 617 618 619 620
#
# 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(
621 622 623
    [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
624 625 626 627 628
    [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(
629 630 631
    [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
632 633 634 635 636
    [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(
637 638 639
    [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
640 641 642
    [AC_DEFINE([HAVE_OPENSSL_ED25519], [1], [define if OpenSSL supports Ed25519])
     AC_MSG_RESULT([yes])],
    [AC_MSG_RESULT([no])])
643

Ondřej Surý's avatar
Ondřej Surý committed
644
AC_MSG_CHECKING([for Ed448 support])
Mark Andrews's avatar
Mark Andrews committed
645 646 647 648 649 650
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])],
651 652
    [AC_MSG_RESULT([no])])

Ondřej Surý's avatar
Ondřej Surý committed
653 654 655 656 657
#
# Check for OpenSSL SHA-1 support
#
AC_CHECK_FUNCS([EVP_sha1], [:],
	       [AC_MSG_FAILURE([SHA-1 support in OpenSSL is mandatory.])])
658

Ondřej Surý's avatar
Ondřej Surý committed
659 660 661 662 663
#
# 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.])])
664

Ondřej Surý's avatar
Ondřej Surý committed
665 666 667 668 669
#
# 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.])])
670

Evan Hunt's avatar
Evan Hunt committed
671
#
Ondřej Surý's avatar
Ondřej Surý committed
672
# Check for OpenSSL 1.1.x/LibreSSL functions
Evan Hunt's avatar
Evan Hunt committed
673
#
674
AC_CHECK_FUNCS([DH_get0_key ECDSA_SIG_get0 RSA_set0_key])
675

676 677 678 679 680 681 682 683 684 685 686 687 688 689 690
#
# 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])])

691
AX_RESTORE_FLAGS([openssl])
692

693
AC_SUBST([OPENSSL_CFLAGS])
Ondřej Surý's avatar
Ondřej Surý committed
694
AC_SUBST([OPENSSL_LIBS])
695

696
#
Ondřej Surý's avatar
Ondřej Surý committed
697
# was --enable-native-pkcs11 specified?
698
#
699
AC_ARG_ENABLE([native-pkcs11],
Ondřej Surý's avatar
Ondřej Surý committed
700 701 702 703 704 705 706
	      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])],
707
	[yes],[CRYPTO=pkcs11
Ondřej Surý's avatar
Ondřej Surý committed
708 709
	       AC_MSG_RESULT([yes])
	       AC_CHECK_FUNCS([getpassphrase])
710
	      ])
711
AM_CONDITIONAL([HAVE_PKCS11], [test "$CRYPTO" = "pkcs11"])
Ondřej Surý's avatar
Ondřej Surý committed
712

713
AC_SUBST([CRYPTO])
Ondřej Surý's avatar
Ondřej Surý committed
714 715 716 717
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])])

718
#
Ondřej Surý's avatar
Ondřej Surý committed
719
# was --with-pkcs11 specified?
720
#
Ondřej Surý's avatar
Ondřej Surý committed
721 722 723 724
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"])
725

Ondřej Surý's avatar
Ondřej Surý committed
726 727 728 729 730
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])

731
AC_CHECK_FUNCS([clock_gettime])
Ondřej Surý's avatar
Ondřej Surý committed
732

733 734
AC_ARG_WITH([gssapi],
	    [AS_HELP_STRING([--with-gssapi=[PATH|[/path/]krb5-config]],
Ondřej Surý's avatar
Ondřej Surý committed
735
			   [Specify path for system-supplied GSSAPI
736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793
				[default=auto]])],
	    [], [with_gssapi="auto"])

KRB5_CONFIG=
AS_CASE([$with_gssapi],
	[no],[AC_MSG_CHECKING([for GSSAPI support])
	      AC_MSG_RESULT([no])],
	[yes],[AC_PATH_PROG([KRB5_CONFIG], [krb5-config])
	       AS_IF([test -z "$KRB5_CONFIG"],
		     [AC_MSG_ERROR([krb5-config required but not found])])],
	[auto],[AC_PATH_PROG([KRB5_CONFIG], [krb5-config])],
	[*krb5-config*],[KRB5_CONFIG="$with_gssapi"],
	[AC_MSG_ERROR([--with-gssapi requires yes|no|auto|/path/to/krb5-config])])

GSSAPI_CFLAGS=
GSSAPI_LIBS=
KRB5_CFLAGS=
KRB5_LIBS=
AS_IF([test -n "$KRB5_CONFIG"],
      [AC_MSG_CHECKING([for gssapi libraries])
       AX_SAVE_FLAGS([gssapi])
       GSSAPI_CFLAGS=`"$KRB5_CONFIG" --cflags gssapi`
       GSSAPI_LIBS=`"$KRB5_CONFIG" --libs gssapi`
       CFLAGS="$CFLAGS $GSSAPI_CFLAGS"
       LIBS="$LIBS $GSSAPI_LIBS"
       AC_MSG_RESULT([$GSSAPI_CFLAGS $GSSAPI_LIBS])
       AC_CHECK_HEADERS([gssapi/gssapi.h], [],
			[AC_CHECK_HEADERS([gssapi.h], [],
					  [AC_MSG_ERROR([neither gssapi/gssapi.h nor gssapi.h found])])])
       AC_CHECK_HEADERS([gssapi/gssapi_krb5.h],
			[AC_CHECK_HEADERS([gssapi_krb5.h], []
					  [AC_MSG_ERROR([neither gssapi/gssapi_krb5.h nor gssapi_krb5.h found])])])
       AC_CHECK_FUNCS([gss_acquire_cred],[],
		      [AC_MSG_ERROR([linking with $GSSAPI_LIBS does not work])])
       AX_RESTORE_FLAGS([gssapi])

       AC_MSG_CHECKING([for krb5 libraries])
       AX_SAVE_FLAGS([krb5])
       KRB5_CFLAGS=`"$KRB5_CONFIG" --cflags krb5`
       KRB5_LIBS=`$KRB5_CONFIG --libs krb5`
       CFLAGS="$CFLAGS $KRB5_CFLAGS"
       LIBS="$CFLAGS $KRB5_LIBS"
       AC_MSG_RESULT([$KRB5_CFLAGS $KRB5_LIBS])
       AC_CHECK_HEADERS([krb5/krb5.h], [],
			[AC_CHECK_HEADERS([krb5.h], [],
					  [AC_MSG_ERROR([neither krb5/krb5.h nor krb5 found])])])
       AC_CHECK_FUNCS([krb5_init_context], [],
		      [AC_MSG_ERROR([linking with $KRB5_LIBS failed])])
       AX_RESTORE_FLAGS([krb5])

       AC_DEFINE([HAVE_GSSAPI], [1], [Define to 1 if you have the Kerberos Framework available])
       # kludge to silence compiler warnings which recommend use of GSS.framework on macOS
       AS_CASE([$host],[*-darwin*],[CFLAGS="$CFLAGS -Wno-deprecated-declarations"])])
AM_CONDITIONAL([HAVE_GSSAPI], [test -n "$GSSAPI_LIBS"])
AC_SUBST([GSSAPI_CFLAGS])
AC_SUBST([GSSAPI_LIBS])
AC_SUBST([KRB5_CFLAGS])
AC_SUBST([KRB5_LIBS])
Francis Dupont's avatar
Francis Dupont committed
794

795 796 797 798
#
# was --with-lmdb specified?
#

Ondřej Surý's avatar
Ondřej Surý committed
799 800 801 802 803
AC_ARG_WITH([lmdb],
	    [AS_HELP_STRING([--with-lmdb=@<:@PATH@:>@],
			    [use LMDB library @<:@default=auto@:>@, optionally specify the prefix for lmdb library])],
	    [:],
	    [with_lmdb="auto"])
804

Ondřej Surý's avatar
Ondřej Surý committed
805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830
ac_lib_lmdb_found=no
AS_CASE([$with_lmdb],
	[no],[],
	[auto|yes], [PKG_CHECK_MODULES([LMDB], [lmdb],
				       [ac_lib_lmdb_found=yes],
				       [for ac_lib_lmdb_path in /usr /usr/local /opt /opt/local; do
						AX_LIB_LMDB([$ac_lib_lmdb_path],
							    [ac_lib_lmdb_found=yes
							     break])
					done
				       ])],
	[AX_LIB_LMDB([$with_lmdb],[ac_lib_lmdb_found=yes])])

# don't fail when in automatic mode
AS_IF([test "$with_lmdb" = "auto" && test "$ac_lib_lmdb_found" = "no"],
      [with_lmdb=no])

# hard fail when LMDB requested, but not found
AS_IF([test "$with_lmdb" != "no" && test "$ac_lib_lmdb_found" != "yes"],
      [AC_MSG_ERROR([LMDB requested, but not found])])

AS_IF([test "$ac_lib_lmdb_found" = "yes"],
      [AC_DEFINE([HAVE_LMDB], [1], [Use lmdb library])])

AC_SUBST([LMDB_CFLAGS])
AC_SUBST([LMDB_LIBS])
831
AM_CONDITIONAL([HAVE_LMDB], [test -n "$LMDB_LIBS"])
832

833 834 835
#
# was --with-libxml2 specified?
#
836 837 838 839 840 841 842 843 844 845 846 847 848
AC_ARG_WITH([libxml2],
	    [AS_HELP_STRING([--with-libxml2],
			    [build with libxml2 library [yes|no|auto] (default is auto)])],
	    [], [with_libxml2="auto"])

AS_CASE([$with_libxml2],
	[no],[],
	[auto],[PKG_CHECK_MODULES([LIBXML2], [libxml-2.0 >= 2.6.0],
				  [AC_DEFINE([HAVE_LIBXML2], [1], [Use libxml2 library])],
				  [:])],
	[yes],[PKG_CHECK_MODULES([LIBXML2], [libxml-2.0 >= 2.6.0],
				 [AC_DEFINE([HAVE_LIBXML2], [1], [Use libxml2 library])])],
	[AC_MSG_ERROR([Specifying libxml2 installation path is not supported, adjust PKG_CONFIG_PATH instead])])
849

850
AM_CONDITIONAL([HAVE_LIBXML2], [test -n "$LIBXML2_LIBS"])
851

852 853 854 855 856 857
#
# was --with-json-c specified?
#
AC_ARG_WITH([json-c],
	    [AS_HELP_STRING([--with-json-c],
			    [build with json-c library [yes|no|detect] (default is detect)])],
858
	    [], [with_json_c="detect"])
859

860 861 862 863 864 865 866 867 868
AS_CASE([$with_json_c],
	[no],[],
	[detect],[PKG_CHECK_MODULES([JSON_C], [json-c >= 0.11],
				    [AC_DEFINE([HAVE_JSON_C], [1], [Use json-c library])],
				    [:])],
	[yes],[PKG_CHECK_MODULES([JSON_C], [json-c >= 0.11],
				 [AC_DEFINE([HAVE_JSON_C], [1], [Use json-c library])])],
	[AC_MSG_ERROR([Specifying json-c installation path is not supported, adjust PKG_CONFIG_PATH instead])]
       )
869

870 871
AM_CONDITIONAL([HAVE_JSON_C], [test -n "$JSON_C_LIBS"])

872 873
AC_SUBST([JSON_C_CFLAGS])
AC_SUBST([JSON_C_LIBS])
874

875 876 877
#
# was --with-zlib specified?
#
878
AC_ARG_WITH([zlib],
879 880 881 882
	    [AS_HELP_STRING([--with-zlib],
			    [build with zlib for HTTP compression
			     [default=yes]])],
	    [], with_zlib="auto")
883 884 885 886

AS_CASE([$with_zlib],
       [no],[],
       [auto],[PKG_CHECK_MODULES([ZLIB], [zlib],
887 888
				 [AC_DEFINE([HAVE_ZLIB], [1], [Use zlib library])],
				 [:])],
889
       [yes],[PKG_CHECK_MODULES([ZLIB], [zlib],
890
				[AC_DEFINE([HAVE_ZLIB], [1], [Use zlib library])])],
891
       [AC_MSG_ERROR([Specifying zlib installation path is not supported, adjust PKG_CONFIG_PATH instead])])
Evan Hunt's avatar
Evan Hunt committed
892 893
AC_SUBST([ZLIB_CFLAGS])
AC_SUBST([ZLIB_LIBS])
894

895 896 897 898 899
#
# Google/Great Performance Tools CPU Profiler
#
AC_MSG_CHECKING(whether to use gperftools profiler)
AC_ARG_WITH(gperftools-profiler,
900 901 902
	    AS_HELP_STRING([--with-gperftools-profiler],
			   [use gperftools CPU profiler]),
	    use_profiler="$withval", use_profiler="no")
903 904 905 906 907 908 909 910 911 912 913 914

case $use_profiler in
	yes)
		AC_MSG_RESULT(yes)
		AC_DEFINE([HAVE_GPERFTOOLS_PROFILER], 1,
		[Define to use gperftools CPU profiler.])
		LIBS="$LIBS -lprofiler"
		;;
	*)
		AC_MSG_RESULT(no)
		;;
esac
915

916
#
917
# Check if the system supports glibc-compatible backtrace() function.
918
#
919 920 921
AC_CHECK_HEADERS([execinfo.h],
		 [AC_SEARCH_LIBS([backtrace], [execinfo],
				 [AC_CHECK_FUNCS([backtrace backtrace_symbols])])])
922

923
AM_CONDITIONAL([HAVE_BACKTRACE], [test "$ac_cv_func_backtrace" = "yes"])
924

925 926 927 928
#
# We do the IPv6 compilation checking after libtool so that we can put
# the right suffix on the files.
#
929 930 931 932 933 934 935 936 937
AC_MSG_CHECKING([for IPv6 structures])
AC_COMPILE_IFELSE(
  [AC_LANG_PROGRAM(
     [[
       #include <sys/types.h>
       #include <sys/socket.h>
       #include <netinet/in.h>
     ]],
     [[
938 939
       struct sockaddr_in6 sin6;
       struct in6_addr in6;
940
       struct in6_pktinfo in6_pi;
941
       struct sockaddr_storage storage;
942
       in6 = in6addr_any;
943
       in6 = in6addr_loopback;
944
       sin6.sin6_scope_id = 0;
945
       return (0);
946 947 948
     ]])],
  [AC_MSG_RESULT([yes])],
  [AC_MSG_FAILURE([IPv6 support is mandatory])])
949

950
#
951 952 953
# Allow forcibly disabling TCP Fast Open support as autodetection might yield
# confusing results on some systems (e.g. FreeBSD; see set_tcp_fastopen()
# comment in lib/isc/unix/socket.c).
954
#
955

956 957 958
AC_ARG_ENABLE([tcp_fastopen],
	      [AS_HELP_STRING([--disable-tcp-fastopen],
			      [disable TCP Fast Open support [default=yes]])],
959
	      [], [enable_tcp_fastopen="yes"])
960

961 962
AS_IF([test "$enable_tcp_fastopen" = "yes"],
      [AC_DEFINE([ENABLE_TCP_FASTOPEN], [1], [define if you want TCP_FASTOPEN enabled if available])])
963

964
#
965
# Check for some other useful functions that are not ever-present.
966
#
967
AC_CHECK_FUNCS([strlcpy strlcat])
968

969
AC_SUBST(READLINE_LIB)
970
AC_ARG_WITH(readline,
971 972 973
	    AS_HELP_STRING([--with-readline[=LIBSPEC]],
			   [specify readline library [default auto]]),
	    use_readline="$withval", use_readline="auto")
974
case "$use_readline" in
975
no)	;;
976
*)
Evan Hunt's avatar
Evan Hunt committed
977
	saved_LIBS="$LIBS"
978 979 980 981 982
	case "$use_readline" in
	yes|auto) try_readline="-ledit"; or_readline="-lreadline" ;;
	*) try_readline="$use_readline"
	esac
	for readline in "$try_readline" $or_readline
Evan Hunt's avatar
Evan Hunt committed
983
	do
984 985
		LIBS="$readline"
		AC_MSG_NOTICE(checking for readline with $readline)
Evan Hunt's avatar
Evan Hunt committed
986
		AC_CHECK_FUNCS(readline)
987
		if test "yes" = "$ac_cv_func_readline"
Evan Hunt's avatar
Evan Hunt committed
988
		then
989
			READLINE_LIB="$readline"
Evan Hunt's avatar
Evan Hunt committed
990 991 992 993
			break
		fi
		for lib in -lterminfo -ltermcap -lncurses -lcurses
		do
994
			AC_MSG_NOTICE(checking for readline with $readline $lib)
Evan Hunt's avatar
Evan Hunt committed
995
			unset ac_cv_func_readline
996
			LIBS="$readline $lib"
Evan Hunt's avatar
Evan Hunt committed
997
			AC_CHECK_FUNCS(readline)
998
			if test "yes" = "$ac_cv_func_readline"
Evan Hunt's avatar
Evan Hunt committed
999
			then
1000
				READLINE_LIB="$readline $lib"
Evan Hunt's avatar
Evan Hunt committed
1001 1002 1003
				break
			fi
		done
1004
		if test "yes" = "$ac_cv_func_readline"
1005 1006 1007
		then
			break
		fi
Evan Hunt's avatar
Evan Hunt committed
1008
	done
1009
	if test "auto" != "$use_readline" &&
1010
	   test "X$READLINE_LIB" = "X"
1011 1012 1013
	then
		AC_MSG_ERROR([The readline library was not found.])
	fi
1014
	LIBS="$saved_LIBS"
1015
	;;
1016
esac
1017
if test "yes" = "$ac_cv_func_readline"
1018 1019 1020 1021
then
	case "$READLINE_LIB" in
	*edit*)
		AC_CHECK_HEADERS(editline/readline.h)
1022 1023
		AC_CHECK_HEADERS(edit/readline/readline.h)
		AC_CHECK_HEADERS(edit/readline/history.h)
1024 1025 1026 1027 1028
		;;
	esac
	AC_CHECK_HEADERS(readline/readline.h)
	AC_CHECK_HEADERS(readline/history.h)
fi
1029

1030 1031 1032
#
# Security Stuff
#
1033 1034
# Note it is very recommended to *not* disable chroot(),
# this is only because chroot() was made obsolete by Posix.
1035
AC_ARG_ENABLE(chroot, AS_HELP_STRING([--disable-chroot], [disable chroot]))
1036 1037 1038 1039 1040 1041 1042
case "$enable_chroot" in
	yes|'')
		AC_CHECK_FUNCS(chroot)
		;;
	no)
		;;
esac
1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057

LIBCAP_LIBS=""
AC_MSG_CHECKING([whether to enable Linux capabilities])
AC_ARG_ENABLE([linux-caps],
	      [AS_HELP_STRING([--disable-linux-caps],
			      [disable Linux capabilities])],
	      [],
	      [AS_CASE([$host],
		       [*-linux*],[enable_linux_caps=yes],
		       [enable_linux_caps=no])])

AS_IF([test "$enable_linux_caps" = "yes"],
      [AC_MSG_RESULT([yes])
       AC_CHECK_HEADERS([sys/capability.h],
			[],
1058 1059
			[AC_MSG_ERROR(m4_normalize([sys/capability.h header is required for Linux capabilities support.
						    Either install libcap or use --disable-linux-caps.]))])
1060
       AX_SAVE_FLAGS([cap])
1061 1062
       AC_SEARCH_LIBS([cap_set_proc], [cap],
		      [LIBCAP_LIBS="$ac_cv_search_cap_set_proc"],
1063 1064
		      [AC_MSG_ERROR(m4_normalize([libcap is required for Linux capabilities support.
						  Either install libcap or use --disable-linux-caps.]))])
1065
       AX_RESTORE_FLAGS([cap])],
1066 1067 1068
      [AC_MSG_RESULT([no])])
AC_SUBST([LIBCAP_LIBS])

1069 1070 1071 1072 1073 1074 1075
case "$host" in
*-solaris*)
	AC_DEFINE(NEED_SECURE_DIRECTORY, 1,
		  [Define if connect does not honour the permission on the UNIX domain socket.])
	;;
esac

1076 1077 1078
#
# Time Zone Stuff
#
1079
AC_CHECK_FUNCS([tzset])
1080

Francis Dupont's avatar
Francis Dupont committed
1081
AC_MSG_CHECKING(for optarg declaration)
1082 1083 1084 1085 1086 1087
AC_TRY_COMPILE([
#include <unistd.h>
],
[optarg = 0;],
[AC_MSG_RESULT(yes)],
[AC_MSG_RESULT(no)
1088
GEN_NEED_OPTARG="-DNEED_OPTARG=1"
1089 1090
AC_DEFINE(NEED_OPTARG, 1, [Defined if extern char *optarg is not declared.])])

1091 1092 1093
#
# Check for nanoseconds in file stats
#
1094 1095 1096 1097 1098 1099 1100 1101
AC_MSG_CHECKING([for st_mtim.tv_nsec])
AC_COMPILE_IFELSE(
  [AC_LANG_PROGRAM(
     [[#include <sys/fcntl.h>]],
     [[struct stat s;
       return(s.st_mtim.tv_nsec);
      ]])],
   [AC_DEFINE([HAVE_STAT_NSEC], [1], [define if struct stat has st_mtim.tv_nsec field])])
1102

1103 1104 1105
#
# Check for if_nametoindex() for IPv6 scoped addresses support
#
1106
AC_CHECK_FUNCS([if_nametoindex])
1107

1108
AC_CHECK_FUNCS(nanosleep usleep explicit_bzero)
1109

1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126
ISC_ATOMIC_LIBS=""
AC_CHECK_HEADERS(
  [stdatomic.h],
  [AC_MSG_CHECKING([for memory model aware atomic operations])
   AC_COMPILE_IFELSE(
     [AC_LANG_PROGRAM(
	[[#include <stdatomic.h>]],
	[[atomic_int_fast32_t val = 0; atomic_fetch_add_explicit(&val, 1, memory_order_relaxed);]]
      )],
     [AC_MSG_RESULT([stdatomic.h])
      AC_MSG_CHECKING([whether -latomic is needed for 64-bit stdatomic.h functions])
      AC_LINK_IFELSE(
	[AC_LANG_PROGRAM(
	   [[#include <stdatomic.h>]],
	   [[atomic_int_fast64_t val = 0; atomic_fetch_add_explicit(&val, 1, memory_order_relaxed);]]
	 )],
	[AC_MSG_RESULT([no])],
1127
	[ISC_ATOMIC_LIBS="-latomic"
1128
	 AX_SAVE_FLAGS([atomic])
1129 1130 1131 1132 1133 1134 1135 1136
	 LIBS="$LIBS $ISC_ATOMIC_LIBS"
	 AC_LINK_IFELSE(
	   [AC_LANG_PROGRAM(
	      [[#include <stdatomic.h>]],
	      [[atomic_int_fast64_t val = 0; atomic_fetch_add_explicit(&val, 1, memory_order_relaxed);]]
	    )],
	   [AC_MSG_RESULT([yes])],
	   [AC_MSG_FAILURE([libatomic needed, but linking with -latomic failed, please fix your toolchain.])])
1137
	 AX_RESTORE_FLAGS([atomic])
1138 1139
	])
     ],
1140
     [AC_MSG_FAILURE([stdatomic.h header found, but compilation failed, please fix your toolchain.])]
1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156
   )],
  [AC_MSG_CHECKING([for memory model aware atomic operations])
   AC_COMPILE_IFELSE(
     [AC_LANG_PROGRAM(
	[[#include <inttypes.h>]],
	[[int32_t val = 0; __atomic_fetch_add(&val, 1, __ATOMIC_RELAXED);]]
      )],
     [AC_MSG_RESULT([__atomic builtins])
      AC_DEFINE([HAVE___ATOMIC], [1], [define if __atomic builtins are not available])
      AC_MSG_CHECKING([whether -latomic is needed for 64-bit __atomic builtins])
      AC_LINK_IFELSE(
	[AC_LANG_PROGRAM(
	   [[#include <inttypes.h>]],
	   [[int64_t val = 0; __atomic_fetch_add(&val, 1, __ATOMIC_RELAXED);]]
	 )],
	[AC_MSG_RESULT([no])],
1157
	[ISC_ATOMIC_LIBS="-latomic"
1158
	 AX_SAVE_FLAGS([atomic])
1159 1160 1161 1162 1163 1164 1165 1166
	 LIBS="$LIBS $ISC_ATOMIC_LIBS"
	 AC_LINK_IFELSE(
	   [AC_LANG_PROGRAM(
	      [[#include <inttypes.h>]],
	      [[int64_t val = 0; __atomic_fetch_add(&val, 1, __ATOMIC_RELAXED);]]
	    )],
	   [AC_MSG_RESULT([yes])],
	   [AC_MSG_FAILURE([libatomic needed, but linking with -latomic failed, please fix your toolchain.])])
1167
	 AX_RESTORE_FLAGS([atomic])
1168 1169 1170 1171 1172 1173
	])
     ],
     [AC_MSG_RESULT([__sync builtins])
     ])
  ])
LIBS="$LIBS $ISC_ATOMIC_LIBS"
1174

1175 1176
AC_CHECK_HEADERS([stdalign.h])

1177 1178
AC_CHECK_HEADERS([uchar.h])

1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193
#
# Check for __builtin_unreachable
#
AC_MSG_CHECKING([compiler support for __builtin_unreachable()])
AC_LINK_IFELSE(
  [AC_LANG_PROGRAM(
     [[]],
     [[__builtin_unreachable();]]
   )],
  [AC_MSG_RESULT([yes])
   AC_DEFINE([HAVE_BUILTIN_UNREACHABLE], [1], [define if the compiler supports __builtin_unreachable().])
  ],
  [AC_MSG_RESULT([no])
  ])

1194 1195 1196 1197 1198
#
# Check for __builtin_expect
#
AC_MSG_CHECKING([compiler support for __builtin_expect])
AC_TRY_LINK(, [
1199
	return (__builtin_expect(1, 1) ? 1 : 0);
1200
], [
1201 1202
	have_builtin_expect=yes
	AC_MSG_RESULT(yes)
1203
], [
1204 1205
	have_builtin_expect=no
	AC_MSG_RESULT(no)
1206
])
1207
if test "yes" = "$have_builtin_expect"; then
1208
	AC_DEFINE(HAVE_BUILTIN_EXPECT, 1, [Define to 1 if the compiler supports __builtin_expect.])