dnl Configure.in.in for KPilot conduits.
dnl
dnl Copyright (C) 2000,2001 Adriaan de Groot
dnl Copyright (C) 2002 Reinhold Kainhofer
dnl
dnl This file is released under the terms of the Gnu General Public
dnl Licence (GPL) Version 2.




dnl ----------------------------------------------------------------------------
dnl
dnl                     checks for the MAL conduit
dnl
dnl ----------------------------------------------------------------------------

dnl 
dnl
dnl Check to see if MAL header and library are available
dnl

dnl
dnl Questions and comments can be sent to kde-pim@kde.org
dnl
dnl This was copied and adapted from kabc's ldap configure.in.in


AC_DEFUN(KPILOT_CHECK_MAL, 
[
AC_REQUIRE([KDE_CHECK_LIB64])
AC_REQUIRE([KPILOT_CHECK_PISOCK])

AC_MSG_CHECKING(for libmal (for KPilots MAL conduit))
AC_ARG_WITH(mal,
[  --with-mal=PATH        set path for libmal files @<:@default=check@:>@],
[ case "$withval" in
  yes)
    with_mal=CHECK
    ;;
  esac ],
[ with_mal=CHECK ]
)dnl

if test "x$with_mal" = "xCHECK" ; then
  with_mal=NOTFOUND
  search_incs="$kde_includes /usr/include /usr/local/include /usr/include/libmal /usr/local/include/libmal"
  AC_FIND_FILE(libmal.h, $search_incs, mal_incdir)
  if test -r $mal_incdir/libmal.h ; then
    test "x$mal_incdir" != "x/usr/include" && MAL_INCLUDE="-I$mal_incdir"
    with_mal=FOUND
  fi
  if test $with_mal = FOUND ; then
    with_mal=NOTFOUND
    for ext in la so sl a ; do
      AC_FIND_FILE(libmal.$ext, $kde_libraries $libdir /usr/lib$kdelibsuff /usr/local/lib$kdelibsuff $libdir/libmal /usr/lib/libmal /usr/local/lib/libmal,
        mal_libdir)
      if test -r $mal_libdir/libmal.$ext ; then
        if test "x$mal_libdir" != "x/usr/lib$kdelibsuff" ; then
          MAL_LIB="-L$mal_libdir "
          test "$USE_RPATH" = yes && MAL_RPATH="-R $mal_libdir"
        fi
        MAL_LIB="${MAL_LIB}-lmal"
        with_mal=FOUND
        break
      fi
    done
  fi
fi

case "$with_mal" in
no) AC_MSG_RESULT(no) ;;
NOTFOUND) AC_MSG_RESULT(searched but not found) 
	AC_MSG_WARN([KPILOT: MAL headers or library not found. AvantGo conduit will not be compiled.])
	AC_MSG_WARN([KPILOT: Download libmal>=0.20 from http://jasonday.home.att.net/code/libmal/])
	;;
*)
  if test "x$with_mal" = "xFOUND" ; then
    msg="incs=$mal_incdir libs=$mal_libdir"
  else
    msg="$with_mal"
    MAL_ROOT="$with_mal"
    if test "x$MAL_ROOT" != "x/usr" ; then
      MAL_INCLUDE="-I${MAL_ROOT}/include"
      MAL_LIB="-L${MAL_ROOT}/lib$kdelibsuff "
      if test "$USE_RPATH" = "yes" ; then
        MAL_RPATH="-R ${MAL_ROOT}/lib$kdelibsuff"
      fi
    fi
    MAL_LIB="${MAL_LIBS}-lmal"
  fi

  CPPFLAGS="$CPPFLAGS $all_includes"
  LDFLAGS="$LDFLAGS $all_libraries"

  kde_safe_LIBS="$LIBS"
  kde_safe_CFLAGS="$CFLAGS"
  kde_safe_CPPFLAGS="$CPPFLAGS"
  LIBS="$LIBS $PISOCK_LIB $MAL_LIB -ldl"
  CFLAGS="$CFLAGS $MAL_INCLUDE"
  CPPFLAGS="$CPPFLAGS $PISOCK_INCLUDE $MAL_INCLUDE"
  AC_LANG_SAVE
  AC_LANG_CPLUSPLUS
  AC_TRY_LINK(dnl
  [
  #include <libmal.h>
  ],
  [
  PalmSyncInfo *psi;
  ],
  , with_mal=no
  )
  AC_LANG_RESTORE
  CFLAGS=$kde_safe_CFLAGS
  CPPFLAGS=$kde_safe_CPPFLAGS
  LIBS=$kde_safe_LIBS
  if test "$with_mal" = "no" ; then
    MAL_INCLUDE=
    MAL_LIB=
    MAL_RPATH=
    AC_MSG_RESULT(no (but first try gave $msg))
    AC_MSG_WARN([KPILOT: MAL headers or library not found. AvantGo conduit will not be compiled.])
    AC_MSG_WARN([KPILOT: Download libmal>=0.20 from http://jasonday.home.att.net/code/libmal/])
  else
    AC_DEFINE(HAVE_LIBMAL, 1, [Define if you have MAL libraries])
    HAVE_LIBMAL=1
    AC_MSG_RESULT($msg)
  fi
  ;;
esac

AC_SUBST(MAL_INCLUDE)
AC_SUBST(MAL_LIB)
AC_SUBST(MAL_RPATH)

AM_CONDITIONAL(include_malconduit, test "$HAVE_LIBMAL" = 1)

])
KPILOT_CHECK_MAL


