#MIN_CONFIG(3.1)
CXXFLAGS="$CXXFLAGS $KDE_DEFAULT_CXXFLAGS"
AC_CHECK_SETENV
AC_CHECK_UNSETENV
dnl ============
dnl Machine type
dnl ============
 
ARCH_CFLAGS="$CFLAGS -O2 -funroll-all-loops -finline-functions -ffast-math"

case "$ARCH_TYPE" in
	i486)
		AC_DEFINE(ARCH_486, 1, [WE ARE BUILDING FOR A 486])
		OPTIMIZED_ARCH="YES"
	;;
	i586)
		AC_DEFINE(ARCH_586, 1, [WE ARE BUILDING FOR A PENTIUM])
		OPTIMIZED_ARCH="YES"
	;;
	i686)
		AC_DEFINE(ARCH_686, 1, [WE ARE BUILDING FOR A PPRO])
		OPTIMIZED_ARCH="YES"
		#EXTRA_CPU_CFLAGS=$(if $CC -march=i686 -S -o /dev/null -xc /dev/null > /dev/null; then echo "-march=i686"; fi)
	;;
	ppc)
		AC_DEFINE(ARCH_PPC, 1, [WE ARE BUILDING FOR A POWERPC])
		OPTIMIZED_ARCH="YES"
	;;
	sun4u)
		AC_DEFINE(ARCH_ULTRA, 1, [WE ARE BUILDING FOR A SUN ULTRASPARC])
		# Is there mpg123 optimization for UltraSparc?
	;;
esac

# ARCH_X86
if test "$ARCH_TYPE" = "i486" || test "$ARCH_TYPE" = "i586" || test "$ARCH_TYPE" = "i686"; then
	MPG123_PLAT_LIB="$MPG123_PLAT_LIB libmpx86.la"
fi
# ARCH_486
if test "$ARCH_TYPE" = "i486"; then
	MPG123_PLAT_LIB="$MPG123_PLAT_LIB libmp486.la"
	ARCH_CFLAGS="$ARCH_CFLAGS -DROT_I386 -DI386_ASSEM -DI486_OPT -DLINUX -DREAL_IS_FLOAT"
fi
# ARCH_586
if test "$ARCH_TYPE" = "i586" -a "$MMX_SUPPORT" = "no"; then
        MPG123_PLAT_LIB="$MPG123_PLAT_LIB libmp586.la"
	ARCH_CFLAGS="$ARCH_CFLAGS -DROT_I386 -DI386_ASSEM -DPENTIUM_OPT -DLINUX -DREAL_IS_FLOAT"
fi
# ARCH_586_MMX
if test "$ARCH_TYPE" = "i586" -a "$MMX_SUPPORT" = "yes"; then
	ARCH_CFLAGS="$ARCH_CFLAGS -DROT_I386 -DI386_ASSEM -DPENTIUM_OPT -DLINUX -DREAL_IS_FLOAT"
	MPG123_PLAT_LIB=libmp586mmx.la
fi
# ARCH_686
if test "$ARCH_TYPE" = "i686" -a "$MMX_SUPPORT" = "no"; then
	ARCH_CFLAGS="$ARCH_CFLAGS -DROT_I386 -DI386_ASSEM -DPENTIUM_OPT -DLINUX -DREAL_IS_FLOAT -march=pentiumpro"
	MPG123_PLAT_LIB=libmp686.la
fi
# ARCH_686_MMX
if test "$ARCH_TYPE" = "i686" -a "$MMX_SUPPORT" = "yes"; then
	ARCH_CFLAGS="$ARCH_CFLAGS -DROT_I386 -DI386_ASSEM -DPENTIUM_OPT -DUSE_MMX -DLINUX -DREAL_IS_FLOAT -march=pentiumpro"
	MPG123_PLAT_LIB=libmp686mmx.la
fi
# ARCH_PPC
if test "$ARCH_TYPE" = "ppc"; then
	ARCH_CFLAGS="$ARCH_CFLAGS -mcpu=ppc"
	MPG123_PLAT_LIB=libmpppc.la
fi
# ARCH_ULTRA
if test "$ARCH_TYPE" = "sun4u"; then
	:
	# nothing for now
fi
# ARCH_PLAIN
if test -z "$OPTIMIZED_ARCH"; then
	MPG123_PLAT_LIB=libmpplain.la
fi

AC_SUBST(ARCH_CFLAGS)

# this is run after libtool configure parts, which set AS to as
# which is the wrong one for us.  E.g. libtool doesn't recognize that as
# tag.  So we unset it here, so the below macro can set it.
save_AS=$AS
unset AS
ifdef([AM_PROG_AS],[AM_PROG_AS],[])
#if the macro did set something useful fallback.
test -z "$AS" && AS=$save_AS
#and if AS was set to as by the macro, and we have a saved value,
#it's likely it contains a better guess (or it's also as)
test "x$AS" = xas && test -n "$save_AS" && AS=$save_AS


linux_scsi=no
AC_MSG_CHECKING(for linux scsi headers)
AC_LANG_SAVE
AC_LANG_CPLUSPLUS
AC_TRY_COMPILE([
	#include <linux/version.h>
	#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,50)
	typedef unsigned char u8;
	#endif
	#include <sys/types.h>
	#include <linux/../scsi/scsi.h> /* cope with silly includes */
	],
	[],
	[linux_scsi=yes])
AC_MSG_RESULT($linux_scsi)

if test "x$linux_scsi" = "xno" ; then
	DO_NOT_COMPILE="$DO_NOT_COMPILE k3b"
fi
AC_LANG_RESTORE


dnl - check the byte order -
dnl this will define WORDS_BIGENDIAN or do nothing
AC_C_BIGENDIAN()


AC_MSG_CHECKING(for ogg/vorbis headers)
ogg_vorbis=no
AC_TRY_COMPILE([
		#include <vorbis/codec.h>
		#include <vorbis/vorbisfile.h>
                ],[
                ],[
                ogg_vorbis=yes
                ])
AC_MSG_RESULT($ogg_vorbis)
if test x$ogg_vorbis = xyes; then
   dnl we need the ogg_vorbis_lib because otherwise we override LIBS !
   AC_CHECK_LIB(vorbisfile,ov_open,ogg_vorbis_lib=yes,
                ogg_vorbis=no,[-lvorbisfile -lvorbis -logg])
fi
if test x$ogg_vorbis = xyes; then
	AC_DEFINE(OGG_VORBIS,1,[Define if you have ogg/vorbis installed])
fi

AM_CONDITIONAL(include_OGG, [test x$ogg_vorbis = xyes])


dnl === libmad MPEG decoder check ===
MAD_LIB=""
AC_CHECK_HEADER(mad.h, [
	AC_CHECK_LIB(mad, mad_synth_frame, [
		MAD_LIB="-lmad"
		AC_DEFINE(HAVE_LIBMAD,1,[defined if you have libmad headers and libraries])
	])
])
AC_SUBST(MAD_LIB)

AM_CONDITIONAL(include_MP3, [test -n "$MAD_LIB"])



dnl === test for FLAC++ and FLAC ====
have_flac=no
KDE_CHECK_HEADERS(FLAC++/decoder.h, [
   AC_CHECK_LIB(FLAC,FLAC__seekable_stream_decoder_process_single,
	        have_flac=yes)])
AM_CONDITIONAL(include_FLAC, [test x$have_flac = xyes])


dnl === check for id3lib ============
ID3_LIB=""
KDE_CHECK_HEADERS(id3/tag.h, [
	ID3_LIB="-lid3"
	AC_DEFINE(HAVE_LIBID3,1,[defined if you have libid3 headers and libraries])
])
AC_SUBST(ID3_LIB)


dnl === check for resmgr ============
RESMGR_LIB=""
AC_CHECK_HEADERS(resmgr.h, [
       AC_CHECK_LIB(resmgr,rsm_open_device,[
               RESMGR_LIB="-lresmgr"
               AC_DEFINE(HAVE_RESMGR,1,[defined if you have resmgr libraries and headers])
       ])
])
AC_SUBST(RESMGR_LIB)


dnl === check for libsamplerate ==========
LIBSAMPLERATE=""
AC_CHECK_HEADERS(samplerate.h, [
	AC_CHECK_LIB(samplerate, src_new, [
		LIBSAMPLERATE="-lsamplerate"	
		AC_DEFINE(HAVE_LIBSAMPLERATE,1,[defined if you have libsamplerate library and header])
	])
])
AC_SUBST(LIBSAMPLERATE)
AM_CONDITIONAL(compile_libsamplerate, [test -z "$LIBSAMPLERATE"])


dnl Find aRts
ARTS_LIBS=""
KDE_CHECK_HEADERS(arts/artsflow.h,
	[KDE_CHECK_HEADERS(arts/kmedia2.h,
		[arts_available=yes
	 	 ARTS_LIBS="-lartskde"],
		[arts_available=no]
	)]
)
AC_SUBST(ARTS_LIBS)

KDE_CHECK_THREADING

compile_k3bsetup=yes
AC_ARG_WITH(k3bsetup, 
	[  --with-k3bsetup[=ARG]     do compile K3bSetup2 KControl Module (default=yes)],
	[compile_k3bsetup=$withval]
)

if test x$compile_k3bsetup = xyes; then
        AC_DEFINE(HAVE_K3BSETUP,1,[defined if K3bSetup is compiled])
fi

AM_CONDITIONAL(with_k3bsetup1, [test x$compile_k3bsetup = xyes])
