dnl
dnl Check location of Qt documentation
dnl
AC_DEFUN([KDEV_PATH_QTDOC],
[
AC_MSG_CHECKING([for Qt documentation])

ac_qt_docdirs=""
AC_ARG_WITH(qtdoc_dir,
[  --with-qtdoc-dir=DIR    where the Qt documentation is installed ],
ac_qt_docdirs=""
qt_docdirs=""
[
  ac_qt_docdirs=$withval
],
)

dnl
dnl not currently used
dnl
qt_docdirs="/usr/doc/qt-doc/html /usr/local/qt/html /usr/local/lib/qt/html /usr/lib/qt/doc/html /usr/X11/lib/qt/html /usr/X11/lib/qt/doc/html /usr/X11R6/share/doc/qt/html /usr/share/doc/packages/qt/html"
test -n "$QTDIR" && qt_docdirs="$QTDIR/html $QTDIR/doc/html $QTDIR/doc $qt_docdirs"
qt_docdirs="$ac_qt_docdirs $qt_docdirs"
AC_FIND_FILE(classes.html, $qt_docdirs, qt_docdir)
AC_MSG_RESULT($qt_docdir)
if test "$qt_docdir" = NO; then
  qt_docdir=""
fi
AC_DEFINE_UNQUOTED(QT_DOCDIR, "$qt_docdir", [Where the Qt documentation is installed])
])


dnl
dnl Check location of tdelibs documentation generated by Doxygen
dnl
AC_DEFUN([KDEV_PATH_KDELIBSDOXY],
[
AC_MSG_CHECKING([for tdelibs documentation generated by Doxygen])

ac_tdelibs_doxydirs=""
AC_ARG_WITH(tdelibsdoxy_dir,
[  --with-tdelibsdoxy-dir=DIR         where the tdelibs documentation is installed ],
ac_tdelibs_doxydirs=""
tdelibs_doxydirs=""
[
  ac_tdelibs_doxydirs=$withval
],
)

if test "${prefix}" = NONE; then
  ac_kde_htmldir="$ac_default_prefix"/share/doc/tde/HTML
else
  ac_kde_htmldir="$prefix"/share/doc/tde/HTML
fi

tdelibs_doxydirs="$ac_tdelibs_doxydirs $ac_kde_htmldir/default/tdelibs-apidocs $ac_kde_htmldir/en/tdelibs-apidocs"
AC_FIND_FILE(tdecore/html/classTDEApplication.html, $tdelibs_doxydirs, tdelibs_doxydir)
AC_MSG_RESULT($tdelibs_doxydir)
if test "$tdelibs_doxydir" = NO; then
  tdelibs_doxydir=""
fi
AC_DEFINE_UNQUOTED(TDELIBS_DOXYDIR, "$tdelibs_doxydir", [where TDE documentation is installed])
])
AC_SUBST(tdelibs_doxydir)


dnl
dnl Check location of tdelibs documentation
dnl
AC_DEFUN([KDEV_PATH_KDELIBSDOC],
[
AC_MSG_CHECKING([for tdelibs documentation])

ac_tdelibs_docdirs=""
AC_ARG_WITH(tdelibsdoc_dir,
[  --with-tdelibsdoc-dir=DIR         where the tdelibs documentation is installed ],
ac_tdelibs_docdirs=""
tdelibs_docdirs=""
[
  ac_tdelibs_docdirs=$withval
],
)

if test "${prefix}" = NONE; then
  ac_kde_htmldir="$ac_default_prefix"/share/doc/tde/HTML
else
  ac_kde_htmldir="$prefix"/share/doc/tde/HTML
fi

tdelibs_docdirs="/usr/doc/tdelibs-doc/html"
if test "$ac_kde_htmldir" != ""; then
 tdelibs_docdirs="$tdelibs_docdirs $ac_kde_htmldir/default/tdelibs $ac_kde_htmldir/en/tdelibs"
fi
tdelibs_docdirs="$ac_tdelibs_docdirs $tdelibs_docdirs"
AC_FIND_FILE(tdecore/index.html, $tdelibs_docdirs, tdelibs_docdir)
AC_MSG_RESULT($tdelibs_docdir)
if test "$tdelibs_docdir" = NO; then
  tdelibs_docdir=""
fi
AC_DEFINE_UNQUOTED(KDELIBS_DOCDIR, "$tdelibs_docdir", [where KDE documentation is installed])
])


dnl
dnl Check whether we support Debian docbase
dnl
AC_DEFUN([KDEV_CHECK_DOCBASE],
[
AC_MSG_CHECKING(for docbase)
AC_ARG_ENABLE(docbase,
[  --enable-docbase        enable Debian docbase support],
[if test "$enableval" = yes; then
  enable_docbase=yes
fi],
enable_docbase=no)
AC_MSG_RESULT($enable_docbase)

if test "$enable_docbase" = "yes"; then
  AC_DEFINE_UNQUOTED(WITH_DOCBASE, 1, [If Debian docbase should be supported])
fi
])


dnl
dnl Check whether we support Python scripting
dnl
AC_DEFUN([KDEV_CHECK_SCRIPTING],
[
AC_MSG_CHECKING(if scripting enabled)
AC_ARG_ENABLE(scripting,
[  --enable-scripting      enable python scripting support],
[if test "$enableval" = yes; then
  enable_scripting=yes
fi],
enable_scripting=no)
AC_MSG_RESULT($enable_scripting)

SCRIPTING=
if test "$enable_scripting" = "yes"; then
  KDE_CHECK_PYTHON(1.5, [
	AC_MSG_ERROR([You enabled scripting but have no python installed.])
  ])
  SCRIPTING=scripting
fi
  AC_SUBST(SCRIPTING)
  AM_CONDITIONAL(include_scripting, test -n "$SCRIPTING")
])


dnl
dnl Check for Python documentation dir
dnl
AC_DEFUN([KDEV_PATH_PYTHONDOCDIR],
[
AC_MSG_CHECKING(for Python documentation directory)
AC_ARG_WITH(pythondocdir,
  [  --with-pythondocdir=pythondocdir    where the Python documentation is installed ],
  kdev_pythondocdir=$withval,
  kdev_pythondocdir=/usr/local/python2.0/html
)

AC_CACHE_VAL(kdev_cv_pythondocdir,
[
  pythondocdirs="/usr/share/doc/packages/python/html /usr/share/doc/python-docs-2.0 /usr/share/doc/python/html $kdev_pythondocdir"
  AC_FIND_FILE(ref/comparisons.html, $pythondocdirs, kdev_cv_pythondocdir)
])

AC_MSG_RESULT($kdev_cv_pythondocdir)
PYTHONDOCDIR=$kdev_cv_pythondocdir
AC_SUBST(PYTHONDOCDIR)
])


dnl
dnl Check for Python documentation dir
dnl
AC_DEFUN([KDEV_PATH_PHPDOCDIR],
[
AC_MSG_CHECKING(for PHP documentation directory)
AC_ARG_WITH(phpdocdir,
  [  --with-phpdocdir=phpdocdir          where the PHP documentation is installed ],
  kdev_phpdocdir=$withval,
  kdev_phpdocdir=/usr/local/php/doc/manual
)

AC_CACHE_VAL(kdev_cv_phpdocdir,
[
  phpdocdirs="/usr/share/doc/packages/phpdoc/manual /usr/share/doc/php3-doc/html $kdev_phpdocdir"
  AC_FIND_FILE(ref.ftp.html, $phpdocdirs, kdev_cv_phpdocdir)
])

AC_MSG_RESULT($kdev_cv_phpdocdir)
PHPDOCDIR=$kdev_cv_phpdocdir
AC_SUBST(PHPDOCDIR)
])


dnl
dnl Check for GNUstep documentation
dnl
AC_DEFUN([KDEV_PATH_GNUSTEPDOCDIR],
[
AC_MSG_CHECKING([for GNUstep documentation])
if test -z ${GNUSTEP_SYSTEM_ROOT:-""} ; then
GNUSTEPDOCDIR=
AC_MSG_RESULT(not found)
else
GNUSTEPDOCDIR=$GNUSTEP_SYSTEM_ROOT/Documentation/Developer
AC_MSG_RESULT($GNUSTEPDOCDIR)
fi
AC_SUBST(GNUSTEPDOCDIR)
AM_CONDITIONAL(GNUSTEPDOCS, test x$GNUSTEPDOCDIR != x)
])


dnl
dnl Check for Gtk documentation dirs
dnl
AC_DEFUN([KDEV_PATH_GTKDOCDIR],
[
AC_ARG_WITH(glibdocdir,
  [  --with-glibdocdir=glibdocdir        where the glib documentation is installed ],
  kdev_glibdocdir=$withval,
  kdev_glibdocdir=""
)
AC_ARG_WITH(gdkdocdir,
  [  --with-gdkdocdir=gdkdocdir          where the gdk documentation is installed ],
  kdev_gdkdocdir=$withval,
  kdev_gdkdocdir=""
)
AC_ARG_WITH(gdkpbdocdir,
  [  --with-gdkpbdocdir=gdkpbdocdir      where the gdk-pixbuf documentation is installed ],
  kdev_gdkpbdocdir=$withval,
  kdev_gdkpbdocdir=""
)
AC_ARG_WITH(gtkdocdir,
  [  --with-gtkdocdir=gtkdocdir          where the gtk documentation is installed ],
  kdev_gtkdocdir=$withval,
  kdev_gtkdocdir=""
)
AC_ARG_WITH(gnomedocdir,
  [  --with-gnomedocdir=gnomedocdir      where the gnome documentation is installed ],
  kdev_gnomedocdir=$withval,
  kdev_gnomedocdir=""
)
AC_ARG_WITH(gnomeuidocdir,
  [  --with-gnomeuidocdir=gnomeuidocdir  where the gnomeui documentation is installed ],
  kdev_gnomeuidocdir=$withval,
  kdev_gnomeuidocdir=""
)

AC_MSG_CHECKING(for GLib documentation directory)
AC_CACHE_VAL(kdev_cv_glibdocdir,
[
  glibdocdirs="/usr/share/doc/packages/glib $kdev_glibdocdir"
  AC_FIND_FILE(glib-arrays.html, $glibdocdirs, kdev_cv_glibdocdir)
])
AC_MSG_RESULT($kdev_cv_glibdocdir)
AC_MSG_CHECKING(for Gdk documentation directory)
AC_CACHE_VAL(kdev_cv_gdkdocdir,
[
  gdkdocdirs="/usr/share/doc/packages/gdk $kdev_gdkdocdir"
  AC_FIND_FILE(gdk-events.html, $gdkdocdirs, kdev_cv_gdkdocdir)
])
AC_MSG_RESULT($kdev_cv_gdkdocdir)
AC_MSG_CHECKING(for Gdk-Pixbuf documentation directory)
AC_CACHE_VAL(kdev_cv_gdkpbdocdir,
[
  gdkpbdocdirs="/usr/share/doc/packages/gdk-pixbuf/html $kdev_gdkpbdocdir"
  AC_FIND_FILE(gdk-pixbuf-rendering.html, $gdkpbdocdirs, kdev_cv_gdkpbdocdir)
])
AC_MSG_RESULT($kdev_cv_gdkpbdocdir)
AC_MSG_CHECKING(for Gtk documentation directory)
AC_CACHE_VAL(kdev_cv_gtkdocdir,
[
  gtkdocdirs="/usr/share/doc/packages/gtk $kdev_gtkdocdir"
  AC_FIND_FILE(gtkcombo.html, $gtkdocdirs, kdev_cv_gtkdocdir)
])
AC_MSG_RESULT($kdev_cv_gtkdocdir)
AC_MSG_CHECKING(for libgnome documentation directory)
AC_CACHE_VAL(kdev_cv_gnomedocdir,
[
  gnomedocdirs="/usr/share/doc/packages/gnome-libs-devel/devel-docs/gnome/html $kdev_gnomedocdir"
  AC_FIND_FILE(libgnome.html, $gnomedocdirs, kdev_cv_gnomedocdir)
])
AC_MSG_RESULT($kdev_cv_gnomedocdir)
AC_MSG_CHECKING(for libgnomeui documentation directory)
AC_CACHE_VAL(kdev_cv_gnomeuidocdir,
[
  gnomeuidocdirs="/usr/share/doc/packages/gnome-libs-devel/devel-docs/gnomeui/html $kdev_gnomeuidocdir"
  AC_FIND_FILE(libgnomeui.html, $gnomeuidocdirs, kdev_cv_gnomeuidocdir)
])
AC_MSG_RESULT($kdev_cv_gnomeuidocdir)

dnl We need all directories or none

if test "$kdev_cv_glibdocdir" = NO; then
  kdev_cv_glib_docdir=""
fi
if test "$kdev_cv_gdkdocdir" = NO; then
  kdev_cv_glib_docdir=""
  kdev_cv_gdk_docdir=""
fi
if test "$kdev_cv_gdkpbdocdir" = NO; then
  kdev_cv_glib_docdir=""
  kdev_cv_gdkpb_docdir=""
fi
if test "$kdev_cv_gtkdocdir" = NO; then
  kdev_cv_glib_docdir=""
  kdev_cv_gtk_docdir=""
fi
if test "$kdev_cv_gnomedocdir" = NO; then
  kdev_cv_glib_docdir=""
  kdev_cv_gnome_docdir=""
fi
if test "$kdev_cv_gnomeuidocdir" = NO; then
  kdev_cv_glib_docdir=""
  kdev_cv_gnomeui_docdir=""
fi

GLIBDOCDIR=$kdev_cv_glibdocdir
AC_SUBST(GLIBDOCDIR)
GDKDOCDIR=$kdev_cv_gdkdocdir
AC_SUBST(GDKDOCDIR)
GDKPBDOCDIR=$kdev_cv_gdkpbdocdir
AC_SUBST(GDKPBDOCDIR)
GTKDOCDIR=$kdev_cv_gtkdocdir
AC_SUBST(GTKDOCDIR)
GNOMEDOCDIR=$kdev_cv_gnomedocdir
AC_SUBST(GNOMEDOCDIR)
GNOMEUIDOCDIR=$kdev_cv_gnomeuidocdir
AC_SUBST(GNOMEUIDOCDIR)
AM_CONDITIONAL(GTKDOCS, test x$kdev_cv_glibdocdir != x)
])


dnl
dnl Check whether we support Java
dnl
AC_DEFUN([KDEV_CHECK_JAVA],
[
AC_MSG_CHECKING(if javasupport enabled)
AC_ARG_ENABLE(javasupport,
[  --enable-javasupport    enable java support],
[if test "$enableval" = yes; then
  enable_javasupport=yes
fi],
enable_javasupport=no)
AC_MSG_RESULT($enable_javasupport)

JAVASUPPORT_SUBDIR=
if test "$enable_javasupport" = "yes"; then
  KDE_CHECK_JAVA_DIR
  if test "x$kde_cv_java_bindir" = xno; then
    AC_MSG_RESULT([not found -- parts/javasupport will NOT be built])
    JAVA_SUBDIRS=""
  else
    JAVA_SUBDIRS="javasupport javadebugger"
  fi
fi
AC_SUBST(JAVA_SUBDIRS)
])

dnl  **********
dnl  Simple Check for Berkeley DB >= 3
dnl  **********

AC_DEFUN([KDEV_CHECK_BDB],
[
  ac_db_includedir=""
  ac_db_libdir=""
  ac_db_lib="db"
  AC_ARG_WITH(db_includedir,
[  --with-db-includedir=DIR
                          where the DB4 headers are installed ],
[
  ac_db_includedir="-I$withval"
],
  ac_db_includedir=""
)
  AC_ARG_WITH(db_libdir,
[  --with-db-libdir=DIR    where the DB4 libraries are installed ],
[
  ac_db_libdir="-L$withval"
],
  ac_db_libdir=""
)
  AC_ARG_WITH(db_lib,
[  --with-db-lib=LIB       library name for the DB4 library ],
[
  ac_db_lib=$withval
],
ac_db_lib=db
)

  AC_MSG_CHECKING(for Berkeley DB >= 4.1)

  AC_CACHE_VAL(ac_cv_bdb,
  [
    AC_LANG_SAVE
    AC_LANG_CPLUSPLUS

    save_CXXFLAGS="$CXXFLAGS"
    save_LDFLAGS="$LDFLAGS"

    CXXFLAGS="$CXXFLAGS $QT_INCLUDES $ac_db_includedir $ac_db_libdir -l$ac_db_lib"
    LDFLAGS="$LDFLAGS $LIBQT"

    AC_TRY_LINK([
      #include <db.h>
    ],
    [
      #if DB_VERSION_MAJOR < 4 && DB_VERSION_MINOR < 1
         choke me
      #else
         DB *db;
         db->open( db, 0, 0, NULL, DB_BTREE, DB_CREATE, 0644 );
      #endif
    ],
    ac_cv_bdb=yes,
    ac_cv_bdb=no
    )
    CXXFLAGS="$save_CXXFLAGS"
    LDFLAGS="$save_LDFLAGS"
    AC_LANG_RESTORE
   ])

  if test "$ac_cv_bdb" = "no"; then
    AC_MSG_ERROR(no - please install Berkeley DB >= 4.1)
  else
    AC_MSG_RESULT([yes])
  fi

DB3LIB="$ac_db_lib"
DB3INCLUDES="$ac_db_includedir"
DB3LDFLAGS="$ac_db_libdir"
AC_SUBST(DB3LIB)
AC_SUBST(DB3INCLUDES)
AC_SUBST(DB3LDFLAGS)
])

dnl  **********
dnl  check wether KDE is at least version 3.4.0
dnl  **********
AC_DEFUN([KDEV_CHECK_TDE_VERSION],
[
    AC_MSG_CHECKING(for KDE >= 3.4.0)


    AC_CACHE_VAL(ac_cv_kde_version_check,
    [
        AC_LANG_SAVE
        AC_LANG_CPLUSPLUS

        save_CXXFLAGS="$CXXFLAGS"

        CXXFLAGS="$CXXFLAGS $QT_INCLUDES -I$ac_kde_includes"

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

    if test "$ac_cv_kde_version_check" = "yes"; then
        AC_MSG_RESULT(yes)
    else
        AC_MSG_ERROR(Installed KDE needs to be version 3.4.0 or later)
    fi
])


dnl  **********
dnl  check for new valgrind version (>= 2.1.0)
dnl  **********

AC_DEFUN([KDEV_CHECK_VALGRIND],
[
  AC_CHECK_PROG(ac_have_valgrind, [valgrind], [yes])
  if test "yes" == $ac_have_valgrind; then
    AC_MSG_CHECKING(valgrind version)
    if test "valgrind-20" == `valgrind --version | $AWK -F \. '{print @S|@1@S|@2}'`; then
      ac_valgrind_ver=20
      AC_MSG_RESULT(< 2.1.0)
    elif test "valgrind-1" == `valgrind --version | $AWK -F \. '{print @S|@1}'`; then
      ac_valgrind_ver=20
      AC_MSG_RESULT(< 2.1.0)
    else
      ac_valgrind_ver=21
      AC_MSG_RESULT(>= 2.1.0)
    fi
  fi
  AC_DEFINE_UNQUOTED(VALGRIND_VERSION, $ac_valgrind_ver, [valgrind version number - 20 for older and 21 for newer])
])