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

dnl Require autoconf 2.56 or later
AC_PREREQ(2.56)

dnl Initialize
AC_INIT([XMMS-SID], [0.8.0beta12], [ccr@tnsp.org])
AC_COPYRIGHT([[(C) 2003-2004 Matti 'ccr' H�m�l�inen]])
AC_CONFIG_SRCDIR([src/xmms-sid.h])
AM_INIT_AUTOMAKE
AC_CONFIG_HEADERS([src/config.h])


dnl ***
dnl *** Define some templates
dnl ***
AH_TEMPLATE([HAVE_SONG_POSITION],[Define if you have XMMS patched with the songpos patch.])
AH_TEMPLATE([HAVE_XMMSEXTRA],[Define if you have XMMS version 1.2.5 or later and you want XMMS-SID to support some extra features.])
AH_TEMPLATE([HAVE_SIDPLAY1],[Define if you have and want to use libSIDPlay 1])
AH_TEMPLATE([HAVE_SIDPLAY2],[Define if you have and want to use libSIDPlay 2])
AH_TEMPLATE([HAVE_NANOSID],[Define if you have and want to use libNanoSID])
AH_TEMPLATE([HAVE_RESID_BUILDER],[Define if you have reSID with libSIDPlay 2])
AH_TEMPLATE([HAVE_HARDSID_BUILDER],[Define if you have HardSID with libSIDPlay 2])


dnl ***
dnl *** Some general checks
dnl ***
AC_PREFIX_PROGRAM(xmms)
AC_DISABLE_STATIC
AC_LIBTOOL_DLOPEN
AC_LIB_RPATH
AM_PROG_LIBTOOL


dnl ***
dnl *** Checks for programs
dnl ***
AC_PROG_CXX
AC_PROG_CC
AC_PROG_CPP
AC_PROG_INSTALL


dnl ***
dnl *** Checks for generic libraries
dnl ***
AM_PATH_GLIB([1.2.5],,AC_MSG_ERROR([*** GLib >= 1.2.5 not found. You either don't have GLib at all or your GLib is too old. Latest GLib can be found from Gtk+ homepages (http://www.gtk.org/)]))
AM_PATH_GTK([1.2.5],,AC_MSG_ERROR([*** Gtk+ >= 1.2.5 not found. You either don't have Gtk+ at all or your Gtk+ is too old. Latest Gtk+ can be found from Gtk+ homepages (http://www.gtk.org/)]), gthread)


dnl ***
dnl *** Checks for header files, types and functions
dnl ***
AC_HEADER_STDC
AC_CHECK_HEADERS([stdlib.h string.h unistd.h])

AC_HEADER_STDBOOL
AC_TYPE_SIZE_T
AC_C_CONST
AC_C_INLINE
AC_C_VOLATILE
AC_C_BIGENDIAN

AC_FUNC_MALLOC
AC_TYPE_SIGNAL
AC_FUNC_STAT
AC_CHECK_FUNCS([memset strcasecmp strerror strrchr])


dnl ***
dnl *** libSIDPlay 1 options
dnl ***
AC_ARG_WITH(sidplay1,
[
  --with-sidplay1=PREFIX   Enable SIDPlay1 with install-PREFIX],
[
if test "$withval" = yes; then
xs_sidplay1=yes
xs_sidplay1_library=""
xs_sidplay1_includes=""
else
if test "$withval" = no; then
	xs_sidplay1=no
	else
	xs_sidplay1=yes
	xs_sidplay1_includes="$withval/include"
	xs_sidplay1_library="$withval/lib"
	fi
fi
],[
xs_sidplay1=xtry
xs_sidplay1_library=""
xs_sidplay1_includes=""
])

AC_ARG_WITH(sidplay1-inc,
[  --with-sidplay1-inc=DIR    Where the SIDPlay1 headers are located],
[xs_sidplay1_includes="$withval"],)

AC_ARG_WITH(sidplay1-lib,
[  --with-sidplay1-lib=DIR    Where the SIDPlay1 library is installed],
[xs_sidplay1_library="$withval"],)


dnl ***
dnl *** libSIDPlay 2 options
dnl ***
AC_ARG_WITH(sidplay2,
[
  --with-sidplay2=PREFIX   Enable SIDPlay2 with install-PREFIX],
[
if test "$withval" = yes; then
xs_sidplay2=yes
xs_sidplay2_library=""
xs_sidplay2_includes=""
else
if test "$withval" = no; then
	xs_sidplay2=no
	else
	xs_sidplay2=yes
	xs_sidplay2_includes="$withval/include"
	xs_sidplay2_library="$withval/lib"
	fi
fi
],[
xs_sidplay2=xtry
xs_sidplay2_library=""
xs_sidplay2_includes=""
])

AC_ARG_WITH(sidplay2-inc,
[  --with-sidplay2-inc=DIR    Where the SIDPlay2 headers are located],
[xs_sidplay2_includes="$withval"],)

AC_ARG_WITH(sidplay2-lib,
[  --with-sidplay2-lib=DIR    Where the SIDPlay2 library is installed],
[xs_sidplay2_library="$withval"],)


dnl ***
dnl *** libNanoSID options
dnl ***
AC_ARG_WITH(nanosid,
[
  --with-nanosid=PREFIX   Enable NanoSID with PREFIX],
[
if test "$withval" = yes; then
xs_nanosid=yes
xs_nanosid_library=""
xs_nanosid_includes=""
else
if test "$withval" = no; then
	xs_nanosid=no
	else
	xs_nanosid=yes
	xs_nanosid_includes="$withval/include"
	xs_nanosid_library="$withval/lib"
	fi
fi
],[
xs_nanosid=xtry
xs_nanosid_library=""
xs_nanosid_includes=""
])

AC_ARG_WITH(nanosid-inc,
[  --with-nanosid-inc=DIR    Where the NanoSID headers are located],
[xs_nanosid_includes="$withval"],)

AC_ARG_WITH(sidplay1-lib,
[  --with-nanosid-lib=DIR    Where the NanoSID library is installed],
[xs_nanosid_library="$withval"],)


dnl ***
dnl *** Determine if libraries are wanted and available
dnl ***
OPT_SIDPLAY1="no"
if test "$xs_sidplay1" = xtry; then
	XS_PATH_LIBSIDPLAY1
	else
	if test "$xs_sidplay1" = yes; then
		XS_PATH_LIBSIDPLAY1
		if test "$xs_have_sidplay1" = no; then
		AC_MSG_ERROR([libSIDPlay1 library and/or headers were not found!])
		fi
	fi
fi
if test "$xs_have_sidplay1" = yes; then
	AC_DEFINE(HAVE_SIDPLAY1)
	OPT_SIDPLAY1="yes"
fi



OPT_SIDPLAY2="no"
LIBSIDPLAY2_REQUIRED_VERSION="2.1.0"
if test "$xs_sidplay2" = xtry; then
	XS_PATH_LIBSIDPLAY2
	else
	if test "$xs_sidplay2" = yes; then
		XS_PATH_LIBSIDPLAY2
		if test "$xs_have_sidplay2" = no; then
		AC_MSG_ERROR([libSIDPlay2 library and/or headers were not found!])
		fi
	fi
fi
if test "$xs_have_sidplay2" = yes; then
	AC_DEFINE(HAVE_SIDPLAY2)
	OPT_SIDPLAY2="yes"
	BUILDERS_FIND
	BUILDERS_FIND_RESID
	BUILDERS_FIND_HARDSID
	if test "$builders_available" = no; then
		AC_MSG_ERROR([No builder modules were found in the sidbuilders directory!]);
	fi
fi


OPT_NANOSID="no"
if test "$xs_nanosid" = xtry; then
	XS_PATH_LIBNANOSID
	else
	if test "$xs_nanosid" = yes; then
		XS_PATH_LIBNANOSID
		if test "$xs_have_nanosid" = no; then
		AC_MSG_ERROR([libNanoSID library and/or headers were not found!])
		fi
	fi
fi
if test "$xs_have_nanosid" = yes; then
	AC_DEFINE(HAVE_NANOSID)
	OPT_NANOSID="yes"
fi


dnl ***
dnl *** Check if we have some emulator library available?
dnl ***
if test "$OPT_SIDPLAY1" = no; then
if test "$OPT_SIDPLAY2" = no; then
if test "$OPT_NANOSID" = no; then
AC_MSG_ERROR([Either libSIDPlay1, libSIDPlay2 or libNanoSID is required! Please read INSTALL for more information!])
fi
fi
fi


dnl ***
dnl *** Song position patch check
dnl ***
AC_MSG_CHECKING([for song position patch])
tmp_CPPFLAGS=$CPPFLAGS
if test -d "$prefix" ;then
  CPPFLAGS="$CPPFLAGS -I${prefix}/include"
fi

AC_EGREP_HEADER(set_song_position,xmms/plugin.h,
[
OPT_SONGPOS="yes"
AC_DEFINE(HAVE_SONG_POSITION)
AC_MSG_RESULT([yes])
],[
OPT_SONGPOS="no"
AC_MSG_RESULT([no])
])

CPPFLAGS=$tmp_CPPFLAGS


dnl ***
dnl *** Check XMMS version
dnl ***
AM_PATH_XMMS(1.2.0,, [
AC_MSG_ERROR([*** XMMS >= 1.2.0 not found. You need XMMS v1.2.0 or later to use XMMS-SID plugin.])
])
libdir=$XMMS_INPUT_PLUGIN_DIR

XMMS_TEST_VERSION($XMMS_VERSION, 1.2.5, [
AC_DEFINE(HAVE_XMMSEXTRA)
OPT_XMMSEXTRA="yes"
], [
OPT_XMMSEXTRA="no"
])


dnl ***
dnl *** And finally, output the all generatable files!
dnl ***
AC_CONFIG_FILES([
Makefile
xmms-sid.spec
])
AC_OUTPUT


dnl ***
dnl *** Show the result message
dnl ***
AC_MSG_RESULT([
	XMMS-SID has been configured successfully:

	Installation directory        : $libdir
	XMMS >= v1.2.5 extra features : $OPT_XMMSEXTRA
	Song-position patch           : $OPT_SONGPOS
	libSIDPlay 1 support          : $OPT_SIDPLAY1
	libSIDPlay 2 support          : $OPT_SIDPLAY2
		Included builders     : $xs_builders
	libNanoSID support            : $OPT_NANOSID

])
