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

4
AC_PREREQ([2.59])
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.3.0-beta-git, 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 30
AC_CANONICAL_HOST

31 32
# Checks for programs.
AC_PROG_CXX
33

34 35 36
# Check for exact Kea version.
AC_MSG_CHECKING(whether this is a tarball or git source)
if test -d "${srcdir}/.git"; then
37
        KEA_SRCID="git `(cd "${top_srcdir}";git rev-parse HEAD)`"
38 39 40 41 42 43 44 45 46
        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".
AC_DEFINE_UNQUOTED([EXTENDED_VERSION], ["${KEA_SRCID}"], [Extended Kea version])

47 48
# Find a separator for path_replacer
for sep in "+" "," ";" "&" "__NONE__"; do
49 50 51 52 53 54
        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
55 56
done
if test "$sep" = "__NONE__"; then
57
        AC_MSG_ERROR([can't find a separator character in '+,;&' for the path_replacer shell script])
58 59 60
fi
AC_SUBST(SEP)

61 62 63
# Enable low-performing debugging facilities? This option optionally
# enables some debugging aids that perform slowly and hence aren't built
# by default.
64 65 66 67
AC_ARG_ENABLE([debug],
  AS_HELP_STRING([--enable-debug],
    [enable debugging (default is no)]),
  [case "${enableval}" in
68 69
    yes) debug_enabled=yes ;;
    no)  debug_enabled=no ;;
70
    *)   AC_MSG_ERROR([bad value ${enableval} for --enable-debug]) ;;
71 72
  esac],[debug_enabled=no])
AM_CONDITIONAL([DEBUG_ENABLED], [test x$debug_enabled = xyes])
73
AM_COND_IF([DEBUG_ENABLED], [AC_DEFINE([ENABLE_DEBUG], [1], [Enable low-performing debugging facilities?])])
74

75
PREMIUM_DIR=
76 77 78 79 80 81 82
if test -d "${srcdir}/premium"; then
   PREMIUM_DIR=premium
   AC_CONFIG_SUBDIRS([premium])
fi

AC_SUBST(PREMIUM_DIR)

83 84
# Libtool configuration
#
Jelte Jansen's avatar
Jelte Jansen committed
85 86 87

# libtool cannot handle spaces in paths, so exit early if there is one
if [ test `echo $PWD | grep -c ' '` != "0"  ]; then
88
    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.])
Jelte Jansen's avatar
Jelte Jansen committed
89 90
fi

91 92
# On FreeBSD (and probably some others), clang++ does not meet an autoconf
# assumption in identifying libtool configuration regarding shared library:
93 94 95 96 97
# 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).
98 99 100 101 102
# 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
103
CXXFLAGS_SAVED=$CXXFLAGS
104
CFLAGS="$CFLAGS $CXX_LIBTOOL_LDFLAGS"
105
CXXFLAGS="$CXXFLAGS $CXX_LIBTOOL_LDFLAGS"
106
LT_INIT
107
CFLAGS=$CFLAGS_SAVED
108
CXXFLAGS=$CXXFLAGS_SAVED
109

110
# Use C++ language
111 112 113
AC_LANG([C++])

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

120
# Check for C++11 features support
121
AX_ISC_CPP11
122

123 124 125 126 127 128 129 130 131 132 133 134 135
# Check for std::is_base_of support
AC_MSG_CHECKING([for std::is_base_of])
AC_COMPILE_IFELSE(
	[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)])

136
dnl Determine if we are using GNU sed
137
GNU_SED=no
138
$SED --version 2> /dev/null | grep GNU > /dev/null 2>&1
139 140 141 142
if test $? -eq 0; then
  GNU_SED=yes
fi

143 144 145 146 147 148 149
# 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
150
        CXX_STANDARD="unknown"
151 152 153
fi
AC_MSG_RESULT([$CXX_STANDARD])

154 155
# Linker options

156
# check -R, "-Wl,-R" or -rpath
157
AX_ISC_RPATH
158

159
# Compiler dependent settings: define some mandatory CXXFLAGS here.
160
# We also use a separate variable KEA_CXXFLAGS.  This will (and should) be
161
# used as the default value for each specific AM_CXXFLAGS:
162
# AM_CXXFLAGS = $(KEA_CXXFLAGS)
163 164 165 166 167 168 169 170
# 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.
171
AC_DEFUN([KEA_CXX_TRY_FLAG], [
172 173
  AC_MSG_CHECKING([whether $CXX supports $1])

174
  kea_save_CXXFLAGS="$CXXFLAGS"
175
  CXXFLAGS="$CXXFLAGS -Werror $1"
176

177
  AC_LINK_IFELSE([AC_LANG_SOURCE([int main(){ return 0;}])],
178 179
                 [kea_cxx_flag=yes], [kea_cxx_flag=no])
  CXXFLAGS="$kea_save_CXXFLAGS"
180

181
  if test "x$kea_cxx_flag" = "xyes"; then
182 183 184 185 186
    ifelse([$2], , :, [$2])
  else
    ifelse([$3], , :, [$3])
  fi

187
  AC_MSG_RESULT([$kea_cxx_flag])
188 189
])

190 191
CXX_VERSION="unknown"

192 193 194
# SunStudio compiler requires special compiler options for boost
# (http://blogs.sun.com/sga/entry/boost_mini_howto)
if test "$SUNCXX" = "yes"; then
195
CXX_VERSION=`$CXX -V 2> /dev/null | head -1`
196
CXXFLAGS="$CXXFLAGS -library=stlport4 -features=tmplife -features=tmplrefstatic"
Francis Dupont's avatar
Francis Dupont committed
197
KEA_CXXFLAGS="$KEA_CXXFLAGS -mt"
198 199 200 201 202 203 204 205 206 207
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.
208
if test "X$CLANGPP" = "Xyes"; then
209
CXX_VERSION=`$CXX --version 2> /dev/null | head -1`
210
KEA_CXXFLAGS="$KEA_CXXFLAGS -Qunused-arguments"
211 212
fi

213
# gcc/clang specific settings:
214
if test "X$GXX" = "Xyes"; then
215
CXX_VERSION=`$CXX --version 2> /dev/null | head -1`
216
KEA_CXXFLAGS="$KEA_CXXFLAGS -Wall -Wextra -Wnon-virtual-dtor -Wwrite-strings -Woverloaded-virtual -Wno-sign-compare"
217 218 219
# 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.`
220
if expr "$CXX_DUMP_VERSION" \< "4.5" > /dev/null; then
221 222 223
       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
224
CPPP="$CPP"
225 226 227 228
# gcc 5 preprocessor requires -P for checking its output
if test "$CXX_DUMP_VERSION" \> "5"; then
       CPPP="$CPP -P"
fi
229

230 231
case "$host" in
*-solaris*)
232 233 234 235
        MULTITHREADING_FLAG=-pthreads
        # In Solaris, IN6ADDR_ANY_INIT and IN6ADDR_LOOPBACK_INIT need -Wno-missing-braces
        KEA_CXXFLAGS="$KEA_CXXFLAGS -Wno-missing-braces"
        ;;
236
*-apple-darwin*)
237 238
        MULTITHREADING_FLAG=
        ;;
239
*)
240 241
        MULTITHREADING_FLAG=-pthread
        ;;
242
esac
243
KEA_CXXFLAGS="$KEA_CXXFLAGS $MULTITHREADING_FLAG"
244

245 246 247
# Disable -Werror by default. Only use it if specifically enabled.
# The usage of this flag is:
#
248 249 250 251 252
# 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
253 254 255 256
#
# In the last case, "value" may be one or more compiler flags, e.g.

# --with-werror=-Wundef
257
# --with-werror='-Wundef -Wconversion'
258

259
werror_extras=
260
AC_ARG_WITH(werror,
261
    AC_HELP_STRING([--with-werror], [Compile using -Werror (default=no)]),
262 263 264 265
    [
     case "${withval}" in
         yes) with_werror=1 ;;
         no)  with_werror=0 ;;
266
         -*)  with_werror=1; werror_extras=${withval} ;;
267
         *)   AC_MSG_ERROR(bad value ${withval} for --with-werror) ;;
268
     esac],
269
     [with_werror=0])
270 271 272 273 274 275 276 277

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"
278
   CXXFLAGS="$CXXFLAGS $KEA_CXXFLAGS -Werror"
279
   AC_MSG_CHECKING(for in-TU anonymous namespace breakage)
280 281 282 283
   # 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_;};} ],,
284 285 286 287
        [AC_MSG_RESULT(no)
         werror_ok=1
         KEA_CXXFLAGS="$KEA_CXXFLAGS -Werror"],
        [AC_MSG_RESULT(yes)])
288 289 290
   CXXFLAGS="$CXXFLAGS_SAVED"
fi

291 292 293 294 295 296 297
# 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],
298
        [KEA_CXXFLAGS="$KEA_CXXFLAGS -Wno-missing-field-initializers"])
299 300

if test "X$CLANGPP" = "Xyes"; then
301 302 303 304
        # 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"
305 306 307 308 309
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
310 311 312
        KEA_CXX_TRY_FLAG([$extra],
                [KEA_CXXFLAGS="$KEA_CXXFLAGS $extra"],
                [AC_MSG_ERROR([$CXX does not support $extra"])])
313 314
done

315
fi                              dnl GXX = yes
316

JINMEI Tatuya's avatar
JINMEI Tatuya committed
317 318 319 320 321 322 323
# 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)
324
AM_COND_IF([USE_STATIC_LINK], [AC_DEFINE([USE_STATIC_LINK], [1], [Was Kea statically linked?])])
JINMEI Tatuya's avatar
JINMEI Tatuya committed
325

JINMEI Tatuya's avatar
JINMEI Tatuya committed
326 327
# Check validity about some libtool options
if test $enable_static_link = yes -a $enable_static = no; then
328
        AC_MSG_ERROR([--enable-static-link requires --enable-static])
JINMEI Tatuya's avatar
JINMEI Tatuya committed
329
fi
330
if test $enable_static_link = no -a $enable_shared = no; then
331
        AC_MSG_ERROR([--disable-static-link requires --enable-shared])
JINMEI Tatuya's avatar
JINMEI Tatuya committed
332 333
fi

334
# OS dependent configuration
335
kea_undefined_pthread_behavior=no
336

337
case "$host" in
338
*-solaris*)
339 340 341 342 343 344 345 346 347 348
        # 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
        ;;
349
*-apple-darwin*)
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368
        # 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])
        ;;
369
*-freebsd*)
370 371 372 373 374 375 376 377 378 379 380
        # 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
        ;;
381
esac
382
if [ test $kea_undefined_pthread_behavior = "yes" ]; then
383 384
   AC_DEFINE([HAS_UNDEFINED_PTHREAD_BEHAVIOR], [1], [Does this platform have some undefined pthreads behavior?])
fi
385

386 387 388 389 390 391 392 393 394 395
# 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)
396 397 398
        AC_DEFINE([HAVE_BROKEN_GET_IPV6_USE_MIN_MTU], [1],
        [Define to 1 if getsockopt(IPV6_USE_MIN_MTU) does not work])
        ;;
399 400
esac

401 402 403 404 405 406 407 408 409

# Kea-shell is written in python. It can work with python 2.7 or any 3.x.
# It may likely work with earlier versions, but 2.7 was the oldest one we tested
# it with. We require python only if kea-shell was enabled. It is disabled
# by default to not introduce hard dependency on python.
AC_ARG_ENABLE(shell, [AC_HELP_STRING([--enable-shell],
  [enable kea-shell, a text management client for Control Agent [default=no]])],
  enable_shell=$enableval, enable_shell=no)

410
DISTCHECK_KEA_SHELL_CONFIGURE_FLAG=
Francis Dupont's avatar
Francis Dupont committed
411
PKGPYTHONDIR=
412 413 414
m4_define_default([_AM_PYTHON_INTERPRETER_LIST],
 [python3 python3.9 python3.8 python3.7 python3.6 python3.5 python3.4 dnl
  python3.3 python3.2 python3.1 python3.0 python python2 python2.7])
415 416
if test "x$enable_shell" != xno ; then
# If kea-shell is enabled, we really need python. 2.7 or anything newer will do.
Tomek Mrugalski's avatar
Tomek Mrugalski committed
417
# We try to find 3.x first. If not found, we can do with 2.7.
418
  AM_PATH_PYTHON([2.7])
Francis Dupont's avatar
Francis Dupont committed
419
  # pkgpythondir needs to be expanded
420 421 422 423
  saved_prefix="$prefix"
  if test "$prefix" = "NONE"; then
    prefix=$ac_default_prefix
  fi
Francis Dupont's avatar
Francis Dupont committed
424 425 426 427 428 429
  PKGPYTHONDIR="$pkgpythondir"
  OLD=
  while test "x$OLD" != "x$PKGPYTHONDIR"; do
    OLD="$PKGPYTHONDIR"
    eval PKGPYTHONDIR="\"$OLD\""
  done
430
  prefix="$saved_prefix"
431
  DISTCHECK_KEA_SHELL_CONFIGURE_FLAG="--enable-shell"
432
else
433
  PYTHON=no
434
fi
435

436 437
# Export to makefiles the info whether we have shell enabled or not
AM_CONDITIONAL(KEA_SHELL, test x$enable_shell != xno)
438
AC_SUBST(DISTCHECK_KEA_SHELL_CONFIGURE_FLAG)
Francis Dupont's avatar
Francis Dupont committed
439
AC_SUBST(PKGPYTHONDIR)
440

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

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

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

   CXX=$CXX_SAVED
fi
459

460
AC_SUBST(KEA_CXXFLAGS)
461

462 463
# Checks for libraries.

464 465
AC_SEARCH_LIBS(inet_pton, [nsl])
AC_SEARCH_LIBS(recvfrom, [socket])
466
AC_SEARCH_LIBS(nanosleep, [rt])
467
AC_SEARCH_LIBS(dlsym, [dl])
468

469 470 471 472 473 474
# Checks for header files.

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

475

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

AM_CONDITIONAL(OS_LINUX, test $OS_TYPE = Linux)
528 529
AM_CONDITIONAL(OS_BSD, test $OS_TYPE = BSD)
AM_CONDITIONAL(OS_SOLARIS, test $OS_TYPE = Solaris)
530 531 532 533
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)
534 535


536 537 538 539 540 541
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)
542
        AC_DEFINE(HAVE_SA_LEN, 1, [Define to 1 if sockaddr has a sa_len member, and corresponding sin_len and sun_len])],
543 544
        AC_MSG_RESULT(no))

545
enable_gtest="no"
546
GTEST_INCLUDES=
547 548 549

AC_ARG_WITH([gtest-source],
            [AS_HELP_STRING([--with-gtest-source=PATH],
550 551
                            [location of the Googletest source])],
            [enable_gtest="yes" ; GTEST_SOURCE="$withval"])
552 553

AC_ARG_WITH([gtest],
554 555 556
            [AS_HELP_STRING([--with-gtest=PATH],
                            [specify a path to gtest header files (PATH/include) and library (PATH/lib)])],
        [gtest_path="$withval"; enable_gtest="yes"], [gtest_path="no"])
557

558
AC_ARG_WITH(lcov,
559
[  --with-lcov[=PROGRAM]         enable gtest and coverage target using the specified lcov], lcov="$withval", lcov="no")
560 561 562

USE_LCOV="no"
if test "$lcov" != "no"; then
563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590
        # force gtest if not set
        if test "$enable_gtest" = "no"; then
#               AC_MSG_ERROR("lcov needs gtest for test coverage report")
                AC_MSG_NOTICE([gtest support is now enabled, because used by coverage tests])
                enable_gtest="yes"
        fi
        if test "$lcov" != "yes"; then
                LCOV=$lcov
        else
                AC_PATH_PROG([LCOV], [lcov])
        fi
        if test -x "${LCOV}"; then
                USE_LCOV="yes"
        else
                AC_MSG_ERROR([Cannot find lcov.])
        fi
        # is genhtml always in the same directory?
        GENHTML=`echo "$LCOV" | ${SED} s/lcov$/genhtml/`
        if test ! -x $GENHTML; then
                AC_MSG_ERROR([genhtml not found, needed for lcov])
        fi
        # GCC specific?
        CXXFLAGS="$CXXFLAGS -fprofile-arcs -ftest-coverage"
        LIBS=" $LIBS -lgcov"
        AC_SUBST(CPPFLAGS)
        AC_SUBST(LIBS)
        AC_SUBST(LCOV)
        AC_SUBST(GENHTML)
591 592 593
fi
AC_SUBST(USE_LCOV)

594 595 596
# Sets up for use of botan unless openssl is specified
# sets variables CRYPTO_*
AX_CRYPTO
597 598

# Check for MySql.  The path to the mysql_config program is given with
599 600
# the --with-mysql-config (default to /usr/bin/mysql-config).  By default,
# the software is not built with MySQL support enabled.
601
mysql_config="no"
602 603 604
AC_ARG_WITH([dhcp-mysql],
  AC_HELP_STRING([--with-dhcp-mysql=PATH],
    [path to the MySQL 'mysql_config' script (MySQL is used for the DHCP database)]),
605 606 607 608 609 610 611 612 613
    [mysql_config="$withval"])

if test "${mysql_config}" = "yes" ; then
    MYSQL_CONFIG="/usr/bin/mysql_config"
elif test "${mysql_config}" != "no" ; then
    MYSQL_CONFIG="${withval}"
fi

if test "$MYSQL_CONFIG" != "" ; then
614 615
    if test -d "$MYSQL_CONFIG" -o ! -x "$MYSQL_CONFIG" ; then
        AC_MSG_ERROR([--with-dhcp-mysql should point to a mysql_config program])
616 617 618 619
    fi

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

    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(
633
            [AC_LANG_PROGRAM([#include <mysql.h>],
634 635 636 637 638 639 640 641 642 643 644 645 646 647 648
                             [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])]
    )

    CPPFLAGS=$CPPFLAGS_SAVED
    LIBS=$LIBS_SAVED

    # Note that MYSQL is present in the config.h file
    AC_DEFINE([HAVE_MYSQL], [1], [MySQL is present])
fi

649
# Solaris puts FIONREAD in filio.h
650
AC_CHECK_HEADERS(sys/filio.h,,,)
651

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

655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673
pg_config="no"
AC_ARG_WITH([dhcp-pgsql],
  AC_HELP_STRING([--with-dhcp-pgsql=PATH],
    [path to the PostgreSQL 'pg_config' script]),
    [pg_config="$withval"])

if test "${pg_config}" = "yes" ; then
    PG_CONFIG="/usr/bin/pg_config"
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
        AC_MSG_ERROR([--with-dhcp-pgsql should point to a pg_config program])
    fi

    PGSQL_CPPFLAGS=`$PG_CONFIG --cppflags`
    PGSQL_INCLUDEDIR=`$PG_CONFIG --includedir`
674 675
    PGSQL_INCLUDEDIR_SERVER=`$PG_CONFIG --includedir-server`
    PGSQL_CPPFLAGS="$PGSQL_CPPFLAGS -I$PGSQL_INCLUDEDIR -I$PGSQL_INCLUDEDIR_SERVER"
676 677
    PGSQL_LIBS=`$PG_CONFIG --libdir`
    PGSQL_LIBS="-L$PGSQL_LIBS -lpq"
678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698
    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])]
    )

699
    AC_CHECK_HEADERS([utils/errcodes.h],,
700
    AC_MSG_ERROR([Missing required header file (errcodes.h) from PostgreSQL server-development package]))
701

702 703 704 705 706 707 708 709 710
    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" != "")
Jelte Jansen's avatar
Jelte Jansen committed
711

Tomek Mrugalski's avatar
Tomek Mrugalski committed
712 713 714 715 716 717 718
cql_config="no"
AC_ARG_WITH([cql],
  AC_HELP_STRING([--with-cql=PATH],
    [path to the Cassandra CQL 'cql_config' script]),
    [cql_config="$withval"])

if test "${cql_config}" = "yes" ; then
719
    CQL_CONFIG="/usr/bin/cql_config"
Tomek Mrugalski's avatar
Tomek Mrugalski committed
720
elif test "${cql_config}" != "no" ; then
Francis Dupont's avatar
Francis Dupont committed
721
    CQL_CONFIG="${cql_config}"
722 723
fi

Tomek Mrugalski's avatar
Tomek Mrugalski committed
724 725 726
if test "$CQL_CONFIG" != "" ; then
    if test -d "$CQL_CONFIG" -o ! -x "$CQL_CONFIG" ; then
        AC_MSG_ERROR([--with-cql should point to a cql_config program])
727 728
    fi

Tomek Mrugalski's avatar
Tomek Mrugalski committed
729
    CQL_INCLUDEDIR=`$CQL_CONFIG --includedir`
730 731
    CQL_CPPFLAGS="`$CQL_CONFIG --cppflags` -I$CQL_INCLUDEDIR"
    CQL_LIBS="-L`$CQL_CONFIG --libdir` -lcassandra_static -luv"
Tomek Mrugalski's avatar
Tomek Mrugalski committed
732
    CQL_VERSION=`$CQL_CONFIG --version`
733

Tomek Mrugalski's avatar
Tomek Mrugalski committed
734 735
    AC_SUBST(CQL_CPPFLAGS)
    AC_SUBST(CQL_LIBS)
736

Tomek Mrugalski's avatar
Tomek Mrugalski committed
737
    # Check that a simple program using CQL functions can compile and link.
738 739 740
    CPPFLAGS_SAVED="$CPPFLAGS"
    LIBS_SAVED="$LIBS"

Tomek Mrugalski's avatar
Tomek Mrugalski committed
741 742
    CPPFLAGS="$CQL_CPPFLAGS $CPPFLAGS"
    LIBS="$CQL_LIBS $LIBS"
743 744 745 746 747

    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
748 749 750
            [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])]
751 752 753 754
    )
    CPPFLAGS=$CPPFLAGS_SAVED
    LIBS=$LIBS_SAVED

Tomek Mrugalski's avatar
Tomek Mrugalski committed
755 756
    # Note that CQL is present in the config.h file
    AC_DEFINE([HAVE_CQL], [1], [CQL is present])
757 758 759
fi

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

762
# Check for log4cplus
763
DISTCHECK_LOG4CPLUS_CONFIGURE_FLAG=
764 765 766 767 768
log4cplus_path="yes"
AC_ARG_WITH([log4cplus],
  AC_HELP_STRING([--with-log4cplus=PATH],
    [specify exact directory of log4cplus library and headers]),
    [log4cplus_path="$withval"])
769
if test "${log4cplus_path}" = "no" ; then
770 771
    AC_MSG_ERROR([Need log4cplus])
elif test "${log4cplus_path}" != "yes" ; then
772
  DISTCHECK_LOG4CPLUS_CONFIGURE_FLAG="-with-log4cplus=${log4cplus_path}"
773
  LOG4CPLUS_INCLUDES="-I${log4cplus_path}/include"
774
  LOG4CPLUS_LIBS="-L${log4cplus_path}/lib"
775 776
else
# If not specified, try some common paths.
777 778 779 780 781 782 783 784 785
        log4cplusdirs="/usr /usr/local /usr/pkg /opt /opt/local"
        for d in $log4cplusdirs
        do
                if test -f $d/include/log4cplus/logger.h; then
                        LOG4CPLUS_INCLUDES="-I$d/include"
                        LOG4CPLUS_LIBS="-L$d/lib -L$d/lib64"
                        break
                fi
        done
786
	DISTCHECK_LOG4CPLUS_CONFIGURE_FLAG="-with-log4cplus"
787 788
fi

Francis Dupont's avatar
Francis Dupont committed
789
LOG4CPLUS_LIBS="$LOG4CPLUS_LIBS -llog4cplus"
790

791
AC_SUBST(DISTCHECK_LOG4CPLUS_CONFIGURE_FLAG)
792
AC_SUBST(LOG4CPLUS_LIBS)
793 794 795 796
AC_SUBST(LOG4CPLUS_INCLUDES)

CPPFLAGS_SAVED=$CPPFLAGS
CPPFLAGS="$LOG4CPLUS_INCLUDES $CPPFLAGS"
797
LIBS_SAVED="$LIBS"
Francis Dupont's avatar
Francis Dupont committed
798
LIBS="$LOG4CPLUS_LIBS $MULTITHREADING_FLAG $LIBS"
799 800 801 802 803 804 805 806 807 808 809 810 811

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

812 813 814
dnl Determine the log4cplus version, used mainly for config.report.
AC_MSG_CHECKING([log4cplus version])
cat > conftest.cpp << EOF
815
#include <log4cplus/version.h>
816 817 818
AUTOCONF_LOG4CPLUS_VERSION=LOG4CPLUS_VERSION_STR
EOF

819
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`
820 821 822 823 824 825
if test -z "$LOG4CPLUS_VERSION"; then
  LOG4CPLUS_VERSION="unknown"
fi
$RM -f conftest.cpp
AC_MSG_RESULT([$LOG4CPLUS_VERSION])

826
CPPFLAGS=$CPPFLAGS_SAVED
827
LIBS=$LIBS_SAVED
828

829 830 831
#
# Configure Boost header path
#
832
AX_BOOST_FOR_KEA
833 834
# Boost offset_ptr is required in one library and not optional right now, so
# we unconditionally fail here if it doesn't work.
835
if test "$BOOST_OFFSET_PTR_WOULDFAIL" = "yes" -a X"$werror_ok" = X1; then
836
    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.])
837
fi
838

839 840 841 842
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

843
# There's a known bug in FreeBSD ports for Boost that would trigger a false
844 845
# warning in build with g++ and -Werror (we exclude clang++ explicitly to
# avoid unexpected false positives).
846
if test "$BOOST_NUMERIC_CAST_WOULDFAIL" = "yes" -a X"$werror_ok" = X1 -a $CLANGPP = "no"; then
847 848 849 850
    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.
851
CPPFLAGS="$CPPFLAGS $CPPFLAGS_BOOST_THREADCONF"
852

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

856
#
857
# Check availability of gtest, which will be used for unit tests.
858
#
859 860 861
GTEST_LDFLAGS=
GTEST_LDADD=
DISTCHECK_GTEST_CONFIGURE_FLAG=
862
GTEST_VERSION="unknown"
863

864
if test "x$enable_gtest" = "xyes" ; then
865

866 867
    DISTCHECK_GTEST_CONFIGURE_FLAG="--with-gtest=$gtest_path"

868
    if test -n "$with_gtest_source" ; then
869

870
        if test "x$GTEST_SOURCE" = "xyes" ; then
871

872
            AC_MSG_CHECKING([for gtest source])
873
            # If not specified, try some common paths.
874
            GTEST_SOURCE=
875 876 877 878 879 880 881
            for d in /usr/src/gtest /usr/local /usr/pkg /opt /opt/local ; do
                if test -f $d/src/gtest-all.cc -a $d/src/gtest_main.cc; then
                    GTEST_SOURCE=$d
                    AC_MSG_RESULT([$GTEST_SOURCE])
                    break
                fi
            done
882
            if test -z $GTEST_SOURCE ; then
883
                AC_MSG_ERROR([no gtest source but it was selected])
884
            fi
885
        else
886 887 888
	    if test ! -d $GTEST_SOURCE/src -a -d $GTEST_SOURCE/googletest; then
		GTEST_SOURCE=$GTEST_SOURCE/googletest
	    fi
889
            AC_CHECK_FILES([$GTEST_SOURCE/src/gtest-all.cc]
890 891 892 893 894
                [$GTEST_SOURCE/src/gtest_main.cc],
                [have_gtest_source=yes],
                [AC_MSG_ERROR([no gtest source at $GTEST_SOURCE])])
        fi
        have_gtest_source=yes
Francis Dupont's avatar
Francis Dupont committed
895
        GTEST_LDADD="\$(top_builddir)/ext/gtest/libgtest.a"
896 897
        DISTCHECK_GTEST_CONFIGURE_FLAG="--with-gtest-source=$GTEST_SOURCE"
        GTEST_INCLUDES="-I$GTEST_SOURCE -I$GTEST_SOURCE/include"
898
	GTEST_VERSION="`basename $GTEST_SOURCE`"
899
    fi
900 901 902 903 904 905 906 907 908

    if test "$gtest_path" != "no" ; then
        if test "$gtest_path" != "yes"; then
            GTEST_PATHS=$gtest_path
            if test -x "${gtest_path}/bin/gtest-config" ; then
                GTEST_CONFIG="${gtest_path}/bin/gtest-config"
            fi
        else
            AC_PATH_PROG([GTEST_CONFIG], [gtest-config])
909
        fi
910 911 912 913 914 915 916 917 918 919 920
        if test -x "${GTEST_CONFIG}" ; then :
            # using cppflags instead of cxxflags
            GTEST_INCLUDES=`${GTEST_CONFIG} --cppflags`
            GTEST_LDFLAGS=`${GTEST_CONFIG} --ldflags`
            GTEST_LDADD=`${GTEST_CONFIG} --libs`
            GTEST_VERSION=`${GTEST_CONFIG} --version`
            GTEST_FOUND="true"
        else
            AC_MSG_WARN([Unable to locate Google Test gtest-config.])
            if test -z "${GTEST_PATHS}" ; then
                GTEST_PATHS="/usr /usr/local"
921
            fi
922 923 924 925 926 927
            GTEST_FOUND="false"
        fi
        if test "${GTEST_FOUND}" != "true"; then
            GTEST_FOUND="false"
            for dir in $GTEST_PATHS; do
                if test -f "$dir/include/gtest/gtest.h"; then
928 929 930 931
                    if ! test -f "$dir/lib/libgtests.a"; then
                        AC_MSG_WARN([Found Google Test include but not the library in $dir.])
                        continue
                    fi
932 933 934 935 936 937 938 939 940 941 942
                    GTEST_INCLUDES="-I$dir/include"
                    GTEST_LDFLAGS="-L$dir/lib"
                    GTEST_LDADD="-lgtest"
                    GTEST_FOUND="true"
                    break
                fi
            done
        fi
        if test "${GTEST_FOUND}" != "true"; then
            AC_MSG_ERROR([Cannot find gtest in: $GTEST_PATHS])
        fi
943

944
    fi
945
fi
946 947
AM_CONDITIONAL(HAVE_GTEST, test $enable_gtest != "no")
AM_CONDITIONAL(HAVE_GTEST_SOURCE, test "X$have_gtest_source" = "Xyes")
948
AC_SUBST(DISTCHECK_GTEST_CONFIGURE_FLAG)
949 950 951
AC_SUBST(GTEST_INCLUDES)
AC_SUBST(GTEST_LDFLAGS)
AC_SUBST(GTEST_LDADD)
952
AC_SUBST(GTEST_SOURCE)
953

954 955 956 957 958 959
#
# 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
960
   CPPFLAGS="$CPPFLAGS $BOOST_INCLUDES $GTEST_INCLUDES"
961 962 963 964 965 966 967 968 969 970
   AC_COMPILE_IFELSE(
       [AC_LANG_PROGRAM(
           [#include <boost/shared_ptr.hpp>
	    #include <gtest/gtest.h>
	    void foo() {
	        boost::shared_ptr<int> bar;
		ASSERT_TRUE(bar);
            }],
	    [return 0;])],
	[AC_MSG_RESULT(yes)],
Francis Dupont's avatar
Francis Dupont committed
971
    	[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])])
972 973
    CPPFLAGS=$CPPFLAGS_SAVED
fi
974

975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997
# 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(
           [#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)])
    CPPFLAGS=$CPPFLAGS_SAVED
998
fi
999

1000 1001 1002
#
# ASIO: we extensively use it as the C++ event management module.
#
1003 1004
# Doesn't seem to be required?
CPPFLAGS="$CPPFLAGS -DBOOST_ASIO_HEADER_ONLY"
1005
#
Francis Dupont's avatar
Francis Dupont committed
1006
# Disable threads: they seems to break things on some systems
1007 1008 1009 1010 1011 1012 1013 1014 1015
CPPFLAGS="$CPPFLAGS -DBOOST_ASIO_DISABLE_THREADS=1"

# 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
1016

1017
# Check for functions that are not available on all platforms
1018 1019
AC_CHECK_FUNCS([pselect])

1020 1021 1022 1023
# /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
1024
# gcc don't provide an option to selectively suppress this warning.
1025 1026 1027
# 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
1028
# run time performance.  Hopefully we can find a better solution or the ASIO
1029 1030
# 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)
1031
if test "X$ac_cv_have_devpoll" = "Xyes" -a "X$GXX" = "Xyes"; then
1032
	CPPFLAGS="$CPPFLAGS -DBOOST_ASIO_DISABLE_DEV_POLL=1"
1033
fi
1034

1035 1036 1037 1038 1039
#
# Perl is optional; it is used only by some of the system test scripts.
#
AC_PATH_PROGS(PERL, perl5 perl)
AC_SUBST(PERL)
1040 1041
AC_PATH_PROGS(AWK, gawk awk)
AC_SUBST(AWK)
1042

1043 1044 1045 1046 1047
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
1048
# Check if flex is available. Flex is not needed for building Kea sources,
1049
# unless you want to regenerate grammars
1050 1051 1052
AC_PROG_LEX

# Check if bison is available. Bison is not needed for building Kea sources,
1053
# unless you want to regenerate grammars
1054 1055
AC_PROG_YACC

1056
if test "x$enable_generate_parser" != "xno"; then
1057 1058

    if test "x$LEX" == "x"; then
1059
       AC_MSG_ERROR([Flex is required for enable-generate-parser, but was not found])
1060 1061 1062
    fi

    if test "x$YACC" == "x"; then
1063
       AC_MSG_ERROR([Bison is required for enable-generate-parser, but was not found])
1064 1065 1066
    fi

# Ok, let's check if we have at least 3.0.0 version of the bison. The code used
1067
# to generate parsers is roughly based on bison 3.0 examples.
1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079
   cat > bisontest.y << EOF
%require "3.0.0"
%token X
%%
%start Y;
Y: X;
EOF
# Try to compile.
    $YACC bisontest.y -o bisontest.cc

    if test $? -ne 0 ; then
        $YACC -V
Francis Dupont's avatar
Francis Dupont committed
1080
        $RM -f bisontest.y bisontest.cc
1081 1082
        AC_MSG_ERROR("Error with $YACC. Possibly incorrect version? Required at least 3.0.0.")
    fi
Francis Dupont's avatar
Francis Dupont committed
1083
    $RM -f bisontest.y bisontest.cc
1084 1085
fi

1086 1087
AM_CONDITIONAL([GENERATE_PARSER], [test x$enable_generate_parser != xno])

1088 1089 1090
AC_ARG_ENABLE(generate_docs, [AC_HELP_STRING([--enable-generate-docs],
  [regenerate documentation using Docbook [default=no]])],
  enable_generate_docs=$enableval, enable_generate_docs=no)
1091

1092
if test "x$enable_generate_docs" != xno ; then
1093 1094

# Check for xsltproc
1095 1096
  AC_PATH_PROG([XSLTPROC], [xsltproc])
  if test -z "$XSLTPROC"; then
1097
    AC_MSG_ERROR("xsltproc not found; it is required for --enable-generate-docs")
1098 1099 1100
  else
    AC_MSG_CHECKING([if $XSLTPROC works])
    # run xsltproc to see if works
1101
    $XSLTPROC --novalid --xinclude http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl
1102 1103 1104
    if test $? -ne 0 ; then
      AC_MSG_ERROR("Error with $XSLTPROC using release/xsl/current/manpages/docbook.xsl")
    fi
1105
    $XSLTPROC --novalid --xinclude http://docbook.sourceforge.net/release/xsl/current/html/docbook.xsl
1106 1107 1108
    if test $? -ne 0 ; then
      AC_MSG_ERROR("Error with $XSLTPROC using release/xsl/current/html/docbook.xsl")
    fi
1109
    AC_MSG_RESULT(yes)
1110
  fi
1111 1112 1113 1114 1115

  AC_PATH_PROG([ELINKS], [elinks])
  if test -z "$ELINKS"; then
    AC_MSG_ERROR("elinks not found; it is required for --enable-generate-docs")
  fi
1116 1117
fi

1118 1119 1120
# Don't fail here if not found, used to generate PDF documentation.
AC_PATH_PROG([DBLATEX], [dblatex])
AM_CONDITIONAL(HAVE_DBLATEX, test "x$DBLATEX" != "x")
1121

1122
AM_CONDITIONAL(GENERATE_DOCS, test x$enable_generate_docs != xno)
1123

1124 1125 1126
AC_ARG_ENABLE(install-configurations,
  [AC_HELP_STRING([--disable-install-configurations],
  [do not install configuration])], install_configurations=$enableval, install_configurations=yes)
1127

1128
AM_CONDITIONAL(INSTALL_CONFIGURATIONS, test x$install_configurations = xyes || test x$install_configurations = xtrue)
1129

1130 1131 1132 1133 1134
AC_ARG_ENABLE(logger-checks, [AC_HELP_STRING([--enable-logger-checks],
  [check logger messages [default=no]])], enable_logger_checks=$enableval, enable_logger_checks=no)
AM_CONDITIONAL(ENABLE_LOGGER_CHECKS, test x$enable_logger_checks != xno)
AM_COND_IF([ENABLE_LOGGER_CHECKS], [AC_DEFINE([ENABLE_LOGGER_CHECKS], [1], [Check logger messages?])])

Mukund Sivaraman's avatar
Mukund Sivaraman committed
1135 1136 1137 1138 1139 1140 1141 1142
# Check for asciidoc
AC_PATH_PROG(ASCIIDOC, asciidoc, no)
AM_CONDITIONAL(HAVE_ASCIIDOC, test "x$ASCIIDOC" != "xno")

# Check for plantuml
AC_PATH_PROG(PLANTUML, plantuml, no)
AM_CONDITIONAL(HAVE_PLANTUML, test "x$PLANTUML" != "xno")

1143 1144 1145 1146
# Check for valgrind
AC_PATH_PROG(VALGRIND, valgrind, no)
AM_CONDITIONAL(HAVE_VALGRIND, test "x$VALGRIND" != "xno")

1147 1148 1149 1150 1151 1152 1153
# Also check for valgrind headers
# We could consider adding them to the source code tree, as this
# is the encouraged method of using them; they are BSD-licensed.
# However, until we find that this is a problem, we just use
# the system-provided ones, if available
AC_CHECK_HEADERS(valgrind/valgrind.h, [AC_DEFINE([HAVE_VALGRIND_HEADERS], [1], [Check valgrind headers])])

1154 1155 1156
found_valgrind="not found"
if test "x$VALGRIND" != "xno"; then
   found_valgrind="found"
1157 1158
fi

1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169
# Check for optreset in unistd.h. On BSD systems the optreset is
# used to reset the state of getopt() function. Resetting its state
# is required if command line arguments are parsed multiple times
# during a program. On Linux this variable will not exist because
# getopt() reset is performed by setting optind = 0. On Operating
# Systems where optreset is defined use optreset = 1 and optind = 1
# to reset internal state of getopt(). Failing to do so will result
# in unpredictable output from getopt().
AC_MSG_CHECKING([whether optreset variable is defined in unistd.h])
AC_TRY_LINK(
    [#include <unistd.h>],
1170
    [extern int optreset; optreset=1;],
1171 1172 1173 1174 1175 1176
    [ AC_MSG_RESULT(yes)
      var_optreset_exists=yes],
    [ AC_MSG_RESULT(no)
      var_optreset_exists=no]
)
AM_CONDITIONAL(HAVE_OPTRESET, test "x$var_optreset_exists" != "xno")
1177
AM_COND_IF([HAVE_OPTRESET], [AC_DEFINE([HAVE_OPTRESET], [1], [Check for optreset?])])
1178

1179 1180
AC_DEFINE([CONFIG_H_WAS_INCLUDED], [1], [config.h inclusion marker])

1181 1182
AC_CONFIG_FILES([Makefile
                 compatcheck/Makefile
1183
                 dns++.pc
1184
                 doc/Makefile
1185
                 doc/design/Makefile
1186
                 doc/design/datasrc/Makefile
1187 1188
                 doc/guide/Makefile
                 doc/version.ent
1189
                 ext/Makefile
1190
                 ext/gtest/Makefile
1191
                 m4macros/Makefile
1192 1193
                 src/Makefile
                 src/bin/Makefile
1194 1195 1196 1197 1198 1199 1200 1201
                 src/bin/admin/Makefile
                 src/bin/admin/kea-admin
                 src/bin/admin/tests/Makefile
                 src/bin/admin/tests/cql_tests.sh
                 src/bin/admin/tests/data/Makefile
                 src/bin/admin/tests/memfile_tests.sh
                 src/bin/admin/tests/mysql_tests.sh
                 src/bin/admin/tests/pgsql_tests.sh
1202 1203
                 src/bin/agent/Makefile
                 src/bin/agent/tests/Makefile
1204
                 src/bin/agent/tests/ca_process_tests.sh
1205
                 src/bin/agent/tests/test_data_files_config.h
1206
                 src/bin/agent/tests/test_libraries.h
1207 1208
                 src/bin/d2/Makefile
                 src/bin/d2/tests/Makefile
1209
                 src/bin/d2/tests/d2_process_tests.sh
1210 1211 1212 1213
                 src/bin/d2/tests/test_data_files_config.h
                 src/bin/dhcp4/Makefile
                 src/bin/dhcp4/spec_config.h.pre
                 src/bin/dhcp4/tests/Makefile
1214
                 src/bin/dhcp4/tests/dhcp4_process_tests.sh
1215
                 src/bin/dhcp4/tests/marker_file.h
1216
                 src/bin/dhcp4/tests/test_data_files_config.h
1217 1218 1219 1220
                 src/bin/dhcp4/tests/test_libraries.h
                 src/bin/dhcp6/Makefile
                 src/bin/dhcp6/spec_config.h.pre
                 src/bin/dhcp6/tests/Makefile
1221
                 src/bin/dhcp6/tests/dhcp6_process_tests.sh
1222 1223 1224
                 src/bin/dhcp6/tests/marker_file.h
                 src/bin/dhcp6/tests/test_data_files_config.h
                 src/bin/dhcp6/tests/test_libraries.h
1225 1226
                 src/bin/keactrl/Makefile
                 src/bin/keactrl/keactrl
1227
                 src/bin/keactrl/keactrl.conf
1228
                 src/bin/keactrl/tests/Makefile
1229
                 src/bin/keactrl/tests/keactrl_tests.sh
1230 1231
                 src/bin/lfc/Makefile
                 src/bin/lfc/tests/Makefile
1232 1233 1234
                 src/bin/perfdhcp/Makefile
                 src/bin/perfdhcp/tests/Makefile
                 src/bin/perfdhcp/tests/testdata/Makefile
1235
                 src/bin/shell/Makefile
1236
                 src/bin/shell/kea-shell
1237 1238
                 src/bin/shell/tests/Makefile
                 src/bin/shell/tests/shell_process_tests.sh
1239
                 src/bin/shell/tests/shell_unittest.py