dnl =======================================================
dnl FILE: ./admin/configure.in.min
dnl =======================================================

dnl    This file is part of the KDE libraries/packages
dnl    Copyright (C) 2001 Stephan Kulow (coolo@kde.org)
 
dnl    This file is free software; you can redistribute it and/or
dnl    modify it under the terms of the GNU Library General Public
dnl    License as published by the Free Software Foundation; either
dnl    version 2 of the License, or (at your option) any later version.
 
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 GNU
dnl    Library General Public License for more details.
 
dnl    You should have received a copy of the GNU Library General Public License
dnl    along with this library; see the file COPYING.LIB.  If not, write to
dnl    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
dnl    Boston, MA 02111-1307, USA.

# Original Author was Kalle@kde.org
# I lifted it in some mater. (Stephan Kulow)
# I used much code from Janos Farkas

dnl Process this file with autoconf to produce a configure script.

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(kst-1.0.0, "3.3.0") dnl searches for some needed programs

KDE_SET_PREFIX

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

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

KDE_USE_QT(3.1)
AC_PATH_KDE
dnl =======================================================
dnl FILE: configure.in.in
dnl =======================================================

#MIN_CONFIG(3.1)
CXXFLAGS="$CXXFLAGS $KDE_DEFAULT_CXXFLAGS"

if test "$build_arts" = "yes"; then
    AC_DEFINE(USE_ARTS, 1, [If we use arts volume])
    LIB_ARTS="-lartskde"
    AC_SUBST(LIB_ARTS)
fi

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

dnl =======================================================
dnl FILE: ./kst/configure.in.in
dnl =======================================================

# C linkage is default
AC_C_BIGENDIAN
AC_PROG_YACC
AM_PROG_LEX
dnl AC_OUTPUT(kst/kst.spec)


# PIOLIB Test
ac_piolib_includes=""
ac_piolib_libraries=""
AC_ARG_WITH(piolib,
    AC_HELP_STRING([--with-piolib=DIR],[where the root of PIOLib is installed ]),
    [  ac_piolib_includes="-I$withval"
       ac_piolib_libraries="-L$withval"
    ])

all_includes_save="$all_includes"
all_includes="$all_includes $ac_piolib_includes"
KDE_CHECK_HEADER(HL2_PIOLIB/PIOLib.h, AC_DEFINE(HAVE_PIOLIB_H, 1, [If we have piolib headers]) have_piolib_h=yes PIOINCLUDES="$ac_piolib_includes", , )
all_includes="$all_includes_save"

ldflags_save="$LDFLAGS"
LDFLAGS="$LDFLAGS $ac_piolib_libraries"
KDE_CHECK_LIB(piolib, PIOGetObjectList, PIOLIBS="$ac_piolib_libraries -lpiolib $PIOLIBS", , -lm -lpthread)
LDFLAGS="$ldflags_save"

if test $ac_cv_lib_piolib_PIOGetObjectList = yes; then
  if test $have_piolib_h = yes; then
    AC_SUBST(PIOLIBS)
    AC_SUBST(PIOINCLUDES)
    AC_DEFINE(KST_HAVE_PLANCK, 1, [If we have the PLANCK I/O libraries.])
  fi
fi

AM_CONDITIONAL(include_piolib, test -n "$PIOLIBS")


# CDF Test
ac_cdf_includes=""
ac_cdf_libraries=""
AC_ARG_WITH(cdf,
    AC_HELP_STRING([--with-cdf=DIR],[where the root of CDF is installed ]),
    [  ac_cdf_includes="-I$withval/include"
       ac_cdf_libraries="-L$withval/lib"
    ])

all_includes_save="$all_includes"
all_includes="$all_includes $ac_cdf_includes"
KDE_CHECK_HEADER(cdf.h, AC_DEFINE(HAVE_CDF_H, 1, [If we have CDF headers]) have_cdf_h=yes CDFINCLUDES="$ac_cdf_includes", , )
all_includes="$all_includes_save"

ldflags_save="$LDFLAGS"
LDFLAGS="$LDFLAGS $ac_cdf_libraries"
KDE_CHECK_LIB(cdf, CDFlib, CDFLIBS="$ac_cdf_libraries -lcdf $CDFLIBS", , )
LDFLAGS="$ldflags_save"

if test $ac_cv_lib_cdf_CDFlib = yes; then
  if test $have_cdf_h = yes; then
    AC_SUBST(CDFLIBS)
    AC_SUBST(CDFINCLUDES)
    AC_DEFINE(KST_HAVE_CDF, 1, [If we have the CDF libraries.])
  fi
fi

AM_CONDITIONAL(include_cdf, test -n "$CDFLIBS")


# GSL Tests
GSL_LIBS="-lgsl -lgslcblas -lm"
AC_SUBST(GSL_LIBS)
GSL_NOISE_SUBDIR="gsl"
GSL_FITS_SUBDIR="gsl"
GSL_FITSNONLINEAR_SUBDIR="gsl"
GSL_INTERPOLATIONS_SUBDIR="gsl"
GSL_PASS_FILTERS_SUBDIR="gsl"
GSL_CONVOLUTION_SUBDIR="gsl"
GSL_CORRELATION_SUBDIR="gsl"
KDE_CHECK_HEADER(gsl/gsl_rng.h, ,[GSL_NOISE_SUBDIR=""] )
KDE_CHECK_LIB(gsl, gsl_rng_alloc, ,[GSL_NOISE_SUBDIR=""], -lgslcblas -lm )
KDE_CHECK_HEADER(gsl/gsl_fit.h, ,[GSL_FITS_SUBDIR=""] )
KDE_CHECK_LIB(gsl, gsl_fit_linear, ,[GSL_FITS_SUBDIR=""], -lgslcblas -lm )
KDE_CHECK_HEADER(gsl/gsl_multifit_nlin.h, ,[GSL_FITSNONLINEAR_SUBDIR=""] )
KDE_CHECK_LIB(gsl, gsl_multifit_fdfsolver_alloc, ,[GSL_FITSNONLINEAR_SUBDIR=""], -lgslcblas -lm )
KDE_CHECK_HEADER(gsl/gsl_spline.h, ,[GSL_INTERPOLATIONS_SUBDIR=""] )
KDE_CHECK_LIB(gsl, gsl_interp_init, ,[GSL_INTERPOLATIONS_SUBDIR=""], -lgslcblas -lm )
KDE_CHECK_HEADER(gsl/gsl_fft_real.h, ,[GSL_PASS_FILTERS_SUBDIR=""] )
KDE_CHECK_LIB(gsl, gsl_fft_real_wavetable_alloc, ,[GSL_PASS_FILTERS_SUBDIR=""], -lgslcblas -lm )
KDE_CHECK_HEADER(gsl/gsl_fft_real.h, ,[GSL_CONVOLUTION_SUBDIR=""] )
KDE_CHECK_LIB(gsl, gsl_fft_real_wavetable_alloc, ,[GSL_CONVOLUTION_SUBDIR=""], -lgslcblas -lm )
KDE_CHECK_HEADER(gsl/gsl_fft_real.h, ,[GSL_CORRELATION_SUBDIR=""] )
KDE_CHECK_LIB(gsl, gsl_fft_real_wavetable_alloc, ,[GSL_CORRELATION_SUBDIR=""], -lgslcblas -lm )
AM_CONDITIONAL(include_noise_plugins, test -n "$GSL_NOISE_SUBDIR")
AM_CONDITIONAL(include_fits_plugins, test -n "$GSL_FITS_SUBDIR")
AM_CONDITIONAL(include_fitsnonlinear_plugins, test -n "$GSL_FITSNONLINEAR_SUBDIR")
AM_CONDITIONAL(include_interpolations_plugins, test -n "$GSL_INTERPOLATIONS_SUBDIR")
AM_CONDITIONAL(include_pass_filters_plugins, test -n "$GSL_PASS_FILTERS_SUBDIR")
AM_CONDITIONAL(include_convolution_plugins, test -n "$GSL_CONVOLUTION_SUBDIR")
AM_CONDITIONAL(include_correlation_plugins, test -n "$GSL_CORRELATION_SUBDIR")

FITSIO_LIBS="-lcfitsio -lm"
AC_SUBST(FITSIO_LIBS)
FITSIO_SUBDIR="fitsio"
KDE_CHECK_HEADER(fitsio.h, ,[FITSIO_SUBDIR=""] )
KDE_CHECK_LIB(cfitsio, fftopn, ,[FITSIO_SUBDIR=""], -lm )
AM_CONDITIONAL(include_fitsio_datasource, test -n "$FITSIO_SUBDIR")

AC_DEFUN([KST_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) | (2<<8) | (0))
         KDE_choke me
      #endif
    ],
      ac_cv_mdi_setup=yes,
      ac_cv_mdi_setup=no
    )
    CXXFLAGS="$save_CXXFLAGS"
    AC_LANG_RESTORE
   ])

  AM_CONDITIONAL(include_libkstkmdi, test "$ac_cv_mdi_setup" = "no")
  if test "$ac_cv_mdi_setup" = "yes"; then
    LIB_KMDI="-lkmdi"
    KMDI_INCLUDES=""
    AC_MSG_RESULT(yes)
  else
    LIB_KMDI='$(top_builddir)/kst/kst/libkstkmdi/libkstkmdi.la'
    KMDI_INCLUDES='-I$(top_srcdir)/kst/kst/libkstkmdi'
    CXXFLAGS="$CXXFLAGS -DCOMPAT_KMDI"
    AC_MSG_RESULT(no)
  fi

  AC_SUBST(LIB_KMDI)
  AC_SUBST(KMDI_INCLUDES)
])

KST_CHECK_MDI

AC_DEFUN([KST_CHECK_CALENDARSYSTEM],
[
  AC_MSG_CHECKING(whether to use kcalendarsystem lib from kdelibs)
  AC_CACHE_VAL(ac_cv_calendarsystem_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) | (2<<8) | (0))
         KDE_choke me
      #endif
    ],
      ac_cv_calendarsystem_setup=yes,
      ac_cv_calendarsystem_setup=no
    )
    CXXFLAGS="$save_CXXFLAGS"
    AC_LANG_RESTORE
   ])

  AM_CONDITIONAL(include_libkstkcalendarsystem, test "$ac_cv_calendarsystem_setup" = "no")
  if test "$ac_cv_calendarsystem_setup" = "yes"; then
    LIB_KCALENDARSYSTEM=""
    KCALENDARSYSTEM_INCLUDES=""
    AC_MSG_RESULT(yes)
  else
    LIB_KCALENDARSYSTEM='$(top_builddir)/kst/kst/libkstkcalendarsystem/libkstkcalendarsystem.la'
    KCALENDARSYSTEM_INCLUDES='-I$(top_srcdir)/kst/kst/libkstkcalendarsystem'
    CXXFLAGS="$CXXFLAGS -DCOMPAT_KCALENDARSYSTEM"
    AC_MSG_RESULT(no)
  fi

  AC_SUBST(LIB_KCALENDARSYSTEM)
  AC_SUBST(KCALENDARSYSTEM_INCLUDES)
])

KST_CHECK_CALENDARSYSTEM

AC_DEFUN([KST_CHECK_JSE],
[
  AC_MSG_CHECKING(whether to compile the Kst JS extension)
  AC_CACHE_VAL(ac_cv_kjs_setup,
  [
    AC_LANG_SAVE
    AC_LANG_CPLUSPLUS
    save_CXXFLAGS="$CXXFLAGS"
    CXXFLAGS="$KDE_INCLUDES $QT_INCLUDES"
    save_LDFLAGS="$LDFLAGS"
    LDFLAGS="$LDFLAGS -L$KDEDIR/lib -lkjsembed"

    AC_TRY_LINK([
      #include <kdeversion.h>
      #include <kjsembed/jssecuritypolicy.h>
    ],
    [
      #if KDE_VERSION < ((3<<16) | (2<<8) | (0))
         KDE_choke me
      #endif
    ],
      ac_cv_kjs_setup=yes,
      ac_cv_kjs_setup=no
    )
    LDFLAGS="$save_LDFLAGS"
    CXXFLAGS="$save_CXXFLAGS"
    AC_LANG_RESTORE
   ])

  AM_CONDITIONAL(include_kjse, test "$ac_cv_kjs_setup" = "yes")
  if test "$ac_cv_kjs_setup" = "yes"; then
    AC_MSG_RESULT(yes)
  else
    AC_MSG_RESULT(no)
  fi
])

KST_CHECK_JSE

KDE_CHECK_HEADER(linux/vt.h, AC_DEFINE(HAVE_LINUX, 1, [If we have a Linux platform]) have_linux=yes, , )
AM_CONDITIONAL(include_linux, test $have_linux = yes)

KDE_CREATE_SUBDIRSLIST
AM_CONDITIONAL(doc_SUBDIR_included, test "x$doc_SUBDIR_included" = xyes)
AM_CONDITIONAL(kst_SUBDIR_included, test "x$kst_SUBDIR_included" = xyes)
AM_CONDITIONAL(po_SUBDIR_included, test "x$po_SUBDIR_included" = xyes)
AC_CONFIG_FILES([ Makefile ])
AC_CONFIG_FILES([ doc/Makefile ])
AC_CONFIG_FILES([ doc/da/Makefile ])
AC_CONFIG_FILES([ doc/da/tutorial/Makefile ])
AC_CONFIG_FILES([ doc/es/Makefile ])
AC_CONFIG_FILES([ doc/es/tutorial/Makefile ])
AC_CONFIG_FILES([ doc/et/Makefile ])
AC_CONFIG_FILES([ doc/fr/Makefile ])
AC_CONFIG_FILES([ doc/it/Makefile ])
AC_CONFIG_FILES([ doc/it/tutorial/Makefile ])
AC_CONFIG_FILES([ doc/kst/Makefile ])
AC_CONFIG_FILES([ doc/nl/Makefile ])
AC_CONFIG_FILES([ doc/nl/tutorial/Makefile ])
AC_CONFIG_FILES([ doc/pt/Makefile ])
AC_CONFIG_FILES([ doc/pt/tutorial/Makefile ])
AC_CONFIG_FILES([ doc/sv/Makefile ])
AC_CONFIG_FILES([ kst/Makefile ])
AC_CONFIG_FILES([ kst/datapush/Makefile ])
AC_CONFIG_FILES([ kst/kst/Makefile ])
AC_CONFIG_FILES([ kst/kst/datasources/Makefile ])
AC_CONFIG_FILES([ kst/kst/datasources/ascii/Makefile ])
AC_CONFIG_FILES([ kst/kst/datasources/cdf/Makefile ])
AC_CONFIG_FILES([ kst/kst/datasources/dirfile/Makefile ])
AC_CONFIG_FILES([ kst/kst/datasources/frame/Makefile ])
AC_CONFIG_FILES([ kst/kst/datasources/indirect/Makefile ])
AC_CONFIG_FILES([ kst/kst/datasources/lfiio/Makefile ])
AC_CONFIG_FILES([ kst/kst/datasources/planck/Makefile ])
AC_CONFIG_FILES([ kst/kst/datasources/template/Makefile ])
AC_CONFIG_FILES([ kst/kst/extensions/Makefile ])
AC_CONFIG_FILES([ kst/kst/extensions/elog/Makefile ])
AC_CONFIG_FILES([ kst/kst/extensions/js/Makefile ])
AC_CONFIG_FILES([ kst/kst/libkstkcalendarsystem/Makefile ])
AC_CONFIG_FILES([ kst/kst/libkstkmdi/Makefile ])
AC_CONFIG_FILES([ kst/kst/pics/Makefile ])
AC_CONFIG_FILES([ kst/misc/Makefile ])
AC_CONFIG_FILES([ kst/plugins/Makefile ])
AC_CONFIG_FILES([ kst/plugins/bin/Makefile ])
AC_CONFIG_FILES([ kst/plugins/chop/Makefile ])
AC_CONFIG_FILES([ kst/plugins/convolution/Makefile ])
AC_CONFIG_FILES([ kst/plugins/convolution/convolve/Makefile ])
AC_CONFIG_FILES([ kst/plugins/convolution/deconvolve/Makefile ])
AC_CONFIG_FILES([ kst/plugins/correlation/Makefile ])
AC_CONFIG_FILES([ kst/plugins/correlation/autocorrelation/Makefile ])
AC_CONFIG_FILES([ kst/plugins/correlation/crosscorrelation/Makefile ])
AC_CONFIG_FILES([ kst/plugins/crossspectrum/Makefile ])
AC_CONFIG_FILES([ kst/plugins/editor/Makefile ])
AC_CONFIG_FILES([ kst/plugins/fits/Makefile ])
AC_CONFIG_FILES([ kst/plugins/fits/gradient_unweighted/Makefile ])
AC_CONFIG_FILES([ kst/plugins/fits/gradient_weighted/Makefile ])
AC_CONFIG_FILES([ kst/plugins/fits/linear_unweighted/Makefile ])
AC_CONFIG_FILES([ kst/plugins/fits/linear_weighted/Makefile ])
AC_CONFIG_FILES([ kst/plugins/fits/polynomial_unweighted/Makefile ])
AC_CONFIG_FILES([ kst/plugins/fits/polynomial_weighted/Makefile ])
AC_CONFIG_FILES([ kst/plugins/fits/sinusoid_unweighted/Makefile ])
AC_CONFIG_FILES([ kst/plugins/fits/sinusoid_weighted/Makefile ])
AC_CONFIG_FILES([ kst/plugins/fits_nonlinear/Makefile ])
AC_CONFIG_FILES([ kst/plugins/fits_nonlinear/exponential/Makefile ])
AC_CONFIG_FILES([ kst/plugins/fits_nonlinear/exponential_weighted/Makefile ])
AC_CONFIG_FILES([ kst/plugins/fits_nonlinear/gaussian/Makefile ])
AC_CONFIG_FILES([ kst/plugins/fits_nonlinear/gaussian_weighted/Makefile ])
AC_CONFIG_FILES([ kst/plugins/fits_nonlinear/lorentzian/Makefile ])
AC_CONFIG_FILES([ kst/plugins/fits_nonlinear/lorentzian_weighted/Makefile ])
AC_CONFIG_FILES([ kst/plugins/interpolations/Makefile ])
AC_CONFIG_FILES([ kst/plugins/interpolations/akima/Makefile ])
AC_CONFIG_FILES([ kst/plugins/interpolations/akima_periodic/Makefile ])
AC_CONFIG_FILES([ kst/plugins/interpolations/cspline/Makefile ])
AC_CONFIG_FILES([ kst/plugins/interpolations/cspline_periodic/Makefile ])
AC_CONFIG_FILES([ kst/plugins/interpolations/linear/Makefile ])
AC_CONFIG_FILES([ kst/plugins/interpolations/polynomial/Makefile ])
AC_CONFIG_FILES([ kst/plugins/linefit/Makefile ])
AC_CONFIG_FILES([ kst/plugins/noise_addition/Makefile ])
AC_CONFIG_FILES([ kst/plugins/pass_filters/Makefile ])
AC_CONFIG_FILES([ kst/plugins/pass_filters/butterworth_bandpass/Makefile ])
AC_CONFIG_FILES([ kst/plugins/pass_filters/butterworth_bandstop/Makefile ])
AC_CONFIG_FILES([ kst/plugins/pass_filters/butterworth_highpass/Makefile ])
AC_CONFIG_FILES([ kst/plugins/pass_filters/butterworth_lowpass/Makefile ])
AC_CONFIG_FILES([ kst/plugins/periodogram/Makefile ])
AC_CONFIG_FILES([ kst/plugins/phase/Makefile ])
AC_CONFIG_FILES([ kst/plugins/statistics/Makefile ])
AC_CONFIG_FILES([ kst/tests/Makefile ])
AC_CONFIG_FILES([ kst/tests/planck/Makefile ])
AC_CONFIG_FILES([ po/Makefile ])
AC_CONFIG_FILES([ po/br/Makefile ])
AC_CONFIG_FILES([ po/ca/Makefile ])
AC_CONFIG_FILES([ po/cy/Makefile ])
AC_CONFIG_FILES([ po/da/Makefile ])
AC_CONFIG_FILES([ po/de/Makefile ])
AC_CONFIG_FILES([ po/en_GB/Makefile ])
AC_CONFIG_FILES([ po/es/Makefile ])
AC_CONFIG_FILES([ po/et/Makefile ])
AC_CONFIG_FILES([ po/fr/Makefile ])
AC_CONFIG_FILES([ po/ga/Makefile ])
AC_CONFIG_FILES([ po/is/Makefile ])
AC_CONFIG_FILES([ po/it/Makefile ])
AC_CONFIG_FILES([ po/nb/Makefile ])
AC_CONFIG_FILES([ po/nl/Makefile ])
AC_CONFIG_FILES([ po/pl/Makefile ])
AC_CONFIG_FILES([ po/pt/Makefile ])
AC_CONFIG_FILES([ po/pt_BR/Makefile ])
AC_CONFIG_FILES([ po/ro/Makefile ])
AC_CONFIG_FILES([ po/ru/Makefile ])
AC_CONFIG_FILES([ po/sr/Makefile ])
AC_CONFIG_FILES([ po/sv/Makefile ])
AC_CONFIG_FILES([ po/ta/Makefile ])
AC_CONFIG_FILES([ po/tr/Makefile ])
AC_CONFIG_FILES([ po/xx/Makefile ])
AC_CONFIG_FILES([ po/zh_CN/Makefile ])
AC_CONFIG_FILES([ kst/kst.spec ])
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
