configure.ac 12.7 KB
Newer Older
Ondřej Surý's avatar
Ondřej Surý committed
1 2
#                                               -*- Autoconf -*-

3
AC_PREREQ([2.60])
Marek Vavruša's avatar
Marek Vavruša committed
4
AC_INIT([knot], [1.5.0-alpha], [knot-dns@labs.nic.cz])
Ondřej Surý's avatar
Ondřej Surý committed
5
AM_INIT_AUTOMAKE([gnits subdir-objects dist-xz -Wall -Werror])
6
AM_SILENT_RULES([yes])
7
AC_CONFIG_SRCDIR([src/knot/main.c])
Ondřej Surý's avatar
Ondřej Surý committed
8 9
AC_CONFIG_HEADERS([src/config.h])
AC_CONFIG_MACRO_DIR([m4])
10
AC_USE_SYSTEM_EXTENSIONS([_GNU_SOURCE])
11

12 13 14 15
# Automatically update release date based on configure.ac date
release_date=`doc/mdate-sh configure.ac`
AC_SUBST([RELEASE_DATE], $release_date)

16 17 18 19
# 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
20

21
# Default compiler flags
22
CFLAGS="$CFLAGS -Wall -Werror=format-security"
23

24
# Checks for programs.
25
m4_ifdef([AM_PROG_AR], [AM_PROG_AR]) # call AM_PROG_AR only if available
26

Ondřej Surý's avatar
Ondřej Surý committed
27
# Initialize libtool
28
AC_DISABLE_STATIC
29
AC_PROG_LIBTOOL
Ondřej Surý's avatar
Ondřej Surý committed
30 31
LT_INIT

32 33 34
# Use pkg-config
PKG_PROG_PKG_CONFIG

35 36 37
AC_CACHE_CHECK([for reentrant lex], [ac_cv_path_LEX],
  [AC_PATH_PROGS_FEATURE_CHECK([LEX], [$LEX flex gflex],
  [cat >conftest.l <<_ACEOF
38 39 40 41 42 43 44 45 46 47 48 49 50 51
%{
%}

%option reentrant
%option bison-bridge
%option noinput
%option nounput
%option noreject

BLANK [ \t\n]

%%
<<EOF>> return 0;
%%
52 53 54 55 56 57 58 59
_ACEOF
_AC_DO_VAR(ac_path_LEX conftest.l)
test $ac_status -eq 0 && ac_cv_path_LEX=$ac_path_LEX ac_path_LEX_found=true
rm -f conftest.l lexyy.c lex.yy.c
],
[AC_MSG_ERROR([could not find lex that supports reentrant parsers])])])
AC_SUBST([LEX], [$ac_cv_path_LEX])
AM_PROG_LEX
60

Ondřej Surý's avatar
Ondřej Surý committed
61
AC_PROG_YACC
62
YACC_BISON=`bison --version | awk '{print $1;exit}'`
63
AS_IF([test "x$YACC_BISON" != "xbison"],
64
    [AC_MSG_ERROR([GNU bison needed for reentrant parsers, set the \$YACC variable before running configure])])
Ondřej Surý's avatar
Ondřej Surý committed
65 66
AC_PROG_INSTALL

67
# Check for Ragel
68 69
AC_PATH_PROG([RAGEL], [ragel], [false])
AM_CONDITIONAL([HAVE_RAGEL], test "$RAGEL" != "false")
70

71 72
# Set FSM type for Ragel
AC_ARG_ENABLE([fastparser],
73
    AS_HELP_STRING([--disable-fastparser], [Don't use faster zone parser]),
74 75 76 77
    [],
    [enable_fastparser=yes])

AS_CASE([$enable_fastparser],
78
    [no], [AC_SUBST([FSM_TYPE], [-T0])],
79 80
    [yes], [AC_SUBST([FSM_TYPE], [-G2])],
    [*], [
81
        AS_IF([test "$RAGEL" = "false"],
82 83 84
	    [AC_MSG_ERROR([Ragel is needed to generate different parsers])])
        AC_SUBST([FSM_TYPE], [$enable_fastparser])
    ])
85
AM_CONDITIONAL([G2_PARSER], test "$enable_fastparser" = "yes")
86
AM_CONDITIONAL([T0_PARSER], test "$enable_fastparser" = "no")
87

88 89 90 91 92 93
# Systemd integration
AC_ARG_ENABLE([systemd],
    AS_HELP_STRING([--enable-systemd=auto|yes|no], [enable systemd notification mechanism [default=auto]]),
    [enable_systemd="$enableval"], [enable_systemd=auto])

case "$enable_systemd" in
94
    auto) PKG_CHECK_MODULES([systemd_daemon], [libsystemd-daemon], [enable_systemd=yes], [enable_systemd=no]) ;;
95 96 97 98 99 100 101 102 103
    yes)  PKG_CHECK_MODULES([systemd_daemon], [libsystemd-daemon]) ;;
    no)   ;;
    *)    AC_MSG_ERROR([Invalid value of --enable-systemd.]) ;;
esac

if test "$enable_systemd" = yes; then
    AC_DEFINE([ENABLE_SYSTEMD_NOTIFY], [1], [Use systemd notifications.])
fi

104 105
# Debug modules
AC_ARG_ENABLE([debug],
106
    AS_HELP_STRING([--enable-debug=server,zones,xfr,packet,rr,ns,loader,dnssec],
107
    [compile selected debug modules [default=none]]),
108
    [
109 110
    echo ${enableval}|tr "," "\n"|while read val; do
        case "${val}" in
111 112 113 114 115 116 117 118
            server) AC_DEFINE([KNOTD_SERVER_DEBUG], [1], [Server debug.]) ;;
            zones) AC_DEFINE([KNOT_ZONES_DEBUG], [1], [Zones debug.]) ;;
            xfr) AC_DEFINE([KNOT_XFR_DEBUG], [1], [XFR debug.]) ;;
            packet) AC_DEFINE([KNOT_PACKET_DEBUG], [1], [Packet debug.]) ;;
            rr) AC_DEFINE([KNOT_RR_DEBUG], [1], [RR debug.]) ;;
            ns) AC_DEFINE([KNOT_NS_DEBUG], [1], [Nameserver debug.]) ;;
            loader) AC_DEFINE([KNOT_LOADER_DEBUG], [1], [Zone loading debug.]) ;;
            dnssec) AC_DEFINE([KNOT_DNSSEC_DEBUG], [1], [DNSSEC debug.]) ;;
119 120
        esac
    done
121
    ], [])
Jan Kadlec's avatar
Jan Kadlec committed
122

123
# Debug level
124 125
AC_ARG_ENABLE([debuglevel],
    AS_HELP_STRING([--enable-debuglevel=brief|verbose|details], [enable given debug level [default=disabled]]),
126 127 128 129 130 131
    # Not all shells support fall-through with ;& so I have to duplicate
    [case "x${enableval}" in
      xdetails)
        AC_DEFINE([DEBUG_ENABLE_DETAILS], [1], [Enable details debugging messages.])
        AC_DEFINE([DEBUG_ENABLE_VERBOSE], [1], [Enable verbose debugging messages.])
        AC_DEFINE([DEBUG_ENABLE_BRIEF], [1], [Enable brief debugging messages.])
132
        ;;
133 134 135
      xverbose)
        AC_DEFINE([DEBUG_ENABLE_VERBOSE], [1], [Enable verbose debugging messages.])
        AC_DEFINE([DEBUG_ENABLE_BRIEF], [1], [Enable brief debugging messages.])
136
        ;;
137 138 139 140
      xbrief)
        AC_DEFINE([DEBUG_ENABLE_BRIEF], [1], [Enable brief debugging messages.])
        ;;
    esac], [])
141

142
# recvmmsg() (valgrind doesn't support it, so disable for debugging)
143
# The check for struct mmsghdr is required when libc doesn't have an API but the function links
144
AC_ARG_ENABLE([recvmmsg],
145
    AS_HELP_STRING([--enable-recvmmsg=yes|no], [enable recvmmsg() network API under Linux (kernel support required) (set to 'no' if you have trouble running server under valgrind) [default=yes]]),
146 147
    [case "${enableval}" in
      yes)
148 149 150
	  AC_CHECK_FUNCS([sendmmsg])
          AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <sys/socket.h>]], [[struct mmsghdr v; recvmmsg(0,0,0,0,0);]])],
          [AC_DEFINE(HAVE_RECVMMSG, 1, [Define if struct mmsghdr and recvmmsg() exists.])])
151
          ;;
152
      no)
153
          ;;
154
      *)
155 156
          AC_MSG_ERROR([bad value ${enableval} for --enable-recvmmsg])
          ;;
157 158 159 160 161 162
    esac],
    [
      AC_CHECK_FUNCS([sendmmsg])
      AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <sys/socket.h>]], [[struct mmsghdr v; recvmmsg(0,0,0,0,0);]])],
      [AC_DEFINE(HAVE_RECVMMSG, 1, [Define if struct mmsghdr and recvmmsg() exists.])])
    ])
163

164
# Check for link time optimizations support and predictive commoning
165
AC_ARG_ENABLE([lto],
166
    AS_HELP_STRING([--enable-lto=yes|no], [enable link-time optimizations, enable if not broken for some extra speed [default=no]]),
167
    [case "${enableval}" in
168
      yes) AX_CHECK_COMPILE_FLAG("-flto", [CFLAGS="$CFLAGS -flto"], []) ;;
169
      no) ;;
170
      *)  AC_MSG_ERROR([bad value ${enableval} for --enable-lto]) ;;
171
    esac])
172

173 174 175 176
# Check for enable microseconds in log messages
AC_ARG_ENABLE([microseconds-log],
    AS_HELP_STRING([--enable-microseconds-log], [enable microseconds in log messages [default=no]]),
    AC_DEFINE([ENABLE_MICROSECONDS_LOG], [1], [microseconds in log messages]))
177

178
AX_CHECK_COMPILE_FLAG("-fpredictive-commoning", [CFLAGS="$CFLAGS -fpredictive-commoning"], [], "-Werror")
179

180 181
# Disable strict aliasing
# FIXME: we break strict aliasing on many occurenes, disable it until resolved or kept
182
AX_CHECK_COMPILE_FLAG("-fno-strict-aliasing", [CFLAGS="$CFLAGS -fno-strict-aliasing"], [])
183

184 185 186
# Default directories
run_dir="${localstatedir}/run/knot"
AC_ARG_WITH([rundir],
187
        AC_HELP_STRING([--with-rundir=path], [Path to run-time variable data (pid, sockets...). [default=LOCALSTATEDIR/run/knot]]),
188 189 190
        [run_dir=$withval])
AC_SUBST(run_dir)

Ondřej Surý's avatar
Ondřej Surý committed
191
storage_dir="${localstatedir}/lib/knot"
192
AC_ARG_WITH([storage],
193
        AC_HELP_STRING([--with-storage=path], [Default storage directory (slave zones, persistent data). [default=LOCALSTATEDIR/lib/knot]]),
194 195 196
        [storage_dir=$withval])
AC_SUBST(storage_dir)

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

Ondřej Surý's avatar
Ondřej Surý committed
203 204
# Checks for libraries.
# FIXME: Replace `main' with a function in `-lm':
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 231 232 233 234

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

AS_IF([test "$with_urcu" != "no"], [
  PKG_CHECK_MODULES([liburcu], liburcu, [
    CPPFLAGS="$CPPFLAGS $liburcu_CFLAGS"
    LIBS="$LIBS $liburcu_LIBS"
    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
	break
      ],[
235 236
        CPPFLAGS="$save_CPPFLAGS"
        LIBS="$save_LIBS"
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292
        with_urcu=no
	# do not cache result of AC_SEARCH_LIBS test
	unset ac_cv_search_rcu_set_pointer_sym
      ])
    done

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

AC_SEARCH_LIBS([urcu_init], [urcu], [AC_MSG_ERROR([liburcu is too old (< 0.4.0), urcu_init symbol found])], [])

dnl Check for OpenSSL
AC_ARG_WITH(openssl,
[  --with-openssl=DIR        where to find openssl library])

AS_IF([test "$with_openssl" != "no"],[
  PKG_CHECK_MODULES([libcrypto], libcrypto, [
    CPPFLAGS="$CPPFLAGS $libcrypto_CFLAGS"
    LIBS="$LIBS $libcrypto_LIBS"
    with_openssl=yes
  ],[

    for try_openssl in "$with_openssl" "" "/usr/local"; do
      save_LIBS="$LIBS"
      save_CPPFLAGS="$CPPFLAGS"

      AS_IF([test -d "$try_openssl"], [
        libcrypto_CFLAGS="-I$try_openssl/include"
        libcrypto_LIBS="-L$try_openssl/lib"
      ],[
        libcrypto_CFLAGS=""
        libcrypto_LIBS=""
      ])

      CPPFLAGS="$CPPFLAGS $libcrypto_CFLAGS"
      LIBS="$LIBS $libcrypto_LIBS"

      AC_SEARCH_LIBS([OpenSSL_add_all_digests], [crypto], [
        with_openssl=yes
	break
      ],[
        with_openssl=no
	# do not cache result of AC_SEARCH_LIBS test
	unset ac_cv_search_OpenSSL_add_all_digests
      ])

      CPPFLAGS="$save_CPPFLAGS"
      LIBS="$save_LIBS"
    done

  ])
])

293 294 295 296 297 298
AS_IF([test "$with_openssl" = "no"],[
  AC_MSG_ERROR([OpenSSL library is required.])
])

AC_EGREP_CPP(openssl_version_ok,
  [#include <openssl/crypto.h>
299
   #if (OPENSSL_VERSION_NUMBER >= 0x10000000L)
300 301 302 303 304
   openssl_version_ok
   #endif
  ],[],[AC_MSG_ERROR([OpenSSL library version >= 1.0.0 is required.])]
)

Daniel Salzman's avatar
Daniel Salzman committed
305 306 307 308 309 310 311 312 313 314 315
AC_ARG_WITH(libidn, AC_HELP_STRING([--with-libidn=[DIR]],
    [Support IDN (needs GNU Libidn)]),
    libidn=$withval, libidn=yes)
if test "$libidn" != "no"; then
    if test "$libidn" != "yes"; then
        LDFLAGS="${LDFLAGS} -L$libidn/lib"
        CPPFLAGS="${CPPFLAGS} -I$libidn/include"
    fi
    AC_CHECK_HEADER(idna.h, AC_CHECK_LIB(idn, stringprep_check_version,
                                 [libidn=yes LIBS="${LIBS} -lidn"], libidn=no),
                    libidn=no)
316 317
fi
if test "$libidn" != "no" ; then
Daniel Salzman's avatar
Daniel Salzman committed
318 319 320
    AC_DEFINE(LIBIDN, 1, [Define to 1 if you want IDN support.])
fi

321 322
AC_SEARCH_LIBS([pow], [m])
AC_SEARCH_LIBS([pthread_create], [pthread], [], [AC_MSG_ERROR([pthreads not found])])
323
AC_SEARCH_LIBS([dlopen], [dl])
Marek Vavrusa's avatar
Marek Vavrusa committed
324
AC_SEARCH_LIBS([clock_gettime], [rt])
325
AC_SEARCH_LIBS([capng_apply], [cap-ng])
326
AC_SEARCH_LIBS([adler32], [z])
Ondřej Surý's avatar
Ondřej Surý committed
327 328 329

# Checks for header files.
AC_HEADER_RESOLV
330
AC_CHECK_HEADERS_ONCE([cap-ng.h netinet/in_systm.h pthread_np.h signal.h sys/select.h sys/time.h sys/wait.h sys/uio.h])
Ondřej Surý's avatar
Ondřej Surý committed
331 332 333 334 335 336 337 338

# Checks for typedefs, structures, and compiler characteristics.
AC_C_INLINE
AC_TYPE_PID_T
AC_TYPE_SIZE_T
AC_TYPE_SSIZE_T

# Checks for library functions.
339
AC_CHECK_FUNCS([clock_gettime gettimeofday fgetln getline madvise malloc_trim poll posix_memalign pselect pthread_setaffinity_np regcomp select setgroups initgroups])
Ondřej Surý's avatar
Ondřej Surý committed
340

341 342
# Check for be64toh function
AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <endian.h>]], [[return be64toh(0);]])],
343
[AC_DEFINE(HAVE_BE64TOH, 1, [Define to 1 if you have the 'be64toh' function.])])
344

345 346 347 348 349 350 351 352
# 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.])])

353 354 355 356
# Use -fvisibility=hidden when linking.
# Let's leave it default now and use -export-symbols-regex in LDFLAGS
#gl_VISIBILITY()
#CFLAGS="$CFLAGS $CFLAG_VISIBILITY"
357

358 359 360
# Add code coverage macro
AX_CODE_COVERAGE

Ondřej Surý's avatar
Ondřej Surý committed
361
AC_CONFIG_FILES([Makefile
362
		 doc/Makefile
363
		 man/Makefile
364
		 samples/Makefile
365
		 patches/Makefile
366 367 368
		 libtap/Makefile
		 src/Makefile
		 tests/Makefile
369
		 src/zscanner/Makefile
370 371 372 373 374 375
		 man/khost.1
		 man/knotc.8
		 man/knotd.8
		 man/kdig.1
		 man/knsupdate.1
		 man/knot.conf.5
376
		 man/knsec3hash.1
377
		 ])
378

Ondřej Surý's avatar
Ondřej Surý committed
379
AC_OUTPUT
380 381 382 383 384 385 386 387 388 389 390 391 392

echo "
  Version: ${PACKAGE_VERSION}
  Prefix: ${prefix}
  Run dir: ${run_dir}
  Storage dir: ${storage_dir}
  Config dir: ${config_dir}
  Compiler: ${CC}
  CFlags: ${CFLAGS} ${CPPFLAGS}
  LDFlags: ${LDFLAGS}
  Libs: ${LIBS}
  Ragel: ${RAGEL} ${FSM_TYPE}
  Utils with IDN: ${libidn}
393
  Use systemd notifications: ${enable_systemd}
394 395

  Continue with 'make' command"