#
#  Top-level configure.in file for Evolution Brutus Connector.
#  Copyright (C) 2005-2008 OMC Denmark ApS
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
#  MA 02111-1307 USA

AC_INIT([evolution-brutus],[1.2.35],[bugs@42tools.com])

AC_COPYRIGHT(Copyright (C) 2008 OMC Denmark ApS)

AC_PREREQ(2.59)

AC_CONFIG_SRCDIR(README)
AM_INIT_AUTOMAKE(AC_PACKAGE_NAME, AC_PACKAGE_VERSION)

dnl Required by autoconf 2.60
AC_SUBST(datarootdir)

EVOLUTION_BRUTUS_NAME=AC_PACKAGE_NAME
AC_SUBST(EVOLUTION_BRUTUS_NAME)

EVOLUTION_BRUTUS_VERSION=AC_PACKAGE_VERSION
AC_SUBST(EVOLUTION_BRUTUS_VERSION)

AC_GNU_SOURCE
AM_CONFIG_HEADER(config.h)

LIBBRUTUS_CURRENT=1
LIBBRUTUS_REVISION=0
LIBBRUTUS_AGE=0
AC_SUBST(LIBBRUTUS_CURRENT)
AC_SUBST(LIBBRUTUS_REVISION)
AC_SUBST(LIBBRUTUS_AGE)

BRUTUSD_VERSION=1.0
AC_SUBST(BRUTUSD_VERSION)

BRUTUS_LOGD_NAME=brutus-logd
AC_SUBST(BRUTUS_LOGD_NAME)

BRUTUS_LOGD_VERSION=1.0
AC_SUBST(BRUTUS_LOGD_VERSION)

LIBBRUTUS_LOGD_CURRENT=1
LIBBRUTUS_LOGD_REVISION=0
LIBBRUTUS_LOGD_AGE=0
AC_SUBST(LIBBRUTUS_LOGD_CURRENT)
AC_SUBST(LIBBRUTUS_LOGD_REVISION)
AC_SUBST(LIBBRUTUS_LOGD_AGE)

dnl Brutus IANA port
AC_DEFINE([BRUTUS_DEFAULT_PORT], [2003], [Default Brutus Server port])
AC_DEFINE([BRUTUS_DEFAULT_PORT_STR], ["2003"], [Default Brutus Server port (stringified)])

dnl
dnl Configure options
dnl
AC_ARG_ENABLE(static,
	      [AS_HELP_STRING([--enable-static[[[[=no/yes]]]]], [Enable static linking if possible [default=no]])],
	      [],
	      enable_static=no)
if test "x$enable_static" = "xyes"; then
	msg_static=yes
else
	msg_static=no
fi
AM_CONDITIONAL([BRUTUS_STATIC], test x$enable_static = xyes)

AC_ARG_ENABLE(brutus-devel,
	      [AS_HELP_STRING([--enable-brutus-devel[[[[=no/yes]]]]], [Install development files [default=no]])],
	      [],
	      enable_brutus_devel=no)
if test "x$enable_brutus_devel" = "xyes"; then
	AC_DEFINE([BRUTUS_DEVEL], [1], [Define if you want to include header and IDL files when installing])
	msg_brutus_devel=yes
else
	msg_brutus_devel=no
fi
AM_CONDITIONAL(BRUTUS_DEVEL, test x$enable_brutus_devel = xyes)

AC_ARG_ENABLE(brutus-debug,
	      [AS_HELP_STRING([--enable-brutus-debug[[[[=no/yes]]]]], [Enable Brutus debugging [default=no]])],
	      [],
	      enable_brutus_debug=no)
if test "x$enable_brutus_debug" = "xyes"; then
	AC_DEFINE([BRUTUS_DEBUG], [1], [Define if you want to make a debug enabled build])
	msg_brutus_debug=yes
else
	msg_brutus_debug=no
fi
AM_CONDITIONAL([BRUTUS_DEBUG], test x$enable_brutus_debug = xyes)

AC_ARG_ENABLE(brutus-spy,
	      [AS_HELP_STRING([--enable-brutus-spy[[[[=no/yes]]]]], [Enable MAPI inspection [default=no]])],
	      [],
	      enable_brutus_spy=no)
if test "x$enable_brutus_spy" = "xyes"; then
	AC_DEFINE([BRUTUS_SPY], [1], [Define if you want to be able to inspect and modify MAPI properties and listen on MAPI notifications])
	msg_brutus_spy=yes
else
	msg_brutus_spy=no
fi
AM_CONDITIONAL([BRUTUS_SPY], test x$enable_brutus_spy = xyes)

AC_ARG_ENABLE(brutus-dist,
	      [AS_HELP_STRING([--enable-brutus-dist[[[[=no/yes]]]]], [Is this a "make dist-<PACKAGE MANAGER>" attempt? [default=no]])],
	      [],
	      ,enable_brutus_dist=no)

BRUTUS_CFLAGS="-Werror -Werror-implicit-function-declaration -Wundef -Wbad-function-cast -Wcast-align -Wmissing-declarations -std=gnu89 -D_REENTRANT"
if test "x$enable_brutus_dist" = "xyes"; then
	msg_brutus_dist=yes
else
	msg_brutus_dist=no
	if test "x$enable_brutus_debug" = "xyes"; then
		BRUTUS_CFLAGS="$BRUTUS_CFLAGS -DG_ENABLE_DEBUG -ggdb -O0"
	else
		BRUTUS_CFLAGS="$BRUTUS_CFLAGS -DG_DISABLE_ASSERT -DG_DISABLE_CHECKS -O2"
	fi
fi 

dnl
dnl Which Linux distribution?
dnl
AX_BRUTUS_CHECK_PLATFORM()

dnl
dnl Adapt to different Linux distributions
dnl
AX_BRUTUS_PLATFORM_ADAPT()

dnl
dnl Program availability checks
dnl
AC_CHECK_PROG(HAVE_INTLTOOL_UPDATE, [intltool-update], yes, no)
if test "x$HAVE_INTLTOOL_UPDATE" = "xno"; then
   AC_MSG_ERROR([[You need the intltool-update(8) program to build evolution-brutus]])
fi

AC_CHECK_PROG(HAVE_MSGCONV, [msgconv], yes, no)
if test "x$HAVE_MSGCONV" = "xno"; then
   AC_MSG_ERROR([[You need the msgconv(1) program to build evolution-brutus]])
fi

AC_CHECK_PROG(HAVE_MSGFMT, [msgfmt], yes, no)
if test "x$HAVE_MSGFMT" = "xno"; then
   AC_MSG_ERROR([[You need the msgfmt(1) program to build evolution-brutus]])
fi

AC_CHECK_PROG(HAVE_CUT, [cut], yes, no)
if test "x$HAVE_CUT" = "xno"; then
   AC_MSG_ERROR([[You need the cut(1) program to build evolution-brutus]])
fi

AC_CHECK_PROG(HAVE_WGET, [wget], yes, no)
if test "x$HAVE_WGET" = "xno"; then
   AC_MSG_ERROR([[You need the wget(1) program to build evolution-brutus]])
fi

AC_CHECK_PROG(HAVE_SED, [sed], yes, no)
if test "x$HAVE_SED" = "xno"; then
   AC_MSG_ERROR([[You need the sed(1) program to build evolution-brutus]])
fi

AC_CHECK_PROG(HAVE_BASENAME, [basename], yes, no)
if test "x$HAVE_BASENAME" = "xno"; then
   AC_MSG_ERROR([[You need the basename(1) program to build evolution-brutus]])
fi

AC_CHECK_PROG(HAVE_DIRNAME, [dirname], yes, no)
if test "x$HAVE_DIRNAME" = "xno"; then
   AC_MSG_ERROR([[You need the dirname(1) program to build evolution-brutus]])
fi

AC_CHECK_PROG(HAVE_FIND, [find], yes, no)
if test "x$HAVE_FIND" = "xno"; then
   AC_MSG_ERROR([[You need the find(1) program to build evolution-brutus 99]])
fi

AC_CHECK_PROG(HAVE_IOR_DECODE_2, [ior-decode-2], yes, no)
if test "x$HAVE_IOR_DECODE_2" = "xno"; then
   AC_MSG_WARN([[You should have the ior-decode-2(2) program to for better debug output]])
else
   AC_DEFINE([HAVE_IOR_DECODE_2], [1], [We get better debug output if ior-decode-2 exists])
fi

AC_CHECK_PROG(HAVE_RPMBUILD, [rpmbuild], yes, no)
if test "x$HAVE_RPMBUILD" = "xno"; then
   AM_CONDITIONAL(BRUTUS_RPMBUILD, false)
   AC_MSG_WARN([[You will need the rpmbuild(8) program to build evolution-brutus RPMs]])
else
   AM_CONDITIONAL(BRUTUS_RPMBUILD, true)
fi

AC_CHECK_PROG(HAVE_RPMDEV_SETUPTREE, [rpmdev-setuptree], yes, no)
if test "x$HAVE_RPMDEV_SETUPTREE" = "xno"; then
   AM_CONDITIONAL(BRUTUS_RPMDEV_SETUPTREE, false)
   AC_MSG_WARN([[You should have the rpmdev-setuptree program if building evolution-brutus RPMs]])
else
   AM_CONDITIONAL(BRUTUS_RPMDEV_SETUPTREE, true)
fi

AC_CHECK_PROG(HAVE_RPMDEV_WIPETREE, [rpmdev-wipetree], yes, no)
if test "x$HAVE_RPMDEV_WIPETREE" = "xno"; then
   AM_CONDITIONAL(BRUTUS_RPMDEV_WIPETREE, false)
   AC_MSG_WARN([[You should have the rpmdev-wipetree program if building evolution-brutus RPMs]])
else
   AM_CONDITIONAL(BRUTUS_RPMDEV_WIPETREE, true)
fi

AC_CHECK_PROG(HAVE_BUILD, [build], yes, no)
if test "x$HAVE_BUILD" = "xno"; then
   AC_MSG_WARN([[You should have the build program if building evolution-brutus RPMs on SUSE]])
fi

AC_CHECK_PROG(HAVE_FAKEROOT, [fakeroot], yes, no)
if test "x$HAVE_FAKEROOT" = "xno"; then
   AC_MSG_WARN([[You will need the fakeroot(1) program to build evolution-brutus DEBs]])
fi

AC_CHECK_PROG(HAVE_DEBHELPER, [dh_builddeb], yes, no)
if test "x$HAVE_DEBHELPER" = "xno"; then
   AC_MSG_WARN([[You will need the debhelper(7) programs to build brutus-keyring DEBs]])
fi

AC_CHECK_PROG(HAVE_DPKG_BUILDPACKAGE, [dpkg-buildpackage], yes, no)
if test "x$HAVE_DPKG_BUILDPACKAGE" = "xno"; then
   AM_CONDITIONAL(BRUTUS_DPKG_BUILDPACKAGE, false)
   AC_MSG_WARN([[You will need the dpkg-dev package to build brutus-keyring DEBs]])
else
   AM_CONDITIONAL(BRUTUS_DPKG_BUILDPACKAGE, true)
fi

AC_CHECK_PROG(HAVE_WAND_CONFIG, [Wand-config], yes, no)
if test "x$HAVE_AND_CONFIG" = "xno"; then
   AC_MSG_WARN([[You will need the Wand-config(1) program to build evolution-brutus DEBs]])
fi

AC_CHECK_PROG(HAVE_DPKG_BUILDPACKAGE, [dpkg-buildpackage], yes, no)
if test "x$HAVE_DPKG_BUILDPACKAGE" = "xno"; then
   AM_CONDITIONAL(BRUTUS_DPKG_BUILDPACKAGE, false)
   AC_MSG_WARN([[You will need the dpkg-buildpackage(8) program to build evolution-brutus DEBs]])
else
   AM_CONDITIONAL(BRUTUS_DPKG_BUILDPACKAGE, true)
fi

dnl
dnl Version checks
dnl

dnl pkgconfig requirement
PKGCONFIG_REQUIRED=0.20
AC_SUBST(PKGCONFIG_REQUIRED)

dnl Brutus Keyring
BRUTUS_KEYRING_REQUIRED=0.9
AC_SUBST(BRUTUS_KEYRING_REQUIRED)
BRUTUS_KEYRING_API_VERSION=1.0
AC_SUBST(BRUTUS_KEYRING_API_VERSION)
BRUTUS_KEYRING=libBrutusKeyringd-1.0

AC_MSG_CHECKING([Brutus Keyring version >= $BRUTUS_KEYRING_REQUIRED])
BRUTUS_KEYRING_SUPPORTED="`pkg-config --exists 'libBrutusKeyringd-1.0 >= 0.9' ; echo $?`"
if test "x$BRUTUS_KEYRING_SUPPORTED" = "x0"; then
   brutus_keyring_version=`pkg-config --modversion $BRUTUS_KEYRING`
   AC_MSG_RESULT([yes (version $brutus_keyring_version)])
else
   AC_MSG_ERROR([Brutus Keyring development libraries not present. You need at least version $BRUTUS_KEYRING_REQUIRED])
fi
BRUTUS_KEYRING_INCLUDEDIR="`pkg-config --variable=privincludedir $BRUTUS_KEYRING`"

dnl Detect Evolution development files
EDS_API_VERSION=1.2
AC_SUBST(EDS_API_VERSION)

AC_MSG_CHECKING(Evolution version)
STANDARD_EVOLUTION_SHELL_PC_FILE="`pkg-config evolution-shell ; echo $?`"
if test "x$STANDARD_EVOLUTION_SHELL_PC_FILE" = "x0"; then
   EVOLUTION_VERSION=`pkg-config --variable=execversion evolution-shell`
   EVOLUTION_NO_VERSION_POSTFIX=`pkg-config --exists 'evolution-shell >= 2.12' ; echo $?`
else
   EVOLUTION_PKGCONFIG_PRESENT=`find $PKGCONFIG_DIR -name 'evolution-shell-*.pc' -print0`
   if test -z "$EVOLUTION_PKGCONFIG_PRESENT"; then
      AC_MSG_ERROR([[Evolution development libraries not present in $PKGCONFIG_DIR]])
   fi
   EVOLUTION_PKGCONFIG_VERSION=`basename $(basename $(find $PKGCONFIG_DIR -name 'evolution-shell-*.pc') | cut -c 17-) .pc`
   EVOLUTION_VERSION=`pkg-config --variable=execversion evolution-shell-$EVOLUTION_PKGCONFIG_VERSION`
   EVOLUTION_NO_VERSION_POSTFIX=`pkg-config --exists 'evolution-shell-$EVOLUTION_PKGCONFIG_VERSION >= 2.12' ; echo $?`
fi
dnl This will work for versions earlier than 2.10
if test -z "$EVOLUTION_VERSION"; then
	EVOLUTION_VERSION=`evolution --version | cut -c 17,18,19 2>/dev/null`
	if test "x$EVOLUTION_VERSION" = "x2.7"; then
		EVOLUTION_VERSION=2.8
	fi
	if test "x$EVOLUTION_VERSION" = "x2.9"; then
		EVOLUTION_VERSION=2.10
	fi
fi
AC_SUBST(EVOLUTION_VERSION)
AC_MSG_RESULT($EVOLUTION_VERSION)

AC_MSG_CHECKING(Evolution Data Server version)
EDS_BASE_VERSION=`pkg-config --variable=execversion evolution-data-server-$EDS_API_VERSION`
if test -z "$EDS_BASE_VERSION"; then
	AC_MSG_ERROR([Evolution Data Server development libraries not present. You need at least version $EDS_API_VERSION])
fi
AC_SUBST(EDS_BASE_VERSION)
AC_MSG_RESULT($EDS_BASE_VERSION)

dnl minimum required EDS version
EDS_BASE_VERSION_REQUIRED=1.6
AC_SUBST(EDS_BASE_VERSION_REQUIRED)

dnl
dnl for BrutusCheck servant
dnl 
if test "x$EVOLUTION_NO_VERSION_POSTFIX" = "x0"; then
	AC_DEFINE_UNQUOTED([EVO_PATHNAME], ["/usr/bin/evolution"], [Full path to Evolution executable])
else
	if test "$brutus_target" = "OpenSUSE_10_2"; then
	   	AC_DEFINE_UNQUOTED([EVO_PATHNAME], ["/opt/gnome/bin/evolution-$EVOLUTION_VERSION"], [Full path to Evolution executable])
	else
		AC_DEFINE_UNQUOTED([EVO_PATHNAME], ["/usr/bin/evolution-$EVOLUTION_VERSION"], [Full path to Evolution executable])
	fi
fi

dnl
dnl enable e-d-s version dependant compilation
dnl
if test "x$EDS_BASE_VERSION" = "x1.4"; then
   AC_DEFINE([EDS_1_4], [1], [Build against EDS Version 1.4])
   AC_DEFINE([EDS_EPOCH], [14], [To enable numerical EDS Version comparisons])
fi
if test "x$EDS_BASE_VERSION" = "x1.6"; then
   AC_DEFINE([EDS_1_6], [1], [Build against EDS Version 1.6])
   AC_DEFINE([EDS_EPOCH], [16], [To enable numerical EDS Version comparisons])
fi
if test "x$EDS_BASE_VERSION" = "x1.8"; then
   AC_DEFINE([EDS_1_8], [1], [Build against EDS Version 1.8])
   AC_DEFINE([EDS_EPOCH], [18], [To enable numerical EDS Version comparisons])
fi
if test "x$EDS_BASE_VERSION" = "x1.10"; then
   AC_DEFINE([EDS_1_10], [1], [Build against EDS Version 1.10])
   AC_DEFINE([EDS_EPOCH], [110], [To enable numerical EDS Version comparisons])
fi
if test "x$EDS_BASE_VERSION" = "x1.12"; then
   AC_DEFINE([EDS_1_12], [1], [Build against EDS Version 1.12])
   AC_DEFINE([EDS_EPOCH], [112], [To enable numerical EDS Version comparisons])
fi
if test "x$EDS_BASE_VERSION" = "x2.22"; then
   AC_DEFINE([EDS_2_22], [1], [Build against EDS Version 2.22])
   AC_DEFINE([EDS_EPOCH], [222], [To enable numerical EDS Version comparisons])
fi
if test "x$EDS_BASE_VERSION" = "x2.24"; then
   AC_DEFINE([EDS_2_24], [1], [Build against EDS Version 2.24])
   AC_DEFINE([EDS_EPOCH], [224], [To enable numerical EDS Version comparisons])
fi
if test "x$EDS_BASE_VERSION" = "x2.26"; then
   AC_DEFINE([EDS_2_26], [1], [Build against EDS Version 2.26])
   AC_DEFINE([EDS_EPOCH], [226], [To enable numerical EDS Version comparisons])
fi
case $EDS_BASE_VERSION in
     1.4|1.6|1.8|1.10|1.12|2.22|2.24|2.26)
     ;;
     *)
	AC_MSG_ERROR([Unsupported version of Evolution Data Server. Please report this to $PACKAGE_BUGREPORT])
	;;
esac

dnl Initialize maintainer mode
AM_MAINTAINER_MODE

AC_PROG_CC
AC_HEADER_STDC
AC_PROG_INSTALL
AC_PROG_LN_S
AC_PROG_MAKE_SET

dnl Initialize libtool
AM_DISABLE_STATIC
AC_LIBTOOL_WIN32_DLL
AM_PROG_LIBTOOL

dnl
dnl Check for Win32
dnl

AC_MSG_CHECKING([for Win32])
case "$host" in
*-mingw*)
    os_win32=yes
    NO_UNDEFINED='-no-undefined'
    ;;
*)  os_win32=no
    NO_UNDEFINED=''
    ;;
esac
AC_MSG_RESULT([$os_win32])
AM_CONDITIONAL(OS_WIN32, [test $os_win32 = yes])
AC_SUBST(NO_UNDEFINED)

dnl
dnl i18n
dnl
AC_PROG_INTLTOOL([0.30])

INTLTOOL_REQUIRED=0.30
AC_SUBST(INTLTOOL_REQUIRED)

GETTEXT_PACKAGE=evolution-brutus-$EVOLUTION_VERSION
AC_SUBST(GETTEXT_PACKAGE)
AC_DEFINE_UNQUOTED([GETTEXT_PACKAGE], ["$GETTEXT_PACKAGE"], [Package name for gettext])

ALL_LINGUAS="da de sv"
AM_GLIB_GNU_GETTEXT

localedir='$(prefix)/$(DATADIRNAME)/locale'
AC_SUBST(localedir)

dnl
dnl CFLAGS, LIBS and stuff
dnl

dnl http://bugzilla.gnome.org/show_bug.cgi?id=516408
AC_DEFINE(HANDLE_LIBICAL_MEMORY, 1, [Define it so memory returned by libical is free'ed properly])

dnl Utility macro to set compiler flags for a specific lib.
dnl  BRUTUS_SET_COMPILE_FLAGS(VAR-PREFIX, DEPS, EXTRA-CFLAGS, EXTRA-LIBS)
AC_DEFUN([BRUTUS_SET_COMPILE_FLAGS], [
	PKG_CHECK_MODULES([$1], [$2])
	$1_CFLAGS="[$]$1_CFLAGS $3"
	$1_LIBS="[$]$1_LIBS $4"
])

dnl CORBA requirements
ORBIT2_REQUIRED=2.14.1
AC_SUBST(ORBIT2_REQUIRED)
ORBIT2=ORBit-2.0
AC_SUBST(ORBIT2)
orbit2_timeout_msg=""
AC_MSG_CHECKING([[Checking for ORBit timeout support]])
ORBIT2_TIMEOUT_SUPPORTED="`pkg-config --exists 'ORBit-2.0 >= 2.14.4' ; echo $?`"
if test "x$ORBIT2_TIMEOUT_SUPPORTED" = "x0"; then
   ORBIT2_TIMEOUT_NG_SUPPORTED="`pkg-config --exists 'ORBit-2.0 >= 2.14.8' ; echo $?`"
   if test "x$ORBIT2_TIMEOUT_NG_SUPPORTED" = "x0"; then
      AC_DEFINE([HAVE_ORBIT2_TIMEOUT_NG], [1], [ORBit2 supports CORBA timeout exceptions (in milliseconds)])
      orbit2_timeout_msg="yes, ORBit2 supports --GIOPTimeoutMSEC"
   else
      AC_DEFINE([HAVE_ORBIT2_TIMEOUT], [1], [ORBit2 supports CORBA timeout exceptions])
      orbit2_timeout_msg="yes, ORBit2 supports --GIOPTimeoutLimit"
   fi
   AC_MSG_RESULT($orbit2_timeout_msg)
else
   AC_MSG_RESULT("no")
fi

LIBIDL_REQUIRED=0.8.5
AC_SUBST(LIBIDL_REQUIRED)
LIBIDL=libIDL-2.0
AC_SUBST(LIBIDL)

dnl brutus-query-password
GTK_CFLAGS=`pkg-config --cflags --libs gtk+-2.0 ORBit-2.0`
AC_SUBST(GTK_CFLAGS)

FULL_GNOME_DEPS="gtk+-2.0 $ORBIT2 >= $ORBIT2_REQUIRED $LIBIDL >= $LIBIDL_REQUIRED"
BRUTUS_SET_COMPILE_FLAGS(GNOME_FULL, $FULL_GNOME_DEPS)
AC_SUBST(GNOME_FULL_CFLAGS)
AC_SUBST(GNOME_FULL_LIBS)

AM_PATH_GLIB_2_0
AM_PATH_ORBIT2($ORBIT2_REQUIRED)
AC_PATH_PROG(GCONFTOOL, gconftool-2, no)
AM_GCONF_SOURCE_2

GNOME_COMPILE_WARNINGS(maximum)

CFLAGS="-I$BRUTUS_KEYRING_INCLUDEDIR $GNOME_FULL_CFLAGS $WARN_CFLAGS $CFLAGS $BRUTUS_CFLAGS -I/usr/include/ImageMagick -I/usr/include/evolution-data-server-$EDS_BASE_VERSION"
AC_SUBST(CFLAGS)

LDFLAGS=""
if test "$brutus_target" = "OpenSUSE_10_2"; then
	CFLAGS="-I/opt/gnome/include $CFLAGS $RPM_OPT_FLAGS"
	LDFLAGS="-L/opt/gnome/lib -L/opt/gnome/lib/glib-2.0"
fi
if test "$brutus_target" = "OpenSUSE_10_3"; then
	CFLAGS="-I/opt/gnome/include $CFLAGS $RPM_OPT_FLAGS"
	LDFLAGS="-L/opt/gnome/lib -L/opt/gnome/lib/glib-2.0"
fi

AC_CHECK_HEADERS([orbit/orbit.h], [], [AC_MSG_ERROR([ development header not installed])],
[[#ifdef HAVE_ORBIT_ORBIT_H
#include <orbit/orbit.h>
#endif
]])
AC_CHECK_HEADERS([orbit/orbit-types.h], [], [AC_MSG_ERROR([ development header not installed])],
[[#ifdef HAVE_ORBIT_ORBIT_TYPES_H
#include <orbit/orbit-types.h>
#endif
]])
AC_CHECK_HEADERS([orbit/orb-core/orbit-interface.h], [], [AC_MSG_ERROR([ development header not installed])],
[[#ifdef HAVE_ORBIT_ORBIT_CORE_ORBIT_INTERFACE_H
#include <orbit/orb-core/orbit-interface.h>
#endif
]])
AC_CHECK_LIB([ORBit-2], [main], [], [AC_MSG_ERROR([ library not installed])])
AC_CHECK_HEADERS([glib-2.0/glib.h], [], [AC_MSG_ERROR([ development header not installed])],
[[#ifdef HAVE_GLIB_2_0_GLIB_H
#include <glib-2.0/glib.h>
#endif
]])
AC_CHECK_LIB([glib-2.0], [main], [], [AC_MSG_ERROR([ library not installed])])

dnl Check for OSSP UUID requirements
AC_CHECK_LIB(nsl, gethostname)
if test ".`echo $LIBS | grep nsl`" = .; then
    AC_CHECK_LIB(nsl, gethostbyname)
fi
AC_CHECK_LIB(socket, accept)
AC_CHECK_HEADERS([sys/time.h sys/types.h sys/param.h sys/ioctl.h sys/socket.h sys/sockio.h], [], [])
AC_CHECK_HEADERS([net/if.h net/if_dl.h net/if_arp.h], [], [])
AC_CHECK_HEADERS([netinet/in.h], [], [])
AC_CHECK_HEADERS([arpa/inet.h], [], [])
AC_CHECK_HEADERS([netdb.h ifaddrs.h], [], [])
AC_CHECK_FUNCS(getifaddrs nanosleep)

dnl ImageMagick requirements
AC_CHECK_HEADER([wand/magick-wand.h], [], [AC_MSG_ERROR([ development header not installed])],
[[#ifdef HAVE_WAND_MAGICK_WAND_H
#include <wand/magick-wand.h>
#endif
]])
BRUTUS_IMAGEMAGICK_LDFLAGS=`Wand-config --ldflags`
BRUTUS_IMAGEMAGICK_LIBS=`Wand-config --libs`
AC_SUBST(BRUTUS_IMAGEMAGICK_LDFLAGS)
AC_SUBST(BRUTUS_IMAGEMAGICK_LIBS)

if test "x$enable_brutus_debug" = "xyes"; then
	LDFLAGS="-rdynamic $LDFLAGS"
fi
LDFLAGS="-pthread $LDFLAGS"
AC_SUBST(LDFLAGS)

AC_DEFINE([G_DISABLE_DEPRECATED],         [1], [No deprecated glib functions])
AC_DEFINE([GDK_DISABLE_DEPRECATED],       [1], [No deprecated gdk functions])
AC_DEFINE([GTK_DISABLE_DEPRECATED],       [1], [No deprecated gtk functions])
AC_DEFINE([GNOME_DISABLE_DEPRECATED],     [1], [No deprecated gnome functions])
AC_DEFINE([BONOBO_DISABLE_DEPRECATED],    [1], [No deprecated bonobo functions])
AC_DEFINE([BONOBO_UI_DISABLE_DEPRECATED], [1], [No deprecated bonoboui functions])
AC_DEFINE([GCONF_DISABLE_DEPRECATED],     [1], [No deprecated gconf functions])
AC_DEFINE([LIBGLADE_DISABLE_DEPRECATED],  [1], [No deprecated libglade functions])

dnl orbit-idl-2 compile flags
BRUTUS_orbit_idl_flags="--showcpperrors --onlytop --headerguardprefix=_BRUTUS_"
AC_SUBST(BRUTUS_orbit_idl_flags)

dnl
dnl Brutus places
dnl
BRUTUS_top_dir="`pwd`"
AC_SUBST(BRUTUS_top_dir)

AC_DEFINE_UNQUOTED([LORICA_DEFAULT_IOR_FILE], ["/var/cache/lorica/lorica.ior"], [Default path to Lorica IOR file])

LORICA_idl_svn_src="http://svn.42tools.net/repos/lorica/trunk"
AC_SUBST(LORICA_idl_svn_src)

BRUTUS_idl_svn_src="http://svn.42tools.net/repos/brutus-server/trunk/brutus_loader/idl"
AC_SUBST(BRUTUS_idl_svn_src)

BRUTUS_idl_dir="$BRUTUS_top_dir/idl"
AC_SUBST(BRUTUS_idl_dir)

BRUTUS_idl_output_dir="$BRUTUS_top_dir/idl_output"
AC_SUBST(BRUTUS_idl_output_dir)

BRUTUS_servant_impl_dir="$BRUTUS_top_dir/servant_impl"
AC_SUBST(BRUTUS_servant_impl_dir)

BRUTUS_idl_install_subdir="idl/brutus"
AC_SUBST(BRUTUS_idl_install_subdir)

dnl
dnl Includes
dnl
ORBIT_includedir="`pkg-config --variable=includedir ORBit-2.0`/orbit-2.0"
AC_SUBST(ORBIT_includedir)

GLIB_includedir="`pkg-config --variable=includedir glib-2.0`/glib-2.0"
AC_SUBST(GLIB_includedir)

GLIB_libdir="`pkg-config --variable=libdir glib-2.0`"
AC_SUBST(GLIB_includedir)

IDL_INCLUDES="-I$ORBIT_includedir -I$GLIB_includedir"
AC_SUBST(IDL_INCLUDES)

dnl
dnl Camel directories
dnl
CAMEL_includedir="`pkg-config --variable=privincludedir camel-provider-$EDS_API_VERSION`"
AC_SUBST(CAMEL_includedir)

CAMEL_providerdir="`pkg-config --variable=camel_providerdir camel-provider-$EDS_API_VERSION`"
AC_SUBST(CAMEL_providerdir)

CAMEL_providerdir_basename=`basename $CAMEL_providerdir`
CAMEL_providerdir_dirname=`dirname $CAMEL_providerdir`
CAMEL_providerdir_parentdir=`basename $CAMEL_providerdir_dirname`
RPM_CAMEL_providerdir="$CAMEL_providerdir_parentdir/$CAMEL_providerdir_basename"
AC_SUBST(RPM_CAMEL_providerdir)

dnl
dnl E-D-S directories
dnl
EDS_privdatadir="`pkg-config --variable=privdatadir evolution-data-server-$EDS_API_VERSION`"
AC_SUBST(EDS_privdatadir)

EDS_privincludedir='${includedir}'/evolution-data-server-$EDS_BASE_VERSION
AC_SUBST(EDS_privincludedir)

extensiondir="`pkg-config --variable=extensiondir evolution-data-server-$EDS_API_VERSION`"
AC_SUBST(extensiondir)

dnl
dnl E-D-S module checks
dnl
PKG_CHECK_MODULES(ADDRESSBOOK, libedata-book-$EDS_API_VERSION camel-provider-$EDS_API_VERSION)
AC_SUBST(ADDRESSBOOK_CFLAGS)

PKG_CHECK_MODULES(CALENDAR, libedata-cal-$EDS_API_VERSION libedataserverui-$EDS_API_VERSION)
AC_SUBST(CALENDAR_CFLAGS)
AC_SUBST(CALENDAR_LIBS)

PKG_CHECK_MODULES(CAMEL, camel-provider-$EDS_API_VERSION)
AC_SUBST(CAMEL_CFLAGS)

PKG_CHECK_MODULES(MAIL, libecal-$EDS_API_VERSION)
AC_SUBST(MAIL_CFLAGS)


dnl
dnl dh_install paths
dnl

dnl Utility macro to get dh_install .install paths
dnl BRUTUS_GET_DH_INSTALL_PATH(VAR-PREFIX, PATH_NAME, PATH)
AC_DEFUN([BRUTUS_GET_DH_INSTALL_PATH], [
	$1_$2=`echo $3 | cut -c 2-`
])

BRUTUS_GET_DH_INSTALL_PATH(DH_INSTALL, extensiondir, $extensiondir)
AC_SUBST(DH_INSTALL_extensiondir)

BRUTUS_GET_DH_INSTALL_PATH(DH_INSTALL, CAMEL_providerdir, $CAMEL_providerdir)
AC_SUBST(DH_INSTALL_CAMEL_providerdir)

BRUTUS_GET_DH_INSTALL_PATH(DH_INSTALL, default_includedir, /usr/include)
AC_SUBST(DH_INSTALL_default_includedir)

BRUTUS_GET_DH_INSTALL_PATH(DH_INSTALL, default_datadir, /usr/share)
AC_SUBST(DH_INSTALL_default_datadir)

BRUTUS_GET_DH_INSTALL_PATH(DH_INSTALL, default_bindir, /usr/bin)
AC_SUBST(DH_INSTALL_default_bindir)

BRUTUS_GET_DH_INSTALL_PATH(DH_INSTALL, default_libdir, /usr/lib)
AC_SUBST(DH_INSTALL_default_libdir)

BRUTUS_GET_DH_INSTALL_PATH(DH_INSTALL, default_docdir, /usr/share/doc/$PACKAGE_NAME)
AC_SUBST(DH_INSTALL_default_docdir)

BRUTUS_GET_DH_INSTALL_PATH(DH_INSTALL, default_libexecdir, /usr/libexec)
AC_SUBST(DH_INSTALL_default_libexecdir)

BRUTUS_GET_DH_INSTALL_PATH(DH_INSTALL, default_localedir, /usr/share/locale)
for lang in $ALL_LINGUAS
do
	linguas="$DH_INSTALL_default_localedir/$lang/LC_MESSAGES/$GETTEXT_PACKAGE.mo\n$linguas"
done
echo -n -e "$linguas" >$srcdir/linguas.cache
AC_SUBST_FILE(DH_INSTALL_linguas)
DH_INSTALL_linguas=$srcdir/linguas.cache

dnl
dnl Check if this is a distribution
dnl
AM_CONDITIONAL(THIS_IS_NOT_A_DISTRIBUTION, [test -f ./nodist])

dnl ******************************
dnl Makefiles
dnl ******************************

AC_CONFIG_FILES([
Makefile
evolution-brutus.spec
deb/rules
deb/watch
deb/version.sed
deb/Makefile
deb/control
deb/copyright
deb/evolution-brutus-dev.install
deb/evolution-brutus.install
docs/Makefile
ebuild/Makefile
ebuild/evolution-brutus.ebuild
idl/Makefile
idl_output/Makefile
idl_output/libBrutusSTUBS.pc
camel/Makefile
calendar/Makefile
addressbook/Makefile
plugin/Makefile
servant_impl/Makefile
servant_impl/libBrutusSKELS.pc
server/Makefile
server/libBrutus.pc
session/Makefile
session/lib/Makefile
session/lib/libBrutusd.pc
session/servants/Makefile
session/servants/libBrutusPROXY.pc
query-password/Makefile
log/Makefile
log/lib/Makefile
log/lib/libBrutusLogd.pc
po/Makefile.in
])
AC_OUTPUT

case "$brutus_target" in
	UNKNOWN)
		AC_MSG_WARN([[Unknown distribution - Please use --enable-brutus-target=<TARGET> to specify a distribution target for your build]])
		;;
	*)	
		brutus_target="`echo $BRUTUS_DIST_RELEASE | sed s/%20/' '/1`"
		;;
esac

echo "\

	Target Linux Distribution:                        $brutus_target
	Making a distribution build:                      $msg_brutus_dist
	Making a debug build:                             $msg_brutus_debug
	Making a static build:                            $msg_static
	MAPI inspection enabled:                          $msg_brutus_spy
	Install Brutus development header and IDL files:  $msg_brutus_devel
	Target Evolution version:                         $EVOLUTION_VERSION
        EDS Epoch:                                        $EDS_BASE_VERSION
"
