configure.ac 24.1 KB
Newer Older
1
AC_PREREQ([2.60])
2

3
m4_define([knot_VERSION_MAJOR], 2)dnl
Daniel Salzman's avatar
Daniel Salzman committed
4
m4_define([knot_VERSION_MINOR], 8)dnl
5 6
m4_define([knot_VERSION_PATCH], )dnl Leave empty if the master branch!
m4_include([m4/knot-version.m4])
7 8

AC_INIT([knot], knot_PKG_VERSION, [knot-dns@labs.nic.cz])
Daniel Salzman's avatar
Daniel Salzman committed
9 10 11 12 13

# Store ./configure parameters and CFLAGS
AC_DEFINE_UNQUOTED([CONFIGURE_PARAMS],["$*"],[Params passed to configure])
AC_DEFINE_UNQUOTED([CONFIGURE_CFLAGS],["$CFLAGS"],[Passed CFLAGS from environment])

14
AM_INIT_AUTOMAKE([foreign std-options subdir-objects no-dist-gzip dist-xz -Wall -Werror])
15
AM_SILENT_RULES([yes])
16
AC_CONFIG_SRCDIR([src/knot])
Ondřej Surý's avatar
Ondřej Surý committed
17 18
AC_CONFIG_HEADERS([src/config.h])
AC_CONFIG_MACRO_DIR([m4])
19
AC_USE_SYSTEM_EXTENSIONS
20
AC_CANONICAL_HOST
21

Daniel Salzman's avatar
Daniel Salzman committed
22 23
# Update library versions
# https://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html
24 25 26 27
AC_SUBST([python_libknot_VERSION],                 ["8"])
AC_SUBST([libknot_VERSION_INFO],     ["-version-info 8:0:0"])
AC_SUBST([libdnssec_VERSION_INFO],   ["-version-info 6:0:0"])
AC_SUBST([libzscanner_VERSION_INFO], ["-version-info 2:0:0"])
Daniel Salzman's avatar
Daniel Salzman committed
28

29 30 31 32
AC_SUBST([KNOT_VERSION_MAJOR], knot_VERSION_MAJOR)
AC_SUBST([KNOT_VERSION_MINOR], knot_VERSION_MINOR)
AC_SUBST([KNOT_VERSION_PATCH], knot_VERSION_PATCH)

33
AC_CONFIG_FILES([src/libknot/version.h
34 35
                 src/libdnssec/version.h
                 src/libzscanner/version.h])
36

Daniel Salzman's avatar
Daniel Salzman committed
37
# Automatically update release date based on NEWS
38 39
AC_PROG_SED
release_date=$($SED -n 's/^Knot DNS .* (\(.*\))/\1/p;q;' ${srcdir}/NEWS)
40 41
AC_SUBST([RELEASE_DATE], $release_date)

42 43 44 45
# Set compiler compatibility flags
AC_PROG_CC_C99
AM_PROG_CC_C_O
AC_PROG_CPP_WERROR
Ondřej Surý's avatar
Ondřej Surý committed
46

Daniel Salzman's avatar
Daniel Salzman committed
47
# Set default CFLAGS
48
CFLAGS="$CFLAGS -Wall -Wshadow -Werror=format-security -Werror=implicit -Wstrict-prototypes"
49

Daniel Salzman's avatar
Daniel Salzman committed
50 51 52 53 54 55 56 57
AX_CHECK_COMPILE_FLAG("-fpredictive-commoning", [CFLAGS="$CFLAGS -fpredictive-commoning"], [], "-Werror")
AX_CHECK_LINK_FLAG(["-Wl,--exclude-libs,ALL"], [ldflag_exclude_libs="-Wl,--exclude-libs,ALL"], [ldflag_exclude_libs=""], "")
AC_SUBST([LDFLAG_EXCLUDE_LIBS], $ldflag_exclude_libs)

# Check if an archiver is available
m4_ifdef([AM_PROG_AR], [AM_PROG_AR])

AC_PROG_INSTALL
58

Ondřej Surý's avatar
Ondřej Surý committed
59 60 61
# Initialize libtool
LT_INIT

62
# Use pkg-config
63
PKG_PROG_PKG_CONFIG
64
m4_ifdef([PKG_INSTALLDIR], [PKG_INSTALLDIR], [AC_SUBST([pkgconfigdir], ['${libdir}/pkgconfig'])])
65
AC_CONFIG_FILES([src/knotd.pc
66 67 68
                 src/libknot.pc
                 src/libdnssec.pc
                 src/libzscanner.pc
69
                 ])
70

71
# Default directories
72
knot_prefix=$ac_default_prefix
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
AS_IF([test "$prefix" != NONE], [knot_prefix=$prefix])

run_dir="${localstatedir}/run/knot"
AC_ARG_WITH([rundir],
        AC_HELP_STRING([--with-rundir=path], [Path to run-time variable data (pid, sockets...). [default=LOCALSTATEDIR/run/knot]]),
        [run_dir=$withval])
AC_SUBST(run_dir)

storage_dir="${localstatedir}/lib/knot"
AC_ARG_WITH([storage],
        AC_HELP_STRING([--with-storage=path], [Default storage directory (slave zones, persistent data). [default=LOCALSTATEDIR/lib/knot]]),
        [storage_dir=$withval])
AC_SUBST(storage_dir)

config_dir="${sysconfdir}/knot"
AC_ARG_WITH([configdir],
        AC_HELP_STRING([--with-configdir=path], [Default directory for configuration. [default=SYSCONFDIR/knot]]),
        [config_dir=$withval])
AC_SUBST(config_dir)

module_dir=
module_instdir="${libdir}/knot/modules-${KNOT_VERSION_MAJOR}.${KNOT_VERSION_MINOR}"
AC_ARG_WITH([moduledir],
        AC_HELP_STRING([--with-moduledir=path], [Path to auto-loaded dynamic modules. [default not set]]),
        [module_dir=$withval module_instdir=$module_dir])
AC_SUBST(module_instdir)
AC_SUBST(module_dir)

101 102 103 104
# Build Knot DNS daemon
AC_ARG_ENABLE([daemon],
    AS_HELP_STRING([--disable-daemon], [Don't build Knot DNS main daemon]), [], [enable_daemon=yes])
AM_CONDITIONAL([HAVE_DAEMON], [test "$enable_daemon" = "yes"])
105

106 107 108 109
# Build Knot DNS modules
AC_ARG_ENABLE([modules],
    AS_HELP_STRING([--disable-modules], [Don't build Knot DNS modules]), [], [enable_modules=yes])

110 111 112 113
# Build Knot DNS utilities
AC_ARG_ENABLE([utilities],
    AS_HELP_STRING([--disable-utilities], [Don't build Knot DNS utilities]), [], [enable_utilities=yes])
AM_CONDITIONAL([HAVE_UTILS], [test "$enable_utilities" = "yes"])
114

115 116 117 118
# Build Knot DNS documentation
AC_ARG_ENABLE([documentation],
    AS_HELP_STRING([--disable-documentation], [Don't build Knot DNS documentation]), [], [enable_documentation=yes])
AM_CONDITIONAL([HAVE_DOCS], [test "$enable_documentation" = "yes"])
119

120 121
AM_CONDITIONAL([HAVE_LIBUTILS], test "$enable_utilities" != "no" -o \
                                     "$enable_daemon" != "no")
122 123 124
######################
# Generic dependencies
######################
125

126
AC_ARG_ENABLE([fastparser],
127 128 129 130
    AS_HELP_STRING([--disable-fastparser], [Disable use of fastest zone parser]),[],[
    # Set zone parser type - fastest on release build, slowest on dev build
    AS_IF([test -d ".git" -o "$PATCH_VERSION" = "dev"],[
        enable_fastparser=no
131 132 133
        ],[
        enable_fastparser=yes
        ])
134
    ])
135

136
AX_CC_CLANG
137
AS_IF([test "$enable_fastparser" = "yes"],[
138
    AS_IF([test -n "$CC_CLANG_VERSION"],[
139 140 141 142
      enable_fastparser=no
      AC_MSG_WARN([Fast zone parser disabled due to possible compiler bug.])
      AC_MSG_WARN([See https://llvm.org/bugs/show_bug.cgi?id=23490 for details.])
      AC_MSG_WARN([Use --enable-fastparser=force if your know your clang is fixed.])
143
    ])
144 145 146
])

AS_IF([test "$enable_fastparser" = "force"],[enable_fastparser=yes])
147

148
AM_CONDITIONAL([FAST_PARSER], [test "$enable_fastparser" = "yes"])
149 150

# GnuTLS crypto backend
151
PKG_CHECK_MODULES([gnutls], [gnutls >= 3.3], [
152
    save_CFLAGS=$CFLAGS
153
    save_LIBS=$LIBS
154
    CFLAGS="$CFLAGS $gnutls_CFLAGS"
155
    LIBS="$LIBS $gnutls_LIBS"
156

157
    AC_CHECK_FUNC([gnutls_pkcs11_copy_pubkey], [enable_pkcs11=yes], [enable_pkcs11=no])
158
    AS_IF([test "$enable_pkcs11" = yes],
Jan Včelák's avatar
Jan Včelák committed
159
        [AC_DEFINE([ENABLE_PKCS11], [1], [PKCS #11 support available])])
160

161 162
    AC_CHECK_DECL([GNUTLS_PK_EDDSA_ED25519],
        [AC_DEFINE([HAVE_ED25519], [1], [GnuTLS ED25519 support available])
Daniel Salzman's avatar
Daniel Salzman committed
163
         enable_ed25519=yes],
164
        [enable_ed25519=no],
Daniel Salzman's avatar
Daniel Salzman committed
165
        [#include <gnutls/gnutls.h>])
166

167 168 169 170 171 172
    AC_CHECK_DECL([GNUTLS_PK_GOST_01],
        [AC_DEFINE([HAVE_GOST], [1], [GnuTLS GOST support available])
         enable_gost=yes],
        [enable_gost=no],
        [#include <gnutls/gnutls.h>])

173 174
    AC_CHECK_FUNC([gnutls_privkey_sign_data2],
        [AC_DEFINE([HAVE_SIGN_DATA2], [1], [gnutls_privkey_sign_data2 available])])
175

176
    CFLAGS=$save_CFLAGS
177
    LIBS=$save_LIBS
178
])
179
AM_CONDITIONAL([ENABLE_PKCS11], [test "$enable_pkcs11" = "yes"])
180

181
AC_ARG_ENABLE([recvmmsg],
182 183 184 185 186 187 188 189 190 191 192 193 194 195
   AS_HELP_STRING([--enable-recvmmsg=auto|yes|no], [enable recvmmsg() network API [default=auto]]),
   [], [enable_recvmmsg=auto])

AS_CASE([$enable_recvmmsg],
   [auto|yes],[
      AC_CHECK_FUNC([recvmmsg],
                    [AC_CHECK_FUNC([sendmmsg],[enable_recvmmsg=yes],[enable_recvmmsg=no])],
                    [enable_recvmmsg=no])],
   [no],[],
   [*], [AC_MSG_ERROR([Invalid value of --enable-recvmmsg.]
 )])

AS_IF([test "$enable_recvmmsg" = yes],[
   AC_DEFINE([ENABLE_RECVMMSG], [1], [Use recvmmsg().])])
196

197 198 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
AC_ARG_ENABLE([reuseport],
    AS_HELP_STRING([--enable-reuseport=auto|yes|no], [enable Linux SO_REUSEPORT support [default=auto]]),
    [enable_reuseport="$enableval"], [enable_reuseport=auto])

AC_DEFUN([CHECK_REUSEPORT], [
  AC_CHECK_DECL(
    [SO_REUSEPORT],
    [$1],
    [$2],
    [
    #include <sys/socket.h>
    ]
  )])

AS_IF([test "$enable_reuseport" != no], [
  AS_CASE([$enable_reuseport],
    [auto],[
      AS_CASE([$host_os],
        [linux*], [CHECK_REUSEPORT([enable_reuseport=yes], [enable_reuseport=no])],
        [*], [enable_reuseport=no]
      )],
    [yes],[
      AS_CASE([$host_os],
        [linux*], [CHECK_REUSEPORT([enable_reuseport=yes], [AC_MSG_ERROR([SO_REUSEPORT support not detected.])])],
        [*], [AC_MSG_ERROR(["SO_REUSEPORT not supported on $host_os."])]
      )],
    [*], [AC_MSG_ERROR([Invalid value of --enable-reuseport.])]
  )])

AS_IF([test "$enable_reuseport" = yes],[
   AC_DEFINE([ENABLE_REUSEPORT], [1], [Use SO_REUSEPORT.])])

229 230 231 232 233 234 235 236 237 238 239
#########################################
# Dependencies needed for Knot DNS daemon
#########################################

# Systemd integration
AC_ARG_ENABLE([systemd],
    AS_HELP_STRING([--enable-systemd=auto|yes|no], [enable systemd integration [default=auto]]),
    [enable_systemd="$enableval"], [enable_systemd=auto])

AS_IF([test "$enable_daemon" = "yes"],[

240
AS_IF([test "$enable_systemd" != "no"],[
241
  AS_CASE([$enable_systemd],
242 243 244
    [auto],[PKG_CHECK_MODULES([systemd], [libsystemd], [enable_systemd=yes], [
            PKG_CHECK_MODULES([systemd], [libsystemd-daemon libsystemd-journal], [enable_systemd=yes], [enable_systemd=no])])],
    [yes],[PKG_CHECK_MODULES([systemd], [libsystemd], [], [
245
            PKG_CHECK_MODULES([systemd], [libsystemd-daemon libsystemd-journal])])],
246 247 248 249 250
    [*],[AC_MSG_ERROR([Invalid value of --enable-systemd.])])
    ])

AS_IF([test "$enable_systemd" = "yes"],[
  AC_DEFINE([ENABLE_SYSTEMD], [1], [Use systemd integration.])])
251

252 253
]) dnl enable_daemon

254 255 256
# Alternative memory allocator
malloc_LIBS=
AC_ARG_WITH([memory-allocator],
257 258
  AS_HELP_STRING([--with-memory-allocator=auto|LIBRARY],
                 [Use specific memory allocator for the server (e.g. jemalloc) [default=auto]]),
259 260 261 262 263 264 265 266
  AS_CASE([$withval],
    [auto], [],
    [*],    [malloc_LIBS="-l$withval"]
  )
  with_memory_allocator=[$withval]
)
AS_IF([test "$with_memory_allocator" = ""], [with_memory_allocator="auto"])
AC_SUBST([malloc_LIBS])
267 268 269 270 271

dnl Check for userspace-rcu library
AC_ARG_WITH(urcu,
[  --with-urcu=DIR        where to find userspace-rcu library])

272 273
AS_IF([test "$enable_daemon" = "yes"],[

274 275
AS_IF([test "$with_urcu" != "no"], [
  PKG_CHECK_MODULES([liburcu], liburcu, [
276
    liburcu_PKGCONFIG="liburcu >= 0.4.0"
277
    AC_SUBST([liburcu_PKGCONFIG])
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296
    with_urcu=yes
  ],[
    for try_urcu in "$with_urcu" "" "/usr/local"; do
      save_LIBS="$LIBS"
      save_CPPFLAGS="$CPPFLAGS"

      AS_IF([test -d "$try_urcu"], [
        liburcu_CFLAGS="-I$try_urcu/include"
        liburcu_LIBS="-L$try_urcu/lib"
      ],[
        liburcu_CFLAGS=""
        liburcu_LIBS=""
      ])

      CPPFLAGS="$CPPFLAGS $liburcu_CFLAGS"
      LIBS="$LIBS $liburcu_LIBS"

      AC_SEARCH_LIBS([rcu_set_pointer_sym], [urcu], [
        with_urcu=yes
297 298 299 300
        liburcu_LIBS="$liburcu_LIBS -lurcu"
        AC_SUBST([liburcu_CFLAGS])
        AC_SUBST([liburcu_LIBS])
        break
301
      ],[
302 303
        CPPFLAGS="$save_CPPFLAGS"
        LIBS="$save_LIBS"
304
        with_urcu=no
305 306
        # do not cache result of AC_SEARCH_LIBS test
        unset ac_cv_search_rcu_set_pointer_sym
307 308
      ])
    done
309 310
    CPPFLAGS="$save_CPPFLAGS"
    LIBS="$save_LIBS"
311 312 313

    AS_IF([test "$with_urcu" = "no"],[
      AC_MSG_ERROR([liburcu is required])
314
      ])
315 316 317
  ])
])

318
])
319

320 321
static_modules=""
shared_modules=""
322 323 324 325
static_modules_declars=""
static_modules_init=""
doc_modules=""

326
KNOT_MODULE([cookies],     "yes")
327 328
KNOT_MODULE([dnsproxy],    "yes", "non-shareable")
KNOT_MODULE([dnstap],      "no")
329
KNOT_MODULE([geoip],       "yes")
330 331
KNOT_MODULE([noudp],       "yes")
KNOT_MODULE([onlinesign],  "yes", "non-shareable")
332
KNOT_MODULE([queryacl],    "yes")
333 334 335 336 337 338 339 340 341 342 343
KNOT_MODULE([rrl],         "yes")
KNOT_MODULE([stats],       "yes")
KNOT_MODULE([synthrecord], "yes")
KNOT_MODULE([whoami],      "yes")

AC_SUBST([STATIC_MODULES_DECLARS], [$(printf "$static_modules_declars")])
AM_SUBST_NOTMAKE([STATIC_MODULES_DECLARS])
AC_SUBST([STATIC_MODULES_INIT], [$(printf "$static_modules_init")])
AM_SUBST_NOTMAKE([STATIC_MODULES_INIT])
AC_SUBST([DOC_MODULES], [$(printf "$doc_modules")])
AM_SUBST_NOTMAKE([DOC_MODULES])
344

345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362
# Check for Dnstap
AC_ARG_ENABLE([dnstap],
  AS_HELP_STRING([--enable-dnstap], [Enable dnstap support for kdig (requires fstrm, protobuf-c)]),
  [], [enable_dnstap=no])

AS_IF([test "$enable_dnstap" != "no" -o "$STATIC_MODULE_dnstap" != "no" -o "$SHARED_MODULE_dnstap" != "no"],[
  AC_PATH_PROG([PROTOC_C], [protoc-c])
  AS_IF([test -z "$PROTOC_C"],[
    AC_MSG_ERROR([The protoc-c program was not found. Please install protobuf-c!])
  ])
  PKG_CHECK_MODULES([libfstrm], [libfstrm])
  PKG_CHECK_MODULES([libprotobuf_c], [libprotobuf-c >= 1.0.0])
  AC_SUBST([DNSTAP_CFLAGS], ["$libfstrm_CFLAGS $libprotobuf_c_CFLAGS"])
  AC_SUBST([DNSTAP_LIBS], ["$libfstrm_LIBS $libprotobuf_c_LIBS"])
])

AS_IF([test "$enable_dnstap" != "no"],[
  AC_DEFINE([USE_DNSTAP], [1], [Define to 1 to enable dnstap support for kdig])
363
])
364
AM_CONDITIONAL([HAVE_DNSTAP], test "$enable_dnstap" != "no")
365

366 367 368
AM_CONDITIONAL([HAVE_LIBDNSTAP], test "$enable_dnstap" != "no" -o \
                                      "$STATIC_MODULE_dnstap" != "no" -o \
                                      "$SHARED_MODULE_dnstap" != "no")
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 398 399 400 401 402 403
# MaxMind DB for the GeoIP module
AC_ARG_ENABLE([maxminddb],
    AS_HELP_STRING([--enable-maxminddb=auto|yes|no], [enable MaxMind DB [default=auto]]),
    [enable_maxminddb="$enableval"], [enable_maxminddb=auto])

AS_IF([test "$enable_daemon" = "no"],[enable_maxminddb=no])
AS_CASE([$enable_maxminddb],
  [no],[],
  [auto],[PKG_CHECK_MODULES([libmaxminddb], [libmaxminddb], [enable_maxminddb=yes], [enable_maxminddb=no])],
  [yes], [PKG_CHECK_MODULES([libmaxminddb], [libmaxminddb])],
  [*],[
    save_CFLAGS="$CFLAGS"
    save_LIBS="$LIBS"
    AS_IF([test "$enable_maxminddb" != ""],[
      LIBS="$LIBS -L$enable_maxminddb"
      CFLAGS="$CFLAGS -I$enable_maxminddb/include"
      ])
    AC_SEARCH_LIBS([MMDB_open], [maxminddb], [
      AS_IF([test "$enable_maxminddb" != ""], [
        libmaxminddb_CFLAGS="-I$enable_maxminddb/include"
        libmaxminddb_LIBS="-L$enable_maxminddb -lmaxminddb"
  ],[
  libmaxminddb_CFLAGS=""
  libmaxminddb_LIBS="$ac_cv_search_MMDB_open"
        ])
      ],[AC_MSG_ERROR("not found in `$enable_maxminddb'")])
    CFLAGS="$save_CFLAGS"
    LIBS="$save_LIBS"
    AC_SUBST([libmaxminddb_CFLAGS])
    AC_SUBST([libmaxminddb_LIBS])
    enable_maxminddb=yes
    ])

AS_IF([test "$enable_maxminddb" = yes], [AC_DEFINE([HAVE_MAXMINDDB], [1], [Define to 1 to enable MaxMind DB.])])
AM_CONDITIONAL([HAVE_MAXMINDDB], [test "$enable_maxminddb" = yes])
404

Jan Včelák's avatar
Jan Včelák committed
405
dnl Check for LMDB
406 407 408 409 410
lmdb_MIN_VERSION_MAJOR=0
lmdb_MIN_VERSION_MINOR=9
lmdb_MIN_VERSION_PATCH=15
lmdb_MIN_VERSION_STRING="$lmdb_MIN_VERSION_MAJOR.$lmdb_MIN_VERSION_MINOR.$lmdb_MIN_VERSION_PATCH"
lmdb_MIN_VERSION_FULL="$((($lmdb_MIN_VERSION_MAJOR << 24) | ($lmdb_MIN_VERSION_MINOR << 16) | $lmdb_MIN_VERSION_PATCH))"
411
AC_ARG_WITH([lmdb],
412
    AC_HELP_STRING([--with-lmdb=[DIR]], [Link with external LMDB (>= $lmdb_MIN_VERSION_STRING)]),[
413 414
    with_lmdb=$withval
    ],[
415
    with_lmdb=auto
416 417 418
    ])

have_lmdb=no
419

420 421 422
AS_IF([test "$with_lmdb" != "no"],[
    save_CPPFLAGS=$CPPFLAGS
    save_LIBS=$LIBS
423 424

    # Look for lmdb in given path and common locations
425 426
    for try_lmdb in "$with_lmdb" "" "/usr/local"; do

427 428 429
      AS_IF([test -d "$try_lmdb"], [
        lmdb_CFLAGS="-I$try_lmdb/include"
        lmdb_LIBS="-L$try_lmdb/lib"
430 431 432
        ],[
        lmdb_CFLAGS=""
        lmdb_LIBS=""
433
        ])
434

435 436
      CPPFLAGS="$save_CPPFLAGS $lmdb_CFLAGS"
      LIBS="$save_LIBS $lmdb_LIBS"
437 438 439

      AC_SEARCH_LIBS([mdb_env_open], [lmdb], [
          AC_CHECK_HEADERS([lmdb.h], [], [
440 441
              AC_MSG_ERROR([lmdb headers not found in `$try_lmdb', is your installation complete?])])
          AC_COMPUTE_INT(lmdb_VERSION_FULL, MDB_VERSION_FULL, [#include <lmdb.h>],
442 443
              AC_MSG_ERROR([Unable to determine lmdb version from MDB_VERSION_FULL]))
          AS_IF([test "$lmdb_VERSION_FULL" -ge "$lmdb_MIN_VERSION_FULL"],[
444 445
              lmdb_LIBS="$lmdb_LIBS -llmdb"
              have_lmdb=yes],[
446 447 448 449 450
              unset lmdb_CFLAGS
              unset lmdb_LIBS
              AC_MSG_WARN([lmdb version 0.9.15 and higher not found, using embedded version])
              ])
          break
451
          ])
452

453 454 455 456
      unset lmdb_CFLAGS
      unset lmdb_LIBS
      # do not cache result of AC_SEARCH_LIBS test
      unset ac_cv_search_mdb_env_open
457
    done
458

459 460
    CPPFLAGS="$save_CPPFLAGS"
    LIBS="$save_LIBS"
461 462

    # fail the configure if we haven't found lmdb library in the system
463
    AS_IF([test "$with_lmdb" != "auto" -a "$have_lmdb" = "no"],[
464
        AC_MSG_ERROR([shared lmdb library not found])
465
        ])
466 467 468
    ])

AS_IF([test "$have_lmdb" != "no"],[
469 470
    AC_SUBST([lmdb_LIBS])
    enable_lmdb=shared
471
    external_lmdb_LIBS=$lmdb_LIBS
472 473
    ],[
    enable_lmdb=embedded
474
    lmdb_CFLAGS="-I\$(top_srcdir)/src/contrib/lmdb"
475
    ])
476
AM_CONDITIONAL([HAVE_LMDB], test "$enable_lmdb" = "shared")
477
AC_SUBST([lmdb_CFLAGS])
478
AC_SUBST([external_lmdb_LIBS])
479

480
# LMDB mapping sizes
481
conf_mapsize_default=500
482
AC_ARG_WITH([conf_mapsize],
483 484 485 486 487 488 489 490
    AC_HELP_STRING([--with-conf-mapsize=NUM], [Configuration DB mapsize in MiB [default=$conf_mapsize_default]]),
    [conf_mapsize=$withval],[conf_mapsize=$conf_mapsize_default])

AS_CASE([$conf_mapsize],
    [yes],[conf_mapsize=$conf_mapsize_default],
    [no], [AC_MSG_ERROR([conf_mapsize must be a number])],
    [*],  [AS_IF([test $conf_mapsize != $(( $conf_mapsize + 0 ))],
                 [AC_ERROR([conf_mapsize must be an integer number])])])
491
AC_DEFINE_UNQUOTED([CONF_MAPSIZE], [$conf_mapsize], [Configuration DB mapsize.])
492
AC_SUBST(conf_mapsize)
493

494
# libedit
495
AS_IF([test "$enable_daemon" = "yes" -o "$enable_utilities" = "yes"], [
496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514
  PKG_CHECK_MODULES([libedit], [libedit], [with_libedit=yes], [
    with_libedit=no
    AC_CHECK_HEADER([histedit.h], [
      # workaround for OpenBSD
      AS_CASE([$host_os],
        [openbsd*], [libedit_deps=-lcurses],
        [libedit_deps=]
      )
      AC_CHECK_LIB([edit], [el_init], [
        with_libedit=yes
        libedit_CFLAGS=
        libedit_LIBS="-ledit $libedit_deps"
        ], [], [$libedit_deps]
      )
    ])
  ])
  AS_IF([test "$with_libedit" != "yes"], [
    AC_MSG_ERROR([libedit not found])
  ])
515
], [
516 517 518 519 520
  with_libedit=no
  libedit_CFLAGS=
  libedit_LIBS=
])

521 522 523 524 525 526
############################################
# Dependencies needed for Knot DNS utilities
############################################

dnl Check for libidn.
AC_ARG_WITH(libidn,
527 528 529 530 531 532 533
  AC_HELP_STRING([--with-libidn=[DIR]], [Support IDN (needs GNU libidn2 or libidn)]),
  with_libidn=$withval,
  with_libidn=yes
)

AS_IF([test "$enable_utilities" = "yes"], [
  AS_IF([test "$with_libidn" != "no"], [
534
    PKG_CHECK_MODULES([libidn2], [libidn2 >= 2.0.0], [
535 536 537 538 539
      with_libidn=yes
      AC_DEFINE([LIBIDN], [1], [Define to 1 to enable IDN support])
      AC_DEFINE([LIBIDN_HEADER], [<idn2.h>], [Define to proper libidn header])
    ], [
      PKG_CHECK_MODULES([libidn], [libidn >= 0.0.0], [
540 541
        with_libidn=yes
        AC_DEFINE([LIBIDN], [1], [Define to 1 to enable IDN support])
542 543
        AC_DEFINE([LIBIDN_HEADER], [<idna.h>], [Define to proper libidn header])
      ], [
544
        with_libidn=no
545 546 547 548
        AC_MSG_WARN([libidn2 or libidn not found])
      ])
    ])
  ])
549
]) # Knot DNS utilities dependencies
550

551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572
AS_IF([test "$enable_daemon" = "yes"], [
  PKG_CHECK_MODULES([cap_ng], [cap-ng], [enable_cap_ng=yes], [
    enable_cap_ng=no
    AC_CHECK_HEADER([cap-ng.h], [
      save_LIBS="$LIBS"
      AC_SEARCH_LIBS([capng_apply], [cap-ng], [
        enable_cap_ng=yes
        cap_ng_LIBS="$ac_cv_search_capng_apply"
        AC_SUBST([cap_ng_LIBS])
      ])
      LIBS="$save_LIBS"
    ])
  ])
], [
  enable_cap_ng=no
  cap_ng_LIBS=
])

AS_IF([test "$enable_cap_ng" = yes],
  [AC_DEFINE([ENABLE_CAP_NG], [1], [POSIX capabilities available])]
)

573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590
save_LIBS="$LIBS"
AC_SEARCH_LIBS([pthread_create], [pthread], [
  pthread_LIBS="$ac_cv_search_pthread_create"
  AC_SUBST([pthread_LIBS])
],[
  AC_MSG_ERROR([pthreads not found])
])
LIBS="$save_LIBS"

save_LIBS="$LIBS"
AC_SEARCH_LIBS([dlopen], [dl], [
  dlopen_LIBS="$ac_cv_search_dlopen"
  AC_SUBST([dlopen_LIBS])
],[
  AC_MSG_ERROR([dlopen not found])
])
LIBS="$save_LIBS"

591 592 593 594 595 596 597 598 599
save_LIBS="$LIBS"
AC_SEARCH_LIBS([pow], [m], [
  math_LIBS="$ac_cv_search_pow"
  AC_SUBST([math_LIBS])
],[
  AC_MSG_ERROR([math not found])
])
LIBS="$save_LIBS"

Ondřej Surý's avatar
Ondřej Surý committed
600 601
# Checks for header files.
AC_HEADER_RESOLV
602
AC_CHECK_HEADERS_ONCE([pthread_np.h sys/uio.h])
Ondřej Surý's avatar
Ondřej Surý committed
603

604 605 606
# Checks for optional library functions.
AC_CHECK_FUNCS([accept4 clock_gettime fgetln getline initgroups malloc_trim \
                pthread_setaffinity_np setgroups strlcat strlcpy sysctlbyname])
607

608
# Check for mandatory library functions.
609 610
AC_CHECK_FUNC([vasprintf], [], [
  AC_MSG_ERROR([vasprintf support in the libc is required])])
Ondřej Surý's avatar
Ondřej Surý committed
611

612 613 614 615 616 617 618 619
# Check for cpu_set_t/cpuset_t compatibility
AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <pthread.h>]], [[cpu_set_t set; CPU_ZERO(&set);]])],
[AC_DEFINE(HAVE_CPUSET_LINUX, 1, [Define if Linux-like cpu_set_t exists.])])
AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <pthread_np.h>]], [[cpuset_t set; CPU_ZERO(&set);]])],
[AC_DEFINE(HAVE_CPUSET_BSD, 1, [Define if FreeBSD-like cpuset_t exists.])])
AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <sched.h>]], [[cpuset_t* set = cpuset_create(); cpuset_destroy(set);]])],
[AC_DEFINE(HAVE_CPUSET_NETBSD, 1, [Define if cpuset_t and cpuset(3) exists.])])

620
AC_LINK_IFELSE(
621 622
  [AC_LANG_PROGRAM([[#include <stdint.h>]],
                   [[uint64_t val = 0; __atomic_add_fetch(&val, 1, __ATOMIC_RELAXED);]])],
623
  [AC_DEFINE(HAVE_ATOMIC, 1, [Define to 1 if you have '__atomic' functions.])]
624 625
)

626
# Prepare CFLAG_VISIBILITY to be used where needed
627
gl_VISIBILITY()
628

629 630 631
# Add code coverage macro
AX_CODE_COVERAGE

632
AX_SANITIZER
633 634
AS_IF([test -n "$sanitizer_CFLAGS"], [CFLAGS="$CFLAGS $sanitizer_CFLAGS"])
AM_CONDITIONAL([FUZZER], [test "$with_fuzzer" != "no"])
635
AM_CONDITIONAL([OSS_FUZZ], [test "$with_oss_fuzz" != "no"])
636

637 638
AS_IF([test "$enable_documentation" = "yes"],[

639
AC_PATH_PROGS([SPHINXBUILD], [sphinx-build sphinx-build-3], [false])
640 641 642 643 644 645 646 647 648 649
AS_IF([test "$SPHINXBUILD" = "false"],
  [AC_MSG_WARN([Could not find the 'sphinx-build' executable, you will be unable to regenerate documentation.])],
  [AC_PATH_PROG([PDFLATEX], [pdflatex], [false])
   AS_IF([test "$PDFLATEX" = ""],
     [AC_MSG_WARN([Could not find the 'pdflatex' executable, you will be unable to generate PDF documentation.])])
   AC_PATH_PROG([MAKEINFO], [makeinfo], [false])
   AS_IF([test "$MAKEINFO" = "false"],
     [AC_MSG_WARN([Could not find the 'makeinfo' executable, you will be unable to generate info documentation.])])
  ])

650 651
])

652 653 654 655
AM_CONDITIONAL([HAVE_SPHINXBUILD], test "$SPHINXBUILD" != "false")
AM_CONDITIONAL([HAVE_PDFLATEX], test "$PDFLATEX" != "false")
AM_CONDITIONAL([HAVE_MAKEINFO], test "$MAKEINFO" != "false")

656
result_msg_base="  Knot DNS $VERSION
657 658 659

    Target:   $host_os $host_cpu
    Compiler: ${CC}
660
    CFLAGS:   ${CFLAGS} ${CPPFLAGS}
661 662 663
    LIBS:     ${LIBS} ${LDFLAGS}
    LibURCU:  ${liburcu_LIBS} ${liburcu_CFLAGS}
    GnuTLS:   ${gnutls_LIBS} ${gnutls_CFLAGS}
664
    Libedit:  ${libedit_LIBS} ${libedit_CFLAGS}
665
    LMDB:     ${enable_lmdb} ${lmdb_LIBS} ${lmdb_CFLAGS}
666
    Config:   ${conf_mapsize} MiB default mapsize
667

668
    Prefix:      ${knot_prefix}
669 670 671
    Run dir:     ${run_dir}
    Storage dir: ${storage_dir}
    Config dir:  ${config_dir}
672
    Module dir:  ${module_dir}
673

674 675
    Static modules: ${static_modules}
    Shared modules: ${shared_modules}
676

677 678
    Knot DNS libraries:     yes
    Knot DNS daemon:        ${enable_daemon}
679
    Knot DNS utilities:     ${enable_utilities}
680 681
    Knot DNS documentation: ${enable_documentation}

682 683
    Use recvmmsg:           ${enable_recvmmsg}
    Use SO_REUSEPORT:       ${enable_reuseport}
684
    Memory allocator:       ${with_memory_allocator}
685 686
    Fast zone parser:       ${enable_fastparser}
    Utilities with IDN:     ${with_libidn}
687
    Utilities with Dnstap:  ${enable_dnstap}
688
    MaxMind DB support:     ${enable_maxminddb}
689
    Systemd integration:    ${enable_systemd}
690
    POSIX capabilities      ${enable_cap_ng}
691
    PKCS #11 support:       ${enable_pkcs11}
692
    Ed25519 support:        ${enable_ed25519}
693
    GOST support:           ${enable_gost}
694
    Code coverage:          ${enable_code_coverage}
695 696
    Sanitizer:              ${with_sanitizer}
    LibFuzzer:              ${with_fuzzer}
697
    OSS-Fuzz:               ${with_oss_fuzz}"
698 699

result_msg_esc=$(echo -n "$result_msg_base" | sed '$!s/$/\\n/' | tr -d '\n')
700 701 702 703

AC_DEFINE_UNQUOTED([CONFIGURE_SUMMARY],["$result_msg_esc"],[Configure summary])

AC_CONFIG_FILES([Makefile
704
                 Doxyfile
705 706 707 708
                 doc/Makefile
                 tests/Makefile
                 tests-fuzz/Makefile
                 samples/Makefile
709
                 distro/Makefile
710
                 python/Makefile
Daniel Salzman's avatar
Daniel Salzman committed
711
                 python/setup.py
712
                 python/libknot/__init__.py
713
                 src/Makefile
714
                 src/knot/modules/static_modules.h
715 716
                 ])

717 718
AC_CONFIG_FILES([doc/modules.rst],
                [cp doc/modules.rst ${srcdir}/doc/modules.rst 2>/dev/null;
719
                 ln -s -f $(readlink -f ${srcdir})/src/knot/modules ${srcdir}/doc 2>/dev/null])
720

721
AC_OUTPUT
722 723 724
AC_MSG_RESULT([
$result_msg_base
])