Skip to content

Commit

Permalink
simplified configure.ac, using generic m4 macros borrowed from BIND 1…
Browse files Browse the repository at this point in the history
…0 examples
  • Loading branch information
jinmei committed Dec 23, 2012
1 parent e0c724f commit e75c13d
Show file tree
Hide file tree
Showing 9 changed files with 308 additions and 150 deletions.
2 changes: 2 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
SUBDIRS = src

ACLOCAL_AMFLAGS = -I m4
17 changes: 3 additions & 14 deletions config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,15 @@
/* Define to 1 if you have the <boost/bind.hpp> header file. */
#undef HAVE_BOOST_BIND_HPP

/* Define to 1 if you have the
<boost/date_time/posix_time/posix_time_types.hpp> header file. */
#undef HAVE_BOOST_DATE_TIME_POSIX_TIME_POSIX_TIME_TYPES_HPP

/* Define to 1 if you have the <boost/foreach.hpp> header file. */
#undef HAVE_BOOST_FOREACH_HPP

/* Define to 1 if you have the <boost/function.hpp> header file. */
#undef HAVE_BOOST_FUNCTION_HPP

/* Define to 1 if you have the
<boost/interprocess/sync/interprocess_upgradable_mutex.hpp> header file. */
#undef HAVE_BOOST_INTERPROCESS_SYNC_INTERPROCESS_UPGRADABLE_MUTEX_HPP

/* Define to 1 if you have the <boost/shared_ptr.hpp> header file. */
#undef HAVE_BOOST_SHARED_PTR_HPP

/* Define to 1 if you have the <dlfcn.h> header file. */
#undef HAVE_DLFCN_H

/* Define to 1 if you have the <dns/rrtype.h> header file. */
#undef HAVE_DNS_RRTYPE_H

/* Define to 1 if you have the <inttypes.h> header file. */
#undef HAVE_INTTYPES_H

Expand Down Expand Up @@ -56,6 +42,9 @@
/* Define to 1 if you have the <unistd.h> header file. */
#undef HAVE_UNISTD_H

/* Define to 1 if you have the <util/buffer.h> header file. */
#undef HAVE_UTIL_BUFFER_H

/* Define to the sub-directory in which libtool stores uninstalled libraries.
*/
#undef LT_OBJDIR
Expand Down
184 changes: 52 additions & 132 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -13,70 +13,68 @@ AC_PROG_LIBTOOL

AC_LANG([C++])

# Checks for libraries.
# Checks for BIND 10 headers and libraries
AX_ISC_BIND10

# Check for BIND10 libdns++ headers
AC_ARG_WITH(bind10-include,
AC_HELP_STRING([--with-bind10-include=PATH],
[specify a path to BIND 10 header files
(PATH, often needs to be in a BIND 10 source such as
<somewhere>/bind10/src/lib)]),
bind10_inc_path="$withval", bind10_inc_path="no")
# If not specified, try some common paths.
if test "$bind10_inc_path" = "no"; then
bind10dirs="/usr/local /usr/pkg /opt /opt/local"
for d in $bind10dirs
do
if test -f $d/dns/rrtype.h; then
bind10_inc_path=$d
break
fi
done
# We use -R, -rpath etc so the resulting program will be more likekly to
# "just work" whenever they are available.
if test "x$BIND10_RPATH" != "x"; then
LDFLAGS="$LDFLAGS $BIND10_RPATH"
fi

# Check for the BIND 10 DNS library.
if test "x$BIND10_DNS_LIB" = "x"; then
AC_MSG_ERROR([unable to find BIND 10 DNS library needed to build 'host'])
fi

#
# Configure ASIO header path
#
# If explicitly specified, use it.
AC_ARG_WITH([asio-include],
AC_HELP_STRING([--with-asio-include=PATH],
[specify exact directory for ASIO headers]),
[asio_include_path="$withval"])
CPPFLAGS_SAVES="$CPPFLAGS"
if test "${bind10_inc_path}" ; then
BIND10_INCLUDES="-I${bind10_inc_path}"
CPPFLAGS="$CPPFLAGS $BIND10_INCLUDES"
CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
if test "${asio_include_path}" ; then
ASIO_CPPFLAGS="-I${asio_include_path}"
CPPFLAGS="$CPPFLAGS $ASIO_CPPFLAGS"
fi
AC_CHECK_HEADERS([dns/rrtype.h],,
AC_MSG_ERROR([Missing required BIND 10 header files.]))
AC_CHECK_HEADERS([asio.hpp],,
AC_MSG_ERROR([Missing required header files.]))
CPPFLAGS="$CPPFLAGS_SAVES"
AC_SUBST(BIND10_INCLUDES)
AC_SUBST(ASIO_CPPFLAGS)

# Check for BIND10 lib libraries
AC_ARG_WITH(bind10-lib,
AC_HELP_STRING([--with-bind10-lib=PATH],
[specify a path to BIND 10 library files (PATH/lib)]),
bind10_lib_path="$withval", bind10_lib_path="no")
# Checks for header files.

if test bind10_lib_path != "no"; then
BIND10_LDFLAGS="-L$bind10_lib_path/lib"
fi
BIND10_LDADD="-lb10-dns++ -lb10-util -lb10-exceptions"
# Checks for typedefs, structures, and compiler characteristics.

CPPFLAGS_SAVED="$CPPFLAGS"
CPPFLAGS="$CPPFLAGS $BIND10_INCLUDES"
LDFLAGS_SAVED="$LDFLAGS"
LDFLAGS="$LDFLAGS $BIND10_LDFLAGS"
LIBS_SAVED=$LIBS
LIBS="$LIBS $BIND10_LDADD"
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.
CXXFLAGS_SAVED="$CXXFLAGS"
CXXFLAGS="$CXXFLAGS -Werror"
AC_MSG_CHECKING(for in-TU anonymous namespace breakage)
AC_TRY_COMPILE([namespace { class Foo {}; }
namespace isc {class Bar {Foo foo_;};} ],,
[AC_MSG_RESULT(no)
werror_ok=1
CXX_WERROR_FLAGS="-Werror"],
[AC_MSG_RESULT(yes)])
CXXFLAGS="$CXXFLAGS_SAVED $CXX_WERROR_FLAGS"

AC_MSG_CHECKING([BIND 10 libraries])
AC_TRY_LINK([
#include <dns/rrtype.h>
],[
isc::dns::RRType rrtype(1);
],
[ AC_MSG_RESULT(yes)],
[ AC_MSG_RESULT(no)
AC_MSG_ERROR(unable to find required BIND 10 libraries)])
if test "X$GXX" = "Xyes"; then
CXXFLAGS="$CXXFLAGS -Wall -Wextra -Wwrite-strings -Woverloaded-virtual -Wno-sign-compare"
fi

CPPFLAGS="$CPPFLAGS_SAVED"
LDFLAGS="$LDFLAGS_SAVES"
LIBS="$LIBS_SAVES"
# Checks for library functions.

AC_SUBST(BIND10_LDFLAGS)
AC_SUBST(BIND10_LDADD)
# See if we need to be explicit for thread support
PTHREAD_LDFLAGS=
AC_CHECK_LIB(pthread, pthread_create,[ PTHREAD_LDFLAGS=-lpthread ], [])
LDFLAGS="$LDFLAGS $PTHREAD_LDFLAGS"

# Check for availability of (optional) gootletest.
AC_ARG_WITH(gtest,
Expand Down Expand Up @@ -172,88 +170,10 @@ else
fi
AM_CONDITIONAL(HAVE_GTEST, test $gtest_path != "no")
AC_SUBST(DISTCHECK_GTEST_CONFIGURE_FLAG)
AC_SUBST(GTEST_INCLUDES)
AC_SUBST(GTEST_CPPFLAGS)
AC_SUBST(GTEST_LDFLAGS)
AC_SUBST(GTEST_LDADD)

#
# Configure Boost header path
#
# If explicitly specified, use it.
AC_ARG_WITH([boost-include],
AC_HELP_STRING([--with-boost-include=PATH],
[specify exact directory for Boost headers]),
[boost_include_path="$withval"])
# If not specified, try some common paths.
if test -z "$with_boost_include"; then
boostdirs="/usr/local /usr/pkg /opt /opt/local"
for d in $boostdirs
do
if test -f $d/include/boost/shared_ptr.hpp; then
boost_include_path=$d/include
break
fi
done
fi
CPPFLAGS_SAVES="$CPPFLAGS"
if test "${boost_include_path}" ; then
BOOST_INCLUDES="-I${boost_include_path}"
CPPFLAGS="$CPPFLAGS $BOOST_INCLUDES"
fi
AC_CHECK_HEADERS([boost/shared_ptr.hpp boost/foreach.hpp boost/interprocess/sync/interprocess_upgradable_mutex.hpp boost/date_time/posix_time/posix_time_types.hpp boost/bind.hpp boost/function.hpp],,
AC_MSG_ERROR([Missing required header files.]))
CPPFLAGS="$CPPFLAGS_SAVES"
AC_SUBST(BOOST_INCLUDES)

#
# Configure ASIO header path
#
# If explicitly specified, use it.
AC_ARG_WITH([asio-include],
AC_HELP_STRING([--with-asio-include=PATH],
[specify exact directory for ASIO headers]),
[asio_include_path="$withval"])
CPPFLAGS_SAVES="$CPPFLAGS"
CPPFLAGS="$CPPFLAGS $BOOST_INCLUDES"
if test "${asio_include_path}" ; then
ASIO_INCLUDES="-I${asio_include_path}"
CPPFLAGS="$CPPFLAGS $ASIO_INCLUDES"
fi
AC_CHECK_HEADERS([asio.hpp],,
AC_MSG_ERROR([Missing required header files.]))
CPPFLAGS="$CPPFLAGS_SAVES"
AC_SUBST(ASIO_INCLUDES)

# Checks for header files.

# Checks for typedefs, structures, and compiler characteristics.

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.
CXXFLAGS_SAVED="$CXXFLAGS"
CXXFLAGS="$CXXFLAGS -Werror"
AC_MSG_CHECKING(for in-TU anonymous namespace breakage)
AC_TRY_COMPILE([namespace { class Foo {}; }
namespace isc {class Bar {Foo foo_;};} ],,
[AC_MSG_RESULT(no)
werror_ok=1
CXX_WERROR_FLAGS="-Werror"],
[AC_MSG_RESULT(yes)])
CXXFLAGS="$CXXFLAGS_SAVED $CXX_WERROR_FLAGS"

if test "X$GXX" = "Xyes"; then
CXXFLAGS="$CXXFLAGS -Wall -Wextra -Wwrite-strings -Woverloaded-virtual -Wno-sign-compare"
fi

# Checks for library functions.

# See if we need to be explicit for thread support
PTHREAD_LDFLAGS=
AC_CHECK_LIB(pthread, pthread_create,[ PTHREAD_LDFLAGS=-lpthread ], [])
LDFLAGS="$LDFLAGS $PTHREAD_LDFLAGS"

# Man pages (optional)
AC_ARG_ENABLE(man, [AC_HELP_STRING([--enable-man],
[regenerate man pages [default=no]])], enable_man=$enableval, enable_man=no)
Expand Down
64 changes: 64 additions & 0 deletions m4/ax_boost_include.m4
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
dnl @synopsis AX_BOOST_INCLUDE
dnl
dnl Test for the Boost C++ header files
dnl
dnl If no path to the installed boost header files is given via the
dnl --with-boost-include option, the macro searchs under
dnl /usr/local /usr/pkg /opt /opt/local directories.
dnl
dnl This macro calls:
dnl
dnl AC_SUBST(BOOST_CPPFLAGS)
dnl

AC_DEFUN([AX_BOOST_INCLUDE], [
AC_LANG_SAVE
AC_LANG([C++])
#
# Configure Boost header path
#
# If explicitly specified, use it.
AC_ARG_WITH([boost-include],
AS_HELP_STRING([--with-boost-include=PATH],
[specify exact directory for Boost headers]),
[boost_include_path="$withval"])
# If not specified, try some common paths.
if test -z "$with_boost_include"; then
boostdirs="/usr/local /usr/pkg /opt /opt/local"
for d in $boostdirs
do
if test -f $d/include/boost/shared_ptr.hpp; then
boost_include_path=$d/include
break
fi
done
fi
CPPFLAGS_SAVED="$CPPFLAGS"
if test "${boost_include_path}" ; then
BOOST_CPPFLAGS="-I${boost_include_path}"
CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
fi
# Make sure some commonly used headers are available
AC_CHECK_HEADERS([boost/shared_ptr.hpp boost/bind.hpp boost/function.hpp],,
AC_MSG_ERROR([Missing required Boost header files.]))
# Detect whether Boost tries to use threads by default, and, if not,
# make it sure explicitly. In some systems the automatic detection
# may depend on preceding header files, and if inconsistency happens
# it could lead to a critical disruption.
AC_MSG_CHECKING([whether Boost tries to use threads])
AC_TRY_COMPILE([
#include <boost/config.hpp>
#ifdef BOOST_HAS_THREADS
#error "boost will use threads"
#endif],,
[AC_MSG_RESULT(no)
CPPFLAGS_BOOST_THREADCONF="-DBOOST_DISABLE_THREADS=1"],
[AC_MSG_RESULT(yes)])
CPPFLAGS="$CPPFLAGS_SAVED $CPPFLAGS_BOOST_THREADCONF"
AC_SUBST(BOOST_CPPFLAGS)
AC_LANG_RESTORE
])dnl AX_BOOST_INCLUDE
Loading

0 comments on commit e75c13d

Please sign in to comment.