dnl ------------------------------------------------------------------------
dnl Try to find if FAM is installed
dnl ------------------------------------------------------------------------
dnl
kde_have_fam=yes
AC_ARG_ENABLE(libfam,
	AC_HELP_STRING([--disable-libfam],[don't search for libfam and do not use it]),
[ kde_have_fam=$enableval ], [])dnl

dnl Bloody libfam is C++ and certainly compiled by GNU C++.  This means,
dnl we can't use it, when compiling with another C++ compiler, as the
dnl runtime systems would conflict (e.g. in KAI C++) (matz)
test "$GXX" = yes || kde_have_fam=no

if test "$kde_have_fam" = "yes" ; then
  AC_LANG_SAVE
  AC_LANG_CPLUSPLUS
  KDE_CHECK_LIB(fam, FAMOpen, [LIBFAM="-lfam"; kde_have_fam=yes],kde_have_fam=no)
  if test $kde_have_fam = yes; then
    AC_DEFINE_UNQUOTED(HAVE_FAM, 1, [Define if your system has libfam])
  fi
  AC_LANG_RESTORE
fi
AC_SUBST(LIBFAM)
dnl ------------------------------------------------------------------------
dnl Try to find if LIBZ is installed
dnl ------------------------------------------------------------------------
dnl

AC_FIND_ZLIB

AC_CHECK_HEADERS(sys/mnttab.h sys/mntent.h mntent.h fstab.h sys/ucred.h sys/mount.h)
AC_CHECK_FUNCS(setmntent getmntinfo)

AH_VERBATIM(_GETMNTINFO, [
#ifdef __osf__
#ifdef __cplusplus
extern "C" {
#endif
#include <sys/mount.h>
int getmntinfo(struct statfs **mntbufp, int flags);
#include <sys/fs_types.h>    /* for mnt_names[] */
#ifdef __cplusplus
}
#endif
#endif
])

dnl ------------------------------------------------------------------------
dnl Try to find if libvolmgt is installed (Solaris)
dnl ------------------------------------------------------------------------
kde_have_volmgt=yes
AC_CHECK_LIB(volmgt, volmgt_running, [LIBVOLMGT=-lvolmgt], kde_have_volmgt=no)
AC_SUBST(LIBVOLMGT)
if test "$kde_have_volmgt" = "yes"; then
  AC_DEFINE_UNQUOTED(HAVE_VOLMGT, 1, [Define, to enable volume management (Solaris 2.x), if you have -lvolmgt])
fi

dnl ------------------------------------------------------------------------
dnl Try to find if we have Linux Dir Notification
dnl ------------------------------------------------------------------------

AC_ARG_ENABLE(dnotify,
AC_HELP_STRING([--enable-dnotify],[enable use of Linux directory notifications]),
[ kde_enable_dnotify=$enableval ], [])dnl

AC_CHECK_GNU_EXTENSIONS

if test "x$kde_enable_dnotify" = "xyes"; then
  AC_MSG_CHECKING([for Linux Directory Notification])
  AC_CACHE_VAL(kde_cv_have_dnotify,
  [
  kde_cv_have_dnotify=no
  AC_LANG_SAVE
  AC_LANG_C

  AC_TRY_COMPILE(
  [
#include <fcntl.h>
#include <signal.h>
  ],
  [
#ifndef F_NOTIFY
#error no dir notification
#endif
    int fd;
    siginfo_t *t = 0;

    fcntl(fd, F_SETSIG, SIGRTMIN);
    fcntl(fd, F_NOTIFY, DN_DELETE|DN_CREATE|DN_MULTISHOT);

  ],kde_cv_have_dnotify=yes)

  AC_LANG_RESTORE
  ])

  if test "$kde_cv_have_dnotify" = "yes" ; then
    AC_DEFINE_UNQUOTED(HAVE_DNOTIFY, 1, [Define if your system has Linux Directory Notification])
    AC_MSG_RESULT(yes)
  else
    AC_MSG_RESULT(no)
  fi
fi

dnl ------------------------------------------------------------------------
dnl Try to find if we have Linux Inode based Dir Notification
dnl ------------------------------------------------------------------------

AC_ARG_ENABLE(inotify,
AC_HELP_STRING([--disable-inotify],[enable use of Linux inode notifications]),
[ kde_enable_inotify=$enableval ], [kde_enable_inotify=yes])dnl

AC_CHECK_GNU_EXTENSIONS

if test "x$kde_enable_inotify" = "xyes"; then
  AC_MSG_CHECKING([for Linux Inotify Notification])
  AC_CACHE_VAL(kde_cv_have_inotify,
  [
  kde_cv_have_inotify=no
  AC_LANG_SAVE
  AC_LANG_C

  AC_TRY_COMPILE(
  [
#include <asm/unistd.h>
#define _S390_BITOPS_H
#include <linux/inotify.h>
  ],
  [
#ifndef IN_ALL_EVENTS
#error no inotify notification
#endif

  ],kde_cv_have_inotify=yes,kde_cv_have_inotify=no)

  AC_LANG_RESTORE
  ])

  AC_CACHE_VAL(kde_cv_have_sys_inotify,
  [
  kde_cv_have_sys_inotify=no
  AC_LANG_SAVE
  AC_LANG_C

  AC_TRY_COMPILE(
  [
#include <sys/inotify.h>
  ],
  [
#ifndef IN_ALL_EVENTS
#error no inotify notification
#endif
  ],kde_cv_have_sys_inotify=yes,kde_cv_have_sys_inotify=no)

  AC_LANG_RESTORE
  ])

  if test "$kde_cv_have_inotify" = "yes" -o "$kde_cv_have_sys_inotify" = "yes"; then
    AC_DEFINE_UNQUOTED(HAVE_INOTIFY, 1, [Define if your system has Linux Inode Notification])
    if test "$kde_cv_have_sys_inotify" = "yes"; then
      AC_DEFINE_UNQUOTED(HAVE_SYS_INOTIFY, 1, [Define if your system has glibc support for inotify])
    fi
    AC_MSG_RESULT(yes)
  else
    AC_MSG_RESULT(no)
  fi
fi
