LIBGG_INCLUDES=""
LIBGG_LIBS=""
ac_libgadu_includes=""
ac_libgadu_libs=""

AC_ARG_WITH(external-libgadu,
  [AC_HELP_STRING(--with-external-libgadu,
    [use external libgadu library @<:@default=check@:>@])],
  [], with_external_libgadu=check)

AC_ARG_WITH(libgadu-includes,
	AC_HELP_STRING([--with-libgadu-includes=DIR], [where the libgadu includes are.]),
	[  ac_libgadu_includes="$withval" ])

if test "$ac_libgadu_includes" != "" ; then
LIBGG_INCLUDES="-I$ac_libgadu_includes"
fi

AC_ARG_WITH(libgadu-libs,
	AC_HELP_STRING([--with-libgadu-libs=DIR], [where the libgadu libraries are.]),
	[  ac_libgadu_libs="$withval" ])

if test "$ac_libgadu_libs" != "" ; then
	LIBGG_LIBS="-L$ac_libgadu_libs"
fi

dnl This may need a test still for compatibility
COMPILE_GADU=true
use_libgadu_copy=
if test "$with_external_libgadu" != "no" ; then
  # Check and setup for libgadu
  KDE_PKG_CHECK_MODULES(LIBGG, libgadu, [have_libgg=yes], [have_libgg=no])
  if test "x$have_libgg" = "xno"; then
    COMPILE_GADU=
    AC_MSG_RESULT([not found])
  else
    AC_MSG_RESULT([found])
  fi
fi

AC_SUBST(LIBGG_INCLUDES)
AC_SUBST(LIBGG_LIBS)
AC_SUBST(COMPILE_GADU)
AM_CONDITIONAL(include_gadu, test -n "$COMPILE_GADU")
AM_CONDITIONAL(include_libggcopy, test -n "$use_libgadu_copy")

KDE_PKG_CHECK_MODULES(IDN, libidn, have_libidn=yes, have_libidn=no)
if test x$have_libidn = xno; then
	AC_MSG_WARN([Libidn not found, Kopete Jabber plugin will not be compiled])
else
	AC_DEFINE(LIBIDN, 1, [Define to 1 if you want IDN support.])
fi
AC_SUBST(IDN_CFLAGS)
AC_SUBST(IDN_LIBS)

AC_MSG_CHECKING([if Libidn can be used])
AC_MSG_RESULT($have_libidn)

AM_CONDITIONAL(include_jabber, test "$have_libidn" = "yes")

# Sametime support

# lower and upper-bound versions of Meanwhile library
m4_define(libmeanwhile_version_min, 1.0.1)
m4_define(libmeanwhile_version_max, 1.1.0)

# Let the user disable the plugin
AC_ARG_ENABLE(meanwhile,
      AC_HELP_STRING([--disable-meanwhile],
      [disable the Kopete Meanwhile plugin (Lotus Sametime support) @<:@default=enabled@:>@]),
      )

if test "x$enable_meanwhile" != "xno"; then
    # Check and setup for libmeanwhile
    KDE_PKG_CHECK_MODULES(MEANWHILE,
        [meanwhile >= libmeanwhile_version_min meanwhile < libmeanwhile_version_max],
        [have_libmeanwhile=yes], [have_libmeanwhile=no])

    if test "x$have_libmeanwhile" = "xno"; then
        enable_meanwhile=no
        AC_MSG_RESULT([not found])
    else
        AC_MSG_RESULT([found])
    fi
fi

AC_SUBST(MEANWHILE_CFLAGS)
AC_SUBST(MEANWHILE_LIBS)

AC_MSG_CHECKING([if Meanwhile plugin should be compiled])
if test "x$enable_meanwhile" != "xno"; then
    AC_MSG_RESULT([yes])
else
    AC_MSG_RESULT([no])
fi

# Set the flag to compile meanwhile
AM_CONDITIONAL(include_meanwhile, [test "x$enable_meanwhile" != "xno"])

# testbed protocol
dnl define the configure option that disables testbed protocol
AC_ARG_ENABLE(testbed, [  --disable-testbed     disable kopete testbed protocol compilation ],  with_testbed=$enableval, with_testbed=yes)
AM_CONDITIONAL(include_testbed, test "$with_testbed" = "yes")

PKG_CHECK_MODULES(GLIB, glib-2.0 gmodule-2.0, have_glib=yes, have_glib=no)
if test x$have_glib = xno; then
	AC_MSG_WARN([GLib 2.0 is required for MSN webcam and Jabber Jingle. You can get it from http://www.gtk.org/])
else
	AC_SUBST(GLIB_CFLAGS)
	AC_SUBST(GLIB_LIBS)
	AC_DEFINE(HAVE_GLIB, 1, [Glib is required for oRTP code and libmimic code])
fi

if test "x$have_glib" != "xyes"; then
    compile_msn_webcam=no
    msn_webcam_val=0
else
    compile_msn_webcam=yes
    msn_webcam_val=1
fi

AC_MSG_CHECKING([if MSN webcam support should be enabled])
AC_MSG_RESULT($compile_msn_webcam)
AC_DEFINE_UNQUOTED(MSN_WEBCAM, $msn_webcam_val, [Define if MSN webcam support can be enabled])

AM_CONDITIONAL(include_msn_webcam, test "x$compile_msn_webcam" = "xyes")

# Check for sms protocol
AC_ARG_ENABLE(smsgsm,
      AC_HELP_STRING([--disable-smsgsm], [disable the GSM SMS protocol]),
      [compile_smsgsm=$enableval],
      [compile_smsgsm=yes]
      )

AC_LANG_PUSH(C++)
ac_save_LIBS="$LIBS"
LIBS="-lgsmme $LIBS"
AC_TRY_LINK([#include <gsmlib/gsm_util.h>],[(void)gsmlib::latin1ToGsm("text");], 
	[have_smsgsm_lib=yes],
	[have_smsgsm_lib=no])
LIBS=$ac_save_LIBS

AC_CHECK_HEADER(gsmlib/gsm_util.h, 
	[have_smsgsm_inc=yes],
	[have_smsgsm_inc=no])

if test "x$have_smsgsm_lib" != "xyes" || test "x$have_smsgsm_inc" != "xyes"; then
    compile_smsgsm=no
fi
AC_LANG_POP(C++)

# Let the user know
AC_MSG_CHECKING([if SMSGSM Plugin should be compiled])
AC_MSG_RESULT($compile_smsgsm)

# Here we go
AM_CONDITIONAL(include_smsgsm, [test "x$compile_smsgsm" = "xyes"])

if test "x$compile_smsgsm" = "xyes"; then
	AC_DEFINE(INCLUDE_SMSGSM, 1, [Define to compile with GSM SMS support])
fi