configure.ac 72 KB
Newer Older
1 2
#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
3

4
AC_PREREQ([2.69])
5 6 7 8 9

# For released versions, this is in x.y.z format.
# For GIT versions, this is x.y.z-git, where x.y.z denotes the software
# version that was used as a base + changes that were made later, but
# are not released yet.
10
AC_INIT(kea,1.7.4, kea-dev@lists.isc.org)
11
AC_CONFIG_SRCDIR(README)
12 13 14 15 16 17 18 19 20 21 22 23 24

# serial-tests is not available in automake version before 1.13, so
# we'll check that and conditionally use serial-tests. This check is
# adopted from code by Richard W.M. Jones:
# https://www.redhat.com/archives/libguestfs/2013-February/msg00102.html
m4_define([serial_tests], [
    m4_esyscmd([automake --version |
                head -1 |
                awk '{split ($NF,a,"."); if (a[1] == 1 && a[2] >= 12) { print "serial-tests" }}'
    ])
])
AM_INIT_AUTOMAKE(foreign serial_tests)

25
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])dnl be backward compatible
26
AC_CONFIG_HEADERS([config.h])
27
AC_CONFIG_MACRO_DIR([m4macros])
28

29
AC_CANONICAL_HOST
30
AC_CANONICAL_BUILD
31

32 33
# Checks for programs.
AC_PROG_CXX
34

35 36 37
# Check for exact Kea version.
AC_MSG_CHECKING(whether this is a tarball or git source)
if test -d "${srcdir}/.git"; then
38
        KEA_SRCID="git `(cd "${top_srcdir}";git rev-parse HEAD)`"
39 40 41 42 43 44 45
        AC_MSG_RESULT("git")
else
        KEA_SRCID="tarball"
        AC_MSG_RESULT("tarball")
fi
# Export EXTENDED_VERSION to config.h
# This will be either "tarball" or "git abcd".
46 47 48 49
# We do not want to put this in a config.h, because it messes up ccache
# horribly. When building different branches, the commit-id is different
# and since the config.h is included in most files *and* has a different
# content, ccache can't use cached content and thus has to do full compilation.
50 51
# Now it is in kea_version.h and config.status substitutes it.
AC_SUBST(KEA_SRCID)
52

53 54
# Find a separator for path_replacer
for sep in "+" "," ";" "&" "__NONE__"; do
55 56 57 58 59 60
        if `pwd | grep -q $sep`; then continue; fi
        if `echo ${prefix} | grep -q $sep`; then continue; fi
        if `echo ${sysconfdir} | grep -q $sep`; then continue; fi
        if `echo ${localstatedir} | grep -q $sep`; then continue; fi
        SEP=$sep
        break
61 62
done
if test "$sep" = "__NONE__"; then
63
        AC_MSG_ERROR([can't find a separator character in '+,;&' for the path_replacer shell script])
64 65 66
fi
AC_SUBST(SEP)

67 68 69
# pkg-config can be required.
AC_PATH_PROG([PKG_CONFIG], [pkg-config])

70 71 72
# Enable low-performing debugging facilities? This option optionally
# enables some debugging aids that perform slowly and hence aren't built
# by default.
73 74 75 76
AC_ARG_ENABLE([debug],
  AS_HELP_STRING([--enable-debug],
    [enable debugging (default is no)]),
  [case "${enableval}" in
77 78
    yes) debug_enabled=yes ;;
    no)  debug_enabled=no ;;
79
    *)   AC_MSG_ERROR([bad value ${enableval} for --enable-debug]) ;;
80 81
  esac],[debug_enabled=no])
AM_CONDITIONAL([DEBUG_ENABLED], [test x$debug_enabled = xyes])
82
AM_COND_IF([DEBUG_ENABLED], [AC_DEFINE([ENABLE_DEBUG], [1], [Enable low-performing debugging facilities?])])
83

84
# Include premium configuration
85 86
INCLUDED_HOOKS=

87
PREMIUM_DIR=
88
DISTCHECK_PREMIUM_CONFIGURE_FLAG=
Francis Dupont's avatar
Francis Dupont committed
89
AC_DEFUN([AX_PREMIUM],[])
90
# m4_sinclude includes the file if it exists at autoreconf time
91
m4_sinclude(premium/config.m4)
92
AC_SUBST(PREMIUM_DIR)
93
AC_SUBST(DISTCHECK_PREMIUM_CONFIGURE_FLAG)
Francis Dupont's avatar
Francis Dupont committed
94
AX_PREMIUM
95

96
# Include contrib configuration
97
# (currently only a provision copied from premium support)
98
CONTRIB_DIR=
99
DISTCHECK_CONTRIB_CONFIGURE_FLAG=
Francis Dupont's avatar
Francis Dupont committed
100
AC_DEFUN([AX_CONTRIB],[])
101
m4_sinclude(contrib/config.m4)
Francis Dupont's avatar
Francis Dupont committed
102
AC_SUBST(CONTRIB_DIR)
103
AC_SUBST(DISTCHECK_CONTRIB_CONFIGURE_FLAG)
Francis Dupont's avatar
Francis Dupont committed
104
AX_CONTRIB
105

106 107
# Libtool configuration
#
108 109 110

# libtool cannot handle spaces in paths, so exit early if there is one
if [ test `echo $PWD | grep -c ' '` != "0"  ]; then
111
    AC_MSG_ERROR([Kea cannot be built in a directory that contains spaces, because of libtool limitations. Please change the directory name, or use a symbolic link that does not contain spaces.])
112 113
fi

114 115
# On FreeBSD (and probably some others), clang++ does not meet an autoconf
# assumption in identifying libtool configuration regarding shared library:
116 117 118 119 120
# the configure script will execute "$CC -shared $CFLAGS/$CXXFLAGS -v" and
# expect the output contains -Lxxx or -Ryyy.  This is the case for g++, but
# not for clang++, and, as a result, it will cause various errors in linking
# programs or running them with a shared object (such as some of our python
# scripts).
121 122 123 124 125
# To work around this problem we define a temporary variable
# "CXX_LIBTOOL_LDFLAGS".  It's expected to be defined as, e.g, "-L/usr/lib"
# to temporarily fake the output so that it will be compatible with that of
# g++.
CFLAGS_SAVED=$CFLAGS
126
CXXFLAGS_SAVED=$CXXFLAGS
127
CFLAGS="$CFLAGS $CXX_LIBTOOL_LDFLAGS"
128
CXXFLAGS="$CXXFLAGS $CXX_LIBTOOL_LDFLAGS"
129
LT_INIT
130
CFLAGS=$CFLAGS_SAVED
131
CXXFLAGS=$CXXFLAGS_SAVED
132

133
# Use C++ language
134 135 136
AC_LANG([C++])

# Identify the compiler: this check must be after AC_PROG_CXX and AC_LANG.
137
AM_CONDITIONAL(USE_GXX, test "X${GXX}" = "Xyes")
138
AC_CHECK_DECL([__SUNPRO_CC], [SUNCXX="yes"], [SUNCXX="no"])
139
AC_CHECK_DECL([__clang__], [CLANGPP="yes"], [CLANGPP="no"])
Josh Soref's avatar
Josh Soref committed
140
# USE_CLANGPP is no longer used, keep it by symmetry with USE_GXX?
141
AM_CONDITIONAL(USE_CLANGPP, test "X${CLANGPP}" = "Xyes")
142

143
# Check for C++11 features support
144
AX_ISC_CPP11
145

146 147 148
# Check for std::is_base_of support
AC_MSG_CHECKING([for std::is_base_of])
AC_COMPILE_IFELSE(
149 150 151 152 153 154 155 156 157
    [AC_LANG_PROGRAM(
        [#include <type_traits>
        class A {};
        class B : A {};]
        [static_assert(std::is_base_of<A, B>::value, "");])],
    [AC_MSG_RESULT(yes)
    AC_DEFINE([HAVE_IS_BASE_OF], [1],
    [Define to 1 if std::is_base_of is available])],
    [AC_MSG_RESULT(no)])
158

159
dnl Determine if we are using GNU sed
160
GNU_SED=no
161
$SED --version 2> /dev/null | grep GNU > /dev/null 2>&1
162 163 164 165
if test $? -eq 0; then
  GNU_SED=yes
fi

166 167 168 169 170 171 172
# Display the C++ version
AC_MSG_CHECKING([C++ version])
cat > conftest.cpp << EOF
long v = __cplusplus;
EOF
CXX_STANDARD=`$CXX $CXXFLAGS -E -o - conftest.cpp | grep '^long v = ' | $SED -e 's/^long v = //' -e 's/[[^0-9]]*$//' 2> /dev/null`
if test -z "$CXX_STANDARD"; then
173
        CXX_STANDARD="unknown"
174 175 176
fi
AC_MSG_RESULT([$CXX_STANDARD])

177 178
# Linker options

179
# check -R, "-Wl,-R" or -rpath
180
AX_ISC_RPATH
181

182
# Compiler dependent settings: define some mandatory CXXFLAGS here.
183
# We also use a separate variable KEA_CXXFLAGS.  This will (and should) be
184
# used as the default value for each specific AM_CXXFLAGS:
185
# AM_CXXFLAGS = $(KEA_CXXFLAGS)
186 187 188 189 190 191 192 193
# AM_CXXFLAGS += ... # add module specific flags
# We need this so that we can disable some specific compiler warnings per
# module basis; since AM_CXXFLAGS are placed before CXXFLAGS, and since
# gcc's -Wno-XXX option must be specified after -Wall or -Wextra, we cannot
# specify the default warning flags in CXXFLAGS and let specific modules
# "override" the default.

# This may be used to try linker flags.
194
AC_DEFUN([KEA_CXX_TRY_FLAG], [
195 196
  AC_MSG_CHECKING([whether $CXX supports $1])

197
  kea_save_CXXFLAGS="$CXXFLAGS"
198
  CXXFLAGS="$CXXFLAGS -Werror $1"
199

200
  AC_LINK_IFELSE([AC_LANG_SOURCE([int main(){ return 0;}])],
201 202
                 [kea_cxx_flag=yes], [kea_cxx_flag=no])
  CXXFLAGS="$kea_save_CXXFLAGS"
203

204
  if test "x$kea_cxx_flag" = "xyes"; then
205 206 207 208 209
    ifelse([$2], , :, [$2])
  else
    ifelse([$3], , :, [$3])
  fi

210
  AC_MSG_RESULT([$kea_cxx_flag])
211 212
])

213 214
CXX_VERSION="unknown"

215 216 217
# SunStudio compiler requires special compiler options for boost
# (http://blogs.sun.com/sga/entry/boost_mini_howto)
if test "$SUNCXX" = "yes"; then
218
CXX_VERSION=`$CXX -V 2> /dev/null | head -1`
219
CXXFLAGS="$CXXFLAGS -library=stlport4 -features=tmplife -features=tmplrefstatic"
Francis Dupont's avatar
Francis Dupont committed
220
KEA_CXXFLAGS="$KEA_CXXFLAGS -mt"
221 222 223 224 225 226 227 228 229 230
MULTITHREADING_FLAG="-mt"
fi

# Newer versions of clang++ promotes "unused driver arguments" warnings to
# a fatal error with -Werror, causing build failure.  Since we use multiple
# compilers on multiple systems, this can easily happen due to settings for
# non clang++ environments that could be just ignored otherwise.  It can also
# happen if clang++ is used via ccache.  So, although probably suboptimal,
# we suppress this particular warning.  Note that it doesn't weaken checks
# on the source code.
231
if test "X$CLANGPP" = "Xyes"; then
232
CXX_VERSION=`$CXX --version 2> /dev/null | head -1`
233
KEA_CXXFLAGS="$KEA_CXXFLAGS -Qunused-arguments"
234 235
fi

236
# gcc/clang specific settings:
237
if test "X$GXX" = "Xyes"; then
238
CXX_VERSION=`$CXX --version 2> /dev/null | head -1`
239
KEA_CXXFLAGS="$KEA_CXXFLAGS -Wall -Wextra -Wnon-virtual-dtor -Wwrite-strings -Woverloaded-virtual -Wno-sign-compare"
240 241 242
# gcc 4.4 would emit warnings about breaking strict aliasing rules.
# See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=41874
CXX_DUMP_VERSION=`$CXX -dumpversion | cut -f1-2 -d.`
243
if expr "$CXX_DUMP_VERSION" \< "4.5" > /dev/null; then
244 245 246
       WARNING_GCC_44_STRICT_ALIASING_CFLAG="-fno-strict-aliasing"
fi
AC_SUBST(WARNING_GCC_44_STRICT_ALIASING_CFLAG)
Francis Dupont's avatar
Francis Dupont committed
247
CPPP="$CPP"
248
# gcc 5 preprocessor requires -P for checking its output
249
if expr "$CXX_DUMP_VERSION" \> "5" > /dev/null; then
250 251
       CPPP="$CPP -P"
fi
252

253 254
case "$host" in
*-solaris*)
255 256 257 258
        MULTITHREADING_FLAG=-pthreads
        # In Solaris, IN6ADDR_ANY_INIT and IN6ADDR_LOOPBACK_INIT need -Wno-missing-braces
        KEA_CXXFLAGS="$KEA_CXXFLAGS -Wno-missing-braces"
        ;;
259
*-apple-darwin*)
260 261
        MULTITHREADING_FLAG=
        ;;
262
*)
263 264
        MULTITHREADING_FLAG=-pthread
        ;;
265
esac
266
KEA_CXXFLAGS="$KEA_CXXFLAGS $MULTITHREADING_FLAG"
267

268 269 270
# Disable -Werror by default. Only use it if specifically enabled.
# The usage of this flag is:
#
271 272 273 274 275
# No flag:            -Werror is disabled
# --with-werror:      -Werror is enabled
# --with-werror=yes:  -Werror is enabled
# --with-werror=no:   -Werror is disabled
# --with-werror=value -Werror is enabled and "value" is included in the compiler flags
276 277 278 279
#
# In the last case, "value" may be one or more compiler flags, e.g.

# --with-werror=-Wundef
280
# --with-werror='-Wundef -Wconversion'
281

282
werror_extras=
283
AC_ARG_WITH(werror,
284
    AC_HELP_STRING([--with-werror], [Compile using -Werror (default=no)]),
285 286 287 288
    [
     case "${withval}" in
         yes) with_werror=1 ;;
         no)  with_werror=0 ;;
289
         -*)  with_werror=1; werror_extras=${withval} ;;
290
         *)   AC_MSG_ERROR(bad value ${withval} for --with-werror) ;;
291
     esac],
292
     [with_werror=0])
293 294 295 296 297 298 299 300

werror_ok=0

# Certain versions of gcc (g++) have a bug that incorrectly warns about
# the use of anonymous name spaces even if they're closed in a single
# translation unit.  For these versions we have to disable -Werror.
if test $with_werror = 1; then
   CXXFLAGS_SAVED="$CXXFLAGS"
301
   CXXFLAGS="$CXXFLAGS $KEA_CXXFLAGS -Werror"
302
   AC_MSG_CHECKING(for in-TU anonymous namespace breakage)
303 304 305 306
   # We use struct, not class, here, because some compilers complain about
   # "unused private members", causing a false positive.
   AC_TRY_COMPILE([namespace { struct Foo {}; }
   namespace isc {struct Bar {Foo foo_;};} ],,
307 308 309 310
        [AC_MSG_RESULT(no)
         werror_ok=1
         KEA_CXXFLAGS="$KEA_CXXFLAGS -Werror"],
        [AC_MSG_RESULT(yes)])
311 312 313
   CXXFLAGS="$CXXFLAGS_SAVED"
fi

314 315 316 317 318 319 320
# Added flags after -Werror

# Some versions of GCC warn about some versions of Boost regarding
# missing initializer for members in its posix_time.
# https://svn.boost.org/trac/boost/ticket/3477
# But older GCC compilers don't have the flag.
KEA_CXX_TRY_FLAG([-Wno-missing-field-initializers],
321
        [KEA_CXXFLAGS="$KEA_CXXFLAGS -Wno-missing-field-initializers"])
322 323

if test "X$CLANGPP" = "Xyes"; then
324 325 326 327
        # This is to workaround unused variables tcout and tcerr in
        # log4cplus's streams.h and unused parameters from some of the
        # Boost headers.
        KEA_CXXFLAGS="$KEA_CXXFLAGS -Wno-unused-variable -Wno-unused-parameter"
328 329 330 331 332
fi

# Add the extras at the very last
# Note it can be used to re-enable a (fatal) warning
for extra in $werror_extras; do
333 334 335
        KEA_CXX_TRY_FLAG([$extra],
                [KEA_CXXFLAGS="$KEA_CXXFLAGS $extra"],
                [AC_MSG_ERROR([$CXX does not support $extra"])])
336 337
done

338
fi                              dnl GXX = yes
339

340 341 342 343 344 345 346
# allow building programs with static link.  we need to make it selective
# because loadable modules cannot be statically linked.
AC_ARG_ENABLE([static-link],
AC_HELP_STRING([--enable-static-link],
  [build programs with static link [[default=no]]]),
  [enable_static_link=yes], [enable_static_link=no])
AM_CONDITIONAL(USE_STATIC_LINK, test $enable_static_link = yes)
347
AM_COND_IF([USE_STATIC_LINK], [AC_DEFINE([USE_STATIC_LINK], [1], [Was Kea statically linked?])])
348

349 350
# Check validity about some libtool options
if test $enable_static_link = yes -a $enable_static = no; then
351
        AC_MSG_ERROR([--enable-static-link requires --enable-static])
352
fi
353
if test $enable_static_link = no -a $enable_shared = no; then
354
        AC_MSG_ERROR([--disable-static-link requires --enable-shared])
355 356
fi

357
# OS dependent configuration
358
kea_undefined_pthread_behavior=no
359

360
case "$host" in
361
*-solaris*)
362 363 364 365 366 367 368 369 370 371
        # Solaris requires special definitions to get some standard libraries
        # (e.g. getopt(3)) available with common used header files.
        CPPFLAGS="$CPPFLAGS -D_XPG4_2 -D__EXTENSIONS__"
        # "now" binding is necessary to prevent deadlocks in C++ static initialization code
        LDFLAGS="$LDFLAGS -z now"
        # Destroying locked mutexes, condition variables being waited
        # on, etc. are undefined behavior on Solaris, so we set it as
        # such here.
        kea_undefined_pthread_behavior=yes
        ;;
372
*-apple-darwin*)
373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391
        # Starting with OSX 10.7 (Lion) we must choose which IPv6 API to use
        # (RFC2292 or RFC3542).
        CPPFLAGS="$CPPFLAGS -D__APPLE_USE_RFC_3542"

        # In OS X 10.9 (and possibly any future versions?) pthread_cond_destroy
        # doesn't work as documented, which makes some of unit tests fail.
        AC_MSG_CHECKING([OS X versions where destroying locked locks do not fail])
        AC_TRY_COMPILE(
        [#include <Availability.h>],
        [#ifdef __MAC_OS_X_VERSION_MIN_REQUIRED
         #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
         #error " OS X >= 10.9"
         #endif
         #endif
         return 1;],
        [AC_MSG_RESULT([OS X < 10.9])],
        [AC_MSG_RESULT([OS X >= 10.9])
         kea_undefined_pthread_behavior=yes])
        ;;
392
*-freebsd*)
393 394 395 396 397 398 399 400 401 402 403
        # On FreeBSD10.1 pthread_cond_destroy doesn't work as documented, which
        # causes the CondVarTest.destroyWhileWait test to fail. According to the
        # pthread_cond_destroy documentation for FreeBSD, this function should
        # return EBUSY error when there is a thread waiting for the conditional
        # variable, whereas this function returned success code. We treat it here
        # as an undefined behavior. Also note that this issue was only visible
        # when gtest 1.7 was in use, because the previous versions of gtest
        # didn't seem to have support for the death tests on FreeBSD. As a
        # result, the test was not executed and the error didn't occur.
        kea_undefined_pthread_behavior=yes
        ;;
404
esac
405
if [ test $kea_undefined_pthread_behavior = "yes" ]; then
406 407
   AC_DEFINE([HAS_UNDEFINED_PTHREAD_BEHAVIOR], [1], [Does this platform have some undefined pthreads behavior?])
fi
408

409 410 411 412 413 414 415 416 417 418
# Our experiments have shown Solaris 10 has broken support for the
# IPV6_USE_MIN_MTU socket option for getsockopt(); it doesn't return the value
# previously set via setsockopt().  We know it doesn't happen on one instance
# on Solaris 11, but we don't know whether it happens for any Solaris 10
# implementations or for earlier versions of Solaris.  In any case, at the
# moment this matters for only one unittest case, so we'll simply disable
# the affected test using the following definition with the specific hardcoding
# of that version of Solaris.
case "$host" in
*-solaris2.10)
419 420 421
        AC_DEFINE([HAVE_BROKEN_GET_IPV6_USE_MIN_MTU], [1],
        [Define to 1 if getsockopt(IPV6_USE_MIN_MTU) does not work])
        ;;
422 423
esac

424 425
# Made perfdhcp optional.
AC_ARG_ENABLE(perfdhcp, [AC_HELP_STRING([--enable-perfdhcp],
426
  [enable perfdhcp, a DHCP benchmarking tool [default=no]])],
427 428
  enable_perfdhcp=$enableval, enable_perfdhcp=no)

429
DISTCHECK_PERFDHCP_CONFIGURE_FLAG=
430
if test "x$enable_perfdhcp" != xno ; then
431
  DISTCHECK_PERFDHCP_CONFIGURE_FLAG="--enable-perfdhcp"
432 433 434 435
fi

# Export to makefiles the info whether we have perfdhcp enabled or not
AM_CONDITIONAL(PERFDHCP, test x$enable_perfdhcp != xno)
436
AC_SUBST(DISTCHECK_PERFDHCP_CONFIGURE_FLAG)
437

438
# produce PIC unless we disable shared libraries. need this for python bindings.
439
if test $enable_shared != "no" -a "X$GXX" = "Xyes"; then
440
   KEA_CXXFLAGS="$KEA_CXXFLAGS -fPIC"
441 442
fi

443
# Look for glib static libs if they're trying to do static builds
444
if test $enable_static_link != "no"; then
445 446 447 448
   CXX_SAVED=$CXX
   CXX="$CXX -static"

   AC_LINK_IFELSE(
449
     [AC_LANG_PROGRAM([#include <math.h>],[(void)sqrt(-1.0);])],
450 451
     [AC_MSG_RESULT([checking for static glib libraries... yes])],
     [AC_MSG_RESULT([checking for static glib libraries... no])
452
      AC_MSG_ERROR([Building with --enable-static-link does not work. You appear to be missing glib static libraries. Check config.log for details.])])
453 454 455

   CXX=$CXX_SAVED
fi
456

457
AC_SUBST(KEA_CXXFLAGS)
458

459 460
# Checks for libraries.

461 462
AC_SEARCH_LIBS(inet_pton, [nsl])
AC_SEARCH_LIBS(recvfrom, [socket])
463
AC_SEARCH_LIBS(nanosleep, [rt])
464
AC_SEARCH_LIBS(dlsym, [dl])
465

466 467 468 469 470 471
# Checks for header files.

# Checks for typedefs, structures, and compiler characteristics.
AC_HEADER_STDBOOL
AC_TYPE_SIZE_T

472

473 474
# Detect OS type (it may be used to do OS-specific things, e.g.
# interface detection in DHCP)
475
AC_MSG_CHECKING(OS type)
476
BSD_TYPE="notaBSD"
477 478 479
case $host in
    *-linux*)
      AC_DEFINE([OS_LINUX], [1], [Running on Linux?])
480
      OS_TYPE="Linux"
481 482
      CPPFLAGS="$CPPFLAGS -DOS_LINUX"
      ;;
483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506
    *-apple-darwin*)
      AC_DEFINE([OS_BSD], [1], [Running on BSD?])
      AC_DEFINE([OS_OSX], [1], [Running on OSX?])
      OS_TYPE="BSD"
      BSD_TYPE="OSX"
      CPPFLAGS="$CPPFLAGS -DOS_BSD"
      ;;
    *-freebsd*)
      AC_DEFINE([OS_BSD], [1], [Running on BSD?])
      AC_DEFINE([OS_FREEBSD], [1], [Running on FreeBSD?])
      OS_TYPE="BSD"
      BSD_TYPE="FreeBSD"
      CPPFLAGS="$CPPFLAGS -DOS_BSD"
      ;;
    *-netbsd*)
      AC_DEFINE([OS_BSD], [1], [Running on BSD?])
      AC_DEFINE([OS_NETBSD], [1], [Running on NetBSD?])
      OS_TYPE="BSD"
      BSD_TYPE="NetBSD"
      CPPFLAGS="$CPPFLAGS -DOS_BSD"
      ;;
    *-openbsd*)
      AC_DEFINE([OS_BSD], [1], [Running on BSD?])
      AC_DEFINE([OS_OPENBSD], [1], [Running on OpenBSD?])
507
      OS_TYPE="BSD"
508
      BSD_TYPE="OpenBSD"
509 510
      CPPFLAGS="$CPPFLAGS -DOS_BSD"
      ;;
511 512
    *-solaris*)
      AC_DEFINE([OS_SOLARIS], [1], [Running on Solaris?])
513
      OS_TYPE="Solaris"
514
      CPPFLAGS="$CPPFLAGS -DOS_SUN"
515 516 517
      ;;
    *)
      OS_TYPE="Unknown"
518 519
      # $host_os is more user friendly than full $host
      AC_MSG_WARN("Unsupported OS: $host_os")
520 521 522
      ;;
esac
AC_MSG_RESULT($OS_TYPE)
523 524

AM_CONDITIONAL(OS_LINUX, test $OS_TYPE = Linux)
525 526
AM_CONDITIONAL(OS_BSD, test $OS_TYPE = BSD)
AM_CONDITIONAL(OS_SOLARIS, test $OS_TYPE = Solaris)
527 528 529 530
AM_CONDITIONAL(OS_OSX, test $BSD_TYPE = OSX)
AM_CONDITIONAL(OS_FREEBSD, test $BSD_TYPE = FreeBSD)
AM_CONDITIONAL(OS_NETBSD, test $BSD_TYPE = NetBSD)
AM_CONDITIONAL(OS_OPENBSD, test $BSD_TYPE = OpenBSD)
531 532


533 534 535 536 537 538
AC_MSG_CHECKING(for sa_len in struct sockaddr)
AC_TRY_COMPILE([
#include <sys/types.h>
#include <sys/socket.h>],
[struct sockaddr sa; sa.sa_len = 0; return (0);],
        [AC_MSG_RESULT(yes)
539
        AC_DEFINE(HAVE_SA_LEN, 1, [Define to 1 if sockaddr has a sa_len member, and corresponding sin_len and sun_len])],
540 541
        AC_MSG_RESULT(no))

542 543 544 545 546 547 548 549 550 551 552 553 554 555
AC_MSG_CHECKING(for usuable C++11 regex)
AC_TRY_RUN([
#include <regex>
#include <iostream>
int main() {
  const std::regex regex(".*");
  const std::string string = "This should match!";
  const auto result = std::regex_search(string, regex);
  return result ? EXIT_SUCCESS : EXIT_FAILURE;
}],
        [AC_MSG_RESULT(yes)
        AC_DEFINE(USE_REGEX, 1, [Define to 1 if C++11 regex is usable])],
        AC_MSG_RESULT(no))

556 557 558 559 560
# Run the gtest detection routines. This supports --with-gtest and --with-gtest-source
# parameters. If specified, those will set the HAVE_GTEST, HAVE_GTEST_SOURCE,
# DISTCHECK_GTEST_CONFIGURE_FLAG, GTEST_INCLUDES, GTEST_LDFLAGS, GTEST_LDADD, GTEST_SOURCE
# variables.
AX_ISC_GTEST
561

Andrei Pavel's avatar
Andrei Pavel committed
562 563 564 565 566 567 568 569 570 571 572 573 574
enable_benchmark="no"
BENCHMARK_INCLUDES=

AC_ARG_WITH([benchmark-source],
            [AS_HELP_STRING([--with-benchmark-source=PATH],
                            [location of the benchmark source])],
            [enable_benchmark="yes" ; BENCHMARK_SOURCE="$withval"])

AC_ARG_WITH([benchmark],
            [AS_HELP_STRING([--with-benchmark=PATH],
                            [specify a path to benchmark header files (PATH/include) and library (PATH/lib)])],
        [benchmark_path="$withval"; enable_benchmark="yes"], [benchmark_path="no"])

575 576 577
# Sets up for use of botan unless openssl is specified
# sets variables CRYPTO_*
AX_CRYPTO
578

579 580 581 582
# List of directories, where tools like mysql_config or pgsql_config will be
# searched for
defaultdirs="/usr /usr/local /usr/pkg /opt /opt/local"

583
# Check for MySql.  The path to the mysql_config program is given with
584 585
# the --with-mysql-config (default to /usr/bin/mysql-config).  By default,
# the software is not built with MySQL support enabled.
586
mysql_config="no"
587 588
AC_ARG_WITH([mysql],
  AC_HELP_STRING([--with-mysql=PATH],
589
    [path to the MySQL 'mysql_config' script (MySQL is used for the DHCP database)]),
590 591
    [mysql_config="$withval"])

592 593 594 595 596 597 598 599
deprec_msg="no"
AC_ARG_WITH([dhcp-mysql],,
    [mysql_config="$withval";deprec_msg="yes"])

if test "${deprec_msg}" = "yes" ; then
    AC_MSG_WARN([--with-dhcp-mysql has been deprecated, please use --with-mysql])
fi

600
if test "${mysql_config}" = "yes" ; then
601
    MYSQL_CONFIG="/usr/bin/mysql_config"
602 603 604 605 606 607 608
    for d in $defaultdirs
    do
        if test -f $d/bin/mysql_config; then
            MYSQL_CONFIG="$d/bin/mysql_config"
            break
        fi
    done
609 610 611 612 613
elif test "${mysql_config}" != "no" ; then
    MYSQL_CONFIG="${withval}"
fi

if test "$MYSQL_CONFIG" != "" ; then
614
    if test -d "$MYSQL_CONFIG" -o ! -x "$MYSQL_CONFIG" ; then
615
        AC_MSG_ERROR([MySQL dependencies cannot be found. Please install MySQL libraries or point --with-mysql to mysql_config program if it is located in non-default directory, eg. --with-mysql=/opt/mysql/bin/mysql_config.])
616 617 618 619
    fi

    MYSQL_CPPFLAGS=`$MYSQL_CONFIG --cflags`
    MYSQL_LIBS=`$MYSQL_CONFIG --libs`
620
    MYSQL_LIBS="$MYSQL_LIBS $CRYPTO_LIBS"
621
    MYSQL_VERSION=`$MYSQL_CONFIG --version`
622 623 624 625 626 627 628 629 630 631 632 633

    AC_SUBST(MYSQL_CPPFLAGS)
    AC_SUBST(MYSQL_LIBS)

    # Check that a simple program using MySQL functions can compile and link.
    CPPFLAGS_SAVED="$CPPFLAGS"
    LIBS_SAVED="$LIBS"

    CPPFLAGS="$MYSQL_CPPFLAGS $CPPFLAGS"
    LIBS="$MYSQL_LIBS $LIBS"

    AC_LINK_IFELSE(
634 635 636 637 638 639 640
        [AC_LANG_PROGRAM([#include <mysql.h>],
                         [MYSQL mysql_handle;
                          (void) mysql_init(&mysql_handle);
                         ])],
        [AC_MSG_RESULT([checking for MySQL headers and library... yes])],
        [AC_MSG_RESULT([checking for MySQL headers and library... no])
         AC_MSG_ERROR([Needs MySQL library])]
641 642
    )

643 644 645 646 647 648 649 650 651 652 653 654
    # Note that MYSQL is present in the config.h file
    AC_DEFINE([HAVE_MYSQL], [1], [MySQL is present])

    # Check is my_bool is defined.
    AC_COMPILE_IFELSE(
        [AC_LANG_PROGRAM([#include <mysql.h>
                          const my_bool MLM_FALSE = 0;]
                         [])],
        [AC_MSG_RESULT([checking for MySQL my_bool... yes])
         AC_DEFINE([HAVE_MYSQL_MY_BOOL], [1], [MySQL uses my_bool])],
        [AC_MSG_RESULT([checking for MySQL my_bool... no])])

655 656 657 658 659
    CPPFLAGS=$CPPFLAGS_SAVED
    LIBS=$LIBS_SAVED

fi

660
# Solaris puts FIONREAD in filio.h
661
AC_CHECK_HEADERS(sys/filio.h,,,)
662

663 664 665
# ... and at the shell level, so Makefile.am can take action depending on this.
AM_CONDITIONAL(HAVE_MYSQL, test "$MYSQL_CONFIG" != "")

666
pg_config="no"
667 668
AC_ARG_WITH([pgsql],
  AC_HELP_STRING([--with-pgsql=PATH],
669 670 671
    [path to the PostgreSQL 'pg_config' script]),
    [pg_config="$withval"])

672 673 674 675 676 677 678 679
deprec_msg="no"
AC_ARG_WITH([dhcp-pgsql],,
    [pg_config="$withval";deprec_msg="yes"])

if test "${deprec_msg}" = "yes" ; then
    AC_MSG_WARN([--with-dhcp-pgsql has been deprecated, please use --with-pgsql])
fi

680
if test "${pg_config}" = "yes" ; then
681
    PG_CONFIG="/usr/bin/pg_config"
682 683 684 685 686 687 688
    for d in $defaultdirs
    do
        if test -f $d/bin/pg_config; then
            PG_CONFIG="$d/bin/pg_config"
            break
        fi
    done
689 690 691 692 693 694
elif test "${pg_config}" != "no" ; then
    PG_CONFIG="${withval}"
fi

if test "$PG_CONFIG" != "" ; then
    if test -d "$PG_CONFIG" -o ! -x "$PG_CONFIG" ; then
695
        AC_MSG_ERROR([PostgreSQL dependencies cannot be found. Please install PostgreSQL libraries or point --with-pgsql to pg_config program if it is located in non-default directory, eg. --with-pgsql=/opt/pgsql/bin/pg_config.])
696 697 698 699
    fi

    PGSQL_CPPFLAGS=`$PG_CONFIG --cppflags`
    PGSQL_INCLUDEDIR=`$PG_CONFIG --includedir`
700 701
    PGSQL_INCLUDEDIR_SERVER=`$PG_CONFIG --includedir-server`
    PGSQL_CPPFLAGS="$PGSQL_CPPFLAGS -I$PGSQL_INCLUDEDIR -I$PGSQL_INCLUDEDIR_SERVER"
702 703
    PGSQL_LIBS=`$PG_CONFIG --libdir`
    PGSQL_LIBS="-L$PGSQL_LIBS -lpq"
704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724
    PGSQL_VERSION=`$PG_CONFIG --version`

    AC_SUBST(PGSQL_CPPFLAGS)
    AC_SUBST(PGSQL_LIBS)

    # Check that a simple program using PostgreSQL functions can compile and link.
    CPPFLAGS_SAVED="$CPPFLAGS"
    LIBS_SAVED="$LIBS"

    CPPFLAGS="$PGSQL_CPPFLAGS $CPPFLAGS"
    LIBS="$PGSQL_LIBS $LIBS"

    AC_LINK_IFELSE(
            [AC_LANG_PROGRAM([#include <libpq-fe.h>],
                             [PGconn * c = PQconnectdb("dbname = 'postgres'");
                              PQfinish(c);])],
            [AC_MSG_RESULT([checking for PostgreSQL headers and library... yes])],
            [AC_MSG_RESULT([checking for PostgreSQL headers and library... no])
             AC_MSG_ERROR([Needs PostgreSQL library])]
    )

725
    AC_CHECK_HEADERS([utils/errcodes.h],,
726
    AC_MSG_ERROR([Missing required header file (errcodes.h) from PostgreSQL server-development package]))
727

728 729 730 731 732 733 734 735 736
    CPPFLAGS=$CPPFLAGS_SAVED
    LIBS=$LIBS_SAVED

    # Note that PostgreSQL is present in the config.h file
    AC_DEFINE([HAVE_PGSQL], [1], [PostgreSQL is present])
fi

# ... and at the shell level, so Makefile.am can take action depending on this.
AM_CONDITIONAL(HAVE_PGSQL, test "$PG_CONFIG" != "")
737

738
# allow building kea programs with static link to cassandra cpp-driver.
739 740 741 742
AC_ARG_ENABLE([cql-static-lib],
AS_HELP_STRING([--enable-cql-static-lib],
    [build programs with cassandra cpp driver static library [[default=no]]]),
    [enable_cql_static_lib=yes], [enable_cql_static_lib=no])
743
AM_CONDITIONAL(USE_CQL_STATIC_LIB, test "$enable_cql_static_lib" = yes)
744 745 746 747 748 749 750
#AC_DEFINE USE_CQL_STATIC_LIB? (unused)

cql_lib="cassandra"
if test "${enable_cql_static_lib}" = "yes" ; then
    cql_lib="${cql_lib}_static"
fi

Tomek Mrugalski's avatar
Tomek Mrugalski committed
751 752 753
cql_config="no"
AC_ARG_WITH([cql],
  AC_HELP_STRING([--with-cql=PATH],
754
    [path to pkg-config or the Cassandra CQL 'cql_config' script]),
Tomek Mrugalski's avatar
Tomek Mrugalski committed
755 756 757
    [cql_config="$withval"])

if test "${cql_config}" = "yes" ; then
758
    CQL_CONFIG="$PKG_CONFIG"
Tomek Mrugalski's avatar
Tomek Mrugalski committed
759
elif test "${cql_config}" != "no" ; then
Francis Dupont's avatar
Francis Dupont committed
760
    CQL_CONFIG="${cql_config}"
761 762
fi

Tomek Mrugalski's avatar
Tomek Mrugalski committed
763 764
if test "$CQL_CONFIG" != "" ; then
    if test -d "$CQL_CONFIG" -o ! -x "$CQL_CONFIG" ; then
765
        AC_MSG_ERROR([--with-cql should point to a pkg-config or cql_config program])
766 767
    fi

768 769 770 771 772
    $CQL_CONFIG --print-errors $cql_lib
    if test $? -ne 0; then
        AC_MSG_ERROR([$CQL_CONFIG $cql_lib failed])
    fi

773
    CQL_INCLUDEDIR=`$CQL_CONFIG --cflags-only-I $cql_lib`
774 775
    CQL_CPPFLAGS=`$CQL_CONFIG --cflags-only-other $cql_lib`
    CQL_LIBS=`$CQL_CONFIG --libs $cql_lib`
776
    CQL_LIBS="$CQL_LIBS $CRYPTO_LIBS"
777
    CQL_VERSION=`$CQL_CONFIG --modversion $cql_lib`
778

Razvan Becheriu's avatar
Razvan Becheriu committed
779
    CQL_CPPFLAGS="${CQL_CPPFLAGS} ${CQL_INCLUDEDIR}"
Tomek Mrugalski's avatar
Tomek Mrugalski committed
780 781
    AC_SUBST(CQL_CPPFLAGS)
    AC_SUBST(CQL_LIBS)
782

Tomek Mrugalski's avatar
Tomek Mrugalski committed
783
    # Check that a simple program using CQL functions can compile and link.
784 785 786
    CPPFLAGS_SAVED="$CPPFLAGS"
    LIBS_SAVED="$LIBS"

Tomek Mrugalski's avatar
Tomek Mrugalski committed
787 788
    CPPFLAGS="$CQL_CPPFLAGS $CPPFLAGS"
    LIBS="$CQL_LIBS $LIBS"
789 790 791 792 793

    AC_LINK_IFELSE(
            [AC_LANG_PROGRAM([#include <cassandra.h>],
                             [CassCluster* cluster = cass_cluster_new();
                              cass_cluster_free(cluster);])],
Tomek Mrugalski's avatar
Tomek Mrugalski committed
794 795 796
            [AC_MSG_RESULT([checking for Cassandra CQL headers and library... yes])],
            [AC_MSG_RESULT([checking for Cassandra CQL headers and library... no])
             AC_MSG_ERROR([Needs Cassandra CQL library])]
797 798 799 800
    )
    CPPFLAGS=$CPPFLAGS_SAVED
    LIBS=$LIBS_SAVED

Tomek Mrugalski's avatar
Tomek Mrugalski committed
801 802
    # Note that CQL is present in the config.h file
    AC_DEFINE([HAVE_CQL], [1], [CQL is present])
803 804 805
fi

# ... and at the shell level, so Makefile.am can take action depending on this.
Tomek Mrugalski's avatar
Tomek Mrugalski committed
806
AM_CONDITIONAL(HAVE_CQL, test "$CQL_CONFIG" != "")
807

808
DISTCHECK_SYSREPO_CONFIGURE_FLAG=
809 810 811
sysrepo_config="no"
AC_ARG_WITH([sysrepo],
  AC_HELP_STRING([--with-sysrepo=PATH],
812
    [path to pkg-config or the Sysrepo 'sysrepo_config' script]),
813 814 815
    [sysrepo_config="$withval"])

if test "${sysrepo_config}" = "yes" ; then
816 817 818
    if test "$PKG_CONFIG" = ""; then
        AC_MSG_ERROR([--with-sysrepo specified without any parameter and pkg-config was not found. Either use --with-sysrepo=path or install pkg-config])
    fi
819
    SYSREPO_CONFIG="$PKG_CONFIG"
820
    DISTCHECK_SYSREPO_CONFIGURE_FLAG="-with-sysrepo=${sysrepo_config}"
821 822
elif test "${sysrepo_config}" != "no" ; then
    SYSREPO_CONFIG="${sysrepo_config}"
823
    DISTCHECK_SYSREPO_CONFIGURE_FLAG="-with-sysrepo=${sysrepo_config}"
824
fi
825
AC_SUBST(DISTCHECK_SYSREPO_CONFIGURE_FLAG)
826

827
if test "$SYSREPO_CONFIG" != "" ; then
828
    if test -d "$SYSREPO_CONFIG" -o ! -x "$SYSREPO_CONFIG" ; then
829
        AC_MSG_ERROR([--with-sysrepo should point to a pkg-config or sysrepo_config program])
830 831
    fi

832
    # Let's get the configuration environment for pure Sysrepo (written in C) first
Andrei Pavel's avatar
Andrei Pavel committed
833 834 835 836
    SYSREPO_INCLUDEDIR=`$SYSREPO_CONFIG --cflags-only-I libsysrepo`
    SYSREPO_CPPFLAGS="$SYSREPO_INCLUDEDIR `$SYSREPO_CONFIG --cflags-only-other libsysrepo`"
    SYSREPO_LIBS="`$SYSREPO_CONFIG --libs libsysrepo`"
    SYSREPO_VERSION=`$SYSREPO_CONFIG --modversion libsysrepo`
837
    SYSREPO_REPO=`$SYSREPO_CONFIG --variable=SR_REPOSITORY_LOC libsysrepo`
838

839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858
    # Now get the environment for C++ bindings for Sysrepo.
    SYSREPOCPP_INCLUDEDIR=`$SYSREPO_CONFIG --cflags-only-I libSysrepo-cpp`
    SYSREPOCPP_CPPFLAGS="$SYSREPO_INCLUDEDIR `$SYSREPO_CONFIG --cflags-only-other libSysrepo-cpp`"
    SYSREPOCPP_LIBS="`$SYSREPO_CONFIG --libs libSysrepo-cpp`"
    SYSREPOCPP_VERSION=`$SYSREPO_CONFIG --modversion libSysrepo-cpp`

    # If include paths are equal, there's no need to include both. But if they're different,
    # we need both.
    if test "${SYSREPO_INCLUDEDIR}" != "${SYSREPOCPP_INCLUDEDIR}"; then
       SYSREPO_INCLUDEDIR="${SYSREPO_INCLUDEDIR} ${SYSREPOCPP_INCLUDEDIR}"
    fi

    if test "${SYSREPO_CPPFLAGS}" != "${SYSREPOCPP_CPPFLAGS}"; then
       SYSREPO_CPPFLAGS="${SYSREPO_CPPFLAGS} ${SYSREPOCPP_CPPFLAGS}"
    fi

    if test "${SYSREPO_LIBS}" != "${SYSREPOCPP_LIBS}"; then
       SYSREPO_LIBS="${SYSREPO_LIBS} ${SYSREPOCPP_LIBS}"
    fi

Razvan Becheriu's avatar
Razvan Becheriu committed
859
    AC_SUBST(SYSREPO_INCLUDEDIR)
860 861
    AC_SUBST(SYSREPO_CPPFLAGS)
    AC_SUBST(SYSREPO_LIBS)
862
    AC_SUBST(SYSREPO_REPO)
863

Andrei Pavel's avatar
Andrei Pavel committed
864
    # Check that a simple program using Sysrepo functions can compile and link.
865 866 867 868 869 870 871
    CPPFLAGS_SAVED="$CPPFLAGS"
    LIBS_SAVED="$LIBS"

    CPPFLAGS="$SYSREPO_CPPFLAGS $CPPFLAGS"
    LIBS="$SYSREPO_LIBS $LIBS"

    AC_LINK_IFELSE(
Andrei Pavel's avatar
Andrei Pavel committed
872 873 874
            [AC_LANG_PROGRAM([extern "C" {
                              #include <sysrepo.h>
                              }],
875 876 877 878 879 880 881 882
                              [sr_conn_ctx_t *connection = NULL;
                              sr_session_ctx_t *session = NULL;
                              sr_connect("configure_test", SR_CONN_DEFAULT, &connection);
                              sr_disconnect(connection);])],
            [AC_MSG_RESULT([checking for Sysrepo headers and library... yes])],
            [AC_MSG_RESULT([checking for Sysrepo headers and library... no])
             AC_MSG_ERROR([Needs Sysrepo library])]
    )
883 884

    AC_LINK_IFELSE(
885 886 887
        [AC_LANG_PROGRAM(
            [#include <sysrepo-cpp/Session.hpp>],
            [sysrepo::Connection("conn-name");])],
888 889 890 891 892 893 894 895 896
        [AC_LINK_IFELSE(
            [AC_LANG_PROGRAM(
                [#include <sysrepo-cpp/Session.hpp>],
                [auto is_empty = [[]](sysrepo::S_Val v){
                    return (v->empty()); };
                ])],
            [AC_MSG_RESULT([checking for Sysrepo C++ bindings headers and library, new])
             AC_DEFINE([HAVE_POST_0_7_7_SYSREPO], [1], [Using sysrepo > 0.7.7])],
            [AC_MSG_RESULT([checking for Sysrepo C++ bindings headers and library, yes])])],
897 898 899 900 901
        [AC_LINK_IFELSE(
            [AC_LANG_PROGRAM(
                [#include <sysrepo-cpp/Session.h>],
                [Connection("conn-name");])],
            [AC_MSG_RESULT([checking for Sysrepo C++ bindings headers and library... old])
902
             AC_DEFINE([HAVE_PRE_0_7_6_SYSREPO], [1], [Using sysrepo < 0.7.6])],
903 904 905
             [AC_MSG_RESULT([checking for Sysrepo C++ bindings headers and library... no])
              AC_MSG_ERROR([Needs Sysrepo C++ bindings (unable to find Sysrepo-ccp library. To get it, you need to compile sysrepo with -DGEN_CPP_BINDINGS=ON.)])]
        )]
906 907
    )

908 909 910
    CPPFLAGS=$CPPFLAGS_SAVED
    LIBS=$LIBS_SAVED

Andrei Pavel's avatar
Andrei Pavel committed
911
    # Note that Sysrepo is present in the config.h file
912 913 914 915 916 917
    AC_DEFINE([HAVE_SYSREPO], [1], [SYSREPO is present])
fi

# ... and at the shell level, so Makefile.am can take action depending on this.
AM_CONDITIONAL(HAVE_SYSREPO, test "$SYSREPO_CONFIG" != "")

918
# Check for log4cplus
919
DISTCHECK_LOG4CPLUS_CONFIGURE_FLAG=
920 921 922 923 924
log4cplus_path="yes"
AC_ARG_WITH([log4cplus],
  AC_HELP_STRING([--with-log4cplus=PATH],
    [specify exact directory of log4cplus library and headers]),
    [log4cplus_path="$withval"])
925
if test "${log4cplus_path}" = "no" ; then
926 927
    AC_MSG_ERROR([Need log4cplus])
elif test "${log4cplus_path}" != "yes" ; then
928
  DISTCHECK_LOG4CPLUS_CONFIGURE_FLAG="-with-log4cplus=${log4cplus_path}"
929
  LOG4CPLUS_INCLUDES="-I${log4cplus_path}/include"
930
  LOG4CPLUS_LIBS="-L${log4cplus_path}/lib"
931 932
else
# If not specified, try some common paths.
933
        for d in $defaultdirs
934 935 936
        do
                if test -f $d/include/log4cplus/logger.h; then
                        LOG4CPLUS_INCLUDES="-I$d/include"
937 938 939 940
                        LOG4CPLUS_LIBS="-L$d/lib"
                        if test -d $d/lib64; then
                                LOG4CPLUS_LIBS="$LOG4CPLUS_LIBS -L$d/lib64"
                        fi
941 942 943
                        break
                fi
        done
944
        DISTCHECK_LOG4CPLUS_CONFIGURE_FLAG="-with-log4cplus"
945 946
fi

Francis Dupont's avatar
Francis Dupont committed
947
LOG4CPLUS_LIBS="$LOG4CPLUS_LIBS -llog4cplus"
948

949
AC_SUBST(DISTCHECK_LOG4CPLUS_CONFIGURE_FLAG)
950
AC_SUBST(LOG4CPLUS_LIBS)
951 952 953 954
AC_SUBST(LOG4CPLUS_INCLUDES)

CPPFLAGS_SAVED=$CPPFLAGS
CPPFLAGS="$LOG4CPLUS_INCLUDES $CPPFLAGS"
955
LIBS_SAVED="$LIBS"
Francis Dupont's avatar
Francis Dupont committed
956
LIBS="$LOG4CPLUS_LIBS $MULTITHREADING_FLAG $LIBS"
957 958 959 960 961 962 963 964 965 966 967 968 969

AC_CHECK_HEADERS([log4cplus/logger.h],,AC_MSG_ERROR([Missing required header files.]))
AC_LINK_IFELSE(
        [AC_LANG_PROGRAM([#include <log4cplus/logger.h>
                         ],
                         [using namespace log4cplus;
                          Logger logger = Logger::getInstance("main");
                         ])],
        [AC_MSG_RESULT([checking for log4cplus library... yes])],
        [AC_MSG_RESULT([checking for log4cplus library... no])
         AC_MSG_ERROR([Needs log4cplus library])]
)

970 971 972
dnl Determine the log4cplus version, used mainly for config.report.
AC_MSG_CHECKING([log4cplus version])
cat > conftest.cpp << EOF
973
#include <log4cplus/version.h>
974 975 976
AUTOCONF_LOG4CPLUS_VERSION=LOG4CPLUS_VERSION_STR
EOF

977
LOG4CPLUS_VERSION=`$CPPP $CPPFLAGS conftest.cpp | grep '^AUTOCONF_LOG4CPLUS_VERSION=' | $SED -e 's/^AUTOCONF_LOG4CPLUS_VERSION=//' -e 's/[[ 	]]//g' -e 's/"//g' 2> /dev/null`
978 979 980 981 982 983
if test -z "$LOG4CPLUS_VERSION"; then
  LOG4CPLUS_VERSION="unknown"
fi
$RM -f conftest.cpp
AC_MSG_RESULT([$LOG4CPLUS_VERSION])

984
CPPFLAGS=$CPPFLAGS_SAVED
985
LIBS=$LIBS_SAVED
986

987 988 989 990
# Older log4cplus versions (1.2.0) don't have the initializer.h header that
# would allow explicit initialization. Newer versions (2.0.4 for sure, possibly
# older as well) have it and it's recommended to use it. We detect whether
# it's present or not and do explicit initalization if possible.
991 992
CPPFLAGS_SAVED=$CPPFLAGS
CPPFLAGS="$LOG4CPLUS_INCLUDES $CPPFLAGS"
993 994
LIBS_SAVED="$LIBS"
LIBS="$LOG4CPLUS_LIBS $LIBS"
995 996 997 998 999 1000 1001 1002
AC_MSG_CHECKING([log4cplus explicit initialization (log4cplus/initializer.h)])
AC_LINK_IFELSE(
        [AC_LANG_PROGRAM([#include <log4cplus/initializer.h>],
                         [log4cplus::Initializer initializer;]
                         )],
        [AC_MSG_RESULT([yes])
         AC_DEFINE(LOG4CPLUS_INITIALIZER_H, [1], [Explicit initialization of log4cplus possible])],
        [AC_MSG_RESULT(no)])
1003
LIBS="$LIBS_SAVED"
1004
CPPFLAGS=$CPPFLAGS_SAVED
1005

1006 1007 1008
#
# Configure Boost header path
#
1009
AX_BOOST_FOR_KEA
1010 1011
# Boost offset_ptr is required in one library and not optional right now, so
# we unconditionally fail here if it doesn't work.
1012
if test "$BOOST_OFFSET_PTR_WOULDFAIL" = "yes" -a X"$werror_ok" = X1; then
1013
    AC_MSG_ERROR([Failed to compile a required header file.  Try upgrading Boost to 1.44 or higher (when using clang++) or specifying --without-werror.  See the ChangeLog entry for Trac no. 2147 for more details.])
1014
fi
1015

1016 1017 1018 1019
if test "$BOOST_STATIC_ASSERT_WOULDFAIL" = "yes" -a X"$werror_ok" = X1; then
    AC_MSG_ERROR([Failed to use Boost static assertions. Try upgrading Boost to 1.54 or higher (when using GCC 4.8) or specifying --without-werror.  See trac ticket no. 3039 for more details.])
fi

1020
# There's a known bug in FreeBSD ports for Boost that would trigger a false
1021 1022
# warning in build with g++ and -Werror (we exclude clang++ explicitly to
# avoid unexpected false positives).
1023
if test "$BOOST_NUMERIC_CAST_WOULDFAIL" = "yes" -a X"$werror_ok" = X1 -a $CLANGPP = "no"; then
1024 1025 1026 1027
    AC_MSG_ERROR([Failed to compile a required header file.  If you are using FreeBSD and Boost installed via ports, retry with specifying --without-werror.  See the ChangeLog entry for Trac no. 1991 for more details.])
fi

# Add some default CPP flags needed for Boost, identified by the AX macro.
1028
CPPFLAGS="$CPPFLAGS $CPPFLAGS_BOOST_THREADCONF"
1029

1030
# Can be required by gtest, boost and perhaps still asio
Francis Dupont's avatar
Francis Dupont committed
1031
AC_CHECK_LIB(pthread, pthread_create,[ LDFLAGS="$LDFLAGS -lpthread" ], [])
1032

1033

Andrei Pavel's avatar
Andrei Pavel committed
1034 1035 1036
#
# Check availability of benchmark.
#
1037
BENCHMARK_CPPFLAGS=
Andrei Pavel's avatar
Andrei Pavel committed
1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072
BENCHMARK_LDFLAGS=
BENCHMARK_LDADD=
DISTCHECK_BENCHMARK_CONFIGURE_FLAG=
BENCHMARK_VERSION="unknown"

if test "x$enable_benchmark" = "xyes" ; then

    DISTCHECK_BENCHMARK_CONFIGURE_FLAG="--with-benchmark=$benchmark_path"

    if test -n "$with_benchmark_source" ; then

        if test "x$BENCHMARK_SOURCE" = "xyes" ; then

            AC_MSG_CHECKING([for benchmark source])
            # If not specified, try some common paths.
            BENCHMARK_SOURCE=
            for d in /usr/src/benchmark /usr/local /usr/pkg /opt /opt/local ; do
                if test -f $d/src/benchmark.cc; then
                    BENCHMARK_SOURCE=$d
                    AC_MSG_RESULT([$BENCHMARK_SOURCE])
                    break
                fi
            done
            if test -z $BENCHMARK_SOURCE ; then
                AC_MSG_ERROR([no benchmark source but it was selected])
            fi
        else
            if test ! -d $BENCHMARK_SOURCE/src; then
                BENCHMARK_SOURCE=$BENCHMARK_SOURCE/benchmark
            fi
            AC_CHECK_FILES([$BENCHMARK_SOURCE/src/benchmark.cc],
                [have_benchmark_source=yes],
                [AC_MSG_ERROR([no benchmark source at $BENCHMARK_SOURCE])])
        fi
        have_benchmark_source=yes
1073 1074
        BENCHMARK_CPPFLAGS=`cat \${BENCHMARK_SOURCE}/build/src/CMakeFiles/benchmark.dir/flags.make | grep CXX_DEFINES | cut -d "=" -f 2`
        BENCHMARK_LDADD="\$(BENCHMARK_SOURCE)/build/src/libbenchmark.a"
Andrei Pavel's avatar
Andrei Pavel committed
1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086
        DISTCHECK_BENCHMARK_CONFIGURE_FLAG="--with-benchmark-source=$BENCHMARK_SOURCE"
        BENCHMARK_INCLUDES="-I$BENCHMARK_SOURCE \
                            -I$BENCHMARK_SOURCE/src \
                            -I$BENCHMARK_SOURCE/include \
                            -I$BENCHMARK_SOURCE/include/benchmark"
        BENCHMARK_VERSION="$(basename $BENCHMARK_SOURCE)"
    fi

    if test "$benchmark_path" != "no" ; then
        if test "$benchmark_path" != "yes"; then
            BENCHMARK_PATHS=$benchmark_path
        fi
1087 1088
        if test -z "${BENCHMARK_PATHS}" ; then
            BENCHMARK_PATHS="/usr /usr/local"
Andrei Pavel's avatar
Andrei Pavel committed
1089
        fi
1090 1091 1092 1093 1094 1095
        BENCHMARK_FOUND="false"
        for dir in ${BENCHMARK_PATHS}; do
            if test -f "$dir/include/benchmark/benchmark.h"; then
                if ! test -f "$dir/lib/libbenchmark.a"; then
                    AC_MSG_WARN([Found Google Benchmark include but not the library in $dir.])
                    continue
Andrei Pavel's avatar
Andrei Pavel committed
1096
                fi
1097 1098 1099 1100 1101 1102 1103
                BENCHMARK_INCLUDES="-I$dir/include"
                BENCHMARK_LDFLAGS="-L$dir/lib"
                BENCHMARK_LDADD="$dir/lib/libbenchmark.a "
                BENCHMARK_FOUND="true"
                break
            fi
        done
Andrei Pavel's avatar
Andrei Pavel committed
1104 1105 1106 1107 1108
        if test "${BENCHMARK_FOUND}" != "true"; then
            AC_MSG_ERROR([Cannot find benchmark in: $BENCHMARK_PATHS])
        fi

    fi
1109 1110

    if test $enable_gtest = no; then
Razvan Becheriu's avatar
Razvan Becheriu committed
1111
        AC_MSG_ERROR([--with-benchmark and --with-benchmark-source require --with-gtest or --with-gtest-source])
1112 1113
    fi

Andrei Pavel's avatar
Andrei Pavel committed
1114 1115 1116 1117
fi
AM_CONDITIONAL(HAVE_BENCHMARK, test $enable_benchmark != "no")
AM_CONDITIONAL(HAVE_BENCHMARK_SOURCE, test "X$have_benchmark_source" = "Xyes")
AC_SUBST(DISTCHECK_BENCHMARK_CONFIGURE_FLAG)
1118
AC_SUBST(BENCHMARK_CPPFLAGS)
Andrei Pavel's avatar
Andrei Pavel committed
1119 1120 1121 1122 1123
AC_SUBST(BENCHMARK_INCLUDES)
AC_SUBST(BENCHMARK_LDFLAGS)
AC_SUBST(BENCHMARK_LDADD)
AC_SUBST(BENCHMARK_SOURCE)

1124 1125 1126 1127 1128 1129
#
# Some Googletest versions bug with C++11 compilers
#
if test $enable_gtest != "no"; then
   AC_MSG_CHECKING([if Google Test is compatible with the compiler])
   CPPFLAGS_SAVED=$CPPFLAGS
1130
   CPPFLAGS="$CPPFLAGS $BOOST_INCLUDES $GTEST_INCLUDES"
1131 1132
   AC_COMPILE_IFELSE(
       [AC_LANG_PROGRAM(
1133 1134 1135 1136 1137
            [#include <boost/shared_ptr.hpp>
            #include <gtest/gtest.h>
            void foo() {
                boost::shared_ptr<int> bar;
                ASSERT_TRUE(bar);
1138
            }],
1139 1140 1141
            [return 0;])],
        [AC_MSG_RESULT(yes)],
        [AC_MSG_ERROR([XXX_TRUE() Google Test macros won't compile; the most likely reason is that a later version of Google Test is required])])
1142 1143
    CPPFLAGS=$CPPFLAGS_SAVED
fi
1144

1145 1146 1147 1148 1149 1150 1151
# Check for CreateUnifiedDiff from gtest >= 1.8.0
if test $enable_gtest != "no"; then
   AC_MSG_CHECKING([for CreateUnifiedDiff in $GTEST_INCLUDES/gtest.h])
   CPPFLAGS_SAVED=$CPPFLAGS
   CPPFLAGS="$CPPFLAGS $BOOST_INCLUDES $GTEST_INCLUDES"
   AC_COMPILE_IFELSE(
       [AC_LANG_PROGRAM(
1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166
            [#include <boost/algorithm/string.hpp>
            #include <gtest/gtest.h>
            #include <string>
            #include <vector>
            std::string nodiff(std::string text) {
                std::vector<std::string> lines;
                boost::split(lines, text, boost::is_any_of("\n"));
                using namespace testing::internal;
                return (edit_distance::CreateUnifiedDiff(lines, lines));
            }],
            [return 0;])],
        [AC_MSG_RESULT(yes)
        AC_DEFINE([HAVE_CREATE_UNIFIED_DIFF], [1],
        [Define to 1 if gtest defines edit_distance::CreateUnifiedDiff])],
        [AC_MSG_RESULT(no)])
1167
    CPPFLAGS=$CPPFLAGS_SAVED
1168
fi
1169

1170 1171
#
# ASIO: we extensively use it as the C++ event management module.
1172 1173 1174 1175
#
# Use our 'coroutine' header from ext
# CPPFLAGS="$CPPFLAGS -I\$(top_srcdir)/ext/coroutine"

1176
#
1177
# Doesn't seem to be required?
1178
#CPPFLAGS="$CPPFLAGS -DBOOST_ASIO_HEADER_ONLY"
1179
#
Francis Dupont's avatar
Francis Dupont committed
1180
# Disable threads: they seems to break things on some systems
1181 1182
# As now we use threads in boost ASIO this is commented out...
# CPPFLAGS="$CPPFLAGS -DBOOST_ASIO_DISABLE_THREADS=1"
1183 1184 1185 1186 1187 1188 1189 1190

# We tried to stay header only
if test "x${BOOST_LIBS}" = "x"; then
   # Don't want boost system library
   CPPFLAGS="$CPPFLAGS -DBOOST_ERROR_CODE_HEADER_ONLY"
   # Avoid boost::system::throws multiple defines
   CPPFLAGS="$CPPFLAGS -DBOOST_SYSTEM_NO_DEPRECATED"
fi
1191

1192
# Check for functions that are not available on all platforms
1193
AC_CHECK_FUNCS([pselect])
1194

1195 1196 1197 1198
# /dev/poll issue: ASIO uses /dev/poll by default if it's available (generally
# the case with Solaris).  Unfortunately its /dev/poll specific code would
# trigger the gcc's "missing-field-initializers" warning, which would
# subsequently make the build fail with -Werror.  Further, older versions of
1199
# gcc don't provide an option to selectively suppress this warning.
1200 1201 1202
# So, for the moment, we simply disable the use of /dev/poll.  Unless we
# implement recursive DNS server with randomized ports, we don't need the
# scalability that /dev/poll can provide, so this decision wouldn't affect
Jeremy C. Reed's avatar
Jeremy C. Reed committed
1203
# run time performance.  Hopefully we can find a better solution or the ASIO
1204 1205
# code will be updated by the time we really need it.
AC_CHECK_HEADERS(sys/devpoll.h, ac_cv_have_devpoll=yes, ac_cv_have_devpoll=no)
1206
if test "X$ac_cv_have_devpoll" = "Xyes" -a "X$GXX" = "Xyes"; then
1207
    CPPFLAGS="$CPPFLAGS -DBOOST_ASIO_DISABLE_DEV_POLL=1"
1208
fi
1209

1210 1211 1212 1213 1214
#
# Perl is optional; it is used only by some of the system test scripts.
#
AC_PATH_PROGS(PERL, perl5 perl)
AC_SUBST(PERL)
1215 1216
AC_PATH_PROGS(AWK, gawk awk)
AC_SUBST(AWK)
1217

1218 1219 1220 1221 1222 1223
AC_ARG_ENABLE(generate_messages, [AC_HELP_STRING([--enable-generate-messages],
  [indicates that the messages files will be regenerated. [default=no]])],
  enable_generate_messages=$enableval, enable_generate_messages=no)

AM_CONDITIONAL([GENERATE_MESSAGES], [test x$enable_generate_messages != xno])

1224 1225 1226 1227 1228 1229 1230
# cross compiling is not compatible with enable-generate-messages.
if test "$cross_compiling" = "yes"; then
    if test "$enable_generate_messages" != "no"; then
        AC_MSG_WARN([To build the message compiler is not compatible with cross compiling])
    fi
fi

1231 1232 1233 1234 1235
AC_ARG_ENABLE(generate_parser, [AC_HELP_STRING([--enable-generate-parser],
  [indicates that the parsers will be regenerated. This implies that the
   bison and flex are required [default=no]])],
   enable_generate_parser=$enableval, enable_generate_parser=no)

Josh Soref's avatar
Josh Soref committed
1236
# Check if flex is available. Flex is not needed for building Kea sources,
1237
# unless you want to regenerate grammars
1238 1239 1240
AC_PROG_LEX

# Check if bison is available. Bison is not needed for building Kea sources,
1241
# unless you want to regenerate grammars
1242 1243
AC_PATH_PROG(YACC, bison)
AC_SUBST(YACC)
1244

1245
if test "x$enable_generate_parser" != "xno"; then
1246

1247
    if test "x$LEX" != "xflex"; then
1248
       AC_MSG_ERROR([Flex is required for enable-generate-parser, but was not found])
1249 1250 1251
    fi

    if test "x$YACC" == "x"; then
Francis Dupont's avatar