
##################################################################
## 
##    kdetv mixer configure script
##    Neil Macvicar (blackmogu@vfemail.net)
##
##################################################################

AC_DEFUN([AC_PATH_ASOUND],
[
LIBASOUND="-lasound"
AC_MSG_CHECKING([for alsa libraries and headers])

ac_alsa_libs=NO ac_alsa_includes=NO
alsa_libraries=""
alsa_includes=""
AC_ARG_WITH(alsa-dir,
	[  --with-alsa-dir=DIR	where the root of alsa-lib is installed],
	[ ac_alsa_includes="$withval"/include
	  ac_alsa_libraries="$withval"/lib
	])

want_alsa_mixer=yes

#AC_ARG_WITH(alsa,
#	[  --without-alsa-mixer	disable alsa mixer plugin],
#	[want_alsa_mixer=NO])

if test $want_alsa_mixer = yes; then
AC_CACHE_VAL(ac_cv_have_alsa,
[# try to guess the location of the ALSA libraries/headers
	alsa_incdirs="/usr/include /usr/local/include $prefix/include $kde_extra_includes"
	alsa_incdirs="$ac_alsa_includes $alsa_incdirs"	
	AC_FIND_FILE(alsa/asoundlib.h, $alsa_incdirs, alsa_incdir)
	ac_alsa_includes="$alsa_incdir"

	alsa_libdirs="/usr/lib /usr/local/lib $prefix/lib $exec_prefix/lib $kde_extra_libs"
	if test ! "$ac_alsa_libraries" = "NO"; then
		alsa_libdirs="$ac_alsa_libraries $alsa_libdirs"
	fi

	test=NONE
	alsa_libdir=NONE

	for dir in $alsa_libdirs; do
		try="ls -1 $dir/libasound*"
		if test=`eval $try 2>/dev/null`; then alsa_libdir=$dir; break; else echo "tried $dir" >&AC_FD_CC ; fi
	done

	ac_alsa_libraries="$alsa_libdir"

	if test "$ac_alsa_includes" = NO || test "$ac_alsa_libraries" = NO; then
		have_alsa=no
	else
		ALSA_INCLUDES="-I$ac_alsa_includes ";
		ALSA_LDFLAGS="-L$ac_alsa_libraries -lasound";
		have_alsa=yes;
	fi
	])

	eval "$ac_cv_have_alsa"
	else
		have_alsa=no
	fi

AC_SUBST(ALSA_INCLUDES)
AC_SUBST(ALSA_LDFLAGS)
AC_SUBST(LIBALSA)
])

AC_PATH_ASOUND

if test "$ac_alsa_includes" = NO || test "$ac_alsa_libraries" = NO; then
	ALSADIRS=
	AC_MSG_RESULT([not found. Alsa mixer plugin disabled])
else
	ALSADIRS="yes"
	AC_MSG_RESULT([found. Alsa mixer plugin enabled])
fi

AM_CONDITIONAL(include_ALSADIR, [test -n "$ALSADIRS"])
