#MIN_CONFIG(3.2.0)

AM_INIT_AUTOMAKE(kftpgrabber, 0.8.0)

dnl Check for the 3.4 kde version (for tdednssd)
AC_DEFUN([CHECK_TDEDNSSD],
[
  AC_MSG_CHECKING(for TDEDNSSD support)
  AC_CACHE_VAL(ac_cv_tdednssd,
  [
    AC_LANG_SAVE
    AC_LANG_CPLUSPLUS

    save_CXXFLAGS="$CXXFLAGS"

    CXXFLAGS="$CXXFLAGS $all_includes"

    AC_TRY_LINK([
      #include <tdeversion.h>
    ],
    [
      #if ! KDE_IS_VERSION(3,4,0)
         KDE_choke me
      #endif
    ],
      ac_cv_tdednssd=yes,
      ac_cv_tdednssd=no
    )
    CXXFLAGS="$save_CXXFLAGS"
    AC_LANG_RESTORE
   ])

  if test "$ac_cv_tdednssd" = "yes"; then
    AC_MSG_RESULT(yes)
    LIB_TDEDNSSD="-ltdednssd"
  else
    AC_MSG_RESULT(no)
    LIB_TDEDNSSD=""
  fi

  AC_SUBST(LIB_TDEDNSSD)
])


dnl Check for the correct kde version
AC_DEFUN([CHECK_KDEVERSION],
[
  AC_MSG_CHECKING(for KDE >= 3.3)
  AC_CACHE_VAL(ac_cv_kde33,
  [
    AC_LANG_SAVE
    AC_LANG_CPLUSPLUS

    save_CXXFLAGS="$CXXFLAGS"

    CXXFLAGS="$CXXFLAGS $all_includes"

    AC_TRY_LINK([
      #include <tdeversion.h>
    ],
    [
      #if ! KDE_IS_VERSION(3,3,0)
         KDE_choke me
      #endif
    ],
      ac_cv_kde33=yes,
      ac_cv_kde33=no
    )
    CXXFLAGS="$save_CXXFLAGS"
    AC_LANG_RESTORE
   ])

  if test "$ac_cv_kde33" = "yes"; then
    AC_MSG_RESULT(yes)
  else
    AC_MSG_RESULT(no)
    
    echo ""
    echo " * You don't have KDE 3.3 or later installed on your system."
    echo " * KFTPGrabber requires at least KDE 3.3 or later."
    echo ""
    exit 1
  fi
])

dnl Stuff required for libssh
AC_CHECK_LIB([resolv],[gethostbyname])
AC_CHECK_LIB([nsl],[gethostbyname])

AC_HEADER_STDC
AC_CHECK_HEADERS([fcntl.h netdb.h netinet/in.h stdlib.h string.h sys/socket.h \
sys/time.h termios.h unistd.h openssl/aes.h openssl/blowfish.h zlib.h \
sys/poll.h ])

AC_FUNC_MALLOC
AC_FUNC_MEMCMP
AC_FUNC_REALLOC
AC_FUNC_SELECT_ARGTYPES
AC_TYPE_SIGNAL
AC_FUNC_VPRINTF
AC_CHECK_FUNCS([endpwent gethostbyaddr gethostbyname getpass memmove memset \
 select socket strchr strdup strerror strstr poll])

dnl Check for some stuff
KDE_CHECK_SSL
CHECK_KDEVERSION
CHECK_TDEDNSSD

AC_C_BIGENDIAN
AC_CHECK_KDEMAXPATHLEN
