dnl Process this file with autoconf to produce a configure script.
AC_INIT(acinclude.m4)

AC_CONFIG_AUX_DIR(admin)

AC_CANONICAL_SYSTEM
AC_ARG_PROGRAM

AM_INIT_AUTOMAKE(LabPlot-1.4.0,0,0)
AC_DEFINE(LVERSION,"1.4.0",[LabPlot version])
AC_DEFINE(LVERSION_DATE,"Nov 28, 2004",[LabPlot release date])

KDE_SET_PREFIX

dnl AM_CONFIG_HEADER(config.h)

dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST

dnl Checks for programs.
AC_PROG_YACC
AC_PROG_CC
AC_PROG_CXX
AC_PROG_MAKE_SET
dnl Checks for library functions.
AC_CHECK_FUNCS(strtod)


CXXFLAGS="$CXXFLAGS $USE_EXCEPTIONS"

AC_CHECK_LIBM

AC_CHECK_LIB(m,log2,LOG2=yes,LOG2=no)

if test "$LOG2" = yes; then
	AC_DEFINE(HAVE_LOG2,1,[use the LOG2 function])
fi

################## TIFF #####################################

AC_ARG_ENABLE(tiff,AC_HELP_STRING([--enable-tiff],[use the tiff library (default=auto)]),[USE_TIFF="$enableval"])

if test "$USE_TIFF" != no; then
AC_CHECK_LIB(tiff,TIFFGetVersion,TIFF=yes,TIFF=no,-lm)
if test "$TIFF" = yes; then
	AC_CHECK_HEADER(tiffio.h,TIFF_H=yes,TIFF_H=no)
	if test "$TIFF_H" = yes; then
		AC_DEFINE(HAVE_TIFF,1,[use the tiff library])
	fi
else
	TIFF_H="-"
fi
else
	TIFF="X"
	TIFF_H="X"
fi

################## GSL ###################################

AC_ARG_ENABLE(gsl,AC_HELP_STRING([--enable-gsl],[use the GNU scientific library (default=auto)]),[USE_GSL="$enableval"])

if test "$USE_GSL" != no; then
AC_CHECK_LIB(gsl,gsl_pow_int,GSL=yes,GSL=no,-lgsl -lgslcblas)
if test "$GSL" = yes; then
	AC_CHECK_HEADER(gsl/gsl_math.h,GSL_H=yes,GSL_H=no)
	if test "$GSL_H" = yes; then
		AC_DEFINE(HAVE_GSL,1,[use the gsl library])
    		GSL_LDFLAGS="-lgsl -lgslcblas"
		AC_CHECK_HEADER(gsl/gsl_const_mksa.h,NEWGSL_H=yes,NEWGSL_H=no)
		if test "$NEWGSL_H" = yes; then
			AC_DEFINE(HAVE_NEWGSL,1,[use the gsl library])
		fi
	fi
else
	GSL_H="-"
    	GSL_LDFLAGS=
fi
else
	GSL_LDFLAGS=
	GSL="X"
	GSL_H="X"
	NEWGSL_H="X"
fi

############## FFTW3 #################################

AC_ARG_ENABLE(fftw3,AC_HELP_STRING([--enable-fftw3],[use the fftw3 library (default=auto)]),[USE_FFTW3="$enableval"])

if test "$USE_FFTW3" != no; then
AC_CHECK_LIB(fftw3,fftw_malloc,FFTW3=yes,FFTW3=no)
if test "${FFTW3}" = yes; then
	AC_CHECK_HEADER(fftw3.h,FFTW3_H=yes,FFTW3_H=no)
	if test "$FFTW3_H" = yes; then
		AC_DEFINE(HAVE_FFTW3,1,[use the fftw3 library])
		FFTW3_LDFLAGS="-lfftw3"
		FFTW3="yes. using this version."
		FFTW_LDFLAGS=""
		USE_FFTW="no"
	fi
else
	FFTW3_LDFLAGS=""
	FFTW3_H="-"
fi
else
	FFTW3_LDFLAGS=""
	FFTW3_H="X"
	FFTW3="X"
fi

############## FFTW ###########################

AC_ARG_ENABLE(fftw,AC_HELP_STRING([--enable-fftw],[use the fftw library (default=auto)]),[USE_FFTW="$enableval"])

if test "$USE_FFTW" != no; then
AC_CHECK_LIB(fftw,fftw_create_plan,FFTW=yes,FFTW=no)
if test "${FFTW}" = yes; then
	AC_CHECK_HEADER(fftw.h,FFTW_H=yes,FFTW_H=no)
	if test "$FFTW_H" = yes; then
		AC_DEFINE(HAVE_FFTW,1,[use the fftw library])
		FFTW_LDFLAGS="-lfftw"
	fi
else
	FFTW_LDFLAGS=""
	FFTW_H="-"
fi
else
	FFTW_LDFLAGS=""
	FFTW_H="X"
	FFTW="X"
fi

############# JASPER #################################

AC_ARG_ENABLE(jasper,AC_HELP_STRING([--enable-jasper],[use the system jasper library (default=auto)]),
	[USE_JASPER="$enableval"])

JASPER_LDFLAGS=
		
if test "$USE_JASPER" != no; then
AC_CHECK_LIB(jasper,jas_stream_fopen,JASPER=yes,JASPER=no)
if test "${JASPER}" = yes; then
	AC_CHECK_HEADER(jasper/jas_config.h,JASPER_H=yes,JASPER_H=no)
	if test "$JASPER_H" = yes; then
		AC_DEFINE(HAVE_JASPER,1,[use the jasper library for jpeg 2000 support])
    		JASPER_LDFLAGS="-ljasper"
	fi
else
	JASPER_H="-"
fi
else
	JASPER="X"
	JASPER_H="X"
fi

################# PSTOEDIT ##################################

AC_ARG_ENABLE(pstoedit,AC_HELP_STRING([--enable-pstoedit],[use pstoedit (default=auto)]),
	[USE_PSTOEDIT="$enableval"])

if test "$USE_PSTOEDIT" != no; then
AC_CHECK_PROG(PSTOEDIT,pstoedit,yes,no)
if test "${PSTOEDIT}" = yes; then
    AC_DEFINE(HAVE_PSTOEDIT,1,[use pstoedit])
fi
else
	PSTOEDIT="X"
fi

############# IMAGEMAGICK #################################

MAGICK_LDFLAGS=
MAGICK_INCFLAGS=

AC_ARG_ENABLE(ImageMagick,AC_HELP_STRING([--enable-ImageMagick],[use ImageMagick (default=auto)]),
	[USE_IMAGEMAGICK="$enableval"])

if test "$USE_IMAGEMAGICK" != no; then
AC_CHECK_PROG(MAGICK,Magick++-config,yes,no)
if test "$MAGICK" = yes; then
	AC_CHECK_HEADER(magick/magick_config.h,MAGICK_H=yes,MAGICK_H=no)
	if test "$MAGICK_H" = yes; then
		# AC_CHECK_HEADER a C++ headers !
		AC_LANG_PUSH(C++)
		AC_CHECK_HEADER(Magick++.h,MAGICKPP_H=yes,MAGICKPP_H=no)
		AC_LANG_POP(C++)
		if test "$MAGICKPP_H" = yes; then
			AC_CHECK_LIB(bz2,BZ2_bzopen,BZ=yes,BZ=no)
			if test "$BZ" = yes; then
	  			MAGICK_LDFLAGS='`Magick++-config --ldflags --libs`'
  				MAGICK_INCFLAGS='`Magick++-config --cppflags`'
    				AC_DEFINE(HAVE_MAGICK,1,[use Magick])
			fi
		fi
	else
	MAGICKPP_H="-"
	fi
else
	MAGICK_H="-"
	MAGICKPP_H="-"
fi
else
	MAGICK="X"
	MAGICK_H="X"
	MAGICKPP_H="X"
	BZ="X"
fi

############# QSA ###################################

AC_ARG_ENABLE(qsa,AC_HELP_STRING([--enable-qsa],[use Qt Script for Applications (default=auto)]),
	[USE_QSA="$enableval"])

QSA_LDFLAGS=""

if test "$USE_QSA" != no; then
AC_CHECK_LIB(qsa,main,QSA=yes,QSA=no,-L$QTDIR/lib)
if test "$QSA" = yes; then
	export CPATH="$CPATH:$QTDIR/include"
	AC_LANG_PUSH(C++)
	AC_CHECK_HEADER(qsinterpreter.h,QSA_H=yes,QSA_H=no)
	AC_CHECK_HEADER(qsworkbench.h,QSA_IDE_H=yes,QSA_IDE_H=no)
	AC_CHECK_HEADER(qsobjectfactory.h,QSA_FAC_H=yes,QSA_FAC_H=no)
	AC_LANG_POP(C++)
	if test "$QSA_H" = yes; then
    		AC_DEFINE(HAVE_QSA,1,[use QSA])
    		QSA_LDFLAGS="-lqsa"
	fi
	if test "$QSA_IDE_H" = yes; then
    		AC_DEFINE(HAVE_QSA_IDE,1,[use QSA workbench])
	fi
	if test "$QSA_FAC_H" = yes; then
    		AC_DEFINE(HAVE_QSA_FAC,1,[use QSA object factory])
	fi
else
	QSA_H="-"
	QSA_IDE_H="-"
	QSA_FAC_H="-"
fi
else
	QSA="X"
	QSA_H="X"
	QSA_IDE_H="X"
	QSA_FAC_H="X"
fi

############## VTK ###############################

## not used anymore

#AC_ARG_ENABLE(vtk,AC_HELP_STRING([--enable-vtk],
#	[use the Visualization Toolkit (default=auto)	VTK_DIR (e.g. /usr/local)]),
#	[USE_VTK="$enableval"])

#VTKQT="VtkQt not compiled."
#VTKQT_DIR=
#VTK_INCFLAGS=
#VTK_LDFLAGS=

#if test "$USE_VTK" != no; then
#AC_CHECK_LIB(vtkRendering,main,VTK=yes,VTK=no,-L$VTK_DIR/lib/vtk)
#if test "$VTK" = yes; then
#	export CPATH="$CPATH:$VTK_DIR/include/vtk"
#	AC_LANG_PUSH(C++)
#	AC_CHECK_HEADER(vtkRenderer.h,VTK_H=yes,VTK_H=no)
#	AC_LANG_POP(C++)
#	if test "$VTK_H" = yes; then
#		VTKQT="compiling included VtkQt."
#		VTK_INCFLAGS="-I$VTK_DIR/include/vtk -I../VtkQt"
#		VTK_LDFLAGS="../VtkQt/libLabPlotVtkQt.la -L$VTK_DIR/lib/vtk -lvtkRendering -lvtkHybrid"
#		AC_DEFINE(HAVE_VTK,1,[use the VTK library])
#		VTKQT_DIR=VtkQt
#	fi
#else
#	VTK_H="-"
#fi
#else
#	VTK="X"
#	VTK_H="X"
#fi


################# GRASS #############################

AC_ARG_ENABLE(grass,AC_HELP_STRING([--enable-grass],
[use the Geographic Resources Analysis Support System (default=auto)	GRASS_DIR (e.g. /usr/local/grass-5.0.3)]),
	[USE_GRASS="$enableval"])

GRASSQT="GRASSQt not compiled."
GRASSQT_DIR=
GRASS_INCFLAGS=
GRASS_LDFLAGS=

if test "$USE_GRASS" != no; then
AC_CHECK_LIB(gis,main,GRASS=yes,GRASS=no,-L$GRASS_DIR/src/libes/LIB.${host})
if test "$GRASS" = yes; then
	export CPATH="$CPATH:$GRASS_DIR/src/include"
	AC_CHECK_HEADER(Vect.h,GRASS_H=yes,GRASS_H=no)
	if test "$GRASS_H" = yes; then
		GRASSQT="compiling included GRASSQt."
		GRASS_INCFLAGS="-I$GRASS_DIR/src/include -I../GRASSQt"
		GRASS_LDFLAGS="../GRASSQt/libLabPlotGRASSQt.la -L$GRASS_DIR/src/libes/LIB.${host} -lvect -ldig2 -lgis -ldatetime"
		AC_DEFINE(HAVE_GRASS,1,[use the GRASS library])
		GRASSQT_DIR=GRASSQt
	fi
else
	GRASS_H="-"
fi
else
	GRASS="X"
	GRASS_H="X"
fi

########################## NETCDF ##############################

AC_ARG_ENABLE(netcdf,AC_HELP_STRING([--enable-netcdf],[use Unidata Network Common Data Form (netCDF) library 
(default=auto)]), [USE_NETCDF="$enableval"])

NETCDF_LDFLAGS="../netcdf/libLabPlotnetCDF.la"
NETCDF_INCFLAGS=-I../netcdf
NETCDF_DIR=netcdf

if test "$USE_NETCDF" != no; then
AC_CHECK_LIB(netcdf,main,NETCDF=yes,NETCDF="no. using included netcdf library.")
if test "$NETCDF" = yes; then
	AC_CHECK_HEADER(netcdf.h,NETCDF_H=yes,NETCDF_H="no. using included netcdf library.")
	if test "$NETCDF_H" = yes; then
		NETCDF_LDFLAGS="-lnetcdf"
		NETCDF_INCFLAGS=
		NETCDF_DIR=
	fi
else
	NETCDF_H="-"
fi
else
	NETCDF="X"
	NETCDF_H="X"
fi

########################## CDF ##############################

AC_ARG_ENABLE(cdf,AC_HELP_STRING([--enable-cdf],[use Common Data Form (CDF) library 
(default=auto)    CDF_DIR (e.g. /usr/local/cdf27-dist) ]), [USE_CDF="$enableval"])

CDF_LDFLAGS=
CDF_INCFLAGS=

if test "$USE_CDF" != no; then
AC_CHECK_LIB(cdf,main,CDF=yes,CDF=no,-L$CDF_DIR/src/lib)
if test "$CDF" = yes; then
	export CPATH="$CPATH:$CDF_DIR/src/include"
	AC_CHECK_HEADER(cdf.h,CDF_H=yes,CDF_H="no")
	if test "$CDF_H" = yes; then
		CDF_INCFLAGS="-I$CDF_DIR/src/include"
		CDF_LDFLAGS="-L$CDF_DIR/src/lib -lcdf"
		AC_DEFINE(HAVE_CDF,1,[use the system CDF library])
	fi
else
	CDF_H="-"
fi
else
	CDF="X"
	CDF_H="X"
fi

########################## AUDIOFILE ##############################

AC_ARG_ENABLE(audiofile,AC_HELP_STRING([--enable-audiofile],[use the Audio File Library (default=auto)]),
[USE_AUDIOFILE="$enableval"])

AUDIOFILE_LDFLAGS="../audiofile/libLabPlotaudiofile.la"
AUDIOFILE_INCFLAGS=-I../audiofile
AUDIOFILE_DIR=audiofile

if test "$USE_AUDIOFILE" != no; then
AC_CHECK_LIB(audiofile,main,AUDIOFILE=yes,AUDIOFILE="no. using included audiofile library.")
if test "$AUDIOFILE" = yes; then
	AC_CHECK_HEADER(audiofile.h,AUDIOFILE_H=yes,AUDIOFILE_H="no. using included audiofile library.")
	if test "$AUDIOFILE_H" = yes; then
		AUDIOFILE_LDFLAGS="-laudiofile"
		AUDIOFILE_INCFLAGS=
		AUDIOFILE_DIR=
	fi
else
	AUDIOFILE_H="-"
fi
else
	AUDIOFILE="X"
	AUDIOFILE_H="X"
fi

################ OpenGL ##################################################

AC_ARG_ENABLE(GL,AC_HELP_STRING([--enable-gl],[use the OpenGL library (default=auto)]),
[USE_GL="$enableval"])

GL_LDFLAGS=""
QWT3D_LDFLAGS=""
QWT3D_INCFLAGS=""

if test "$USE_GL" != no; then
AC_CHECK_LIB(GL,main,GL=yes,GL=no,"-L/usr/X11R6/lib")
if test "$GL" = yes; then
	GL_LDFLAGS="-lGL -lGLU"
	AC_DEFINE(HAVE_GL,1,[use the OpenGL library])
	QWT3D_LDFLAGS="-L../qwtplot3d/ -lLabPlotqwtplot3d"
	QWT3D_INCFLAGS="-I../qwtplot3d/"
fi
else
	GL="X"
fi

############################################################################


############################################################################

AC_SUBST(GSL_LDFLAGS)
AC_SUBST(FFTW_LDFLAGS)
AC_SUBST(FFTW3_LDFLAGS)
AC_SUBST(JASPER_LDFLAGS)
AC_SUBST(MAGICK_LDFLAGS)
AC_SUBST(MAGICK_INCFLAGS)
AC_SUBST(QSA_LDFLAGS)
AC_SUBST(GRASS_LDFLAGS)
AC_SUBST(GRASS_INCFLAGS)
AC_SUBST(GRASSQT_DIR)
#AC_SUBST(VTK_LDFLAGS)
#AC_SUBST(VTK_INCFLAGS)
#AC_SUBST(VTKQT_DIR)
AC_SUBST(NETCDF_LDFLAGS)
AC_SUBST(NETCDF_INCFLAGS)
AC_SUBST(NETCDF_DIR)
AC_SUBST(CDF_LDFLAGS)
AC_SUBST(CDF_INCFLAGS)
AC_SUBST(AUDIOFILE_LDFLAGS)
AC_SUBST(AUDIOFILE_INCFLAGS)
AC_SUBST(AUDIOFILE_DIR)
AC_SUBST(GL_LDFLAGS)
AC_SUBST(QWT3D_INCFLAGS)
AC_SUBST(QWT3D_LDFLAGS)

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

KDE_USE_QT(3.1)
AM_KDE_WITH_NLS

AC_PATH_KDE

dnl Checks for header files.
AC_HEADER_STDC

##########################################################################

KDE_CREATE_SUBDIRSLIST
AC_CONFIG_FILES([ Makefile ])
AC_CONFIG_FILES([ cephes/Makefile ])
#if test "${VTK_H}" == yes; then
#AC_CONFIG_FILES([ VtkQt/Makefile ])
#fi
if test "${GRASS_H}" == yes; then
AC_CONFIG_FILES([ GRASSQt/Makefile ])
fi
if test "${NETCDF_H}" != yes; then
AC_CONFIG_FILES([ netcdf/Makefile ])
fi
if test "${AUDIOFILE_H}" != yes; then
AC_CONFIG_FILES([ audiofile/Makefile ])
fi
if test "${HAVE_GL}" != yes; then
AC_CONFIG_FILES([ qwtplot3d/Makefile ])
fi
AC_CONFIG_FILES([ src/Makefile ])
AC_CONFIG_FILES([ src/icons/Makefile ])
AC_CONFIG_FILES([ doc/Makefile ])
AC_CONFIG_FILES([ doc/en/Makefile ])
AC_CONFIG_FILES([ doc/de/Makefile ])
AC_CONFIG_FILES([ man/Makefile ])
AC_CONFIG_FILES([ po/Makefile ])
AC_CONFIG_FILES([ examples/Makefile ])
AC_OUTPUT

########################################################################

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."
AC_MSG_RESULT([
System :		${host}
Source directory :	$srcdir
Installation prefix :	$prefix
C compiler : 		$CC $CFLAGS
C++ compiler :		$CXX $CXXFLAGS
log2 in libm :		$LOG2
cephes :		using included cephes library.
tiff :			$TIFF
tiff-devel :		$TIFF_H
libjasper :		$JASPER
libjasper devel :	$JASPER_H
GSL :			$GSL
GSL >= 1.4 :		$NEWGSL_H
GSL-devel :		$GSL_H
pstoedit :		$PSTOEDIT
ImageMagick++ :		$MAGICK
ImageMagick-devel :	$MAGICK_H
ImageMagick++-devel :	$MAGICKPP_H
bzip2-devel :		$BZ
FFTW 3 :		$FFTW3
FFTW 3 devel :		$FFTW3_H
FFTW :			$FFTW
FFTW devel :		$FFTW_H
GRASS :			$GRASS		GRASS_DIR=$GRASS_DIR
GRASS header :		$GRASS_H
GRASSQt :		$GRASSQT
netCDF :		$NETCDF
netCDF devel :		$NETCDF_H
CDF :			$CDF
CDF devel :		$CDF_H
audiofile :		$AUDIOFILE
audiofile devel :	$AUDIOFILE_H
QSA :			$QSA	(not used)
QSA devel :		$QSA_H
QSA workbench :		$QSA_IDE_H
QSA object factory :	$QSA_FAC_H
OpenGL :		$GL
qwtplot3d :		$GL

"-" not checked, "X" disabled, "yes" found, "no" not found
])

fi
