dnl $Id: check-var-libs.m4,v 1.1 2000/02/20 13:12:16 lha Exp $
dnl
dnl AC_CHECK_VAR_LIBS(includes, variable, libs, extra-lib, extra-args)
dnl
AC_DEFUN(AC_CHECK_VAR_LIBS, [
AC_MSG_CHECKING(for $2)
AC_CACHE_VAL(ac_cv_libvar_$2, [
if eval "test \"\$ac_cv_libvar_$2\" != yes" ; then
	for ac_lib in "" $3; do
		if test -n "$ac_lib"; then 
			ac_lib="-l$ac_lib"
		else
			ac_lib=""
		fi
		LIBS="$5 $ac_lib $4 $ac_save_LIBS"
		AC_TRY_LINK([$1
			extern int $2;
			int foo() { return $2; }],
	    		[foo()],
	    		if test -n "$ac_lib"; then eval "ac_cv_libvar_$2=$ac_lib" ; else eval "ac_cv_libvar_$2=yes" ; fi ; break)
		eval "ac_cv_libvar_$2=\${ac_cv_libvar_$2-no}"
 		LIBS="$ac_save_LIBS"
	done
	LIBS="$ac_save_LIBS"
fi])

eval "ac_cv_funclib_$2=\${ac_cv_funclib_$2-no}"

eval "ac_res=\$ac_cv_libvar_$2"

define([foo], [HAVE_]translit($2, [a-z], [A-Z]))
eval "ac_tr_lib=HAVE_LIB_[]upcase($ac_res | sed -e 's/-l//')"

dnl autoheader tricks *sigh*
: << END
@@@libs="$libs $3"@@@
END

eval "LIB_$2=$ac_res"

case "$ac_res" in
	yes)
	eval "ac_cv_var_$2=yes"
	eval "LIB_$2="
	AC_DEFINE_UNQUOTED(foo, 1, [define if you have $2])
	AC_MSG_RESULT([yes])
	;;
	no)
	eval "ac_cv_var_$2=yes"
	eval "LIB_$2="
	AC_MSG_RESULT([no])
	;;
	*)
	eval "ac_cv_var_$2=yes"
	eval "LIB_$2=$ac_tr_lib"
	AC_DEFINE_UNQUOTED(foo, 1, [define if you have $2])
	AC_DEFINE_UNQUOTED($ac_tr_lib)
	AC_MSG_RESULT([yes])
	;;
esac
AC_SUBST(LIB_$2)
undefine([foo])
])
