# Autoconf script for Goanna
# configure.ac Copyright (c) 2005-2006 Iowa State University
# See the file LICENSE in the top level directory of the Goanna distribution
# for copying terms and conditions.

AC_INIT(goanna, 0.5.0, brett@scl.ameslab.gov)
AC_REVISION($Revision$)

AC_CONFIG_AUX_DIR([config])

AC_CONFIG_FILES([images/mkpng.sh
		 ftrace/Makefile
		 src/nifty++/Makefile
		 src/nifty++/test/Makefile
		 src/gtkwrap/Makefile
		 src/gtkwrap/test/Makefile
		 src/goanna/Makefile
		 src/goanna/model/Makefile
		 src/goanna/topography/Makefile
		 src/goanna/gl/Makefile
		 src/goanna/glade/Makefile
		 src/tools/Makefile
		 src/Makefile
		 doc/manual/Makefile
		 doc/Makefile
		 images/pngs/Makefile
		 images/pngs/hicolor/16x16/Makefile
		 images/pngs/hicolor/22x22/Makefile
		 images/pngs/hicolor/24x24/Makefile
		 images/pngs/hicolor/32x32/Makefile
		 images/pngs/hicolor/48x48/Makefile
		 images/textures/Makefile
		 images/Makefile
		 Makefile
		 goanna.spec],
		 [chmod +x images/mkpng.sh])
AC_CONFIG_HEADERS([goanna-config.h])

AM_INIT_AUTOMAKE([1.9 foreign])
AM_MAINTAINER_MODE

# Check whether to enable tracing and debugging
AC_ARG_ENABLE([debug],
              AS_HELP_STRING([--enable-debug], [Enables debug code]))
AC_ARG_ENABLE([tracing],
              AS_HELP_STRING([--enable-trace],
                             [Enables trace messages; implies --enable-debug.]))
AC_ARG_ENABLE([memory-debugging],
              AS_HELP_STRING([--enable-memory-debugging],
                             [Enables extra memory allocation/deallocation logging.
			      Implies --enable-debug.]))
AC_ARG_ENABLE([dmalloc],
              AS_HELP_STRING([--disable-dmalloc],
                             [If memory debugging is enabled, it tries to link with dmalloc.
			      This disables that.]))
AC_ARG_ENABLE([gui],
	      AS_HELP_STRING([--disable-gui],
			     [Disables building the GUI. You don't want this.]))
AC_ARG_ENABLE([test-programs],
	      AS_HELP_STRING([--enable-test-programs],
			     [Enable a few small test programs]))
AC_ARG_ENABLE([tools],
	      AS_HELP_STRING([--enable-tools],
			     [Build helper/utility tools]))
AC_ARG_ENABLE([segfaults],
	      AS_HELP_STRING([--enable-segfaults],
			     [Disable null pointer checks in smartpointers]))
AC_ARG_ENABLE([build-manual],
	      AS_HELP_STRING([--enable-build-manual],
			     [Enables rules to build the manual]))
AC_ARG_ENABLE([manual],
	      AS_HELP_STRING([--enable-manual],
			     [Install the manual]))
AC_ARG_ENABLE([update-xdg],
              AS_HELP_STRING([--enable-update-xdg],
                             [Update FreeDesktop databases]))
AC_ARG_ENABLE([threading],
	      [AS_HELP_STRING([--disable-threading],
			     [Disable multithreading support])])
AC_ARG_ENABLE([trace-functions],
	      [AS_HELP_STRING([--enable-trace-functions],
			      [Enables function call tracing])])

AC_ARG_WITH([bamboo],
	    AS_HELP_STRING([--with-bamboo=PATH], [Specify location of bamboo library]))
AC_ARG_WITH([bamboo-config],
	    AS_HELP_STRING([--with-bamboo-config=PATH], [Specify location of libbamboo-config script]))
AC_ARG_WITH([gtk],
	    AS_HELP_STRING([--with-gtk=PATH],
			   [Specify the location of GTK]))
AC_ARG_WITH([default-log-level],
	    AS_HELP_STRING([--with-default-log-level=LEVEL],
			   [Specify an alternative default log level]))
AC_ARG_WITH([opengl],
	    AS_HELP_STRING([--with-opengl=PATH],
			   [Specifiy the prefix of the OpenGL installation
			    (use --without-opengl to disable GL code)]))
AC_ARG_WITH([xdg-path],
            AS_HELP_STRING([--with-xdg-path=PATH],
                           [Use the specified path as the freedesktop.org configuration root]))

# Conditionally build tools
AM_CONDITIONAL([BUILD_TESTS],
	       [test ! -z "${enable_test_programs}" -a X"${enable_test_programs}" != X"no"])
AM_CONDITIONAL([NO_GUI],
	       [test X"${enable_gui}" = X"no"])
if test ! -z "${enable_tools}" -a X"${enable_tools}" != X"no"; then
	DO_BUILD_TOOLS="yes"
else
	DO_BUILD_TOOLS="no"
fi

AM_CONDITIONAL([STATIC_BUILD],
               [test ! -z "${enable_shared}" -a X"${enable_shared}" = Xno])

AC_CANONICAL_HOST

# Set up compilers
AC_PROG_CC
AC_PROG_CXX

AC_PROG_LIBTOOL


# Tweak compiler environments
if test ! -z "${enable_segfaults}" -a X"${enable_segfaults}" != X"no"; then
	# AC_DEFINE([NULL_CHECK_SEGFAULT], [], [Define to disable null pointer checks])
	CPPFLAGS="-DNULL_CHECK_SEGFAULT ${CPPFLAGS}"
fi

if [ -z "$CXXFLAGS" ]; then
	CXXFLAGS="$CFLAGS"
fi

if test -d "${srcdir}/.svn"; then
	AC_MSG_NOTICE([You seem to be building from a Subversion working directory, enabling extra stuff by default])
	IN_VCS=svn
	true "${enable_build_manual:=yes}"
	if ! echo "$CXXFLAGS" |grep "Wall" >/dev/null; then
		CXXFLAGS="$CXXFLAGS -Wall"
	fi
	if ! echo "$CXXFLAGS" |grep "Wextra" >/dev/null; then
		CXXFLAGS="$CXXFLAGS -Wextra"
	fi
	AC_DEFINE([SVN_SNAPSHOT], [], [Define this when building from Subversion])
else
	IN_VCS="no"
	true "${enable_build_manual:=no}"
fi
AM_CONDITIONAL([BUILDING_FROM_SVN],
	       [test X"${IN_VCS}" = Xsvn])

AC_MSG_CHECKING([whether to use OpenGL])
if test ! -z "${with_opengl}"; then
	if test X"${with_opengl}" = Xno; then
		AC_MSG_RESULT([no])
		USE_OPENGL=no
	else
		AC_MSG_RESULT([yes, in ${with_opengl}])
		CPPFLAGS="-I${with_opengl}/include ${CPPFLAGS}"
		LDFLAGS="-L${with_opengl}/lib ${CPPFLAGS}"
		USE_OPENGL=yes
	fi
else
	AC_MSG_RESULT([yes])
	USE_OPENGL=yes
fi

AC_MSG_CHECKING([for specified libbamboo-config])
BAMBOO_CONFIG=""
BAMBOO_PATH=""
if test -n "${with_bamboo_config}" -a "${with_bamboo_config}" != no; then
	AC_MSG_RESULT([yes, ${with_bamboo_config}])
	BAMBOO_CONFIG="${with_bamboo_config}"
else
	AC_MSG_RESULT([no])
	AC_MSG_CHECKING([for alternate Bamboo path])
	if test -n "${with_bamboo}" -a "${with_bamboo}" != no; then
		AC_MSG_RESULT([yes, ${with_bamboo}])
		BAMBOO_PATH="${with_bamboo}/bin"
	else
		AC_MSG_RESULT([no])
	fi
fi

AC_MSG_CHECKING([for alternate GTK path])
if test ! -z "${with_gtk}"; then
	AC_MSG_RESULT([yes, ${with_gtk}])
        if test -z "$PKG_CONFIG_PATH"; then
                export PKG_CONFIG_PATH="${with_gtk}/lib/pkgconfig"
        else
                export PKG_CONFIG_PATH="${with_gtk}/lib/pkgconfig:${PKG_CONFIG_PATH}"
        fi
else
	AC_MSG_RESULT([no])
fi


AC_MSG_CHECKING([for default log level])
if test ! -z "${with_default_log_level}"; then
	NEW_LOG_LEVEL=`echo "${with_default_log_level}" |tr [[:lower:]] [[:upper:]]`
	AC_DEFINE_UNQUOTED([DEFAULT_LOG_LEVEL], [LOG_${NEW_LOG_LEVEL}],
			   [Define this to define a default logging level at compile time.])
	AC_MSG_RESULT([yes, ${NEW_LOG_LEVEL}])
else
	AC_MSG_RESULT([no])
fi

AC_MSG_CHECKING([for freedesktop.org path])
if test ! -z "${with_xdg_path}"; then
  XDG_PATH="${with_xdg_path}";
else
  XDG_PATH="${datadir}"
fi
AC_MSG_RESULT([$XDG_PATH])
AC_SUBST([XDG_PATH])
AM_CONDITIONAL([UPDATE_XDG],
               [test ! -z "${enable_update_xdg}" -a X"${enable_update_xdg}" == Xyes])

if test ! -z "${enable_memory_debugging}" -a X"{$enable_memory_tracing}" != X"no"; then
	CPPFLAGS="-DMEM_DEBUG ${CPPFLAGS}"
	TRY_DMALLOC="yes"
	enable_debug="yes"
fi
if test \( ! -z "${enable_tracing}" -a X"{$enable_tracing}" != X"no" \) \
	-o \( ! -z "${enable_trace}" -a X"${enable_trace}" != X"no" \); then
	CPPFLAGS="-DTRACE ${CPPFLAGS}"
	enable_debug="yes"
fi
if ! test ! -z "${enable_debug}" -a X"${enable_debug}" != X"no"; then
	CPPFLAGS="-DRELEASE ${CPPFLAGS}"
fi

AC_MSG_NOTICE([Using pkg-config search path of ${PKG_CONFIG_PATH}])

# Set up programs
AC_PATH_PROG([M4], [m4])
AC_PATH_PROG([PERL], [perl], [false])
AC_PATH_PROG([PYTHON], [python])
AC_CHECK_PROG([XCF2PNG], [xcf2png], [xcf2png], [false])
AC_CHECK_PROG([DOXYGEN], [doxygen], [doxygen], [false])
AC_CHECK_PROG([RSYNC], [rsync], [rsync], [false])

PKG_PROG_PKG_CONFIG

# We use C++
AC_LANG(C++)

AC_MSG_CHECKING([if dmalloc is to be tried])
if test ! -z "${TRY_DMALLOC}" -a "${enable_dmalloc:-yes}" = "yes"; then
        AC_MSG_RESULT([yes])
	AC_CHECK_LIB([dmalloccxx], [dmalloc_free])
else
        AC_MSG_RESULT([no])
fi

AC_CHECK_HEADER([execinfo.h],
		AC_DEFINE([HAVE_EXECINFO_H], [], [Define this when execinfo.h is available]))
AC_CHECK_FUNC([backtrace],
	      AC_DEFINE([HAVE_BACKTRACE], [], [Define this if backtrace() is available]))

AC_CHECK_HEADER([zlib.h],,
		AC_MSG_ERROR([Could not find zlib.h; make sure zlib devel packages are installed]))
AC_CHECK_LIB([z], [gzopen],
	     [true],
	     AC_MSG_ERROR([Could not link against zlib; make sure zlib devel packages are installed.]))

AX_CXX_GCC_ABI_DEMANGLE

# Search for SGI STL extensions
AC_MSG_CHECKING([how to get SGI STL extensions])
STL_LOC=""
AC_COMPILE_IFELSE([
    AC_LANG_PROGRAM([#include <functional>
		     using std::compose1;],
		     [])],
    [STL_LOC="std"], [])
if test -z "${STL_LOC}"; then
AC_COMPILE_IFELSE([
    AC_LANG_PROGRAM([#include <ext/functional>
		     using __gnu_cxx::compose1;],
		     [])],
    [STL_LOC="ext_gnu_cxx"], [])
fi
case "${STL_LOC}" in
	std)
		AC_MSG_RESULT([std])
		AC_DEFINE([SGI_STL_IN_STD], [],
			  [Define this if SGI STL extensions are in std])
		;;
	ext_gnu_cxx)
		AC_MSG_RESULT([__gnu_cxx])
		AC_DEFINE([SGI_STL_IN_GNU_CXX], [],
			  [Define this if SGI STL extensions are in GNU ext headers])
		;;
	*)
		AC_MSG_ERROR([Cannot find SGI STL extensions.])
		;;
esac

# Search for C++ TR1
AC_MSG_CHECKING([for C++ TR1 type traits])
AC_COMPILE_IFELSE([
    AC_LANG_PROGRAM([#include <tr1/type_traits>
		     using std::tr1::is_integral;],
		     [])],
    [HAVE_CXX_TR1=yes], [])
if test X"$HAVE_CXX_TR1" = Xyes; then
	AC_MSG_RESULT([yes])
	AC_DEFINE([HAVE_CXX_TR1], [], [Define this if TR1 is available])
else
	AC_MSG_RESULT([no])
	AC_CHECK_HEADER([boost/type_traits.hpp], [],
			[AC_MSG_ERROR([either boost or G++ w/ TR1 is required])])
fi

if test "$USE_OPENGL" = "yes"; then
	AC_MSG_CHECKING([for gtkglext-1.0])
	if pkg-config --exists gtkglext-1.0; then
		AC_MSG_RESULT([yes])
		GTKGL_CPPFLAGS="`pkg-config --cflags gtkglext-1.0`"
		GTKGL_LIBS="`pkg-config --libs gtkglext-1.0`"
	else
		AC_MSG_RESULT([no])
		AC_MSG_WARN([gtkglext not found. Disabling OpenGL.])
		AC_MSG_NOTICE([If this is in error, try changing PKG_CONFIG_PATH.])
		USE_OPENGL=no
	fi
fi

##################################################
## BEGIN OpenGL detection
##################################################
CPPFLAGS_ogl_save="$CPPFLAGS"
CPPFLAGS="${GTKGL_CPPFLAGS} ${CPPFLAGS}"
LIBS_ogl_save="$LIBS"
LIBS="${GTKGL_LIBS} ${LIBS}"
if test "$USE_OPENGL" = "yes"; then
	AC_MSG_NOTICE([Checking for necessary OpenGL facilities...])
	AC_CHECK_HEADER([GL/gl.h],
			[HAVE_GL_H="yes"],
			[HAVE_GL_H="no"])
	if test "$HAVE_GL_H" != "yes"; then
		AC_MSG_WARN([OpenGL headers not found. Disablng OpenGL.])
		USE_OPENGL=no
	fi
fi

if test "$USE_OPENGL" = "yes"; then
	AC_CHECK_HEADER([GL/glu.h],
			[HAVE_GLU_H="yes"],
			[HAVE_GLU_H="no"])
	if test "$HAVE_GLU_H" != "yes"; then
		AC_MSG_WARN([GLU headers not found. Disablng OpenGL.])
		USE_OPENGL=no
	fi
fi

if test "$USE_OPENGL" = "yes"; then
	AC_CHECK_LIB([GL], [glBegin],
		     [HAVE_LIBGL="yes"],
		     [HAVE_LIBGL="no"])
	if test "$HAVE_LIBGL" != "yes"; then
		AC_MSG_WARN([OpenGL libraries not found. Disabling OpenGL.])
		USE_OPENGL=no
	fi
fi

GL_LIBS=""
if test "$USE_OPENGL" = "yes"; then
	AC_CHECK_LIB([GLU], [gluPerspective],
		     [HAVE_LIBGLU="yes"],
		     [HAVE_LIBGLU="no"])
	if test "$HAVE_LIBGLU" = "yes"; then
		GL_LIBS="-lGLU"
	else
		AC_MSG_WARN([GLU libraries not found. Disabling OpenGL.])
		USE_OPENGL=no
	fi
fi
AC_SUBST([GL_LIBS])
LIBS="${LIBS_ogl_save}"
CPPFLAGS="${CPPFLAGS_ogl_save}"
##################################################
## END OpenGL detection
##################################################

if test "$USE_OPENGL" = "yes" -a \( ! -z "${enable_test_programs}" -a X"${enable_test_programs}" != X"no" \); then
	AC_CHECK_HEADER([GL/glut.h],
			[HAVE_GLUT="yes"],
			[HAVE_GLUT="no"])
	if test "$HAVE_GLUT" = "yes"; then
		AC_CHECK_LIB([glut], [glutInit],
			     [HAVE_GLUT="yes"],
			     [HAVE_GLUT="no"],
			     [-lGLU -lGL])
	fi
fi

AM_CONDITIONAL([HAVE_GLUT], [test X"${HAVE_GLUT}" = Xyes])

if test "$USE_OPENGL" = "yes"; then
	AC_MSG_NOTICE([Found everything. OpenGL support enabled.])
fi

# Configure Bamboo
if test -z "$BAMBOO_CONFIG"; then
	AC_PATH_PROG([BAMBOO_CONFIG], libbamboo-config, "notfound",
		     [$BAMBOO_PATH:$PATH])
fi
BAMBOO_THREADS=none
if test -n "$BAMBOO_CONFIG" -a -x "$BAMBOO_CONFIG"; then
	# We have libbamboo-config
	# check for >= 2.0.96, to know about threading
	AC_MSG_CHECKING([if bamboo >= 2.0.96])
	if "$BAMBOO_CONFIG" --atleast-version 2.0.96; then
		AC_MSG_RESULT([yes])
		AC_MSG_CHECKING([bamboo threading mode])
		BAMBOO_THREADS=`"$BAMBOO_CONFIG" --threading-type`
		AC_MSG_RESULT([$BAMBOO_THREADS])
	else
		AC_MSG_RESULT([no, assuming no threading])
	fi
	AC_MSG_CHECKING([for bamboo xml document cloning support])
	if "$BAMBOO_CONFIG" --atleast-version 2.0.97; then
		AC_MSG_RESULT([yes])
		AC_DEFINE([BAMBOO_SUPPORTS_CLONING], [],
			  [Define this if BambooLib supports XML cloning])
	else
		AC_MSG_RESULT([no])
	fi
	BAMBOO_CFLAGS="`\"$BAMBOO_CONFIG\" --cflags`"
	BAMBOO_LIBS="`\"$BAMBOO_CONFIG\" --libs`"
else
	# Use pkgconfig-path
	OLD_PKG_PATH="$PKG_CONFIG_PATH"
	if test -n "$BAMBOO_PATH"; then
		export PKG_CONFIG_PATH="$BAMBOO_PATH:$PKG_CONFIG_PATH"
	fi
	PKG_CHECK_MODULES([BAMBOO], [libbamboo >= 2.0.3])
	export PKG_CONFIG_PATH="$OLD_PKG_PATH"
fi

if test -z "${enable_threading}" -o "${enable_threading}" != no; then
	case "$BAMBOO_THREADS" in
		pthreads) THREADING_ENABLED=yes ;;
		*) THREADING_ENABLED=no ;;
	esac
else
	THREADING_ENABLED=no
fi

# Check GTK things
if test X"$THREADING_ENABLED" = Xyes; then
	THREAD_LIBS="gthread-2.0"
fi
PKG_CHECK_MODULES([GLIB],
		  [glib-2.0 >= 2.4.0
		   gobject-2.0 >= 2.4.0
		   $THREAD_LIBS])
PKG_CHECK_MODULES([LIBXML], [libxml-2.0 >= 2.6.0])
PKG_CHECK_MODULES([SIGC], [sigc++-2.0])
if test ! X"${enable_gui}" = Xno; then
	MODULES="gtk+-2.0 >= 2.4.0 libglade-2.0 >= 2.4.0 $THREAD_LIBS"
	if test X"$USE_OPENGL" = Xyes; then
		MODULES="${MODULES} gtkglext-1.0 >= 1.0.0"
	fi
	PKG_CHECK_MODULES([GTK], [${MODULES}])
fi
if test ! -z "$DO_BUILD_TOOLS"; then
	AC_MSG_CHECKING([for sufficient glib for tools])
	if "${PKG_CONFIG}" --atleast-version=2.6.0 "glib-2.0"; then
		AC_MSG_RESULT([yes])
	else
		AC_MSG_RESULT([no, disabling tools])
		DO_BUILD_TOOLS=no
	fi
fi

if test X"$THREADING_ENABLED" = Xyes; then
	AC_DEFINE([HAVE_THREADING], [1], [Define this if threading is available])
fi
AM_CONDITIONAL([THREADING_ENABLED], [test X"$THREADING_ENABLED" = Xyes])

save_CPPFLAGS="${CPPFLAGS}"
CPPFLAGS="${LIBXML_CFLAGS} ${CPPFLAGS}"
AC_CHECK_TYPE([xmlSaveOption],
	      [AC_DEFINE([HAVE_XML_SAVE_OPTION], [], [Define this if xmlSaveOption is available])],
	      [], [#include <libxml/xmlsave.h>])
CPPFLAGS="${save_CPPFLAGS}"

CPPFLAGS="${BAMBOO_CFLAGS} ${CPPFLAGS}"

case "${host}" in
	*-apple-darwin*)
		MOD_LINK_EXTRA="-bundle"
		;;
esac
AC_SUBST([MOD_LINK_EXTRA])

# Add one more INCLUDE directory to point nicely
CPPFLAGS='-I$(top_srcdir)/src -I$(top_builddir)/src'" ${CPPFLAGS}"

if test X"${USE_OPENGL}" = Xyes; then 
	AC_DEFINE(USE_OPENGL, [], [Define this if OpenGL is to be used])
	AC_MSG_NOTICE([Building with OpenGL support])
fi
AM_CONDITIONAL([HAVE_OPENGL], [test X"${USE_OPENGL}" = Xyes])

if test \( X"${enable_netview}" = Xno \) -o \( "${USE_OPENGL}" = no \); then
	BUILD_NETVIEW=no
else
	AC_MSG_NOTICE([Building network topography viewer])
	BUILD_NETVIEW=yes
	AC_DEFINE([BUILD_TOPOGRAPHY], [], [Define this to enable topography code])
fi
AM_CONDITIONAL([BUILD_TOPOGRAPHY], [test X"${BUILD_NETVIEW}" = Xyes])

AC_MSG_CHECKING([for cppunit])
if "${PKG_CONFIG}" --exists cppunit; then
	AC_MSG_RESULT([yes])
	HAVE_CPPUNIT="yes"
	CPPUNIT_CPPFLAGS="`pkg-config --cflags cppunit`"
	CPPUNIT_LIBS="`pkg-config --libs cppunit`"
else
	AC_MSG_RESULT([not sure])
	AC_CHECK_PROG([CPPUNIT_CONFIG], [cppunit-config], [cppunit-config], [false])
	if test X"$CPPUNIT_CONFIG" = Xcppunit-config; then
		HAVE_CPPUNIT="yes"
		CPPUNIT_CPPFLAGS="`cppunit-config --cflags`"
		CPPUNIT_LIBS="`cppunit-config --libs`"
	else
		HAVE_CPPUNIT="no"
	fi
fi

if test X"$HAVE_CPPUNIT" = Xyes; then
	AC_MSG_CHECKING([for Qt])
	if "${PKG_CONFIG}" --exists qt; then
		AC_MSG_RESULT([qt])
		QT_PC=qt
		PKG_CHECK_MODULES([QT], [qt])
	elif "${PKG_CONFIG}" --exists qt-mt; then
		AC_MSG_RESULT([qt-mt])
		QT_PC=qt-mt
		PKG_CHECK_MODULES([QT], [qt-mt])
	else
	    AC_MSG_RESULT([no])
	    QT_PC=unavailable
	fi
	if test "$QT_PC" != unavailable; then
		AC_CHECK_LIB([qttestrunner], [_init],
			     [QT_LIB_PRESENT=yes], [],
			     ["$CPPUNIT_LIBS" "$QT_LIBS"])
		if test X"$QT_LIB_PRESENT" = Xyes; then
			AC_CHECK_HEADER([cppunit/ui/qt/QtTestRunner.h],
					[QT_HEADER_PRESENT=yes], [QT_HEADER_PRESENT=no])
			if test X"$QT_HEADER_PRESENT" = Xyes; then
				HAVE_QT_TEST_RUNNER=yes
				AC_MSG_NOTICE([Building Qt test runner support ])
				AC_DEFINE([HAVE_CPPUNIT_QT], [],
					  [Define this if the Qt test runner is available])
			else
				AC_MSG_NOTICE([Could not find Qt test headers, not building Qt support])
			fi
		else
			AC_MSG_NOTICE([Could not find libqttestrunner.so, not building Qt support])
		fi
	fi
fi
AM_CONDITIONAL([HAVE_CPPUNIT_QT], [test X"$HAVE_QT_TEST_RUNNER" = Xyes])

AC_SUBST([CPPUNIT_CPPFLAGS])
AC_SUBST([CPPUNIT_LIBS])
AM_CONDITIONAL([HAVE_CPPUNIT], [test X"$HAVE_CPPUNIT" = Xyes])

AC_MSG_CHECKING([whether to build the manual])
if test X"${enable_build_manual}" = X"yes"; then
	AC_MSG_RESULT([yes])
	DO_BUILD_MANUAL="yes"
	AC_MSG_NOTICE([I'm going to build documentation, but won't check for the])
	AC_MSG_NOTICE([necessary tools.  If documentation build fails, re-run])
	AC_MSG_NOTICE([configure with --disable-build-manual to disable DocBook builds])
else
	AC_MSG_RESULT([no])
	DO_BUILD_MANUAL="no"
fi
AC_MSG_CHECKING([whether to integrate the manual])
echo "${enable_manual:=no}" >/dev/null
if test X"${enable_manual}" = Xyes; then
	AC_MSG_RESULT([yes])
	DO_INSTALL_MANUAL=yes
else
	AC_MSG_RESULT([no])
	DO_INSTALL_MANUAL=no
fi

AM_CONDITIONAL([BUILD_IMAGES],
	       [test X"${DO_BUILD_IMAGES}" = X"yes"])
AM_CONDITIONAL([BUILD_MANUAL],
	       [test X"${DO_BUILD_MANUAL}" = X"yes"])
AM_CONDITIONAL([DO_MANUAL],
	       [test X"${DO_INSTALL_MANUAL}" = X"yes"])

if test X"${DO_INSTALL_MANUAL}" = Xyes; then
	AC_CHECK_PROG([SK_UPDATE], scrollkeeper-update, scrollkeeper-update, false)
	AC_CHECK_PROG([SK_PREINST], scrollkeeper-preinstall, scrollkeeper-preinstall, false)
	AC_CHECK_PROG([SK_CONFIG], scrollkeeper-config, scrollkeeper-config, false)
	AC_MSG_CHECKING([for OMF directory])
	omfdir=`$SK_CONFIG --omfdir`
	AC_MSG_RESULT($omfdir)
else
	omfdir="$docdir"
fi
AC_SUBST([omfdir])

AC_SUBST([SED])

if test -z "${datarootdir}"; then
	datarootdir="${datadir}"
	AC_SUBST([datarootdir])
fi

if test -z "${docdir}"; then
	# be compatible with old make's
	docdir='${datarootdir}/doc/${PACKAGE}'
	dvidir='${docdir}'
	pdfdir='${docdir}'
	psdir='${docdir}'
	htmldir='${docdir}'
	AC_SUBST([docdir])
	AC_SUBST([dvidir])
	AC_SUBST([pdfdir])
	AC_SUBST([psdir])
	AC_SUBST([htmldir])
fi

AC_MSG_CHECKING([whether to use -ffast-math])
if test X"$GXX" = Xyes; then
	if ! echo "$CXXFLAGS" |grep fast-math >/dev/null; then
		AC_MSG_RESULT([yes])
		CXXFLAGS="${CXXFLAGS} -ffast-math"
	else
		AC_MSG_RESULT([no, -ffast-math or -fno-fast-math already specified])
	fi
else
	AC_MSG_RESULT([no])
fi

AM_CONDITIONAL([BUILD_TOOLS],
	       [test X"${DO_BUILD_TOOLS}" = Xyes])

if test -n "${enable_trace_functions}"; then
	AC_MSG_NOTICE([Enabling function tracing])
	CXXFLAGS="${CXXFLAGS} -finstrument-functions"
	LIBS="${LIBS} "'-L${top_builddir}/ftrace -lftrace'
	AC_DEFINE([TRACE_FUNCTIONS], [], [Define to include function tracing support])
else
	AC_MSG_NOTICE([Function tracing disabled])
fi
AM_CONDITIONAL([TRACE_FUNCTIONS],
	       [test -n "${enable_trace_functions}"])

AC_OUTPUT

cat <<EOF
Summary:
  Using Bamboo cflags: $BAMBOO_CFLAGS
  Using Bamboo libs: $BAMBOO_LIBS
  Using GTK cflags: $GTK_CFLAGS
  Using GTK libs: $GTK_LIBS
  Bamboo threading mode: $BAMBOO_THREADS
  Threading enabled: $THREADING_ENABLED
  CFLAGS: $CFLAGS
  CXXFLAGS: $CXXFLAGS
  CPPFLAGS: $CPPFLAGS
EOF
if test X"$BUILD_NETVIEW" = Xyes; then
        echo "  Building topography code"
else
        echo "  Not building topography code"
fi
if test X"$DO_BUILD_MANUAL" = Xyes; then
	echo "  Including rules to rebuild the manual (--disable-build-manual to disable)"
	echo "    Note that this requires a lot of DocBook XML stuff and tools."
else
	echo "  Not including manual rebuild rules (--enable-build-manual to enable)"
fi
if test X"$DO_INSTALL_MANUAL" = Xyes; then
	echo "  Processing the manual directory (--disable-manual to disable)"
	echo "    The manual will be included in make install and make dist.  If the"
	echo "    manual rebuild rules are not included, this will cause an error if"
	echo "    the manual output files are not found.  Distribution tarballs include"
	echo "    copies of the manual output files, so this won't be a problem unless"
	echo "    you are building from a Subversion checkout."
else
	echo "  Not processing the manual directory (--enable-manual to enable)"
	echo "    This means that make install will not install the manual"
fi