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.6.0,0,0)
AC_DEFINE(LVERSION,"1.6.0",[LabPlot version])
AC_DEFINE(LVERSION_DATE,["Dec 17, 2007"],[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_CC
AC_PROG_CXX
AC_PROG_YACC
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
	TIFF_LDFLAGS=-ltiff
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,-lgslcblas -lm)
if test "$GSL" = yes; then
	AC_CHECK_HEADER(gsl/gsl_version.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"

		# check versions
		AM_PATH_GSL(1.4,GSL14=yes,GSL14=no)
		if test "$GSL14" = yes; then
			AC_DEFINE(HAVE_GSL14,1,[use the gsl library])
			AM_PATH_GSL(1.6,GSL16=yes,GSL16=no)
			if test "$GSL16" = yes; then
				AC_DEFINE(HAVE_GSL16,1,[use the gsl library])
				AM_PATH_GSL(1.7,GSL17=yes,GSL17=no)
				if test "$GSL17" = yes; then
					AC_DEFINE(HAVE_GSL17,1,[use the gsl library])
					AC_DEFINE(GSL_DISABLE_DEPRECATED,1,[needed for --enable-final])
					AM_PATH_GSL(1.8,GSL18=yes,GSL18=no)
					if test "$GSL18" = yes; then
						AC_DEFINE(HAVE_GSL18,1,[use the gsl library])
					else
						echo "PLEASE IGNORE THIS MESSAGE."
					fi
				else
					echo "PLEASE IGNORE THIS MESSAGE."
				fi
			else
				echo "PLEASE IGNORE THIS MESSAGE."
			fi
		else
			echo "PLEASE IGNORE THIS MESSAGE."
		fi
	fi
else
	GSL_H="-"
    	GSL_LDFLAGS=
fi
else
	GSL_LDFLAGS=
	GSL="X"
	GSL_H="X"
	GSL14="X"
	GSL16="X"
	GSL17="X"
fi

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

# check for config header
AC_CHECK_HEADER(fftw-config.h,FFTW_CONFIG_H=yes,FFTW_CONFIG_H=no)
if test "$FFTW_CONFIG_H" = yes; then
	AC_DEFINE(HAVE_FFTW_CONFIG,1,[use the fftw config header])
fi

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])
		AC_CHECK_LIB(fftw3_threads,fftw_init_threads,FFTW3_THREADS=yes,FFTW3_THREADS=no,-lfftw3)
		if test "${FFTW3_THREADS}" = yes; then
			FFTW3_LDFLAGS="-lfftw3 -lfftw3_threads -lpthread"
			AC_DEFINE(HAVE_FFTW3_THREADS,1,[use the fftw3 threads library])
		else
			FFTW3_LDFLAGS="-lfftw3"
		fi
		FFTW3="using this version."
		FFTW_LDFLAGS=""
		USE_FFTW="no"
	fi
else
	FFTW3_LDFLAGS=""
	FFTW3_H="-"
	FFTW3_THREADS="-"
fi
else
	FFTW3_LDFLAGS=""
	FFTW3_H="X"
	FFTW3="X"
	FFTW3_THREADS="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 / PS2EPS / PS2PDF ##################################

AC_CHECK_PROG(PSTOEDIT,pstoedit,yes,no)
AC_CHECK_PROG(PS2EPS,ps2epsi,yes,no)
AC_CHECK_PROG(PS2PDF,ps2pdf,yes,no)

################# TEXVC ##################################

AC_ARG_ENABLE(texvc,AC_HELP_STRING([--enable-texvc],[use texvc for LaTeX label (default=auto)]),
	[USE_TEXVC="$enableval"])

if test "$USE_TEXVC" != no; then
AC_CHECK_PROG(TEXVC,texvc,yes,no)
if test "${TEXVC}" = yes; then
	OCAML="-"
fi
else
	TEXVC="X"
fi

AC_ARG_ENABLE(ocaml,AC_HELP_STRING([--enable-ocaml],[use ocaml to compile texvc for LaTeX label (default=auto)]),
	[USE_OCAML="$enableval"])

if test "$USE_OCAML" != no; then
AC_CHECK_PROG(OCAML,ocaml,yes,no)
if test "${OCAML}" = yes; then
	TEXVC_DIR=texvc
	TEXVC="using included version."
fi
else
	TEXVC="X"
	OCAML="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_LANG_PUSH(C++)
	AC_CHECK_HEADER(magick/api.h,MAGICK_H=yes,MAGICK_H=no)
	AC_LANG_POP(C++)
	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
case "$target" in
x86_64*)
	AC_CHECK_LIB(qsa,main,QSA=yes,QSA=no,-L/usr/lib -L/usr/lib64 -L$QTDIR/lib -L$QTDIR/lib64)
	;;
*)
	AC_CHECK_LIB(qsa,main,QSA=yes,QSA=no,-L/usr/lib -L$QTDIR/lib)
	;;
esac
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])
		case "$target" in
		x86_64*)
    			QSA_LDFLAGS="-L/usr/lib -L/usr/lib64 -lqsa"
			;;
		*)
    			QSA_LDFLAGS="-L/usr/lib -lqsa"
			;;
		esac
	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

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

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

AC_ARG_ENABLE(system-netcdf,AC_HELP_STRING([--disable-system-netcdf],[use included Unidata Network Common Data Form (netCDF) library 
(default=auto)]), [USE_SYSTEM_NETCDF="$enableval"])

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

if test "$USE_NETCDF" != no; then
	USE_NETCDF="yes"
	AC_DEFINE(HAVE_NETCDF,1,[use the netCDF library])
	if test "$USE_SYSTEM_NETCDF" == no; then
		USE_SYSTEM_NETCDF="X"
	else
		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=
				USE_SYSTEM_NETCDF="yes"
			else
				USE_SYSTEM_NETCDF="-"
			fi
		else
			USE_SYSTEM_NETCDF="-"
		fi
	fi
else
	USE_NETCDF="X"
	USE_SYSTEM_NETCDF="X"
	NETCDF_LDFLAGS=
	NETCDF_INCFLAGS=
	NETCDF_DIR=
fi

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

# check for config header
export CPATH="$CPATH:$CDF_DIR/src/include"
AC_CHECK_HEADER(cdfrev.h,CDF_CONFIG_H=yes,CDF_CONFIG_H=no)
if test "$CDF_CONFIG_H" = yes; then
	AC_DEFINE(HAVE_CDF_CONFIG,1,[use the cdf config header])
fi

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
	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_INCFLAGS=
AUDIOFILE_DIR=

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.")
	if test "$AUDIOFILE_H" = yes; then
		AUDIOFILE_LDFLAGS="-laudiofile"
		AUDIOFILE_INCFLAGS=
		AUDIOFILE_DIR=
		AC_DEFINE(HAVE_AUDIOFILE,1,[use the audiofile library])
	fi
else
	AUDIOFILE_H="-"
fi
else
	AUDIOFILE="X"
	AUDIOFILE_H="X"
fi

########################## HDF5 ##############################

AC_ARG_ENABLE(hdf5,AC_HELP_STRING([--enable-hdf5],[use the hdf5 (default=auto)]),
[USE_HDF5="$enableval"])

HDF5_LDFLAGS=

if test "$USE_HDF5" != no; then
AC_CHECK_LIB(hdf5,main,HDF5=yes,HDF5="no")
if test "$HDF5" = yes; then
	AC_CHECK_HEADER(hdf5.h,HDF5_H=yes,HDF5_H="no")
	if test "$HDF5_H" = yes; then
		HDF5_LDFLAGS="-lhdf5"
		AC_DEFINE(HAVE_HDF5,1,[use the hdf5 library])
	fi
else
	HDF5_H="-"
fi
else
	HDF5="X"
	HDF5_H="X"
fi

########################## KexiDB ##############################

AC_ARG_ENABLE(KexiDB,AC_HELP_STRING([--enable-KexiDB],[use the KexiDB library  KEXIDB_DIR (default=auto)]),
[USE_KEXIDB="$enableval"])

KEXIDB_LDFLAGS=
KEXIDB_INCFLAGS=
		
if test "$USE_KEXIDB" != no; then
case "$target" in
x86_64*)
	if test -n "$KEXIDB_DIR"; then
	AC_CHECK_LIB(kexidb,main,KEXIDB=yes,KEXIDB=no,-L$KDEDIR/lib -L$DKEDIR/lib64 -L$KEXIDB_DIR/lib -L$KEXIDB_DIR/lib64 -lkexidbparser)
	else
	AC_CHECK_LIB(kexidb,main,KEXIDB=yes,KEXIDB=no,-L$KDEDIR/lib -L$DKEDIR/lib64 -lkexidbparser)
	fi
	;;
*)
	if test -n "$KEXIDB_DIR"; then
	AC_CHECK_LIB(kexidb,main,KEXIDB=yes,KEXIDB=no,-L$KDEDIR/lib -L$KEXIDB_DIR/lib -lkexidbparser)
	else
	AC_CHECK_LIB(kexidb,main,KEXIDB=yes,KEXIDB=no,-L$KDEDIR/lib -lkexidbparser)
	fi
	;;
esac
if test "$KEXIDB" = yes; then
	export CPATH="$CPATH:$KDEDIR/include:$KEXIDB_DIR:$KEXIDB_DIR/include:$KEXIDB_DIR/include/kexidb:$QTDIR/include"
	AC_LANG_PUSH(C++)
	AC_CHECK_HEADER(kexidb/driver.h,KEXIDB_H=yes,KEXIDB_H="no")
	AC_LANG_POP(C++)
	if test "$KEXIDB_H" = yes; then
		KEXIDB_LDFLAGS="-L$KEXIDB_DIR/lib -L$KEXIDB_DIR/lib64 -lkexidb -lkexidbparser"
		KEXIDB_INCFLAGS="-I$KEXIDB_DIR -I$KEXIDB_DIR/include -I$KDEDIR/include/kexidb -I$KEXIDB_DIR/include/kexidb"
		AC_DEFINE(HAVE_KEXIDB,1,[use the KexiDB library])
	fi
else
	KEXIDB_H="-"
fi
else
	KEXIDB="X"
	KEXIDB_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=""

AC_ARG_ENABLE(system-qwtplot3d,AC_HELP_STRING([--enable-system-qwtplot3d],
[use the system qwtplot3d library (default=no) (uses QWT3D_PATH) ]),
[USE_SYSTEM_QWT3D="yes"],[USE_SYSTEM_QWT3D="no"])

QWT3D_DIR=

if test "$USE_GL" != no; then
	AC_CHECK_LIB(GL,main,GL=yes,GL=no,-L/usr/X11R6/lib)
	if test "$GL" = yes; then
		AC_CHECK_HEADER(GL/glu.h,GL_H=yes,GL_H="no")
		if test "$GL_H" = yes; then
			GL_LDFLAGS="-lGL -lGLU"
			AC_DEFINE(HAVE_GL,1,[use the OpenGL library])

			if test "$USE_SYSTEM_QWT3D" != no; then
				AC_CHECK_LIB(qwtplot3d,main,SYSTEM_QWT3D=yes,SYSTEM_QWT3D=no,-L$QWT3D_PATH/lib)
				if test "$SYSTEM_QWT3D" = yes; then
					QWT3D_LDFLAGS="-L$QWT3D_PATH/lib -lqwtplot3d"
					QWT3D_INCFLAGS="-I$QWT3D_PATH/include -I$QWT3D_PATH/include/qwtplot3d"
					QWT3D="using system version. QWT3D_PATH=$QWT3D_PATH"
				else
					QWT3D="using included version."
					QWT3D_LDFLAGS="../qwtplot3d/libLabPlotqwtplot3d.la"
					QWT3D_INCFLAGS="-I../qwtplot3d/"
					QWT3D_DIR=qwtplot3d
				fi
			else
				QWT3D="yes. using included version."
				QWT3D_LDFLAGS="../qwtplot3d/libLabPlotqwtplot3d.la"
				QWT3D_INCFLAGS="-I../qwtplot3d/"
				QWT3D_DIR=qwtplot3d
			fi
		else
			QWT3D="-"
		fi
	else
		GL_H="-"
	fi
else
	GL="X"
	GL_H="X"
	QWT3D="-"
fi

#################### R ###############################################
AC_ARG_ENABLE(R,AC_HELP_STRING([--enable-R],[use R (default=auto) (uses R_HOME, R must be compiled with --enable-R-shlib)]),
[USE_R="$enableval"])

R_LDFLAGS=""
R_INCFLAGS=""

if test "$USE_R" != no; then
	AC_CHECK_LIB(R,R_alloc,R=yes,R=no,-L$R_HOME/lib)
	if test "$R" = yes; then
		export CPATH="$CPATH:$R_HOME/include"
		AC_CHECK_HEADER(R.h,R_H=yes,R_H=no)
		if test "$R_H" = yes; then
			R_LDFLAGS="-L$R_HOME/lib -lR"
			R_INCFLAGS="-I$R_HOME/include"
			AC_DEFINE(HAVE_R,1,[use the R library])
		fi
	else
		R_H="-"
	fi
else
	R="X"
	R_H="X"
fi

#################### LIBUNDO ###############################################
#AC_ARG_ENABLE(libundo,AC_HELP_STRING([--enable-libundo],[use the libundo library (default=auto)]),
#[USE_LIBUNDO="$enableval"])
#
#if test "$USE_LIBUNDO" != no; then
#	LIBUNDO="enabled"
#	AC_DEFINE(HAVE_UNDO,1,[use the libundo library])
#	LIBUNDO_DIR=libundo
#	LIBUNDO_LDFLAGS="../libundo/libLabPlotundo.la"
#else
#	LIBUNDO="X"
#fi
#
#################### LIBORGIN ###############################################
AC_ARG_ENABLE(system-liborigin,AC_HELP_STRING([--enable-system-liborigin],[use the system liborigin library (default=auto)]),
[USE_SYSTEM_LIBORIGIN="$enableval"])

LIBORIGIN_INCFLAGS=""
LIBORIGIN_LDFLAGS=""

if test "$USE_SYSTEM_LIBORIGIN" != no; then
	AC_CHECK_LIB(origin,main,LIBORIGIN=yes,LIBORIGIN=no)
	if test "$LIBORIGIN" = yes; then
		AC_LANG_PUSH(C++)
		AC_CHECK_HEADER(liborigin/OPJFile.h,LIBORIGIN_H=yes,LIBORIGIN_H="no")
		AC_LANG_POP(C++)
		if test "$LIBORIGIN_H" = yes; then
			rm -f liborigin-test.cpp
			cat >liborigin-test.cpp << EOF
#include <liborigin/OPJFile.h>

#if LIBORIGIN_VERSION < 0x00070926
#error "Your system version of liborigin is too old!"
#endif
EOF
			${CXX} -c liborigin-test.cpp
			if test $? -eq 0; then
				LIBORIGIN_LDFLAGS="-lorigin"
				LIBORIGIN="yes"
			else
				LIBORIGIN="using included version."
			fi
			rm -f liborigin-test.*
		else
			LIBORIGIN="system header not found. using included version."
		fi
	else
		LIBORIGIN="system library not found. using included version."
	fi
fi

if test "$LIBORIGIN" != yes; then
	LIBORIGIN_LDFLAGS="../liborigin-20070926/OPJFile.cpp"
	LIBORIGIN_INCFLAGS="-I../liborigin-20070926"
fi

#################### QHULL ###############################################
AC_ARG_ENABLE(qhull,AC_HELP_STRING([--enable-qhull],[use the qhull library (default=auto)]),
[USE_QHULL="$enableval"])

if test "$USE_QHULL" != no; then
	AC_CHECK_PROG(QHULL,qdelaunay,yes,no)
	if test "${QHULL}" = yes; then
		QHULL="using system version."
		QHULL_DIR=
	else
		QHULL="using included version."
		QHULL_DIR=qhull
	fi
	AC_DEFINE(HAVE_QHULL,1,[use the qhull library])
else
	QHULL="X"
fi
############################################################################

AC_SUBST(TIFF_LDFLAGS)
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(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)
AC_SUBST(QWT3D_DIR)
AC_SUBST(TEXVC_DIR)
AC_SUBST(KEXIDB_LDFLAGS)
AC_SUBST(KEXIDB_INCFLAGS)
AC_SUBST(R_LDFLAGS)
AC_SUBST(R_INCFLAGS)
AC_SUBST(LIBORIGIN_INCFLAGS)
AC_SUBST(LIBORIGIN_LDFLAGS)
AC_SUBST(QHULL_DIR)
AC_SUBST(HDF5_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 "$USE_QHULL" != no; then
	AC_CONFIG_FILES([ qhull/Makefile ])
fi
if test "$NETCDF_H" != yes -a "$USE_NETCDF" != no; then
	AC_CONFIG_FILES([ netcdf/Makefile ])
fi
if test "$QWT3D" != yes; then
	AC_CONFIG_FILES([ qwtplot3d/Makefile ])
fi
if test "$OCAML" != no; then
	AC_CONFIG_FILES([ texvc/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([ doc/fr/Makefile ])
AC_CONFIG_FILES([ doc/sv/Makefile ])
AC_CONFIG_FILES([ doc/br/Makefile ])
AC_CONFIG_FILES([ doc/it/Makefile ])
AC_CONFIG_FILES([ doc/pl/Makefile ])
AC_CONFIG_FILES([ doc/nl/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.
libtiff :		$TIFF
libtiff-devel :		$TIFF_H
libjasper :		$JASPER
libjasper-devel :	$JASPER_H
gsl :			$GSL
gsl-devel :		$GSL_H
gsl >= 1.4 :		$GSL14
gsl >= 1.6 :		$GSL16
gsl >= 1.7 :		$GSL17
gsl >= 1.8 :		$GSL18
pstoedit :		$PSTOEDIT	(used dynamical)
ps2eps :		$PS2EPS	(used dynamical)
ps2pdf :		$PS2PDF	(used dynamical)
texvc :			$TEXVC	(used dynamical)
ocaml :			$OCAML
ImageMagick++ :		$MAGICK
ImageMagick-devel :	$MAGICK_H
ImageMagick++-devel :	$MAGICKPP_H
bzip2-devel :		$BZ
fftw3 :			$FFTW3
fftw3 devel :		$FFTW3_H
fftw3 threads :		$FFTW3_THREADS
fftw :			$FFTW
fftw devel :		$FFTW_H
fftw config :		$FFTW_CONFIG_H
netCDF :		$USE_NETCDF
system netCDF :		$USE_SYSTEM_NETCDF
CDF :			$CDF
CDF devel :		$CDF_H
CDF config :		$CDF_CONFIG_H
audiofile :		$AUDIOFILE
audiofile devel :	$AUDIOFILE_H
hdf5 :			$HDF5
hdf5 header :		$HDF5_H
KexiDB :		$KEXIDB
KexiDB header :		$KEXIDB_H
qsa :			$QSA
qsa-devel :		$QSA_H
qsa workbench :		$QSA_IDE_H
QSA object factory :	$QSA_FAC_H
OpenGL :		$GL
OpenGL header :		$GL_H
qwtplot3d :		$QWT3D
liborigin : 		$LIBORIGIN
R library :		$R
R header :		$R_H
QHull :			$QHULL

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

fi

####################################################################
#### WARNINGS

if test "X$USE_EXCEPTIONS" = "X"
then
	echo " WARNING : Your compiler does not support the \"-fexceptions\" option."
	echo " This may cause problems during compilation."
	echo ""
else
	AC_DEFINE(HAVE_EXCEPTIONS,1,[exceptions available])
fi 
if test "$GSL16" = "yes" -a "$GSL17" = "no"
then
	echo " WARNING : Please don't use \"--enable-final\"."
	echo " The gsl version 1.6 has a bug which may cause problems."
	echo ""
fi
if test "$GL" = "no" -o "$GL_H" = "no"
then
	echo " WARNING : Could not find the GL library or header."
	echo " Disabling support for 3 dimensional QWT plots."
	echo ""
fi
