#MIN_CONFIG(3)

AM_INIT_AUTOMAKE(juk,1.0)

AC_ARG_WITH(musicbrainz,
  	[AC_HELP_STRING(--with-musicbrainz,
	[enable support for MusicBrainz @<:@default=check@:>@])],
	[], with_musicbrainz=check)

have_musicbrainz=no

if test "x$with_musicbrainz" != xno; then
  	KDE_CHECK_HEADER(tunepimp-0.5/tp_c.h, have_musicbrainz=yes)

  	if test "x$with_musicbrainz" != xcheck && test "x$have_musicbrainz" != xyes; then
    		AC_MSG_ERROR([--with-musicbrainz was given, but test for MusicBrainz failed])
  	fi
fi

if test "x$have_musicbrainz" = xyes; then
	v=1
  	KDE_CHECK_LIB(tunepimp, tp_SetFileNameEncoding,
		[v=4])
	case "$v" in
	4) KDE_CHECK_LIB(tunepimp, tp_SetTRMCollisionThreshold,
		AC_DEFINE(HAVE_MUSICBRAINZ, 4, [have MusicBrainz 0.4.x]),
		[AC_MSG_WARN([Tunepimp 0.5 detected - disabled.])
		AC_DEFINE(HAVE_MUSICBRAINZ, 0, [have MusicBrainz 0.5.x - disabled])
		])
		;;
	*) AC_DEFINE(HAVE_MUSICBRAINZ, 1, [have MusicBrainz]) ;;
	esac
else
  	AC_DEFINE(HAVE_MUSICBRAINZ, 0, [have MusicBrainz])
fi

AM_CONDITIONAL(link_lib_MB, test "x$have_musicbrainz" = xyes)

AC_ARG_WITH(gstreamer,
  	[AC_HELP_STRING(--with-gstreamer,
    	[enable support for GStreamer @<:@default=check@:>@])],
	[], with_gstreamer=check)

have_gst=no

if test "x$with_gstreamer" != xno; then
  	# pkg-config seems to have a bug where it masks needed -L entries when it
	# shouldn't, so disable that.

  	PKG_CONFIG_ALLOW_SYSTEM_LIBS=1
	export PKG_CONFIG_ALLOW_SYSTEM_LIBS

	GST_MAJORMINOR=0.10
	GST_REQ=0.10.0
	GST_VERSION=10

	PKG_CHECK_MODULES(GST, \
		gstreamer-$GST_MAJORMINOR >= $GST_REQ, \
		have_gst=yes, have_gst=no)

	if test "x$have_gst" != xyes; then

		GST_MAJORMINOR=0.8
		GST_REQ=0.8.0
		GST_VERSION=8

		PKG_CHECK_MODULES(GST, \
			gstreamer-$GST_MAJORMINOR >= $GST_REQ, \
			have_gst=yes, have_gst=no)
	fi

	if test "x$with_gstreamer" != xcheck && test "x$have_gst" != xyes; then
		AC_MSG_ERROR([--with-gstreamer was given, but test for GStreamer failed])
	fi
fi

if test "x$have_gst" = "xno"; then
	GST_CFLAGS=""
	LDADD_GST=""
	LDFLAGS_GST=""
	AC_DEFINE(HAVE_GSTREAMER, 0, [have GStreamer])
else
	LDADD_GST=`$PKG_CONFIG --libs-only-l gstreamer-$GST_MAJORMINOR`
	LDFLAGS_GST=`$PKG_CONFIG --libs-only-other gstreamer-$GST_MAJORMINOR`

	# Append -L entries, since they are masked by --libs-only-l and
	# --libs-only-other
	LIBDIRS_GST=`$PKG_CONFIG --libs-only-L gstreamer-$GST_MAJORMINOR`
	LDADD_GST="$LDADD_GST $LIBDIRS_GST"

	AC_MSG_NOTICE([GStreamer version >= $GST_REQ found.])
	AC_DEFINE(HAVE_GSTREAMER, 1, [have GStreamer])
	AC_DEFINE_UNQUOTED(GSTREAMER_VERSION, $GST_VERSION, [GStreamer Version])
fi

AC_SUBST(GST_CFLAGS)
AC_SUBST(LDADD_GST)
AC_SUBST(LDFLAGS_GST)

if test "x$have_taglib" != xyes || ( test "x$build_arts" = "xno" && test "x$have_gst" = "xno" && test "x$have_akode" = "xno") ; then
	DO_NOT_COMPILE="$DO_NOT_COMPILE juk"
fi