1AC_PREREQ([2.69])
2
3m4_define([knot_VERSION_MAJOR], 3)dnl
4m4_define([knot_VERSION_MINOR], 1)dnl
5m4_define([knot_VERSION_PATCH], 5)dnl Leave empty if the master branch!
6m4_include([m4/knot-version.m4])
7
8AC_INIT([knot], [knot_PKG_VERSION], [knot-dns@labs.nic.cz])
9AM_INIT_AUTOMAKE([foreign std-options subdir-objects no-dist-gzip dist-xz -Wall -Werror])
10AM_SILENT_RULES([yes])
11AC_CONFIG_SRCDIR([src/knot])
12AC_CONFIG_HEADERS([src/config.h])
13AC_CONFIG_MACRO_DIR([m4])
14AC_USE_SYSTEM_EXTENSIONS
15AC_CANONICAL_HOST
16
17# Update library versions
18# https://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html
19KNOT_LIB_VERSION([libknot],    12, 0, 0)
20KNOT_LIB_VERSION([libdnssec],   8, 0, 0)
21KNOT_LIB_VERSION([libzscanner], 4, 0, 0)
22
23AC_SUBST([KNOT_VERSION_MAJOR], knot_VERSION_MAJOR)
24AC_SUBST([KNOT_VERSION_MINOR], knot_VERSION_MINOR)
25AC_SUBST([KNOT_VERSION_PATCH], knot_VERSION_PATCH)
26
27# Store ./configure parameters and CFLAGS
28AC_DEFINE_UNQUOTED([CONFIGURE_PARAMS],["$*"],[Params passed to configure])
29AC_DEFINE_UNQUOTED([CONFIGURE_CFLAGS],["$CFLAGS"],[Passed CFLAGS from environment])
30
31AC_CONFIG_FILES([src/libknot/version.h
32                 src/libdnssec/version.h
33                 src/libzscanner/version.h])
34
35# Automatically update release date based on NEWS
36AC_PROG_SED
37release_date=$($SED -n 's/^Knot DNS .* (\(.*\))/\1/p;q;' ${srcdir}/NEWS)
38AC_SUBST([RELEASE_DATE], $release_date)
39
40# Set compiler compatibility flags
41AC_PROG_CC_C99 # AC_PROG_CC not supported by CentOS 7
42AM_PROG_CC_C_O # Needed by CentOS 7
43AC_PROG_CPP_WERROR
44
45# Set default CFLAGS
46CFLAGS="$CFLAGS -Wall -Wshadow -Werror=format-security -Werror=implicit -Werror=attributes -Wstrict-prototypes"
47
48AX_CHECK_COMPILE_FLAG("-fpredictive-commoning", [CFLAGS="$CFLAGS -fpredictive-commoning"], [], "-Werror")
49AX_CHECK_LINK_FLAG(["-Wl,--exclude-libs,ALL"], [ldflag_exclude_libs="-Wl,--exclude-libs,ALL"], [ldflag_exclude_libs=""], "")
50AC_SUBST([LDFLAG_EXCLUDE_LIBS], $ldflag_exclude_libs)
51
52# Get processor byte ordering
53AC_C_BIGENDIAN([endianity=big-endian], [endianity=little-endian])
54AS_IF([test "$endianity" = "little-endian"],[
55    AC_DEFINE([ENDIANITY_LITTLE], [1], [System is little-endian.])])
56
57# Check if an archiver is available
58m4_ifdef([AM_PROG_AR], [AM_PROG_AR])
59
60AC_PROG_INSTALL
61
62# Initialize libtool
63LT_INIT
64
65# Use pkg-config
66PKG_PROG_PKG_CONFIG
67m4_ifdef([PKG_INSTALLDIR], [PKG_INSTALLDIR], [AC_SUBST([pkgconfigdir], ['${libdir}/pkgconfig'])])
68AC_CONFIG_FILES([src/knotd.pc
69                 src/libknot.pc
70                 src/libdnssec.pc
71                 src/libzscanner.pc
72                 ])
73
74# Default directories
75knot_prefix=$ac_default_prefix
76AS_IF([test "$prefix" != NONE], [knot_prefix=$prefix])
77
78run_dir="${localstatedir}/run/knot"
79AC_ARG_WITH([rundir],
80        AS_HELP_STRING([--with-rundir=path], [Path to run-time variable data (pid, sockets...). [default=LOCALSTATEDIR/run/knot]]),
81        [run_dir=$withval])
82AC_SUBST(run_dir)
83
84storage_dir="${localstatedir}/lib/knot"
85AC_ARG_WITH([storage],
86        AS_HELP_STRING([--with-storage=path], [Default storage directory (slave zones, persistent data). [default=LOCALSTATEDIR/lib/knot]]),
87        [storage_dir=$withval])
88AC_SUBST(storage_dir)
89
90config_dir="${sysconfdir}/knot"
91AC_ARG_WITH([configdir],
92        AS_HELP_STRING([--with-configdir=path], [Default directory for configuration. [default=SYSCONFDIR/knot]]),
93        [config_dir=$withval])
94AC_SUBST(config_dir)
95
96module_dir=
97module_instdir="${libdir}/knot/modules-${KNOT_VERSION_MAJOR}.${KNOT_VERSION_MINOR}"
98AC_ARG_WITH([moduledir],
99        AS_HELP_STRING([--with-moduledir=path], [Path to auto-loaded dynamic modules. [default not set]]),
100        [module_dir=$withval module_instdir=$module_dir])
101AC_SUBST(module_instdir)
102AC_SUBST(module_dir)
103
104# Build Knot DNS daemon
105AC_ARG_ENABLE([daemon],
106    AS_HELP_STRING([--disable-daemon], [Don't build Knot DNS main daemon]), [], [enable_daemon=yes])
107AM_CONDITIONAL([HAVE_DAEMON], [test "$enable_daemon" = "yes"])
108
109# Build Knot DNS modules
110AC_ARG_ENABLE([modules],
111    AS_HELP_STRING([--disable-modules], [Don't build Knot DNS modules]), [], [enable_modules=yes])
112
113# Build Knot DNS utilities
114AC_ARG_ENABLE([utilities],
115    AS_HELP_STRING([--disable-utilities], [Don't build Knot DNS utilities]), [], [enable_utilities=yes])
116AM_CONDITIONAL([HAVE_UTILS], [test "$enable_utilities" = "yes"])
117
118# Build Knot DNS documentation
119AC_ARG_ENABLE([documentation],
120    AS_HELP_STRING([--disable-documentation], [Don't build Knot DNS documentation]), [], [enable_documentation=yes])
121AM_CONDITIONAL([HAVE_DOCS], [test "$enable_documentation" = "yes"])
122
123AM_CONDITIONAL([HAVE_LIBUTILS], test "$enable_utilities" != "no" -o \
124                                     "$enable_daemon" != "no")
125######################
126# Generic dependencies
127######################
128
129AC_ARG_ENABLE([fastparser],
130    AS_HELP_STRING([--disable-fastparser], [Disable use of fast zone parser]),
131    [], [AS_IF([test -d ".git"], [enable_fastparser=no], [enable_fastparser=yes])]
132)
133AM_CONDITIONAL([FAST_PARSER], [test "$enable_fastparser" = "yes"])
134
135# GnuTLS crypto backend
136PKG_CHECK_MODULES([gnutls], [gnutls >= 3.3], [
137    save_CFLAGS=$CFLAGS
138    save_LIBS=$LIBS
139    CFLAGS="$CFLAGS $gnutls_CFLAGS"
140    LIBS="$LIBS $gnutls_LIBS"
141
142    AC_CHECK_FUNC([gnutls_pkcs11_copy_pubkey], [enable_pkcs11=yes], [enable_pkcs11=no])
143    AS_IF([test "$enable_pkcs11" = yes],
144        [AC_DEFINE([ENABLE_PKCS11], [1], [PKCS #11 support available])])
145
146    AC_CHECK_DECL([GNUTLS_PK_EDDSA_ED25519],
147        [AC_DEFINE([HAVE_ED25519], [1], [GnuTLS ED25519 support available])
148         enable_ed25519=yes],
149        [enable_ed25519=no],
150        [#include <gnutls/gnutls.h>])
151
152    AC_CHECK_DECL([GNUTLS_SIGN_EDDSA_ED448],
153        [AC_DEFINE([HAVE_ED448], [1], [GnuTLS ED448 support available])
154         enable_ed448=yes],
155        [enable_ed448=no],
156        [#include <gnutls/gnutls.h>])
157
158    AC_CHECK_DECL([GNUTLS_PRIVKEY_FLAG_REPRODUCIBLE],
159        [AC_DEFINE([HAVE_GLNUTLS_REPRODUCIBLE], [1], [GnuTLS reproducible signing available])
160         # Ensure the version is at least 3.6.10
161         AC_CHECK_FUNC([gnutls_aead_cipher_encryptv2], [enable_repro_signing=yes], [enable_repro_signing=no])],
162        [enable_repro_signing=no],
163        [#include <gnutls/abstract.h>])
164
165    AC_CHECK_FUNC([gnutls_privkey_sign_data2],
166        [AC_DEFINE([HAVE_SIGN_DATA2], [1], [gnutls_privkey_sign_data2 available])])
167
168    AC_CHECK_FUNC([gnutls_privkey_export_x509],
169        [AC_DEFINE([HAVE_EXPORT_X509], [1], [gnutls_privkey_export_x509 available])])
170
171    AC_CHECK_FUNC([gnutls_memset],
172        [AC_DEFINE([HAVE_GNUTLS_MEMSET], [1], [gnutls_memset available])
173         gnutls_memset=yes], [gnutls_memset=no])
174
175    CFLAGS=$save_CFLAGS
176    LIBS=$save_LIBS
177])
178AM_CONDITIONAL([ENABLE_PKCS11], [test "$enable_pkcs11" = "yes"])
179
180AC_ARG_ENABLE([recvmmsg],
181   AS_HELP_STRING([--enable-recvmmsg=auto|yes|no], [enable recvmmsg() network API [default=auto]]),
182   [], [enable_recvmmsg=auto])
183
184AS_CASE([$enable_recvmmsg],
185   [auto|yes],[
186      AC_CHECK_FUNC([recvmmsg],
187                    [AC_CHECK_FUNC([sendmmsg],[enable_recvmmsg=yes],[enable_recvmmsg=no])],
188                    [enable_recvmmsg=no])],
189   [no],[],
190   [*], [AC_MSG_ERROR([Invalid value of --enable-recvmmsg.]
191 )])
192
193AS_IF([test "$enable_recvmmsg" = yes],[
194   AC_DEFINE([ENABLE_RECVMMSG], [1], [Use recvmmsg().])])
195
196# XDP support
197AC_ARG_ENABLE([xdp],
198   AS_HELP_STRING([--enable-xdp=auto|yes|no], [enable eXpress Data Path [default=auto]]),
199   [], [enable_xdp=auto])
200
201AS_CASE([$enable_xdp],
202   [auto], [PKG_CHECK_MODULES([libbpf], [libbpf >= 0.0.6], [enable_xdp=yes], [enable_xdp=no])],
203   [yes], [PKG_CHECK_MODULES([libbpf], [libbpf >= 0.0.6], [enable_xdp=yes],
204             [PKG_CHECK_MODULES([libelf], [libelf],
205                [AC_CHECK_FUNC([reallocarray],
206                   [enable_xdp=embedded
207                    embedded_libbpf_CFLAGS="-I\$(top_srcdir)/src/contrib/libbpf/include -I\$(top_srcdir)/src/contrib/libbpf/include/uapi"
208                    embedded_libbpf_LIBS=$libelf_LIBS
209                    libbpf_CFLAGS="-I\$(top_srcdir)/src/contrib/libbpf -I\$(top_srcdir)/src/contrib/libbpf/include/uapi"],
210                   [enable_xdp=no
211                    AC_MSG_WARN([reallocarray not available])])],
212                [AC_MSG_ERROR([libelf is required])])])],
213   [no], [],
214   [*], [AC_MSG_ERROR([Invalid value of --enable-xdp.])]
215)
216AM_CONDITIONAL([EMBEDDED_LIBBPF], [test "$enable_xdp" = "embedded"])
217AM_CONDITIONAL([ENABLE_XDP], [test "$enable_xdp" != "no"])
218AC_SUBST([embedded_libbpf_CFLAGS])
219AC_SUBST([embedded_libbpf_LIBS])
220AC_SUBST([libbpf_CFLAGS])
221AC_SUBST([libbpf_LIBS])
222
223AS_IF([test "$enable_xdp" != "no"],[
224    AC_DEFINE([ENABLE_XDP], [1], [Use eXpress Data Path.])])
225
226# Reuseport support
227AS_CASE([$host_os],
228  [freebsd*], [reuseport_opt=SO_REUSEPORT_LB],
229  [*], [reuseport_opt=SO_REUSEPORT],
230)
231
232AC_ARG_ENABLE([reuseport],
233  AS_HELP_STRING([--enable-reuseport=auto|yes|no],
234                 [enable SO_REUSEPORT(_LB) support [default=auto]]),
235  [], [enable_reuseport=auto]
236)
237
238AS_CASE([$enable_reuseport],
239  [auto], [
240    AS_CASE([$host_os],
241      [freebsd*|linux*], [AC_CHECK_DECL([$reuseport_opt],
242                                        [enable_reuseport=yes],
243                                        [enable_reuseport=no],
244                                        [#include <sys/socket.h>
245                                        ])],
246      [*], [enable_reuseport=no]
247    )],
248  [yes], [AC_CHECK_DECL([$reuseport_opt], [],
249                        [AC_MSG_ERROR([SO_REUSEPORT(_LB) not supported.])],
250                        [#include <sys/socket.h>
251                        ])],
252  [no], [],
253  [*], [AC_MSG_ERROR([Invalid value of --enable-reuseport.])]
254)
255
256AS_IF([test "$enable_reuseport" = yes],[
257   AC_DEFINE([ENABLE_REUSEPORT], [1], [Use SO_REUSEPORT(_LB).])])
258
259#########################################
260# Dependencies needed for Knot DNS daemon
261#########################################
262
263# Systemd integration
264AC_ARG_ENABLE([systemd],
265    AS_HELP_STRING([--enable-systemd=auto|yes|no], [enable systemd integration [default=auto]]),
266    [enable_systemd="$enableval"], [enable_systemd=auto])
267
268AS_IF([test "$enable_daemon" = "yes"],[
269
270AS_IF([test "$enable_systemd" != "no"],[
271  AS_CASE([$enable_systemd],
272    [auto],[PKG_CHECK_MODULES([systemd], [libsystemd], [enable_systemd=yes], [
273            PKG_CHECK_MODULES([systemd], [libsystemd-daemon libsystemd-journal], [enable_systemd=yes], [enable_systemd=no])])],
274    [yes],[PKG_CHECK_MODULES([systemd], [libsystemd], [], [
275            PKG_CHECK_MODULES([systemd], [libsystemd-daemon libsystemd-journal])])],
276    [*],[AC_MSG_ERROR([Invalid value of --enable-systemd.])])
277    ])
278
279AS_IF([test "$enable_systemd" = "yes"],[
280  AC_DEFINE([ENABLE_SYSTEMD], [1], [Use systemd integration.])])
281
282]) dnl enable_daemon
283
284# Socket polling method
285socket_polling=
286AC_ARG_WITH([socket-polling],
287  AS_HELP_STRING([--with-socket-polling=auto|poll|epoll|kqueue|libkqueue],
288                 [Use specific socket polling method [default=auto]]),
289  [socket_polling=$withval], [socket_polling=auto]
290)
291
292AS_CASE([$socket_polling],
293  [auto], [AC_CHECK_FUNCS([kqueue],
294             [AC_DEFINE([HAVE_KQUEUE], [1], [kqueue available])
295              socket_polling=kqueue],
296             [AC_CHECK_FUNCS([epoll_create],
297                [AC_DEFINE([HAVE_EPOLL], [1], [epoll available])
298                 socket_polling=epoll],
299                [socket_polling=poll])])],
300  [poll], [socket_polling=poll],
301  [epoll], [AC_CHECK_FUNCS([epoll_create],
302              [AC_DEFINE([HAVE_EPOLL], [1], [epoll available])
303               socket_polling=epoll],
304              [AC_MSG_ERROR([epoll not available.])])],
305  [kqueue], [AC_CHECK_FUNCS([kqueue],
306               [AC_DEFINE([HAVE_KQUEUE], [1], [kqueue available])
307                socket_polling=kqueue],
308               [AC_MSG_ERROR([kqueue not available.])])],
309  [libkqueue], [PKG_CHECK_MODULES([libkqueue], [libkqueue],
310                  [AC_DEFINE([HAVE_KQUEUE], [1], [libkqueue available])
311                   socket_polling=libkqueue],
312                  [AC_MSG_ERROR([libkqueue not available.])])],
313  [*], [AC_MSG_ERROR([Invalid value of --socket-polling.])]
314)
315
316# Alternative memory allocator
317malloc_LIBS=
318AC_ARG_WITH([memory-allocator],
319  AS_HELP_STRING([--with-memory-allocator=auto|LIBRARY],
320                 [Use specific memory allocator for the server (e.g. jemalloc) [default=auto]]),
321  AS_CASE([$withval],
322    [auto], [],
323    [*],    [malloc_LIBS="-l$withval"]
324  )
325  with_memory_allocator=[$withval]
326)
327AS_IF([test "$with_memory_allocator" = ""], [with_memory_allocator="auto"])
328AC_SUBST([malloc_LIBS])
329
330dnl Check for userspace-rcu library
331AC_ARG_WITH(urcu,
332[  --with-urcu=DIR        where to find userspace-rcu library])
333
334AS_IF([test "$enable_daemon" = "yes"],[
335
336AS_IF([test "$with_urcu" != "no"], [
337  PKG_CHECK_MODULES([liburcu], liburcu, [
338    liburcu_PKGCONFIG="liburcu >= 0.4.0"
339    AC_SUBST([liburcu_PKGCONFIG])
340    with_urcu=yes
341  ],[
342    for try_urcu in "$with_urcu" "" "/usr/local"; do
343      save_LIBS="$LIBS"
344      save_CPPFLAGS="$CPPFLAGS"
345
346      AS_IF([test -d "$try_urcu"], [
347        liburcu_CFLAGS="-I$try_urcu/include"
348        liburcu_LIBS="-L$try_urcu/lib"
349      ],[
350        liburcu_CFLAGS=""
351        liburcu_LIBS=""
352      ])
353
354      CPPFLAGS="$CPPFLAGS $liburcu_CFLAGS"
355      LIBS="$LIBS $liburcu_LIBS"
356
357      AC_SEARCH_LIBS([rcu_set_pointer_sym], [urcu], [
358        with_urcu=yes
359        liburcu_LIBS="$liburcu_LIBS -lurcu"
360        AC_SUBST([liburcu_CFLAGS])
361        AC_SUBST([liburcu_LIBS])
362        break
363      ],[
364        CPPFLAGS="$save_CPPFLAGS"
365        LIBS="$save_LIBS"
366        with_urcu=no
367        # do not cache result of AC_SEARCH_LIBS test
368        unset ac_cv_search_rcu_set_pointer_sym
369      ])
370    done
371    CPPFLAGS="$save_CPPFLAGS"
372    LIBS="$save_LIBS"
373
374    AS_IF([test "$with_urcu" = "no"],[
375      AC_MSG_ERROR([liburcu is required])
376      ])
377  ])
378])
379
380])
381
382static_modules=""
383shared_modules=""
384static_modules_declars=""
385static_modules_init=""
386doc_modules=""
387
388KNOT_MODULE([cookies],     "yes")
389KNOT_MODULE([dnsproxy],    "yes", "non-shareable")
390KNOT_MODULE([dnstap],      "no")
391KNOT_MODULE([geoip],       "yes")
392KNOT_MODULE([noudp],       "yes")
393KNOT_MODULE([onlinesign],  "yes", "non-shareable")
394KNOT_MODULE([probe],       "yes")
395KNOT_MODULE([queryacl],    "yes")
396KNOT_MODULE([rrl],         "yes")
397KNOT_MODULE([stats],       "yes")
398KNOT_MODULE([synthrecord], "yes")
399KNOT_MODULE([whoami],      "yes")
400
401AC_SUBST([STATIC_MODULES_DECLARS], [$(printf "$static_modules_declars")])
402AM_SUBST_NOTMAKE([STATIC_MODULES_DECLARS])
403AC_SUBST([STATIC_MODULES_INIT], [$(printf "$static_modules_init")])
404AM_SUBST_NOTMAKE([STATIC_MODULES_INIT])
405AC_SUBST([DOC_MODULES], [$(printf "$doc_modules")])
406AM_SUBST_NOTMAKE([DOC_MODULES])
407
408# Check for Dnstap
409AC_ARG_ENABLE([dnstap],
410  AS_HELP_STRING([--enable-dnstap], [Enable dnstap support for kdig (requires fstrm, protobuf-c)]),
411  [], [enable_dnstap=no])
412
413AS_IF([test "$enable_dnstap" != "no" -o "$STATIC_MODULE_dnstap" != "no" -o "$SHARED_MODULE_dnstap" != "no"],[
414  AC_PATH_PROG([PROTOC_C], [protoc-c])
415  AS_IF([test -z "$PROTOC_C"],[
416    AC_MSG_ERROR([The protoc-c program was not found. Please install protobuf-c!])
417  ])
418  PKG_CHECK_MODULES([libfstrm], [libfstrm])
419  PKG_CHECK_MODULES([libprotobuf_c], [libprotobuf-c >= 1.0.0])
420  AC_SUBST([DNSTAP_CFLAGS], ["$libfstrm_CFLAGS $libprotobuf_c_CFLAGS"])
421  AC_SUBST([DNSTAP_LIBS], ["$libfstrm_LIBS $libprotobuf_c_LIBS"])
422])
423
424AS_IF([test "$enable_dnstap" != "no"],[
425  AC_DEFINE([USE_DNSTAP], [1], [Define to 1 to enable dnstap support for kdig])
426])
427AM_CONDITIONAL([HAVE_DNSTAP], test "$enable_dnstap" != "no")
428
429AM_CONDITIONAL([HAVE_LIBDNSTAP], test "$enable_dnstap" != "no" -o \
430                                      "$STATIC_MODULE_dnstap" != "no" -o \
431                                      "$SHARED_MODULE_dnstap" != "no")
432# MaxMind DB for the GeoIP module
433AC_ARG_ENABLE([maxminddb],
434    AS_HELP_STRING([--enable-maxminddb=auto|yes|no], [enable MaxMind DB [default=auto]]),
435    [enable_maxminddb="$enableval"], [enable_maxminddb=auto])
436
437AS_IF([test "$enable_daemon" = "no"],[enable_maxminddb=no])
438AS_CASE([$enable_maxminddb],
439  [no],[],
440  [auto],[PKG_CHECK_MODULES([libmaxminddb], [libmaxminddb], [enable_maxminddb=yes], [enable_maxminddb=no])],
441  [yes], [PKG_CHECK_MODULES([libmaxminddb], [libmaxminddb])],
442  [*],[
443    save_CFLAGS="$CFLAGS"
444    save_LIBS="$LIBS"
445    AS_IF([test "$enable_maxminddb" != ""],[
446      LIBS="$LIBS -L$enable_maxminddb"
447      CFLAGS="$CFLAGS -I$enable_maxminddb/include"
448      ])
449    AC_SEARCH_LIBS([MMDB_open], [maxminddb], [
450      AS_IF([test "$enable_maxminddb" != ""], [
451        libmaxminddb_CFLAGS="-I$enable_maxminddb/include"
452        libmaxminddb_LIBS="-L$enable_maxminddb -lmaxminddb"
453  ],[
454  libmaxminddb_CFLAGS=""
455  libmaxminddb_LIBS="$ac_cv_search_MMDB_open"
456        ])
457      ],[AC_MSG_ERROR("not found in `$enable_maxminddb'")])
458    CFLAGS="$save_CFLAGS"
459    LIBS="$save_LIBS"
460    AC_SUBST([libmaxminddb_CFLAGS])
461    AC_SUBST([libmaxminddb_LIBS])
462    enable_maxminddb=yes
463    ])
464
465AS_IF([test "$enable_maxminddb" = yes], [AC_DEFINE([HAVE_MAXMINDDB], [1], [Define to 1 to enable MaxMind DB.])])
466AM_CONDITIONAL([HAVE_MAXMINDDB], [test "$enable_maxminddb" = yes])
467
468AC_ARG_WITH([lmdb],
469  [AS_HELP_STRING([--with-lmdb=DIR], [explicit location where to find LMDB])]
470)
471PKG_CHECK_MODULES([lmdb], [lmdb >= 0.9.15], [], [
472  save_CPPFLAGS=$CPPFLAGS
473  save_LIBS=$LIBS
474
475  have_lmdb=no
476
477  for try_lmdb in "$with_lmdb" "" "/usr/local" "/usr/pkg"; do
478    AS_IF([test -d "$try_lmdb"], [
479      lmdb_CFLAGS="-I$try_lmdb/include"
480      lmdb_LIBS="-L$try_lmdb/lib"
481    ],[
482      lmdb_CFLAGS=""
483      lmdb_LIBS=""
484    ])
485
486    CPPFLAGS="$save_CPPFLAGS $lmdb_CFLAGS"
487    LIBS="$save_LIBS $lmdb_LIBS"
488
489    AC_SEARCH_LIBS([mdb_txn_id], [lmdb], [
490      have_lmdb=yes
491      lmdb_LIBS="$lmdb_LIBS -llmdb"
492      AC_SUBST([lmdb_CFLAGS])
493      AC_SUBST([lmdb_LIBS])
494      break
495    ])
496
497    # do not cache result of AC_SEARCH_LIBS test
498    unset ac_cv_search_mdb_txn_id
499  done
500
501  CPPFLAGS="$save_CPPFLAGS"
502  LIBS="$save_LIBS"
503
504  AS_IF([test "$have_lmdb" = "no"], [
505    AC_MSG_ERROR([lmdb library not found])
506  ])
507])
508
509# LMDB mapping sizes
510conf_mapsize_default=500
511AC_ARG_WITH([conf_mapsize],
512    AS_HELP_STRING([--with-conf-mapsize=NUM], [Configuration DB mapsize in MiB [default=$conf_mapsize_default]]),
513    [conf_mapsize=$withval],[conf_mapsize=$conf_mapsize_default])
514
515AS_CASE([$conf_mapsize],
516    [yes],[conf_mapsize=$conf_mapsize_default],
517    [no], [AC_MSG_ERROR([conf_mapsize must be a number])],
518    [*],  [AS_IF([test $conf_mapsize != $(( $conf_mapsize + 0 ))],
519                 [AC_MSG_ERROR(conf_mapsize must be an integer number)])])
520AC_DEFINE_UNQUOTED([CONF_MAPSIZE], [$conf_mapsize], [Configuration DB mapsize.])
521AC_SUBST(conf_mapsize)
522
523# libedit
524AS_IF([test "$enable_daemon" = "yes" -o "$enable_utilities" = "yes"], [
525  PKG_CHECK_MODULES([libedit], [libedit], [with_libedit=yes], [
526    with_libedit=no
527    AC_CHECK_HEADER([histedit.h], [
528      # workaround for OpenBSD
529      AS_CASE([$host_os],
530        [openbsd*], [libedit_deps=-lcurses],
531        [libedit_deps=]
532      )
533      AC_CHECK_LIB([edit], [el_init], [
534        with_libedit=yes
535        libedit_CFLAGS=
536        libedit_LIBS="-ledit $libedit_deps"
537        ], [], [$libedit_deps]
538      )
539    ])
540  ])
541  AS_IF([test "$with_libedit" != "yes"], [
542    AC_MSG_ERROR([libedit not found])
543  ])
544], [
545  with_libedit=no
546  libedit_CFLAGS=
547  libedit_LIBS=
548])
549
550############################################
551# Dependencies needed for Knot DNS utilities
552############################################
553
554dnl Check for libidn.
555AC_ARG_WITH(libidn,
556  AS_HELP_STRING([--with-libidn=[DIR]], [Support IDN (needs GNU libidn2 or libidn)]),
557  with_libidn=$withval,
558  with_libidn=yes
559)
560
561dnl Check for libnghttp2.
562AC_ARG_WITH(libnghttp2,
563  AS_HELP_STRING([--with-libnghttp2=[DIR]], [Support DoH (needs libnghttp2)]),
564  with_libnghttp2=$withval,
565  with_libnghttp2=yes
566)
567
568AS_IF([test "$enable_utilities" = "yes"], [
569  AS_IF([test "$with_libidn" != "no"], [
570    PKG_CHECK_MODULES([libidn2], [libidn2 >= 2.0.0], [
571      with_libidn=libidn2
572      AC_DEFINE([LIBIDN], [1], [Define to 1 to enable IDN support])
573      AC_DEFINE([LIBIDN_HEADER], [<idn2.h>], [Define to proper libidn header])
574    ], [
575      PKG_CHECK_MODULES([libidn], [libidn >= 0.0.0], [
576        with_libidn=libidn
577        AC_DEFINE([LIBIDN], [1], [Define to 1 to enable IDN support])
578        AC_DEFINE([LIBIDN_HEADER], [<idna.h>], [Define to proper libidn header])
579      ], [
580        with_libidn=no
581        AC_MSG_WARN([libidn2 or libidn not found])
582      ])
583    ])
584  ])
585
586  AS_IF([test "$with_libnghttp2" != "no"], [
587    PKG_CHECK_MODULES([libnghttp2], [libnghttp2], [
588      with_libnghttp2=libnghttp2
589      AC_DEFINE([LIBNGHTTP2], [1], [Define to 1 to enable DoH support])
590    ], [
591      with_libnghttp2=no
592      AC_MSG_WARN([libnghttp2 not found])
593    ])
594  ])
595
596  AS_IF([test "$enable_xdp" != "no"], [
597    PKG_CHECK_MODULES([libmnl], [libmnl], [], [
598      AC_MSG_ERROR([libmnl not found])
599    ])
600  ])
601]) # Knot DNS utilities dependencies
602
603AC_ARG_ENABLE([cap-ng],
604    AS_HELP_STRING([--enable-cap-ng=auto|no], [enable POSIX capabilities [default=auto]]),
605    [enable_cap_ng="$enableval"], [enable_cap_ng=auto])
606
607AS_IF([test "$enable_daemon" = "yes"], [
608
609AS_IF([test "$enable_cap_ng" != "no"],[
610  PKG_CHECK_MODULES([cap_ng], [cap-ng], [enable_cap_ng=yes], [
611    enable_cap_ng=no
612    AC_CHECK_HEADER([cap-ng.h], [
613      save_LIBS="$LIBS"
614      AC_SEARCH_LIBS([capng_apply], [cap-ng], [
615        AS_IF([test "$ac_cv_search_capng_apply" != "none required"],
616          [cap_ng_LIBS="$ac_cv_search_capng_apply"], [cap_ng_LIBS=])
617        AC_SUBST([cap_ng_LIBS])
618        enable_cap_ng=yes
619      ])
620      LIBS="$save_LIBS"
621    ])
622  ])
623], [
624  enable_cap_ng=no
625  cap_ng_LIBS=
626])])
627
628AS_IF([test "$enable_cap_ng" = yes],
629  [AC_DEFINE([ENABLE_CAP_NG], [1], [POSIX capabilities available])]
630)
631
632save_LIBS="$LIBS"
633AC_SEARCH_LIBS([pthread_create], [pthread], [
634  AS_IF([test "$ac_cv_search_pthread_create" != "none required"],
635    [pthread_LIBS="$ac_cv_search_pthread_create"], [pthread_LIBS=])
636  AC_SUBST([pthread_LIBS])
637],[
638  AC_MSG_ERROR([pthreads not found])
639])
640LIBS="$save_LIBS"
641
642save_LIBS="$LIBS"
643AC_SEARCH_LIBS([dlopen], [dl], [
644  AS_IF([test "$ac_cv_search_dlopen" != "none required"],
645    [dlopen_LIBS="$ac_cv_search_dlopen"], [dlopen_LIBS=])
646  AC_SUBST([dlopen_LIBS])
647],[
648  AC_MSG_ERROR([dlopen not found])
649])
650LIBS="$save_LIBS"
651
652save_LIBS="$LIBS"
653AC_SEARCH_LIBS([pow], [m], [
654  AS_IF([test "$ac_cv_search_pow" != "none required"],
655    [math_LIBS="$ac_cv_search_pow"], [math_LIBS=])
656  AC_SUBST([math_LIBS])
657],[
658  AC_MSG_ERROR([math not found])
659])
660LIBS="$save_LIBS"
661
662save_LIBS="$LIBS"
663AC_SEARCH_LIBS([pthread_setaffinity_np], [pthread], [
664  AC_DEFINE([HAVE_PTHREAD_SETAFFINITY_NP], [1],
665  [Define to 1 if you have the pthread_setaffinity_np function.])
666])
667LIBS="$save_LIBS"
668
669# Checks for header files.
670AC_HEADER_RESOLV
671AC_CHECK_HEADERS_ONCE([pthread_np.h sys/uio.h bsd/string.h])
672
673# Checks for optional library functions.
674AC_CHECK_FUNCS([accept4 clock_gettime fgetln getline initgroups malloc_trim \
675                setgroups strlcat strlcpy sysctlbyname])
676
677# Check for robust memory cleanup implementations.
678AC_CHECK_FUNC([explicit_bzero], [
679  AC_DEFINE([HAVE_EXPLICIT_BZERO], [1], [explicit_bzero available])
680  explicit_bzero=yes], [explicit_bzero=no]
681)
682AC_CHECK_FUNC([explicit_memset], [
683  AC_DEFINE([HAVE_EXPLICIT_MEMSET], [1], [explicit_memset available])
684  explicit_memset=yes], [explicit_memset=no]
685)
686AM_CONDITIONAL([USE_GNUTLS_MEMSET], [test "$explicit_bzero" = "no" -a "$explicit_memset" = "no" -a "$gnutls_memset" = "yes"])
687
688# Check for mandatory library functions.
689AC_CHECK_FUNC([vasprintf], [], [
690  AC_MSG_ERROR([vasprintf support in the libc is required])])
691
692# Check for cpu_set_t/cpuset_t compatibility
693AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <pthread.h>]], [[cpu_set_t set; CPU_ZERO(&set);]])],
694[AC_DEFINE(HAVE_CPUSET_LINUX, 1, [Define if Linux-like cpu_set_t exists.])])
695AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <pthread_np.h>]], [[cpuset_t set; CPU_ZERO(&set);]])],
696[AC_DEFINE(HAVE_CPUSET_BSD, 1, [Define if FreeBSD-like cpuset_t exists.])])
697AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <sched.h>]], [[cpuset_t* set = cpuset_create(); cpuset_destroy(set);]])],
698[AC_DEFINE(HAVE_CPUSET_NETBSD, 1, [Define if cpuset_t and cpuset(3) exists.])])
699
700# Check for '__atomic' compiler builtin atomic functions.
701AC_LINK_IFELSE(
702  [AC_LANG_PROGRAM([[#include <stdint.h>]],
703                   [[uint64_t val = 0; __atomic_add_fetch(&val, 1, __ATOMIC_RELAXED);]])],
704  [AC_DEFINE(HAVE_ATOMIC, 1, [Define to 1 if you have '__atomic' functions.])]
705)
706
707# Check for '__sync' compiler builtin atomic functions.
708AC_LINK_IFELSE(
709  [AC_LANG_PROGRAM([[#include <stdint.h>]],
710                   [[int val = 0; __sync_add_and_fetch(&val, 1);]])],
711  [AC_DEFINE(HAVE_SYNC_ATOMIC, 1, [Define to 1 if you have '__sync' functions.])]
712)
713
714# Prepare CFLAG_VISIBILITY to be used where needed
715gl_VISIBILITY()
716
717# Add code coverage macro
718AX_CODE_COVERAGE
719
720AX_SANITIZER
721AS_IF([test -n "$sanitizer_CFLAGS"], [CFLAGS="$CFLAGS $sanitizer_CFLAGS"])
722AM_CONDITIONAL([FUZZER], [test "$with_fuzzer" != "no"])
723AM_CONDITIONAL([OSS_FUZZ], [test "$with_oss_fuzz" != "no"])
724
725AS_IF([test "$enable_documentation" = "yes"],[
726
727AC_PATH_PROGS([SPHINXBUILD], [sphinx-build sphinx-build-3], [false])
728AS_IF([test "$SPHINXBUILD" = "false"],
729  [AC_MSG_WARN([Could not find the 'sphinx-build' executable, you will be unable to regenerate documentation.])],
730  [AC_PATH_PROG([PDFLATEX], [pdflatex], [false])
731   AS_IF([test "$PDFLATEX" = ""],
732     [AC_MSG_WARN([Could not find the 'pdflatex' executable, you will be unable to generate PDF documentation.])])
733   AC_PATH_PROG([MAKEINFO], [makeinfo], [false])
734   AS_IF([test "$MAKEINFO" = "false"],
735     [AC_MSG_WARN([Could not find the 'makeinfo' executable, you will be unable to generate info documentation.])])
736  ])
737
738])
739
740AM_CONDITIONAL([HAVE_SPHINXBUILD], test "$SPHINXBUILD" != "false")
741AM_CONDITIONAL([HAVE_PDFLATEX], test "$PDFLATEX" != "false")
742AM_CONDITIONAL([HAVE_MAKEINFO], test "$MAKEINFO" != "false")
743
744# Strip -fdebug-prefix-map= parameters from flags for better reproducibility of binaries.
745filtered_cflags=$(echo -n "$CFLAGS" | \
746                  sed 's/[[^[:alnum:]]]-f[[^[:space:]]]*-prefix-map=[[^[:space:]]]*//g')
747filtered_cppflags=$(echo -n "$CPPFLAGS" | \
748                    sed 's/[[^[:alnum:]]]-f[[^[:space:]]]*-prefix-map=[[^[:space:]]]*//g')
749
750result_msg_base="  Knot DNS $VERSION
751
752    Target:   $host_os $host_cpu $endianity
753    Compiler: ${CC}
754    CFLAGS:   ${filtered_cflags} ${filtered_cppflags}
755    LIBS:     ${LIBS} ${LDFLAGS}
756    LibURCU:  ${liburcu_LIBS} ${liburcu_CFLAGS}
757    GnuTLS:   ${gnutls_LIBS} ${gnutls_CFLAGS}
758    Libedit:  ${libedit_LIBS} ${libedit_CFLAGS}
759    LMDB:     ${lmdb_LIBS} ${lmdb_CFLAGS}
760    Config:   ${conf_mapsize} MiB default mapsize
761
762    Prefix:      ${knot_prefix}
763    Run dir:     ${run_dir}
764    Storage dir: ${storage_dir}
765    Config dir:  ${config_dir}
766    Module dir:  ${module_dir}
767
768    Static modules: ${static_modules}
769    Shared modules: ${shared_modules}
770
771    Knot DNS libraries:     yes
772    Knot DNS daemon:        ${enable_daemon}
773    Knot DNS utilities:     ${enable_utilities}
774    Knot DNS documentation: ${enable_documentation}
775
776    Use recvmmsg:           ${enable_recvmmsg}
777    Use SO_REUSEPORT(_LB):  ${enable_reuseport}
778    XDP support:            ${enable_xdp}
779    Socket polling:         ${socket_polling}
780    Memory allocator:       ${with_memory_allocator}
781    Fast zone parser:       ${enable_fastparser}
782    Utilities with IDN:     ${with_libidn}
783    Utilities with DoH:     ${with_libnghttp2}
784    Utilities with Dnstap:  ${enable_dnstap}
785    MaxMind DB support:     ${enable_maxminddb}
786    Systemd integration:    ${enable_systemd}
787    POSIX capabilities:     ${enable_cap_ng}
788    PKCS #11 support:       ${enable_pkcs11}
789    Ed25519 support:        ${enable_ed25519}
790    Ed448 support:          ${enable_ed448}
791    Reproducible signing:   ${enable_repro_signing}
792    Code coverage:          ${enable_code_coverage}
793    Sanitizer:              ${with_sanitizer}
794    LibFuzzer:              ${with_fuzzer}
795    OSS-Fuzz:               ${with_oss_fuzz}"
796
797result_msg_esc=$(echo -n "$result_msg_base" | sed '$!s/$/\\n/' | tr -d '\n')
798
799AC_DEFINE_UNQUOTED([CONFIGURE_SUMMARY],["$result_msg_esc"],[Configure summary])
800
801AC_CONFIG_FILES([Makefile
802                 Doxyfile
803                 doc/Makefile
804                 tests/Makefile
805                 tests-fuzz/Makefile
806                 samples/Makefile
807                 distro/Makefile
808                 python/Makefile
809                 python/setup.py
810                 python/libknot/__init__.py
811                 src/Makefile
812                 src/libknot/xdp/Makefile
813                 src/knot/modules/static_modules.h
814                 ])
815
816AC_CONFIG_FILES([doc/modules.rst],
817                [cp doc/modules.rst "${srcdir}"/doc/modules.rst 2>/dev/null
818                 abs_srcdir=$(cd "${srcdir}" && pwd)
819                 ln -s -f "${abs_srcdir}"/src/knot/modules "${srcdir}"/doc 2>/dev/null])
820
821AC_OUTPUT
822AC_MSG_RESULT([
823$result_msg_base
824])
825