#MIN_CONFIG(3.3)
dnl If the quanta executable name and the data dirs are changed from the default "quanta",
dnl the following changes are needed:
dnl  - change the quanta_datadir
dnl  - change the QUANTA_PACKAGE and QUANTA_VERSION in quanta/src/quanta.h
dnl  - change the KDE_ICON in quanta/data/icons/Makefile.am
dnl  - create a .desktop file and the corresponding icons
dnl  - make sure the .desktop file is installed in the quanta/src/Makefile.am
dnl    (kdelnk_DATA = quanta.desktop line)
dnl  - change the bin_PROGRAMS and the _SOURCES, _LDADD, _METASOURCES, _LDFLAGS
dnl    below it in the quanta/src/Makefile.am, so it reflects the new executable name

AM_INIT_AUTOMAKE(@MODULENAME@, @VERSION@)
KDE_ENABLE_HIDDEN_VISIBILITY

quanta_datadir='${kde_datadir}/quanta'
package="quanta"
AC_SUBST(package)
AC_SUBST(quanta_datadir)
AM_CONDITIONAL(QUANTAUIRC_HOOK, test "x$package" != "xquanta")

dnl These are common macros that you might or might not want to use

dnl Checks for header files.
AC_HEADER_DIRENT
AC_HEADER_STDC
AC_HEADER_TIME
AC_CHECK_HEADERS(fcntl.h sys/time.h unistd.h stdlib.h paths.h sys/statvfs.h sys/statfs.h sys/vfs.h sys/mount.h sys/param.h stdarg.h)
AC_CHECK_FUNCS(usleep)
AC_CHECK_FUNCS(statvfs)

AC_DEFINE_UNQUOTED(PREFIX,"$prefix",[Define the PREFIX to be used later])

dnl
dnl The following new parameters were added to offer
dnl the ability to specify the location of the libxml
dnl library during linking and compilation.
dnl Mathieu Lacage 30/03/2000
dnl
LIBXML_PREFIX=""
AC_ARG_WITH(libxml-prefix,
        [  --with-libxml-prefix=[PFX]     Specify location of libxml],
   LIBXML_PREFIX="$withval"
)

if test "x${LIBXML_PREFIX}" != "x"
then
  AC_MSG_RESULT(Using a libxml prefix of ${LIBXML_PREFIX})
fi


AC_SUBST(LIBXML_LIBS)

dnl Test for libxml2 version
XML_CONFIG="xml2-config"
AC_MSG_CHECKING(for libxml libraries >= "2.6.0")
XML_WARNING=""
if test "x$LIBXML_PREFIX" != "x"
then
  if ${LIBXML_PREFIX}/bin/xml2-config --libs print > /dev/null 2>&1
  then
    XML_CONFIG=${LIBXML_PREFIX}/bin/xml2-config
  else
    XML_WARNING="1"
    XML_CONFIG=xml2-config
  fi
fi

AC_DEFUN([VERSION_TO_NUMBER],
[`$1 | sed -e 's/libxml //' | $AWK 'BEGIN { FS = "."; } { printf "%d",
 ([$]1* 1000 + [$]2) * 1000 + [$]3;}'`])

dnl
dnl test version and init our variables
dnl
if test "x$XML_CONFIG" != "x"
then
  vers=VERSION_TO_NUMBER($XML_CONFIG --version)
  if test "$vers" -lt VERSION_TO_NUMBER(echo "2.6.0")
  then
    CXXFLAGS="$CXXFLAGS -DLIBXML_2_5"
    AC_MSG_RESULT(not found - assuming 2.5.x)
  else
    AC_MSG_RESULT(found)
  fi
  LIBXML_LIBS="`$XML_CONFIG --libs`"
  LIBXML_CFLAGS="`$XML_CONFIG --cflags`"
  LIBXML_PREFIX="$XML_CONFIG --prefix"
else
  AC_MSG_ERROR(Could not find libxml2 anywhere, check ftp://xmlsoft.org/.)
fi

if test "x${XML_WARNING}" != "x"
then
   AC_MSG_RESULT(
!!Warning!! using xml2-config in default path
)
fi

LIBXML_PREFIX_DIR="`$XML_CONFIG --prefix`"

AC_SUBST(XML_CONFIG)
AC_SUBST(LIBXML_PREFIX)
AC_SUBST(LIBXML_LIBS)
AC_SUBST(LIBXML_CFLAGS)

LIBXSLT_PREFIX=""
AC_ARG_WITH(libxslt-prefix,
        [  --with-libxslt-prefix=[PFX]    Specify location of libxslt],
   LIBXSLT_PREFIX="$withval"
)

if test "x${LIBXSLT_PREFIX}" != "x"
then
  AC_MSG_RESULT(Using a libxslt prefix of ${LIBXSLT_PREFIX})
fi

dnl
dnl find libxslt
dnl
XSLT_CONFIG="xslt-config"
XSLT_WARNING=""
AC_SUBST(LIBXSLT_REQUIRED_VERSION)
AC_MSG_CHECKING(for libxslt libraries >= $LIBXSLT_REQUIRED_VERSION)
if test "x$LIBXSLT_PREFIX" != "x"
then
  if ${LIBXSLT_PREFIX}/bin/xslt-config --libs print > /dev/null 2>&1
  then
    XSLT_CONFIG=${LIBXSLT_PREFIX}/bin/xslt-config
  else
          XSLT_WARNING="1"
    XSLT_CONFIG=xslt-config
  fi
fi


AC_DEFUN([VERSION_TO_NUMBER],
[`$1 | sed -e 's/libxslt //' | $AWK 'BEGIN { FS = "."; } { printf "%d",
 ([$]1  * 1000 + [$]2) * 1000 + [$]3;}'`])

dnl
dnl test version and init our variables
dnl
if test "x$XSLT_CONFIG" != "x"
then
  vers=VERSION_TO_NUMBER($XSLT_CONFIG --version)
  if test "$vers" -ge VERSION_TO_NUMBER(echo $LIBXSLT_REQUIRED_VERSION)
  then
    LIBXSLT_LIBS="-lexslt `$XSLT_CONFIG --libs`"
    LIBXSLT_CFLAGS="`$XSLT_CONFIG --cflags`"
    AC_MSG_RESULT(found)
          if test "x$LIBXSLT_PREFIX" != "x"
     then
       AC_MSG_RESULT(
Don't forget to make sure that ${LIBXSLT_PREFIX}/lib has been added
  to your LD_LIBRARY_PATH environment variable)
    else
      LIBXSLT_PREFIX="$XSLT_CONFIG --prefix"
          fi
  else
    AC_MSG_ERROR(You need at least libxslt $LIBXSLT_REQUIRED_VERSION for this
  version of xsldbg)
  fi
else
  AC_MSG_ERROR(Could not find libxslt anywhere, check
 ftp://xmlsoft.org/XSLT/.)
fi

if test "x${XSLT_WARNING}" != "x"
then
   AC_MSG_RESULT(
!!Warning!! using xslt-config in default path
)
fi

AC_SUBST(XSLT_CONFIG)
AC_SUBST(LIBXSLT_PREFIX)
AC_SUBST(LIBXSLT_LIBS)
AC_SUBST(LIBXSLT_CFLAGS)


dnl  **********
dnl  check whether we need the qextmdi lib
dnl  (Shamlesly stolen from gideon souorces and
dnl  modified for quanta by fredi)
dnl  **********

AC_DEFUN([QUANTA_CHECK_MDI],
[
  AC_MSG_CHECKING(whether to use kmdi lib from kdelibs)
  AC_CACHE_VAL(ac_cv_mdi_setup,
  [
    AC_LANG_SAVE
    AC_LANG_CPLUSPLUS
    save_CXXFLAGS="$CXXFLAGS"
    CXXFLAGS="$KDE_INCLUDES $QT_INCLUDES"

    AC_TRY_LINK([
      #include <kdeversion.h>
    ],
    [
      #if KDE_VERSION < ((3<<16) | (3<<8) | (92))
         KDE_choke me
      #endif
    ],
      ac_cv_mdi_setup=yes,
      ac_cv_mdi_setup=no
    )
    CXXFLAGS="$save_CXXFLAGS"
    AC_LANG_RESTORE
   ])

  if test "$ac_cv_mdi_setup" = "yes"; then
    LIB_KMDI="-lkmdi"
    QEXTMDI_SUBDIR=""
    KMDI_INCLUDES=""
    AC_MSG_RESULT(yes)
  else
    LIB_KMDI='$(top_builddir)/lib/compatibility/kmdi/libquantakmdi.la'
    QEXTMDI_SUBDIR="kmdi"
    KMDI_INCLUDES='-I$(top_srcdir)/lib/compatibility/kmdi/qextmdi'
    CXXFLAGS="$CXXFLAGS -DCOMPAT_KMDI"
    AC_MSG_RESULT(no)
  fi

  AC_SUBST(LIB_KMDI)
  AC_SUBST(KMDI_INCLUDES)
  AC_SUBST(QEXTMDI_SUBDIR)
  AM_CONDITIONAL(include_qextmdi, test -n "$QEXTMDI_SUBDIR")
])

dnl Check if kmdi is present, if not use giden's one
QUANTA_CHECK_MDI

KDE_CHECK_HEADER(cvsservice_stub.h, [cvsservice_stub_h="found"], [cvsservice_stub_h="none"])
AM_CONDITIONAL(include_cvsservice, test "$cvsservice_stub_h" = "found")
if test "$cvsservice_stub_h" = "found"; then
  CXXFLAGS="$CXXFLAGS -DENABLE_CVSSERVICE"
fi

#check for KNewStuffSecure headers
KNEWSTUFF_INCLUDES=""
LIB_KNEWSTUFF="-lknewstuff"
KDE_CHECK_HEADER(knewstuff/knewstuffsecure.h, [knewstuffsecure_h="found"], [knewstuffsecure_h="none"])
AM_CONDITIONAL(include_knewstuff, test "$knewstuffsecure_h" != "found")
if test "$knewstuffsecure_h" != "found"; then
  KNEWSTUFF_INCLUDES='-I$(top_srcdir)/lib/compatibility'
  LIB_KNEWSTUFF='$(top_builddir)/lib/compatibility/knewstuff/libknewstuff.la'
fi
AC_SUBST(KNEWSTUFF_INCLUDES)
AC_SUBST(LIB_KNEWSTUFF)



AC_ARG_ENABLE(editors, [  --enable-editors        Enable selection of other editors aside of Kate],
[enable_editors=$enableval], [enable_editors="no"])

if test "$enable_editors" = "yes"; then
  CXXFLAGS="$CXXFLAGS -DENABLE_EDITORS"
fi
AC_SUBST(enable_editors)
