AC_INIT(README)
AC_CANONICAL_SYSTEM
AM_CONFIG_HEADER(config.h)
AM_INIT_AUTOMAKE(evolution-sharp, 0.17.1)
AM_MAINTAINER_MODE

AC_PROG_INSTALL
AM_PROG_LIBTOOL

AC_PATH_PROG(PKG_CONFIG, pkg-config, no)
if test "x$PKG_CONFIG" = "xno"; then
	AC_MSG_ERROR([You need to install pkg-config])
fi

# If you change these, update the error text below.
PKG_CHECK_MODULES(EVOLUTION_DATA_SERVER_1_8, evolution-data-server-1.2 >= 1.8 evolution-data-server-1.2 < 1.9, edsver="1.8", AC_MSG_RESULT([no]))
PKG_CHECK_MODULES(EVOLUTION_DATA_SERVER_1_9, evolution-data-server-1.2 >= 1.9 evolution-data-server-1.2 < 1.10, edsver="1.9", AC_MSG_RESULT([no]))
PKG_CHECK_MODULES(EVOLUTION_DATA_SERVER_1_10, evolution-data-server-1.2 >= 1.10 evolution-data-server-1.2 < 2.23.2, edsver="1.10", AC_MSG_RESULT([no]))
PKG_CHECK_MODULES(TOO_NEW_EDS, evolution-data-server-1.2 >= 2.23.2, edsver="unsupported", AC_MSG_RESULT([no]))

if test "x$edsver" = "x1.8"; then
	EDS_VERSION=-1.2
	EDS_SOVERSION=7
	EBOOK_SOVERSION=9
	ECAL_SOVERSION=7
elif test "x$edsver" = "x1.9" -o "x$edsver" = "x1.10"; then
	# SEE COMMENT IN evolution/Makefile.am ABOUT EDS 1.9/1.10!
	EDS_VERSION=-1.2
	EDS_SOVERSION=9
	EBOOK_SOVERSION=9
	ECAL_SOVERSION=7
elif test "x$edsver" = "xunsupported"; then
	AC_MSG_ERROR([

Your evolution-data-server is too new for this evolution-sharp.  Check to see
if there is a newer version than $VERSION at:
  
    http://download.gnome.org/sources/evolution-sharp

If not, you'll have to wait to support the newest version.  You may want to
file a bug against evolution-sharp at http://bugzilla.gnome.org.  Patches
welcome!
])
else
	AC_MSG_ERROR([

You are missing evolution-data-server development files for a supported
version of e-d-s.  Supported versions are:

    1.8.x
    1.9.x
    1.10.x
    1.11.1, 1.11.2

If you have a supported evolution-data-server installed, you are probably
missing the development files, which are often found bundled separately,
depending on the operating system.  On Linux, they're often found in the
evolution-data-server-devel or evolution-data-server-dev packages.  Source
code can be downloaded from:

    http://download.gnome.org/sources/evolution-data-server

Lastly, if you have e-d-s devel files installed, you may need to set your
PKG_CONFIG_PATH environment variable.

])
fi

AC_SUBST(EDS_VERSION)
AC_SUBST(EDS_SOVERSION)
AC_SUBST(EBOOK_SOVERSION)
AC_SUBST(ECAL_SOVERSION)

AM_CONDITIONAL(USE_EDS_1_8, test "x$edsver" = "x1.8")
AM_CONDITIONAL(USE_EDS_1_9, test "x$edsver" = "x1.9")
AM_CONDITIONAL(USE_EDS_1_10, test "x$edsver" = "x1.10")

PKG_CHECK_MODULES(MONO, mono >= 1.0.0)
AC_PATH_PROG(CSC, mcs, no)
if test "x$CSC" = "xno"; then
	AC_MSG_ERROR([Your mono installation doesn't expose mcs])
fi
AC_PATH_PROG(GACUTIL, gacutil, no)
if test "x$GACUTIL" = "xno"; then
	AC_MSG_ERROR([Your mono installation doesn't expose gacutil])
fi

if test `uname -s` = "Darwin"; then
        LIB_PREFIX=
        LIB_SUFFIX=.dylib
else
        LIB_PREFIX=.so
        LIB_SUFFIX=
fi

AC_SUBST(CSC)
AC_SUBST(GACUTIL)
AC_SUBST(LIB_PREFIX)
AC_SUBST(LIB_SUFFIX)

PKG_CHECK_MODULES(GTK_SHARP, gtk-sharp-2.0 >= 2.4.0)
AC_SUBST(GTK_SHARP_LIBS)

AC_PATH_PROG(GAPI_CODEGEN, gapi2-codegen, no)
if test "x$GAPI_CODEGEN" = "xno"; then
	AC_MSG_ERROR([You need to install gtk-sharp2-gapi])
fi

AC_PATH_PROG(GAPI_FIXUP, gapi2-fixup, no)
if test "x$GAPI_FIXUP" = "xno"; then
	AC_MSG_ERROR([You need to install gtk-sharp2-gapi])
fi

LIBECAL_PKG_NAME="libecal$EDS_VERSION"
PKG_CHECK_MODULES(LIBECAL, $LIBECAL_PKG_NAME >= 1.2.0)
AC_SUBST(LIBECAL_CFLAGS)
AC_SUBST(LIBECAL_LIBS)

LIBEBOOK_PKG_NAME="libebook$EDS_VERSION"
PKG_CHECK_MODULES(LIBEBOOK, $LIBEBOOK_PKG_NAME >= 1.2.0)
AC_SUBST(LIBEBOOK_CFLAGS)
AC_SUBST(LIBEBOOK_LIBS)

API_VERSION=3.0.0.0
AC_SUBST(API_VERSION)

AC_OUTPUT([
glue/Makefile
evolution/Makefile
evolution/AssemblyInfo.cs
evolution/evolution-sharp.dll.config
evolution-sharp.pc
evolution-sharp.spec
Makefile
])

echo "---"
echo "Configuration successful."
echo
echo "Using evolution-data-server ${edsver}.x API"
echo "---"

