dnl =======================================================
dnl FILE: configure.in.in
dnl =======================================================

dnl    Configure check stuff for TaskJuggler
dnl    Copyright (c) 2002 Chris Schlaeger <cs@kde.org>
dnl    Copyright (c) 2002 Klaas Freitag <freitag@suse.de>

dnl    This file is free software; you can redistribute it and/or
dnl    modify it under the terms of version 2 of the GNU General
dnl    Public License as published by the Free Software Foundation.

dnl    This library is distributed in the hope that it will be useful,
dnl    but WITHOUT ANY WARRANTY; without even the implied warranty of
dnl    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
dnl    GNU General Public License for more details.

dnl    You should have received a copy of the GNU General Public License
dnl    along with this library; see the file COPYING.  If not, write to
dnl    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
dnl    Boston, MA 02110-1301, USA.

dnl The following part was taken from the KDE admin directory
dnl Start of configure.in.min

AC_INIT(acinclude.m4) dnl a source file from your sub dir

dnl This is so we can use kde-common
AC_CONFIG_AUX_DIR(admin)

dnl This ksh/zsh feature conflicts with `cd blah ; pwd`
unset CDPATH

dnl Checking host/target/build systems, for make, install etc.
AC_CANONICAL_SYSTEM 
dnl Perform program name transformation
AC_ARG_PROGRAM

dnl Automake doc recommends to do this only here. (Janos)
AM_INIT_AUTOMAKE(taskjuggler, [2.4.3])

dnl AM_INIT_AUTOMAKE(taskjuggler-2.4.3, "3.3.91") dnl searches for some needed programs

AC_MSG_CHECKING([for KDE support])
AC_ARG_WITH(kde-support,
        [  --with-kde-support[={yes|no}] Integrate KDE support [default=yes]],
        [
                case "${withval}" in
                        yes|no) cv_option_kdesupport=$withval;;
                        *)  AC_MSG_ERROR(bad value ${withval} for --with-kde-support) ;;
                esac
        ], [cv_option_kdesupport=yes])
AC_MSG_RESULT([$cv_option_kdesupport])

if test "$cv_option_kdesupport" = yes ;then
  KDE_SET_PREFIX
fi  
KDE_CHECK_LIB64

AC_MSG_CHECKING([for iCal support])
AC_ARG_WITH(ical-support,
        [  --with-ical-support[={yes|no}] Enable iCal support [default=yes]],
        [
                case "${withval}" in
                        yes|no) cv_option_icalsupport=$withval;;
                        *)  AC_MSG_ERROR(bad value ${withval} for --with-ical-support) ;;
                esac
        ], [cv_option_icalsupport=yes])
AC_MSG_RESULT([$cv_option_icalsupport])

dnl generate the config header
AM_CONFIG_HEADER(config.h) dnl at the distribution this done

dnl Checks for programs.
AC_CHECK_COMPILERS
AC_ENABLE_SHARED(yes)
AC_ENABLE_STATIC(no)
KDE_PROG_LIBTOOL

PACKAGES_DIR=${prefix}/share/doc/packages/taskjuggler/
AC_ARG_WITH(
  docdir,
  AC_HELP_STRING([--with-docdir=DIR],[Directory where additional
  documentation will be put
  (default is /usr/share/doc/packages/taskjuggler]),
  [ PACKAGES_DIR="${withval}" ]
  [ cv_option_docdir="${withval}" ])
AC_MSG_RESULT([$cv_option_docdir])  
AC_SUBST(PACKAGES_DIR)

dnl for NLS support. Call them in this order!
dnl WITH_NLS is for the po files
AM_KDE_WITH_NLS

dnl KDE_USE_QT
dnl AC_PATH_KDE

dnl End of configure.in.min

AM_CONDITIONAL(include_KDE, test "$cv_option_kdesupport" = yes)
AM_CONDITIONAL(include_ARTS, false)
AC_PATH_QT

find TestSuite -name ignorelist | xargs rm
if test "$cv_option_kdesupport" = yes ;then
    AC_DEFINE(HAVE_KDE,1,[Define if you have KDE])
    KDE_CHECK_THREADING
    AC_PATH_KDE 

    AC_SUBST(KDE_LIBS)
    DO_NOT_COMPILE=""
else
    kde_htmldir=${datadir}/taskjuggler
    DO_NOT_COMPILE="TaskJugglerUI Contrib"
fi

if test "$cv_option_icalsupport" = yes ; then
    dnl These libs are part of KDEPIM
    LIBKCAL="-lkcal"
    dnl Some distros split off a KDEPIM devel package most people
    dnl forget to install.
    KDE_CHECK_HEADERS(libkcal/calendarlocal.h libkcal/todo.h)
    if test "$ac_cv_header_libkcal_calendarlocal_h" = "no" -o \
            "$ac_cv_header_libkcal_todo_h" = "no" ; then
      AC_MSG_ERROR([KDEPIM header files no found. Please make sure
you have KDEPIM and the corresponding development packages
installed!])
    fi
    AC_DEFINE(HAVE_ICAL_SUPPORT,1,[Define if you have iCal (KDEPIM3) support])
else
    echo "ICalReport.tjp" > TestSuite/Syntax/Correct/ignorelist
    LIBKCAL=""
fi  

AC_SUBST(LIBKCAL)

AC_CHECK_PROG(PERL, perl, perl, no)

AC_ARG_ENABLE(
  docs,
  AC_HELP_STRING([--disable-docs],[Don't generate documentation]),
  tj_enable_docs=$enableval,
)
if test "$tj_enable_docs" = no ; then
  DO_NOT_COMPILE="$DO_NOT_COMPILE docs man"
fi

AC_DEFUN([CHECK_PERL_MODULE],[ 
AC_MSG_CHECKING([for Perl module $1])
TMPFILE=conftest.pl
rm -f $TMPFILE
cat >$TMPFILE <<'EOT'
use $1;
EOT
$PERL $TMPFILE 2> /dev/null
if test $? -eq 0 ; then
    $2="yes"
    AC_MSG_RESULT(found)
else
    $2="no"
    AC_MSG_RESULT(not found)
fi
rm -f $TMPFILE
])

if test "$tj_enable_docs" != "no" ; then
  dnl Check for the stuff needed to generate man pages
  AC_CHECK_PROG(XSLTPROC, xsltproc, xsltproc, no)
  AC_CHECK_PROG(DOCBOOK_TO_MAN, docbook-to-man, docbook-to-man, no)

  dnl Check for the stuff needed to create the HTML manual
  if test "$XSLTPROC" = no ; then
    AC_MSG_WARN([Documentation will not be generated])
    DO_NOT_COMPILE="${DO_NOT_COMPILE} docs"
  else  
    dnl meinproc is usualy part of kdelibs
    AC_CHECK_PROG(MEINPROC, meinproc, meinproc, no)
    if test "$MEINPROC" = no ; then
      AC_MSG_WARN([KDE online help will not be generated])
    fi  
    AC_CHECK_PROG(DB2HTML, docbook2html, docbook2html, no)
    if test "$DB2HTML" = no ; then
      AC_MSG_WARN([HTML manual will not be generated])
      HTMLMANUAL="no"
    else
      HTMLMANUAL="yes"
    fi
    AC_SUBST(HTMLMANUAL)
  
    dnl Check for the stuff needed to create the PS manual
    AC_CHECK_PROG(DB2PS, docbook2ps, docbook2ps, no)
    AC_CHECK_PROG(DB2PDF, docbook2pdf, docbook2pdf, no)
    AC_CHECK_PROG(JADE, openjade, openjade, no)
    AC_CHECK_PROG(JADETEX, jadetex, jadetex, no)
    AC_CHECK_PROG(DVIPS, dvips, dvips, no)
    if test "$XSLTPROC" = no -o "$DB2PS" = no -o \
            "$JADE" = no -o "$JADETEX" = no -o \
            "$DVIPS" = no ; then
      AC_MSG_WARN([Postscript manual will not be generated])
      PSMANUAL="no"
    else
      PSMANUAL="yes"
    fi
    AC_SUBST(PSMANUAL)
  
    AC_OUTPUT(docs/en/taskjuggler.xml)
  fi

  if test "$DOCBOOK_TO_MAN" = no ; then
    AC_MSG_WARN([Man pages will not be generated])
    DO_NOT_COMPILE="${DO_NOT_COMPILE} man"
  fi  
fi

dnl KDE_INIT_DOXYGEN([The TaskJuggler API Reference], [Version $VERSION])

KDE_CREATE_SUBDIRSLIST
AC_CONFIG_FILES([ Makefile ])
AC_CONFIG_FILES([ Contrib/Makefile ])
AC_CONFIG_FILES([ Contrib/kate/Makefile ])
AC_CONFIG_FILES([ Examples/Makefile ])
AC_CONFIG_FILES([ Examples/BigProject/Makefile ])
AC_CONFIG_FILES([ Examples/BigProject/Common/Makefile ])
AC_CONFIG_FILES([ Examples/BigProject/Project1/Makefile ])
AC_CONFIG_FILES([ Examples/BigProject/Project2/Makefile ])
AC_CONFIG_FILES([ Examples/FirstProject/Makefile ])
AC_CONFIG_FILES([ Examples/ShiftSchedule/Makefile ])
AC_CONFIG_FILES([ TaskJugglerUI/Makefile ])
AC_CONFIG_FILES([ TaskJugglerUI/Templates/Makefile ])
AC_CONFIG_FILES([ TaskJugglerUI/Templates/en_US/Makefile ])
AC_CONFIG_FILES([ TaskJugglerUI/pics/Makefile ])
AC_CONFIG_FILES([ TestSuite/Makefile ])
AC_CONFIG_FILES([ docs/Makefile ])
AC_CONFIG_FILES([ docs/en/Makefile ])
AC_CONFIG_FILES([ i18n/Makefile ])
AC_CONFIG_FILES([ i18n/TaskJugglerUI/Makefile ])
AC_CONFIG_FILES([ man/Makefile ])
AC_CONFIG_FILES([ man/en/Makefile ])
AC_CONFIG_FILES([ taskjuggler/Makefile ])
AC_OUTPUT
# Check if KDE_SET_PREFIX was called, and --prefix was passed to configure
if test -n "$kde_libs_prefix" -a -n "$given_prefix"; then
  # And if so, warn when they don't match
  if test "$kde_libs_prefix" != "$given_prefix"; then
    # And if kde doesn't know about the prefix yet
    echo ":"`kde-config --path exe`":" | grep ":$given_prefix/bin/:" 2>&1 >/dev/null
    if test $? -ne 0; then
      echo ""
      echo "Warning: you chose to install this package in $given_prefix,"
      echo "but KDE was found in $kde_libs_prefix."
      echo "For this to work, you will need to tell KDE about the new prefix, by ensuring"
      echo "that KDEDIRS contains it, e.g. export KDEDIRS=$given_prefix:$kde_libs_prefix"
      echo "Then restart KDE."
      echo ""
    fi
  fi
fi

if test "$all_tests" = "bad"; then
  if test ! "$cache_file" = "/dev/null"; then
    echo ""
    echo "Please remove the file $cache_file after changing your setup"
    echo "so that configure will find the changes next time."
    echo ""
  fi
else
  echo ""
  echo "Good - your configure finished. Start make now"
  echo ""
fi
