#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

AC_PREREQ(2.50)
AC_INIT(lmms, 0.3.0, lmms-devel/at/lists/dot/sf/dot/net)
AM_INIT_AUTOMAKE(lmms, 0.3.0)

AM_CONFIG_HEADER(config.h)

# Checks for programs.
AC_PROG_CXX
AC_PROG_CC
AC_LIBTOOL_WIN32_DLL
AC_PROG_LN_S
AC_PROG_GCC_TRADITIONAL
AM_PROG_LIBTOOL

if ! test -z "${prefix}" -o "${prefix}" = "NONE" ; then
	CFLAGS="$CFLAGS -I${prefix}/include"
	CPPFLAGS="$CPPFLAGS -I${prefix}/include"
	LDFLAGS="$LDFLAGS -L${prefix}/bin"
fi

AH_TEMPLATE(BUILD_LINUX, [Build LMMS for Linux])
AH_TEMPLATE(BUILD_WIN32, [Build LMMS for Win32])
AC_ARG_WITH(linux,
	[  --with-linux		explicit build LMMS for Linux], [ build_linux=true ], [ build_linux=false ])
AC_ARG_WITH(win32,
	[  --with-win32		explicit build LMMS for Win32], [ build_win32=true ], [ build_win32=false ])
AC_MSG_CHECKING([platform to build for])
if test "x$build_win32" = "xtrue" ; then
	AC_MSG_RESULT([Win32, will enable support for it])
	AC_DEFINE(BUILD_WIN32)
	AC_DEFINE(WIN32)
	build_linux="false"
	build_win32="true"
else
#	if test `uname -s | tr -s 'LINUX' 'linux'` = "linux" -o "x$build_linux" = "xyes" ; then
		AC_MSG_RESULT([Linux, will enable support for it])
		AC_DEFINE(BUILD_LINUX)
		build_linux="true"
		build_win32="false"
#	if uname -s | grep MINGW32 ; then
#	else
#		AC_MSG_ERROR([*** non usable found... Run ./configure --help to see a list of available platforms, you can also specify explicit, if your platform was not recognized properly. Otherwise your platform isn't supported yet. In this case please contact the maintainer (see README)])
	#fi
fi

AM_CONDITIONAL(BUILD_WIN32, test "$build_win32" = "true")
AM_CONDITIONAL(BUILD_LINUX, test "$build_linux" = "true")


# -fomit-frame-pointer crashes wine on Ubuntu Dapper--Danny 7/21/06
#DEFAULTFLAGS="-floop-optimize2 -fomit-frame-pointer -fgcse-sm -fgcse-las"
DEFAULTFLAGS="-O2 -fPIC" #"-floop-optimize2 -fgcse-sm  -fgcse-las"

# Tested with GCC 4.0--needs to be tested with 4.1--Danny 7/21/06
if test "x`$CC --version|head -1|cut -d\  -f3|cut -d. -f1`" = "x4" ; then
	DEFAULTFLAGS="$DEFAULTFLAGS -ftree-vectorize -ftree-loop-linear"
#	if test "x`$CC --version|head -1|cut -d\  -f3|cut -d. -f2`" != "x0" ; then
#		DEFAULTFLAGS="$DEFAULTFLAGS -funsafe-loop-optimizations -Wunsafe-loop-optimizations"
#	fi	
fi

CFLAGS="$DEFAULTFLAGS $CFLAGS"
CXXFLAGS="$DEFAULTFLAGS $CXXFLAGS"

AC_PATH_XTRA
gw_CHECK_QT


# checks for header files.
AC_HEADER_STDC
AC_HEADER_SYS_WAIT
AC_CHECK_HEADERS([fcntl.h memory.h string.h sys/ioctl.h unistd.h stdlib.h pthread.h sys/ipc.h sys/shm.h sys/time.h sys/select.h sys/types.h stdarg.h signal.h sched.h ctype.h])

# checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
AC_C_INLINE
AC_TYPE_SIZE_T
AC_HEADER_TIME
AC_STRUCT_TM
AC_C_VOLATILE
AC_C_BIGENDIAN
AC_CHECK_TYPES([mode_t, off_t, pid_t, size_t, ssize_t, long long])

# checks for library functions.
AC_FUNC_ALLOCA
AC_FUNC_MALLOC
AC_FUNC_MEMCMP
AC_TYPE_SIGNAL

AC_CHECK_FUNCS([usleep pipe sprintf])



# search for include-path of SDL (just for supporting the FreeBSD-guys.... ;-)
for i in SDL SDL10 SDL11 SDL12 ; do
	FOUND=""
	AC_CHECK_HEADER($i/SDL.h, FOUND="true")
	if test "$FOUND" = "true" ; then
		SDL_INC_PATH="$i"
		break
	fi
done


AH_TEMPLATE(SDL_SDL_H, [Define to location of SDL.h])
AH_TEMPLATE(SDL_SDL_AUDIO_H, [Define to location of SDL_audio.h])
AH_TEMPLATE(SDL_SDL_SOUND_H, [Define to location of SDL_sound.h])

OLD_LIBS="$LIBS"
#LIBS="$LIBS -lpthread"

# check for SDL-lib
AC_ARG_WITH(sdl,
	AS_HELP_STRING([--without-sdl],
			[disable support for SDL-audio-output]), ,
 	[ with_sdlaudio=yes ])
AH_TEMPLATE(HAVE_SDL_SDL_AUDIO_H, [Define to 1 if you have the <$SDL_INC_PATH/SDL_audio.h> header file.])
if test "x$with_sdlaudio" = "xyes" -a ! -z "$SDL_INC_PATH"; then
	AC_CHECK_HEADER($SDL_INC_PATH/SDL_audio.h, HAVE_SDL_SDL_AUDIO_H="true")
	AC_CHECK_LIB([SDL], [SDL_OpenAudio], HAVE_LIBSDL="true", HAVE_SDL_SDL_AUDIO_H="")
fi
if test ! -z "$HAVE_SDL_SDL_AUDIO_H" ; then
	AC_DEFINE_UNQUOTED(SDL_SDL_H, <$SDL_INC_PATH/SDL.h>)
	AC_DEFINE_UNQUOTED(SDL_SDL_AUDIO_H, <$SDL_INC_PATH/SDL_audio.h>)
	AC_DEFINE(HAVE_SDL_SDL_AUDIO_H)
fi
AM_CONDITIONAL(HAVE_LIBSDL, test ! -z "$HAVE_SDL_SDL_AUDIO_H")


# check for SDL_sound-lib
AC_ARG_WITH(sdlsound,
	AS_HELP_STRING([--without-sdlsound],
			[disable support for reading samples via SDL_sound]), ,
 	[ with_sdlsound=yes ])
AH_TEMPLATE(HAVE_SDL_SDL_SOUND_H, [Define to 1 if you have the <$SDL_INC_PATH/SDL_sound.h> header file.])
if test "x$with_sdlsound" = "xyes" -a ! -z "$SDL_INC_PATH"; then
	AC_CHECK_HEADER($SDL_INC_PATH/SDL_sound.h, HAVE_SDL_SDL_SOUND_H="true")
	AC_CHECK_LIB([SDL_sound], [Sound_Init], HAVE_LIBSDL_SOUND="true", HAVE_SDL_SDL_SOUND_H="")
fi
if test ! -z "$HAVE_SDL_SDL_SOUND_H" ; then
	AC_DEFINE_UNQUOTED(SDL_SDL_SOUND_H, <$SDL_INC_PATH/SDL_sound.h>)
	AC_DEFINE(HAVE_SDL_SDL_SOUND_H)
fi

AM_CONDITIONAL(HAVE_LIBSDL_SOUND, test ! -z "$HAVE_LIBSDL_SOUND")

LIBS="$OLD_LIBS"


# check for ALSA-lib
AC_ARG_WITH(asound,
	AS_HELP_STRING([--without-asound],
			[disable support for ALSA-sound-output]), ,
 	[ with_asound=yes ])
AH_TEMPLATE(HAVE_ALSA_ASOUNDLIB_H, [Define to 1 if you have the <alsa/asoundlib.h> header file.])
if test "x$with_asound" = "xyes" ; then
	AC_CHECK_HEADER(alsa/asoundlib.h, HAVE_ALSA_ASOUNDLIB_H="true")
	AC_CHECK_LIB([asound], [snd_pcm_open], HAVE_LIBASOUND="true", HAVE_ALSA_ASOUNDLIB_H="")
fi
if test ! -z "$HAVE_ALSA_ASOUNDLIB_H" ; then
	AC_DEFINE(HAVE_ALSA_ASOUNDLIB_H)
fi
AM_CONDITIONAL(HAVE_LIBASOUND, test ! -z "$HAVE_ALSA_ASOUNDLIB_H")


# check for OSS
AC_ARG_WITH(oss,
	AS_HELP_STRING([--without-oss],
			[disable support for OSS-sound-output]), ,
 	[ with_oss=yes ])
AH_TEMPLATE(HAVE_SYS_SOUNDCARD_H, [Define to 1 if you have the <sys/soundcard.h> header file.])
AH_TEMPLATE(HAVE_SOUNDCARD_H, [Define to 1 if you have the <soundcard.h> header file.])
if test "x$with_oss" = "xyes" ; then
	AC_CHECK_HEADER(sys/soundcard.h, HAVE_SYS_SOUNDCARD_H="true")
	AC_CHECK_HEADER(soundcard.h, HAVE_SOUNDCARD_H="true")
fi
if test ! -z "$HAVE_SYS_SOUNDCARD_H" ; then
	AC_DEFINE(HAVE_SYS_SOUNDCARD_H)
fi
if test ! -z "$HAVE_SOUNDCARD_H" ; then
	AC_DEFINE(HAVE_SOUNDCARD_H)
fi


# check for JACK
AC_ARG_WITH(jack,
	AS_HELP_STRING([--without-jack],
			[disable support for JACK-transport]), ,
 	[ with_jack=yes ])
AH_TEMPLATE(HAVE_JACK_JACK_H, [Define to 1 if you have the <jack/jack.h> header file.])
AH_TEMPLATE(OLD_JACK, [Define to 1 if your JACK-version doesnt know about jack_client_open() etc.])
if test "x$with_jack" = "xyes" ; then
	AC_CHECK_HEADER(jack/jack.h, HAVE_JACK_JACK_H="true")
	AC_CHECK_LIB([jack], [jack_client_new], HAVE_LIBJACK="true", HAVE_JACK_JACK_H="")
	AC_CHECK_LIB([jack], [jack_client_open], JACK_CLIENT_OPEN="true")
	if test -z "$JACK_CLIENT_OPEN" ; then
		AC_DEFINE(OLD_JACK)
	fi
fi
if test ! -z "$HAVE_JACK_JACK_H" ; then
	AC_DEFINE(HAVE_JACK_JACK_H)
fi
AM_CONDITIONAL(HAVE_LIBJACK, test ! -z "$HAVE_JACK_JACK_H")


# check for proper WINE-installation and existing Steinberg headers
AC_ARG_WITH(vst,
	AS_HELP_STRING([--without-vst],
			[disable support for builtin VST-plugin-hosting]), , [ with_vst=yes ])
if test "x$with_vst" = "xyes" ; then

	if echo $CFLAGS $CXXFLAGS | grep "fomit-frame-pointer" > /dev/null ; then
		AC_MSG_ERROR([*** passing -fomit-frame-pointer as compiler-flag will break LMMS' VST-support so either disable VST-support using --without-vst or remove it from compiler-flags])
	fi

	if test "$build_linux" = "true" ; then
		AC_CHECK_PROG(WINECXX, wineg++, /usr/bin/wineg++,,/usr/bin)
		AC_CHECK_LIB([wine], [wine_init], true)
		if test ! -z "$WINECXX" ; then
			AC_LANG_PUSH(C++)
#			CXXFLAGS="$CXXFLAGS -I${prefix}/include/wine/windows"
			OLDCXX="$CXX"
			OLDCPPFLAGS="$CPPFLAGS"
			CXX="$WINECXX"
			CPPFLAGS="$CPPFLAGS -I${prefix}/include/wine/windows"
			AC_CHECK_HEADER(windows.h, HAVE_WINDOWS_H="true")
			CXX="$OLDCXX"
			CPPFLAGS="$OLDCPPFLAGS"
			AC_LANG_POP(C++)
			if test -z "$HAVE_WINDOWS_H" ; then
				WINECXX=""
			fi
		fi
	fi
fi
AM_CONDITIONAL(VST_SUPPORT, test ! -z "$WINECXX")


# check for LADSPA-SDK
AC_ARG_WITH(ladspa,
	AS_HELP_STRING([--without-ladspa], [disable support for LADSPA]), , [ with_ladspa=yes ] )
AH_TEMPLATE(HAVE_LADSPA_H, [Define to 1 if you have the <ladspa.h> header file.])
AH_TEMPLATE(LADSPA_SUPPORT, [Define to 1 if you have the <ladspa.h> header file.])
if test "x$with_ladspa" = "xyes" ; then
	AC_CHECK_HEADER(ladspa.h, HAVE_LADSPA_H="true")
fi
if test ! -z "$HAVE_LADSPA_H" ; then
	AC_DEFINE(HAVE_LADSPA_H)
fi
if [ "$build_linux" = "true" ] ; then
	AC_DEFINE(LADSPA_SUPPORT)
fi
#AM_CONDITIONAL(HAVE_LADSPA_H, test ! -z "$HAVE_LADSPA_H")
AM_CONDITIONAL(LADSPA_SUPPORT, test "$build_linux" = "true" )


# check for STK
AC_LANG_PUSH(C++)
AC_ARG_WITH(stk,
	AS_HELP_STRING([--without-stk], [disable support for STK plugins]), ,
	[ with_stk=yes ])
AH_TEMPLATE(HAVE_STK_H, [Define to 1 if you have the <stk/Stk.h> header file.])
if test "x$with_stk" = "xyes" ; then
	AC_CHECK_HEADER([stk/Stk.h], HAVE_STK_H="true")
	AC_CHECK_LIB([stk], [main], HAVE_STK="true", HAVE_STK_H="", 
							[-ljack -lasound])
fi
if test ! -z "$HAVE_STK_H" ; then
	AC_DEFINE(HAVE_STK_H)
	AC_SUBST(stk_includes, [/usr/include/stk])
	AC_SUBST(stk_lib, [/usr/lib])
fi
AM_CONDITIONAL(STK_SUPPORT, test ! -z "$HAVE_STK_H")
AC_LANG_POP(C++)


# check for vorbis-lib
AC_ARG_WITH(vorbis,
 	AS_HELP_STRING([--without-vorbis],
		[disable support for exporting song to OGG-files]), ,
 	[ with_vorbis=yes ])
AH_TEMPLATE(HAVE_VORBIS_CODEC_H, [Define to 1 if you have the <vorbis/codec.h> header file.])
AH_TEMPLATE(HAVE_VORBIS_VORBISENC_H, [Define to 1 if you have the <vorbis/vorbisenc.h> header file.])
AH_TEMPLATE(HAVE_VORBIS_VORBISFILE_H, [Define to 1 if you have the <vorbis/vorbisfile.h> header file.])
if test "x$with_vorbis" = "xyes" ; then
	OGG_SUPPORT="true"
	AC_CHECK_HEADER(vorbis/codec.h, HAVE_VORBIS_CODEC_H="true",OGG_SUPPORT="")
	AC_CHECK_HEADER(vorbis/vorbisenc.h, HAVE_VORBIS_VORBISENC_H="true",OGG_SUPPORT="")
	AC_CHECK_HEADER(vorbis/vorbisfile.h, HAVE_VORBIS_VORBISFILE_H="true",OGG_SUPPORT="")
	AC_CHECK_LIB([vorbis], [vorbis_analysis], HAVE_LIBVORBIS="true", OGG_SUPPORT="")
fi
if test ! -z "$OGG_SUPPORT" ; then
	AC_DEFINE(HAVE_VORBIS_CODEC_H)
	AC_DEFINE(HAVE_VORBIS_VORBISENC_H)
	AC_DEFINE(HAVE_VORBIS_VORBISFILE_H)
fi
AM_CONDITIONAL(HAVE_LIBVORBIS, test ! -z "$OGG_SUPPORT")


# check for libFLAC
AC_ARG_WITH(flac,
	AS_HELP_STRING([--without-flac],
		[disable support for internal encoding/decoding with FLAC]), ,
 	[ with_flac=yes ])
AH_TEMPLATE(HAVE_FLAC_STREAM_ENCODER_H, [Define to 1 if you have the <FLAC/stream_encoder.h> header file.])
AH_TEMPLATE(HAVE_FLAC_STREAM_DECODER_H, [Define to 1 if you have the <FLAC/stream_decoder.h> header file.])
if test "x$with_flac" = "xyes" ; then
	AC_CHECK_HEADER(FLAC/stream_encoder.h, HAVE_FLAC_STREAM_ENCODER_H="true")
	AC_CHECK_HEADER(FLAC/stream_decoder.h, HAVE_FLAC_STREAM_DECODER_H="true")
	AC_CHECK_LIB([FLAC], [FLAC__stream_encoder_new], HAVE_LIBFLAC="true")
fi
if test ! -z "$HAVE_FLAC_STREAM_ENCODER_H" -a ! -z "$HAVE_FLAC_STREAM_DECODER_H" -a ! -z "$HAVE_LIBFLAC"; then
	AC_DEFINE(HAVE_FLAC_STREAM_ENCODER_H)
	AC_DEFINE(HAVE_FLAC_STREAM_DECODER_H)
fi
AM_CONDITIONAL(HAVE_LIBFLAC, test ! -z "$HAVE_LIBFLAC")


# check for libsamplerate
AC_CHECK_HEADER(samplerate.h, HAVE_SAMPLERATE_H="true")
AC_CHECK_LIB([samplerate], [src_simple], HAVE_LIBSRC="true", HAVE_SAMPLERATE_H="")
AH_TEMPLATE(USE_3RDPARTY_LIBSRC, [Define to 1 if you do not have the <samplerate.h> header file.])
AM_CONDITIONAL(USE_3RDPARTY_LIBSRC, test -z "$HAVE_SAMPLERATE_H")
if test -z "$HAVE_SAMPLERATE_H" ; then
	AC_DEFINE(USE_3RDPARTY_LIBSRC)
	AC_CHECK_FUNCS(malloc calloc free memcpy memmove)

	AC_CHECK_LIB([m],floor)
	AC_CHECK_FUNCS(floor ceil fmod)

	AC_C99_FUNC_LRINT
	AC_C99_FUNC_LRINTF
	# AC_C99_FUNC_LLRINT  Don't need this (yet?).

	case "x$ac_cv_c99_lrint$ac_cv_c99_lrintf" in
		xyesyes)
			;;
		*)
			AC_MSG_WARN([[*** Missing C99 standard functions lrint() and lrintf().]])
			AC_MSG_WARN([[*** This may cause benign compiler warnings on some systems (ie Solaris).]])
			;;
		esac

	#====================================================================================
	# Determine if the processor can do clipping on float to int conversions.

	AC_C_CLIP_MODE

	AC_DEFINE_UNQUOTED(CPU_CLIPS_POSITIVE, ${ac_cv_c_clip_positive},
		[Target processor clips on positive float to int conversion.])
	AC_DEFINE_UNQUOTED(CPU_CLIPS_NEGATIVE, ${ac_cv_c_clip_negative},
		[Target processor clips on negative float to int conversion.])

fi

# check for Festival
AC_LANG_PUSH(C++)
AC_ARG_WITH(singerbot,
	AS_HELP_STRING([--without-singerbot],
		[disable support for SingerBot plugin]), ,
	[ with_singerbot=yes ])
AH_TEMPLATE(SINGERBOT_SUPPORT,
	[Define to 1 to enable SingerBot plugin support.])
if test "x$with_singerbot" = "xyes" ; then
	ORIG_CPPFLAGS=$CPPFLAGS
	CPPFLAGS="$CPPFLAGS -I/usr/include/festival -I/usr/include/speech_tools -Wno-non-template-friend"
	AC_CHECK_HEADER([festival.h], FESTIVAL_SUPPORT="true")
	AC_CHECK_LIB([Festival], [main], true, FESTIVAL_SUPPORT="")
	CPPFLAGS=$ORIG_CPPFLAGS
fi
if test ! -z "$FESTIVAL_SUPPORT" ; then
	AC_DEFINE(SINGERBOT_SUPPORT)
fi
AC_LANG_POP(C++)
AM_CONDITIONAL(SINGERBOT_SUPPORT, test ! -z "$FESTIVAL_SUPPORT" )


# libsndfile-stuff
AC_ARG_WITH(libsf,
 	AS_HELP_STRING([--without-libsf],
		[disable support for importing files via libsndfile]), ,
 	[ with_libsf=yes ])
AH_TEMPLATE(HAVE_SNDFILE_H, [Define to 1 if you have the <sndfile.h> header file.])
if test "x$with_libsf" = "xyes" ; then
	AC_CHECK_HEADER(sndfile.h, HAVE_SNDFILE_H="true")
	AC_CHECK_LIB([sndfile], [sf_command], HAVE_LIBSF="true", HAVE_SNDFILE_H="")
	AC_MSG_CHECKING([version of libsndfile])
	AH_TEMPLATE(OLD_SNDFILE, [Define to 1 if libsndfile < 1.0.11])
	OLD_LIBS="$LIBS"
	LIBS="$LIBS -lsndfile"
	AC_RUN_IFELSE([	#include <sndfile.h>
			int main( void )
			{
				SF_INFO si;
				( void )sf_open( "", SFM_READ, &si );
				return 0;
			}],
	AC_MSG_RESULT([>= 1.0.11]),
	AC_MSG_RESULT([< 1.0.11])
	AC_DEFINE(OLD_SNDFILE)
		)
	LIBS="$OLD_LIBS"
fi
if test ! -z "$HAVE_SNDFILE_H" ; then
	AC_DEFINE(HAVE_SNDFILE_H)
fi
AM_CONDITIONAL(HAVE_LIBSF, test ! -z "$HAVE_SNDFILE_H")

AC_ARG_WITH(nosmpdecs,
	AS_HELP_STRING([--without-sample-decoders],
			[force compiling LMMS even if no usable libraries for sample-decoding were found]),
 	[ with_smpdecs=yes ])

if test -z "$HAVE_SND_FILE" -a -z "$HAVE_SDL_SDL_SOUND_H" -a -z "$OGG_SUPPORT" -a ! -z "$with_smpdecs"; then
	AC_MSG_ERROR([*** neither libsndfile nor SDL_sound nor libvorbis (or according devel-files) were found which would make LMMS unable to load any samples so please install at least one of the packages and try again! Use --without-sample-decoders to force compiling without any sample-decoding-libraries.])
fi



# check whether to disable surround-support
AC_MSG_CHECKING([whether to disable surround-support])
AH_TEMPLATE(DISABLE_SURROUND, [Define if you want to disable surround-support in LMMS.])
AC_ARG_ENABLE([surround],
	AS_HELP_STRING([--disable-surround],
			[compile LMMS without surround-support]),
	[ENABLE_SURROUND=$enableval])
if test "x$ENABLE_SURROUND" = "xno" ; then
	AC_MSG_RESULT(yes)
	AC_DEFINE(DISABLE_SURROUND)
else
	AC_MSG_RESULT(no)
fi


# check whether to enable high-quality sinc-resampling
AC_MSG_CHECKING([whether to enable high quality sinc-resampling])
AH_TEMPLATE(HQ_SINC, [Define if you want to enable high quality sinc-resampling.])
AC_ARG_ENABLE([hqsinc],
	AS_HELP_STRING([--enable-hqsinc],
		[enable high quality sinc-resampling]), [HQ_SINC=$enableval])
if test "x$HQ_SINC" = "xyes" ; then
	AC_MSG_RESULT(yes)
	AC_DEFINE(HQ_SINC)
else
	AC_MSG_RESULT(no)
fi

# check whether to disable single-source-compile
AC_MSG_CHECKING([whether to enable single-source-compile])
# AH_TEMPLATE(SINGLE_SOURCE_COMPILE, [Define if you want to enable single-source-compile.])
AC_ARG_ENABLE([ssc],
	AS_HELP_STRING([--enable-ssc],
		[enable single-source-compile]), [ENABLE_SSC=$enableval])
if test "x$ENABLE_SSC" = "xyes" ; then
	AC_MSG_RESULT(yes)
	# AC_DEFINE(SINGLE_SOURCE_COMPILE)
	CXXFLAGS="$CXXFLAGS -DSINGLE_SOURCE_COMPILE"
else
	AC_MSG_RESULT(no)
fi



# check whether compiler of current platform supports attribute regparm(x)
AC_MSG_CHECKING([whether we can use function-attribute regparm(x) on current platform])
AH_TEMPLATE(FASTCALL, [Define to any attribute, speeding up function-calls])
AC_RUN_IFELSE([	int  __attribute__((regparm(3))) foo( int a, int b, int c )
			{ return( a=b=c ); }
		int __attribute__((regparm(3))) main( void )
			{ return( foo(2,1,0) ); }],
	AC_MSG_RESULT(yes)
	AC_DEFINE(FASTCALL, [__attribute__((regparm(3)))]),
	AC_MSG_RESULT(no)
	AC_DEFINE_UNQUOTED(FASTCALL,[])
		)


AC_MSG_CHECKING([whether floorf is known by compiler])
AH_TEMPLATE(floorf, [Define to floor if floorf is not known])
AC_TRY_LINK([#include <math.h>], [ floorf ],
	AC_MSG_RESULT(yes),
	AC_MSG_RESULT([no - will use floor instead])
	AC_DEFINE(floorf, floor)
		)

AC_MSG_CHECKING([whether powf is known by compiler])
AH_TEMPLATE(powf, [Define to pow if powf is not known])
AC_TRY_LINK([#include <math.h>], [ powf ],
	AC_MSG_RESULT(yes),
	AC_MSG_RESULT([no - will use pow instead])
	AC_DEFINE(powf, pow)
		)

AC_MSG_CHECKING([whether fabsf is known by compiler])
AH_TEMPLATE(fabsf, [Define to pow if fabsf is not known])
AC_TRY_LINK([#include <math.h>], [ fabsf ],
	AC_MSG_RESULT(yes),
	AC_MSG_RESULT([no - will use fabs instead])
	AC_DEFINE(fabsf, fabs)
		)

AC_MSG_CHECKING([whether logf is known by compiler])
AH_TEMPLATE(logf, [Define to lof if logf is not known])
AC_TRY_LINK([#include <math.h>], [ logf ],
	AC_MSG_RESULT(yes),
	AC_MSG_RESULT([no - will use log instead])
	AC_DEFINE(logf, log)
		)


# check whether to enable debugging-code
AC_MSG_CHECKING([whether to enable debugging-code])
AH_TEMPLATE(LMMS_DEBUG, [Define if you want to disable debbuging-code in LMMS.])
AC_ARG_ENABLE([debug],
	AS_HELP_STRING([--enable-debug],
		[compile LMMS with additional debugging support]),
	[DEBUG=$enableval])
if test "x$DEBUG" = "xyes" ; then
	AC_MSG_RESULT(yes)
	AC_DEFINE(LMMS_DEBUG)
else
	AC_MSG_RESULT(no)
fi


AC_MSG_CHECKING([whether to ship caps])
AC_ARG_WITH([caps],
	AS_HELP_STRING([--without-caps],
		[do not ship C* Audio Plugin Suite]), ,
	[ with_caps=yes ])
if test "x$with_caps" = "xyes" ; then
	AC_MSG_RESULT(yes)
else
	AC_MSG_RESULT(no)
fi
AM_CONDITIONAL(SHIP_CAPS, test "x$with_caps" = "xyes")


if [ "$build_win32" = "true" ] ; then
	BIN2RES=`pwd`/buildtools/bin2res.exe
else
	BIN2RES=`pwd`/buildtools/bin2res
fi
AC_SUBST(BIN2RES)


# check for rpm SOURCES path
echo -n "checking for rpm sources path... "
RPMSOURCEDIR="NOT-FOUND"
for directory in packages OpenLinux redhat RedHat rpm RPM "" ; do
	if test -d /usr/src/${directory}/SOURCES ; then
		RPMSOURCEDIR="/usr/src/${directory}/SOURCES/"
	fi
done
echo "$RPMSOURCEDIR"
AM_CONDITIONAL(HAVE_RPM, test "$RPMSOURCEDIR" != "NOT-FOUND")
AC_SUBST(RPMSOURCEDIR)

lmmsdatadir="$datadir/$PACKAGE"
AC_SUBST(lmmsdatadir)


EXTRA_WARNINGS="-Wextra -Wno-unused-parameter -Winline -Wdisabled-optimization"
if test "x$CXX" == "xg++" ; then
	CXXFLAGS="$CXXFLAGS -ansi -Wall $EXTRA_WARNINGS -fno-exceptions"
fi

LDFLAGS="$LDFLAGS -L/usr/local/lib"
CXXFLAGS="$CXXFLAGS -I/usr/local/include"

AC_CONFIG_FILES([Makefile
		 buildtools/Makefile
		 data/Makefile
		 data/locale/Makefile
		 data/midi-maps/Makefile
		 data/presets/Makefile
		 data/presets/AudioFileProcessor/Makefile
		 data/presets/BitInvader/Makefile
		 data/presets/Organic/Makefile
		 data/presets/PluckedStringSynth/Makefile
		 data/presets/TripleOscillator/Makefile
		 data/presets/VeSTige/Makefile
		 data/projects/Makefile
		 data/projects/cool_songs/Makefile
		 data/projects/covers/Makefile
		 data/projects/demos/Makefile
		 data/projects/misc/Makefile
		 data/projects/recorded_loops/Makefile
		 data/projects/templates/Makefile
		 data/projects/tutorials/Makefile
		 data/samples/Makefile
		 data/samples/basses/Makefile
		 data/samples/bassloopes/Makefile
		 data/samples/beats/Makefile
		 data/samples/drums/Makefile
		 data/samples/effects/Makefile
		 data/samples/instruments/Makefile
		 data/samples/latin/Makefile
		 data/samples/misc/Makefile
		 data/samples/shapes/Makefile
		 data/samples/stringsnpads/Makefile
		 data/themes/Makefile
		 data/track_icons/Makefile
		 plugins/Makefile
		 plugins/audio_file_processor/Makefile
		 plugins/bass_booster/Makefile
		 plugins/bit_invader/Makefile
		 plugins/flp_import/Makefile
		 plugins/kicker/Makefile
		 plugins/ladspa_base/Makefile
		 plugins/ladspa_effect/Makefile
		 plugins/ladspa_effect/caps/Makefile
		 plugins/lb302/Makefile
		 plugins/live_tool/Makefile
		 plugins/midi_import/Makefile
		 plugins/organic/Makefile
		 plugins/patman/Makefile
		 plugins/singerbot/Makefile
		 plugins/stk/Makefile
		 plugins/stk/mallets/Makefile
		 plugins/triple_oscillator/Makefile
		 plugins/vestige/Makefile
		 plugins/vibed/Makefile
		 plugins/vst_base/Makefile
		 plugins/vst_effect/Makefile
		 lmms.spec])
AC_OUTPUT

with_warnings="false"

echo
echo

PLUGINS_TO_BUILD=""


if test -z "$HAVE_ALSA_ASOUNDLIB_H" ; then
	echo " ========================"
	echo " ===  LMMS - WARNING  ======================================================="
	echo " ========================"
	echo " ="
	echo " = You don't seem to have ALSA-library installed and/or ALSA-lib-development-"
	echo " = package is missing. This will disable support for sound-output via ALSA!"
	echo " = Consider installing the missing packages for using the full power of LMMS."
	echo " ="
	with_warnings="true"
else
	PLUGINS_TO_BUILD="$PLUGINS_TO_BUILD\n\t\* ALSA for audio- and MIDI-input/output"
fi



if test -z "$HAVE_JACK_JACK_H" ; then
	echo " ========================"
	echo " ===  LMMS - WARNING  ======================================================="
	echo " ========================"
	echo " ="
	echo " = You don't seem to have JACK-library installed and/or JACK-lib-development-"
	echo " = package is missing. This will disable support for JACK-transport."
	echo " = This is no problem but you'll miss the great possibilities of interacting"
	echo " = with other sound-applications in realtime!"
	echo " = Consider installing the missing packages for using the full power of LMMS."
	echo " ="
	with_warnings="true"
else
	PLUGINS_TO_BUILD="$PLUGINS_TO_BUILD\n\t\* JACK for audio-input/output"
fi




if test -z "$HAVE_SOUNDCARD_H" -a -z "$HAVE_SYS_SOUNDCARD_H" ; then
	echo " ========================"
	echo " ===  LMMS - WARNING  ======================================================="
	echo " ========================"
	echo " ="
	echo " = You don't seem to have soundcard.h which is neccessary for outputting "
	echo " = sound via OSS under Linux/BSD/Solaris."
	echo " = This will also disable support for MIDI using OSS."
	echo " = If you're building for a different platform or do not need OSS-support, you"
	echo " = can ignore this warning."
	echo " ="
	with_warnings="true"
else
	PLUGINS_TO_BUILD="$PLUGINS_TO_BUILD\n\t\* OSS for audio- and MIDI-input/output"
fi




if test -z "$HAVE_SDL_SDL_AUDIO_H" ; then
	echo " ========================"
	echo " ===  LMMS - WARNING  ======================================================="
	echo " ========================"
	echo " ="
	echo " = You don't seem to have SDL-library installed and/or SDL-lib-development-"
	echo " = package is missing. This will disable support for sound-output via SDL, "
	echo " = which is important, if you're using sound-daemons (arts, ESD etc.)"
	echo " = When compiling without SDL, you'll always have to kill your sound-daemon"
	echo " = before using LMMS...!"
	echo " = Consider installing the missing packages for using the full power of LMMS."
	echo " ="
	with_warnings="true"
else
	PLUGINS_TO_BUILD="$PLUGINS_TO_BUILD\n\t\* SDL for audio-output"
fi



if test -z "$OGG_SUPPORT" ; then
	echo " ========================"
	echo " ===  LMMS - WARNING  ======================================================="
	echo " ========================"
	echo " ="
	echo " = You don't seem to have libvorbis installed and/or libvorbis-development-"
	echo " = package is missing. This will disable support for exporting songs to"
	echo " = OGG-files! If SDL_sound is missing too, you'll not be able to use the "
	echo " = samples coming with LMMS since libsndfile currently has no OGG-support!"
	echo " = Consider installing the missing packages for using the full power of LMMS."
	echo " ="
	with_warnings="true"
else
	PLUGINS_TO_BUILD="$PLUGINS_TO_BUILD\n\t\* libvorbis for encoding/decoding OGG-files"
fi



if test -z "$HAVE_SDL_SDL_SOUND_H" ; then
	echo " ========================"
	echo " ===  LMMS - WARNING  ======================================================="
	echo " ========================"
	echo " ="
	echo " = You don't seem to have SDL_sound-library installed and/or SDL_sound-"
	echo " = development-package is missing. This means that you can only load samples"
	echo " = within LMMS if you have libsndfile and libvorbis installed!"
	echo " = Consider installing the missing packages for using the full power of LMMS."
	echo " ="
	with_warnings="true"
else
	PLUGINS_TO_BUILD="$PLUGINS_TO_BUILD\n\t\* SDL_sound for sample-decoding"
fi




if test -z "$HAVE_SNDFILE_H" ; then
	echo " ========================"
	echo " ===  LMMS - WARNING  ======================================================="
	echo " ========================"
	echo " ="
	echo " = You don't seem to have libsndfile installed and/or libsndfile-development-"
	echo " = package is missing. This is not that fatal as long as you have SDL_sound"
	echo " = installed. Otherwise it's strongly recommended to install libsndfile and"
	echo " = libvorbis for being able to use samples within LMMS."
	echo " = Consider installing the missing packages for using the full power of LMMS."
	echo " ="
	with_warnings="true"
else
	PLUGINS_TO_BUILD="$PLUGINS_TO_BUILD\n\t\* libsndfile for sample-decoding"
fi


if test -z "$HAVE_SAMPLERATE_H" ; then
	echo " ========================"
	echo " ===  LMMS - WARNING  ======================================================="
	echo " ========================"
	echo " ="
	echo " = You don't seem to have libsamplerate installed and/or libsamplerate-"
	echo " = development-package is missing. If you ignore this warning the"
	echo " = according source-code of libsamplerate will be directly compiled into"
	echo " = LMMS which is no problem at all. If you're building official LMMS-packages"
	echo " = for a distribution DO NOT IGNORE THIS WARNING."
	echo " ="
fi




if test "$build_linux" = "true" ; then
	PLUGINS_TO_BUILD="$PLUGINS_TO_BUILD\n\t\* LADSPA-plugins"
	if test -z "$HAVE_LADSPA_H" ; then
		echo " ========================"
		echo " ===  LMMS - WARNING  ======================================================="
		echo " ========================"
		echo " ="
		echo " = As the header file ladspa.h could not be found on your system, a version"
		echo " = shipped with LMMS will be used. This is no problem at all but generally"
		echo " = it's better to use files being customized to your system/distribution."
		echo " = If you encounter problems related to LADSPA-support, try to install"
		echo " = LADSPA-SDK-package (ladspa-sdk, ladspa-dev or similiar) and run configure"
		echo " = again."
		echo " ="
		with_warnings="true"
	fi
else
	echo " ========================"
	echo " ===  LMMS - WARNING  ======================================================="
	echo " ========================"
	echo " ="
	echo " = You're building LMMS for a platform other than Linux which will prevent"
	echo " = configure from enabling LADSPA-support."
	echo " ="
	with_warnings="true"
fi



if test -z "$HAVE_STK_H" ; then
	echo " ========================"
	echo " ===  LMMS - WARNING  ======================================================="
	echo " ========================"
	echo " ="
	echo " = You don't seem to have STK installed and/or STK-development-package"
	echo " = (Debian/Ubuntu: libstk0-dev) is missing. Without this package, the "
	echo " = STK instrument plugins (\"Mallets\") won't be built."
	echo " = Consider installing the missing packages for using the full power of LMMS."
	echo " ="
	with_warnings="true"
else
	PLUGINS_TO_BUILD="$PLUGINS_TO_BUILD\n\t\* STK instrument plugins"
fi



if test -z "$FESTIVAL_SUPPORT" ; then
	if test "x$with_singerbot" = "xyes" ; then
		echo " ========================"
		echo " ===  LMMS - WARNING  ======================================================="
		echo " ========================"
		echo " ="
		echo " = You don't seem to have Festival development files."
		echo " = The SingerBot instrument plugin will be ignored."
		echo " = Before enabling this plugin, bear in mind that it is still experimental."
		echo " ="
		echo " = To remove this warning, please pass"
		echo " = "
		echo " = --without-singerbot"
		echo " ="
		with_warnings="true"
	fi
else
	PLUGINS_TO_BUILD="$PLUGINS_TO_BUILD\n\t\* SingerBot instrument plugin"
fi


if test ! -z "$WINECXX" ; then
	PLUGINS_TO_BUILD="$PLUGINS_TO_BUILD\n\t\* LMMS VST Support Layer (LVSL) for built-in VST-plugin usage"
else
	echo " ========================"
	echo " ===  LMMS - WARNING  ======================================================="
	echo " ========================"
	echo " ="
	echo " = You don't seem to have installed WINE or it's development-packages (headers,"
	echo " = winegcc etc.) which are neccessary for building LMMS with built-in"
	echo " = VST-support."
	echo " = If you do not intend to use VST-plugins with LMMS you can ignore this "
	echo " = warning."
	echo " = Consider installing the missing packages (Debian: libwine-dev,"
	echo " = Ubuntu: wine-dev, openSUSE: wine-devel) for using the full power of LMMS."
	echo " ="
	with_warnings="true"
fi


echo
echo
echo "LMMS will be able to use $PLUGINS_TO_BUILD" | sed -e "s/\\\n/\n/g" | sed -e "s/\\\t/\t/g" | sed -e "s/\\\\\*/\*/g"
echo
echo
echo " ============================"
echo " ===  LMMS - INFORMATION  ==================================================="
echo " ============================"
echo " ="
if test "$with_warnings" = "false" ; then
	echo " = LMMS has been configured successfully. Now you can build it by typing 'make'."
	echo " = After the compilation-process has finished, you can install LMMS by"
	echo " = typing 'make install' (do this as \"root\"!)."
else
	echo " = LMMS has been configured, but there were one or more warnings you should"
	echo " = not ignore. First try to solve the mentioned problems before"
	echo " = proceeding. Otherwise don't complain, if LMMS doesn't run the way"
	echo " = you might expect..."
fi
echo " ="
echo " = If there're problems while compiling LMMS, please send a mail to "
echo " = lmms-devel \[at\] lists.sf.net!"
echo " ="
echo

