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

Francis Dupont's avatar
Francis Dupont committed
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.3.0-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

Francis Dupont's avatar
Francis Dupont committed
75
# Include premium configuration
76
PREMIUM_DIR=
77
DISTCHECK_PREMIUM_CONFIGURE_FLAG=
Francis Dupont's avatar
Francis Dupont committed
78
AC_DEFUN([AX_PREMIUM],[])
Francis Dupont's avatar
Francis Dupont committed
79 80
# m4_sinclude includes the file if it exists at autoreconf time
m4_sinclude(premium/config.m4)
Francis Dupont's avatar
Francis Dupont committed
81 82
m4_sinclude(premium/tier1.m4)
m4_sinclude(premium/tier2.m4)
83
AC_SUBST(PREMIUM_DIR)
84
AC_SUBST(DISTCHECK_PREMIUM_CONFIGURE_FLAG)
Francis Dupont's avatar
Francis Dupont committed
85
AX_PREMIUM
86

Francis Dupont's avatar
Francis Dupont committed
87
# Include contrib configuration
88
# (currently only a provision copied from premium support)
Francis Dupont's avatar
Francis Dupont committed
89
CONTRIB_DIR=
90
DISTCHECK_CONTRIB_CONFIGURE_FLAG=
Francis Dupont's avatar
Francis Dupont committed
91
AC_DEFUN([AX_CONTRIB],[])
Francis Dupont's avatar
Francis Dupont committed
92
m4_sinclude(contrib/config.m4)
Francis Dupont's avatar
Francis Dupont committed
93
AC_SUBST(CONTRIB_DIR)
94
AC_SUBST(DISTCHECK_CONTRIB_CONFIGURE_FLAG)
Francis Dupont's avatar
Francis Dupont committed
95
AX_CONTRIB
96

97 98
# Libtool configuration
#
Jelte Jansen's avatar
Jelte Jansen committed
99 100 101

# libtool cannot handle spaces in paths, so exit early if there is one
if [ test `echo $PWD | grep -c ' '` != "0"  ]; then
102
    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
103 104
fi

105 106
# On FreeBSD (and probably some others), clang++ does not meet an autoconf
# assumption in identifying libtool configuration regarding shared library:
107 108 109 110 111
# 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).
112 113 114 115 116
# 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
117
CXXFLAGS_SAVED=$CXXFLAGS
118
CFLAGS="$CFLAGS $CXX_LIBTOOL_LDFLAGS"
119
CXXFLAGS="$CXXFLAGS $CXX_LIBTOOL_LDFLAGS"
120
LT_INIT
121
CFLAGS=$CFLAGS_SAVED
122
CXXFLAGS=$CXXFLAGS_SAVED
123

124
# Use C++ language
125 126 127
AC_LANG([C++])

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

134
# Check for C++11 features support
135
AX_ISC_CPP11
136

137 138 139 140 141 142 143 144 145 146 147 148 149
# 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)])

150
dnl Determine if we are using GNU sed
151
GNU_SED=no
152
$SED --version 2> /dev/null | grep GNU > /dev/null 2>&1
153 154 155 156
if test $? -eq 0; then
  GNU_SED=yes
fi

157 158 159 160 161 162 163
# 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
164
        CXX_STANDARD="unknown"
165 166 167
fi
AC_MSG_RESULT([$CXX_STANDARD])

168 169
# Linker options

170
# check -R, "-Wl,-R" or -rpath
171
AX_ISC_RPATH
172

173
# Compiler dependent settings: define some mandatory CXXFLAGS here.
174
# We also use a separate variable KEA_CXXFLAGS.  This will (and should) be
175
# used as the default value for each specific AM_CXXFLAGS:
176
# AM_CXXFLAGS = $(KEA_CXXFLAGS)
177 178 179 180 181 182 183 184
# 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.
185
AC_DEFUN([KEA_CXX_TRY_FLAG], [
186 187
  AC_MSG_CHECKING([whether $CXX supports $1])

188
  kea_save_CXXFLAGS="$CXXFLAGS"
189
  CXXFLAGS="$CXXFLAGS -Werror $1"
190

191
  AC_LINK_IFELSE([AC_LANG_SOURCE([int main(){ return 0;}])],
192 193
                 [kea_cxx_flag=yes], [kea_cxx_flag=no])
  CXXFLAGS="$kea_save_CXXFLAGS"
194

195
  if test "x$kea_cxx_flag" = "xyes"; then
196 197 198 199 200
    ifelse([$2], , :, [$2])
  else
    ifelse([$3], , :, [$3])
  fi

201
  AC_MSG_RESULT([$kea_cxx_flag])
202 203
])

204 205
CXX_VERSION="unknown"

206 207 208
# SunStudio compiler requires special compiler options for boost
# (http://blogs.sun.com/sga/entry/boost_mini_howto)
if test "$SUNCXX" = "yes"; then
209
CXX_VERSION=`$CXX -V 2> /dev/null | head -1`
210
CXXFLAGS="$CXXFLAGS -library=stlport4 -features=tmplife -features=tmplrefstatic"
Francis Dupont's avatar
Francis Dupont committed
211
KEA_CXXFLAGS="$KEA_CXXFLAGS -mt"
212 213 214 215 216 217 218 219 220 221
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.
222
if test "X$CLANGPP" = "Xyes"; then
223
CXX_VERSION=`$CXX --version 2> /dev/null | head -1`
224
KEA_CXXFLAGS="$KEA_CXXFLAGS -Qunused-arguments"
225 226
fi

227
# gcc/clang specific settings:
228
if test "X$GXX" = "Xyes"; then
229
CXX_VERSION=`$CXX --version 2> /dev/null | head -1`
230
KEA_CXXFLAGS="$KEA_CXXFLAGS -Wall -Wextra -Wnon-virtual-dtor -Wwrite-strings -Woverloaded-virtual -Wno-sign-compare"
231 232 233
# 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.`
234
if expr "$CXX_DUMP_VERSION" \< "4.5" > /dev/null; then
235 236 237
       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
238
CPPP="$CPP"
239 240 241 242
# gcc 5 preprocessor requires -P for checking its output
if test "$CXX_DUMP_VERSION" \> "5"; then
       CPPP="$CPP -P"
fi
243

244 245
case "$host" in
*-solaris*)
246 247 248 249
        MULTITHREADING_FLAG=-pthreads
        # In Solaris, IN6ADDR_ANY_INIT and IN6ADDR_LOOPBACK_INIT need -Wno-missing-braces
        KEA_CXXFLAGS="$KEA_CXXFLAGS -Wno-missing-braces"
        ;;
250
*-apple-darwin*)
251 252
        MULTITHREADING_FLAG=
        ;;
253
*)
254 255
        MULTITHREADING_FLAG=-pthread
        ;;
256
esac
257
KEA_CXXFLAGS="$KEA_CXXFLAGS $MULTITHREADING_FLAG"
258

259 260 261
# Disable -Werror by default. Only use it if specifically enabled.
# The usage of this flag is:
#
262 263 264 265 266
# 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
267 268 269 270
#
# In the last case, "value" may be one or more compiler flags, e.g.

# --with-werror=-Wundef
271
# --with-werror='-Wundef -Wconversion'
272

273
werror_extras=
274
AC_ARG_WITH(werror,
275
    AC_HELP_STRING([--with-werror], [Compile using -Werror (default=no)]),
276 277 278 279
    [
     case "${withval}" in
         yes) with_werror=1 ;;
         no)  with_werror=0 ;;
280
         -*)  with_werror=1; werror_extras=${withval} ;;
281
         *)   AC_MSG_ERROR(bad value ${withval} for --with-werror) ;;
282
     esac],
283
     [with_werror=0])
284 285 286 287 288 289 290 291

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"
292
   CXXFLAGS="$CXXFLAGS $KEA_CXXFLAGS -Werror"
293
   AC_MSG_CHECKING(for in-TU anonymous namespace breakage)
294 295 296 297
   # 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_;};} ],,
298 299 300 301
        [AC_MSG_RESULT(no)
         werror_ok=1
         KEA_CXXFLAGS="$KEA_CXXFLAGS -Werror"],
        [AC_MSG_RESULT(yes)])
302 303 304
   CXXFLAGS="$CXXFLAGS_SAVED"
fi

305 306 307 308 309 310 311
# 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],
312
        [KEA_CXXFLAGS="$KEA_CXXFLAGS -Wno-missing-field-initializers"])
313 314

if test "X$CLANGPP" = "Xyes"; then
315 316 317 318
        # 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"
319 320 321 322 323
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
324 325 326
        KEA_CXX_TRY_FLAG([$extra],
                [KEA_CXXFLAGS="$KEA_CXXFLAGS $extra"],
                [AC_MSG_ERROR([$CXX does not support $extra"])])
327 328
done

329
fi                              dnl GXX = yes
330

JINMEI Tatuya's avatar
JINMEI Tatuya committed
331 332 333 334 335 336 337
# 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)
338
AM_COND_IF([USE_STATIC_LINK], [AC_DEFINE([USE_STATIC_LINK], [1], [Was Kea statically linked?])])
JINMEI Tatuya's avatar
JINMEI Tatuya committed
339

JINMEI Tatuya's avatar
JINMEI Tatuya committed
340 341
# Check validity about some libtool options
if test $enable_static_link = yes -a $enable_static = no; then
342
        AC_MSG_ERROR([--enable-static-link requires --enable-static])
JINMEI Tatuya's avatar
JINMEI Tatuya committed
343
fi
344
if test $enable_static_link = no -a $enable_shared = no; then
345
        AC_MSG_ERROR([--disable-static-link requires --enable-shared])
JINMEI Tatuya's avatar
JINMEI Tatuya committed
346 347
fi

348
# OS dependent configuration
349
kea_undefined_pthread_behavior=no
350

351
case "$host" in
352
*-solaris*)
353 354 355 356 357 358 359 360 361 362
        # 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
        ;;
363
*-apple-darwin*)
364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382
        # 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])
        ;;
383
*-freebsd*)
384 385 386 387 388 389 390 391 392 393 394
        # 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
        ;;
395
esac
396
if [ test $kea_undefined_pthread_behavior = "yes" ]; then
397 398
   AC_DEFINE([HAS_UNDEFINED_PTHREAD_BEHAVIOR], [1], [Does this platform have some undefined pthreads behavior?])
fi
399

400 401 402 403 404 405 406 407 408 409
# 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)
410 411 412
        AC_DEFINE([HAVE_BROKEN_GET_IPV6_USE_MIN_MTU], [1],
        [Define to 1 if getsockopt(IPV6_USE_MIN_MTU) does not work])
        ;;
413 414
esac

415 416 417 418 419 420 421 422 423

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

424
DISTCHECK_KEA_SHELL_CONFIGURE_FLAG=
Francis Dupont's avatar
Francis Dupont committed
425
PKGPYTHONDIR=
426 427 428
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])
429 430
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
431
# We try to find 3.x first. If not found, we can do with 2.7.
432
  AM_PATH_PYTHON([2.7])
Francis Dupont's avatar
Francis Dupont committed
433
  # pkgpythondir needs to be expanded
434 435 436 437
  saved_prefix="$prefix"
  if test "$prefix" = "NONE"; then
    prefix=$ac_default_prefix
  fi
Francis Dupont's avatar
Francis Dupont committed
438 439 440 441 442 443
  PKGPYTHONDIR="$pkgpythondir"
  OLD=
  while test "x$OLD" != "x$PKGPYTHONDIR"; do
    OLD="$PKGPYTHONDIR"
    eval PKGPYTHONDIR="\"$OLD\""
  done
444
  prefix="$saved_prefix"
445
  DISTCHECK_KEA_SHELL_CONFIGURE_FLAG="--enable-shell"
446
else
447
  PYTHON=no
448
fi
449

450 451
# Export to makefiles the info whether we have shell enabled or not
AM_CONDITIONAL(KEA_SHELL, test x$enable_shell != xno)
452
AC_SUBST(DISTCHECK_KEA_SHELL_CONFIGURE_FLAG)
Francis Dupont's avatar
Francis Dupont committed
453
AC_SUBST(PKGPYTHONDIR)
454

455
# produce PIC unless we disable shared libraries. need this for python bindings.
456
if test $enable_shared != "no" -a "X$GXX" = "Xyes"; then
457
   KEA_CXXFLAGS="$KEA_CXXFLAGS -fPIC"
458 459
fi

460
# Look for glib static libs if they're trying to do static builds
461
if test $enable_static_link != "no"; then
462 463 464 465
   CXX_SAVED=$CXX
   CXX="$CXX -static"

   AC_LINK_IFELSE(
466
     [AC_LANG_PROGRAM([#include <math.h>],[(void)sqrt(-1.0);])],
467 468
     [AC_MSG_RESULT([checking for static glib libraries... yes])],
     [AC_MSG_RESULT([checking for static glib libraries... no])
469
      AC_MSG_ERROR([Building with --enable-static-link does not work. You appear to be missing glib static libraries. Check config.log for details.])])
470 471 472

   CXX=$CXX_SAVED
fi
473

474
AC_SUBST(KEA_CXXFLAGS)
475

476 477
# Checks for libraries.

478 479
AC_SEARCH_LIBS(inet_pton, [nsl])
AC_SEARCH_LIBS(recvfrom, [socket])
480
AC_SEARCH_LIBS(nanosleep, [rt])
481
AC_SEARCH_LIBS(dlsym, [dl])
482

483 484 485 486 487 488
# Checks for header files.

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

489

490 491
# Detect OS type (it may be used to do OS-specific things, e.g.
# interface detection in DHCP)
492
AC_MSG_CHECKING(OS type)
493
BSD_TYPE="notaBSD"
494 495 496
case $host in
    *-linux*)
      AC_DEFINE([OS_LINUX], [1], [Running on Linux?])
497
      OS_TYPE="Linux"
498 499
      CPPFLAGS="$CPPFLAGS -DOS_LINUX"
      ;;
500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523
    *-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?])
524
      OS_TYPE="BSD"
525
      BSD_TYPE="OpenBSD"
526 527
      CPPFLAGS="$CPPFLAGS -DOS_BSD"
      ;;
528 529
    *-solaris*)
      AC_DEFINE([OS_SOLARIS], [1], [Running on Solaris?])
530
      OS_TYPE="Solaris"
531
      CPPFLAGS="$CPPFLAGS -DOS_SUN"
532 533 534
      ;;
    *)
      OS_TYPE="Unknown"
535 536
      # $host_os is more user friendly than full $host
      AC_MSG_WARN("Unsupported OS: $host_os")
537 538 539
      ;;
esac
AC_MSG_RESULT($OS_TYPE)
540 541

AM_CONDITIONAL(OS_LINUX, test $OS_TYPE = Linux)
542 543
AM_CONDITIONAL(OS_BSD, test $OS_TYPE = BSD)
AM_CONDITIONAL(OS_SOLARIS, test $OS_TYPE = Solaris)
544 545 546 547
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)
548 549


550 551 552 553 554 555
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)
556
        AC_DEFINE(HAVE_SA_LEN, 1, [Define to 1 if sockaddr has a sa_len member, and corresponding sin_len and sun_len])],
557 558
        AC_MSG_RESULT(no))

559
enable_gtest="no"
560
GTEST_INCLUDES=
561 562 563

AC_ARG_WITH([gtest-source],
            [AS_HELP_STRING([--with-gtest-source=PATH],
564 565
                            [location of the Googletest source])],
            [enable_gtest="yes" ; GTEST_SOURCE="$withval"])
566 567

AC_ARG_WITH([gtest],
568 569 570
            [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"])
571

572
AC_ARG_WITH(lcov,
573
[  --with-lcov[=PROGRAM]         enable gtest and coverage target using the specified lcov], lcov="$withval", lcov="no")
574 575 576

USE_LCOV="no"
if test "$lcov" != "no"; then
577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604
        # 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)
605 606 607
fi
AC_SUBST(USE_LCOV)

608 609 610
# Sets up for use of botan unless openssl is specified
# sets variables CRYPTO_*
AX_CRYPTO
611 612

# Check for MySql.  The path to the mysql_config program is given with
613 614
# the --with-mysql-config (default to /usr/bin/mysql-config).  By default,
# the software is not built with MySQL support enabled.
615
mysql_config="no"
616 617
AC_ARG_WITH([mysql],
  AC_HELP_STRING([--with-mysql=PATH],
618
    [path to the MySQL 'mysql_config' script (MySQL is used for the DHCP database)]),
619 620 621 622 623 624 625 626 627
    [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
628
    if test -d "$MYSQL_CONFIG" -o ! -x "$MYSQL_CONFIG" ; then
629
        AC_MSG_ERROR([--with-mysql should point to a mysql_config program])
630 631 632 633
    fi

    MYSQL_CPPFLAGS=`$MYSQL_CONFIG --cflags`
    MYSQL_LIBS=`$MYSQL_CONFIG --libs`
634
    MYSQL_VERSION=`$MYSQL_CONFIG --version`
635 636 637 638 639 640 641 642 643 644 645 646

    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(
647
            [AC_LANG_PROGRAM([#include <mysql.h>],
648 649 650 651 652 653 654 655 656 657 658 659 660 661 662
                             [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

663
# Solaris puts FIONREAD in filio.h
664
AC_CHECK_HEADERS(sys/filio.h,,,)
665

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

669
pg_config="no"
670 671
AC_ARG_WITH([pgsql],
  AC_HELP_STRING([--with-pgsql=PATH],
672 673 674 675 676 677 678 679 680 681 682
    [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
683
        AC_MSG_ERROR([--with-pgsql should point to a pg_config program])
684 685 686 687
    fi

    PGSQL_CPPFLAGS=`$PG_CONFIG --cppflags`
    PGSQL_INCLUDEDIR=`$PG_CONFIG --includedir`
688 689
    PGSQL_INCLUDEDIR_SERVER=`$PG_CONFIG --includedir-server`
    PGSQL_CPPFLAGS="$PGSQL_CPPFLAGS -I$PGSQL_INCLUDEDIR -I$PGSQL_INCLUDEDIR_SERVER"
690 691
    PGSQL_LIBS=`$PG_CONFIG --libdir`
    PGSQL_LIBS="-L$PGSQL_LIBS -lpq"
692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712
    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])]
    )

713
    AC_CHECK_HEADERS([utils/errcodes.h],,
714
    AC_MSG_ERROR([Missing required header file (errcodes.h) from PostgreSQL server-development package]))
715

716 717 718 719 720 721 722 723 724
    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
725

Tomek Mrugalski's avatar
Tomek Mrugalski committed
726 727 728 729 730 731 732
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
733
    CQL_CONFIG="/usr/bin/cql_config"
Tomek Mrugalski's avatar
Tomek Mrugalski committed
734
elif test "${cql_config}" != "no" ; then
Francis Dupont's avatar
Francis Dupont committed
735
    CQL_CONFIG="${cql_config}"
736 737
fi

Tomek Mrugalski's avatar
Tomek Mrugalski committed
738 739 740
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])
741 742
    fi

Tomek Mrugalski's avatar
Tomek Mrugalski committed
743
    CQL_INCLUDEDIR=`$CQL_CONFIG --includedir`
744
    CQL_CPPFLAGS="`$CQL_CONFIG --cppflags` -I$CQL_INCLUDEDIR"
745
    CQL_LIBS="-L`$CQL_CONFIG --libdir` -lcassandra -luv"
Tomek Mrugalski's avatar
Tomek Mrugalski committed
746
    CQL_VERSION=`$CQL_CONFIG --version`
747

Tomek Mrugalski's avatar
Tomek Mrugalski committed
748 749
    AC_SUBST(CQL_CPPFLAGS)
    AC_SUBST(CQL_LIBS)
750

Tomek Mrugalski's avatar
Tomek Mrugalski committed
751
    # Check that a simple program using CQL functions can compile and link.
752 753 754
    CPPFLAGS_SAVED="$CPPFLAGS"
    LIBS_SAVED="$LIBS"

Tomek Mrugalski's avatar
Tomek Mrugalski committed
755 756
    CPPFLAGS="$CQL_CPPFLAGS $CPPFLAGS"
    LIBS="$CQL_LIBS $LIBS"
757 758 759 760 761

    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
762 763 764
            [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])]
765 766 767 768
    )
    CPPFLAGS=$CPPFLAGS_SAVED
    LIBS=$LIBS_SAVED

Tomek Mrugalski's avatar
Tomek Mrugalski committed
769 770
    # Note that CQL is present in the config.h file
    AC_DEFINE([HAVE_CQL], [1], [CQL is present])
771 772 773
fi

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

776
# Check for log4cplus
777
DISTCHECK_LOG4CPLUS_CONFIGURE_FLAG=
778 779 780 781 782
log4cplus_path="yes"
AC_ARG_WITH([log4cplus],
  AC_HELP_STRING([--with-log4cplus=PATH],
    [specify exact directory of log4cplus library and headers]),
    [log4cplus_path="$withval"])
783
if test "${log4cplus_path}" = "no" ; then
784 785
    AC_MSG_ERROR([Need log4cplus])
elif test "${log4cplus_path}" != "yes" ; then
786
  DISTCHECK_LOG4CPLUS_CONFIGURE_FLAG="-with-log4cplus=${log4cplus_path}"
787
  LOG4CPLUS_INCLUDES="-I${log4cplus_path}/include"
788
  LOG4CPLUS_LIBS="-L${log4cplus_path}/lib"
789 790
else
# If not specified, try some common paths.
791 792 793 794 795 796 797 798 799
        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
800
	DISTCHECK_LOG4CPLUS_CONFIGURE_FLAG="-with-log4cplus"
801 802
fi

Francis Dupont's avatar
Francis Dupont committed
803
LOG4CPLUS_LIBS="$LOG4CPLUS_LIBS -llog4cplus"
804

805
AC_SUBST(DISTCHECK_LOG4CPLUS_CONFIGURE_FLAG)
806
AC_SUBST(LOG4CPLUS_LIBS)
807 808 809 810
AC_SUBST(LOG4CPLUS_INCLUDES)

CPPFLAGS_SAVED=$CPPFLAGS
CPPFLAGS="$LOG4CPLUS_INCLUDES $CPPFLAGS"
811
LIBS_SAVED="$LIBS"
Francis Dupont's avatar
Francis Dupont committed
812
LIBS="$LOG4CPLUS_LIBS $MULTITHREADING_FLAG $LIBS"
813 814 815 816 817 818 819 820 821 822 823 824 825

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

826 827 828
dnl Determine the log4cplus version, used mainly for config.report.
AC_MSG_CHECKING([log4cplus version])
cat > conftest.cpp << EOF
829
#include <log4cplus/version.h>
830 831 832
AUTOCONF_LOG4CPLUS_VERSION=LOG4CPLUS_VERSION_STR
EOF

833
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`
834 835 836 837 838 839
if test -z "$LOG4CPLUS_VERSION"; then
  LOG4CPLUS_VERSION="unknown"
fi
$RM -f conftest.cpp
AC_MSG_RESULT([$LOG4CPLUS_VERSION])

840
CPPFLAGS=$CPPFLAGS_SAVED
841
LIBS=$LIBS_SAVED
842

843 844 845
#
# Configure Boost header path
#
846
AX_BOOST_FOR_KEA
847 848
# Boost offset_ptr is required in one library and not optional right now, so
# we unconditionally fail here if it doesn't work.
849
if test "$BOOST_OFFSET_PTR_WOULDFAIL" = "yes" -a X"$werror_ok" = X1; then
850
    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.])
851
fi
852

853 854 855 856
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

857
# There's a known bug in FreeBSD ports for Boost that would trigger a false
858 859
# warning in build with g++ and -Werror (we exclude clang++ explicitly to
# avoid unexpected false positives).
860
if test "$BOOST_NUMERIC_CAST_WOULDFAIL" = "yes" -a X"$werror_ok" = X1 -a $CLANGPP = "no"; then
861 862 863 864
    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.
865
CPPFLAGS="$CPPFLAGS $CPPFLAGS_BOOST_THREADCONF"
866

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

870
#
871
# Check availability of gtest, which will be used for unit tests.
872
#
873 874 875
GTEST_LDFLAGS=
GTEST_LDADD=
DISTCHECK_GTEST_CONFIGURE_FLAG=
876
GTEST_VERSION="unknown"
877

878
if test "x$enable_gtest" = "xyes" ; then
879

880 881
    DISTCHECK_GTEST_CONFIGURE_FLAG="--with-gtest=$gtest_path"

882
    if test -n "$with_gtest_source" ; then
883

884
        if test "x$GTEST_SOURCE" = "xyes" ; then
885

886
            AC_MSG_CHECKING([for gtest source])
887
            # If not specified, try some common paths.
888
            GTEST_SOURCE=
889 890 891 892 893 894 895
            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
896
            if test -z $GTEST_SOURCE ; then
897
                AC_MSG_ERROR([no gtest source but it was selected])
898
            fi
899
        else
900 901 902
	    if test ! -d $GTEST_SOURCE/src -a -d $GTEST_SOURCE/googletest; then
		GTEST_SOURCE=$GTEST_SOURCE/googletest
	    fi
903
            AC_CHECK_FILES([$GTEST_SOURCE/src/gtest-all.cc]
904 905 906 907 908
                [$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
909
        GTEST_LDADD="\$(top_builddir)/ext/gtest/libgtest.a"
910 911
        DISTCHECK_GTEST_CONFIGURE_FLAG="--with-gtest-source=$GTEST_SOURCE"
        GTEST_INCLUDES="-I$GTEST_SOURCE -I$GTEST_SOURCE/include"
912
	GTEST_VERSION="`basename $GTEST_SOURCE`"
913
    fi
914 915 916 917 918 919 920 921 922

    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])
923
        fi
924 925 926 927 928 929 930 931 932 933 934
        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"
935
            fi
936 937 938 939 940 941
            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
942 943 944 945
                    if ! test -f "$dir/lib/libgtests.a"; then
                        AC_MSG_WARN([Found Google Test include but not the library in $dir.])
                        continue
                    fi
946 947 948 949 950 951 952 953 954 955 956
                    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
957

958
    fi
959
fi
960 961
AM_CONDITIONAL(HAVE_GTEST, test $enable_gtest != "no")
AM_CONDITIONAL(HAVE_GTEST_SOURCE, test "X$have_gtest_source" = "Xyes")
962
AC_SUBST(DISTCHECK_GTEST_CONFIGURE_FLAG)
963 964 965
AC_SUBST(GTEST_INCLUDES)
AC_SUBST(GTEST_LDFLAGS)
AC_SUBST(GTEST_LDADD)
966
AC_SUBST(GTEST_SOURCE)
967

968 969 970 971 972 973
#
# 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
974
   CPPFLAGS="$CPPFLAGS $BOOST_INCLUDES $GTEST_INCLUDES"
975 976 977 978 979 980 981 982 983 984
   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
985
    	[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])])
986 987
    CPPFLAGS=$CPPFLAGS_SAVED
fi
988

989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011
# 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
1012
fi
1013

1014 1015 1016
#
# ASIO: we extensively use it as the C++ event management module.
#
1017 1018
# Doesn't seem to be required?
CPPFLAGS="$CPPFLAGS -DBOOST_ASIO_HEADER_ONLY"
1019
#
Francis Dupont's avatar
Francis Dupont committed
1020
# Disable threads: they seems to break things on some systems
1021 1022 1023 1024 1025 1026 1027 1028 1029
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
1030

1031
# Check for functions that are not available on all platforms
1032 1033
AC_CHECK_FUNCS([pselect])

1034 1035 1036 1037
# /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
1038
# gcc don't provide an option to selectively suppress this warning.
1039 1040 1041
# 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
1042
# run time performance.  Hopefully we can find a better solution or the ASIO
1043 1044
# 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)
1045
if test "X$ac_cv_have_devpoll" = "Xyes" -a "X$GXX" = "Xyes"; then
1046
	CPPFLAGS="$CPPFLAGS -DBOOST_ASIO_DISABLE_DEV_POLL=1"
1047
fi
1048

1049 1050 1051 1052 1053
#
# Perl is optional; it is used only by some of the system test scripts.
#
AC_PATH_PROGS(PERL, perl5 perl)
AC_SUBST(PERL)
1054 1055
AC_PATH_PROGS(AWK, gawk awk)
AC_SUBST(AWK)
1056

1057 1058 1059 1060 1061
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
1062
# Check if flex is available. Flex is not needed for building Kea sources,
1063
# unless you want to regenerate grammars
1064 1065 1066
AC_PROG_LEX

# Check if bison is available. Bison is not needed for building Kea sources,
1067
# unless you want to regenerate grammars
1068 1069
AC_PROG_YACC

1070
if test "x$enable_generate_parser" != "xno"; then
1071 1072

    if test "x$LEX" == "x"; then
1073
       AC_MSG_ERROR([Flex is required for enable-generate-parser, but was not found])
1074 1075 1076
    fi

    if test "x$YACC" == "x"; then