dnl -*- mode: Autoconf; -*-
dnl Invoke autogen.sh to produce a configure script.

AC_CHECK_PROGS([QMAKE], [qmake qmake-qt4])

# Check for Akonadi. There is no .pc file for it,
# so fall back to normal header file and library checking.
# kdepimlibs5-dev >= 4.3 provides the necessary files.
AKONADIFOUND=yes
if ! test "$KDEPIM_CFLAGS"; then
   KDEPIM_CFLAGS="-I`kde4-config --path include` -I`kde4-config --path include`/KDE"
   if test "$QMAKE"; then
      KDEPIM_CFLAGS="$KDEPIM_CFLAGS -I`$QMAKE -query QT_INSTALL_HEADERS`"
   fi
fi
if ! test "$KDEPIM_LIBS"; then
   KDEPIM_LIBS="-L`kde4-config --prefix`/lib`kde4-config --libsuffix` -lakonadi-kde -lQtDBus -lQtCore -lkdeui -lkdecore"
fi
AC_LANG_PUSH(C++)
old_CPPFLAGS="$CPPFLAGS"
CPPFLAGS="$CPPFLAGS $KDEPIM_CFLAGS"
AC_CHECK_HEADERS(Akonadi/Collection, [], [AKONADIFOUND=no])
CPPFLAGS="$old_CPPFLAGS"
AC_LANG_POP(C++)

# In contrast to the Evolution backend, the Akonadi backend is
# currently considered optional. "configure" will enable it only
# if explicitly enabled (was turned on automatically previously,
# for example on Ubuntu Hardy, and didn't compile).
AC_ARG_ENABLE_BACKEND(akonadi, akonadi,
                      AS_HELP_STRING([--disable-akonadi], [disable access to Akonadi (default is to use it if akonadi.pc is found)]),
                      [enable_akonadi="$enableval"
                       test $AKONADIFOUND = "yes" || test $enable_akonadi = "no" || AC_MSG_ERROR([akonadi.pc not found. Install it to compile with the Akonadi backend enabled.])],
                      [enable_akonadi=no])

if test "$enable_akonadi" = "yes"; then
        # conditional compilation in preprocessor
        AC_DEFINE(ENABLE_AKONADI, 1, [Akonadi available])
else
        # avoid unneeded dependencies on Akonadi
        KDEPIM_CFLAGS=
        KDEPIM_LIBS=
fi
AC_SUBST(KDEPIM_LIBS)
AC_SUBST(KDEPIM_CFLAGS)

# conditional compilation in make
AM_CONDITIONAL([ENABLE_AKONADI], [test "$enable_akonadi" = "yes"])

# let others include Akonadi backend's header file
# (not strictly necessary, could be avoided by not
# including Akonadi header files in public header file
# of source)
BACKEND_CPPFLAGS="$BACKEND_CPPFLAGS $KDEPIM_CFLAGS"
