dnl ------------------------------------------------------------------------
dnl Try to find the zvbi headers and libraries.
dnl $(ZVBI_LDFLAGS) will be -Lzvbi (if needed)
dnl and $(ZVBI_INCLUDES) will be -Izvbi (if needed)
dnl ------------------------------------------------------------------------
dnl
AC_DEFUN(AC_PATH_ZVBI,
[
LIBZVBI="-lzvbi"
AC_MSG_CHECKING([for libzvbi])

ac_zvbi_includes=NO ac_zvbi_libraries=NO
zvbi_libraries=""
zvbi_includes=""
AC_ARG_WITH(zvbi-dir,
    [  --with-zvbi-dir=DIR     where the root of libzvbi is installed],
    [  ac_zvbi_includes="$withval"/include
       ac_zvbi_libraries="$withval"/lib
    ])

want_zvbi=yes
AC_ARG_WITH(zvbi,
    [  --without-zvbi          disable libzvbi checks],
    [want_zvbi=$withval])

if test $want_zvbi = yes; then

AC_CACHE_VAL(ac_cv_have_zvbi,
[#try to guess libzvbi locations

  zvbi_incdirs="/usr/include /usr/local/include /usr/local/zvbi/include /opt/zvbi/include $prefix/include $kde_extra_includes"
  zvbi_incdirs="$ac_zvbi_includes $zvbi_incdirs"
  AC_FIND_FILE(libzvbi.h, $zvbi_incdirs, zvbi_incdir)
  ac_zvbi_includes="$zvbi_incdir"

  zvbi_libdirs="/usr/lib /usr/local/lib /usr/local/zvbi/lib $prefix/lib $exec_prefix/lib $kde_extra_libs"
  if test ! "$ac_zvbi_libraries" = "NO"; then
    zvbi_libdirs="$ac_zvbi_libraries $zvbi_libdirs"
  fi

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

  ac_zvbi_libraries="$zvbi_libdir"

  if test "$ac_zvbi_includes" = NO || test "$ac_zvbi_libraries" = NO; then
    have_zvbi=no
  else
    ZVBI_INCLUDES="-I$ac_zvbi_includes ";
    ZVBI_LDFLAGS="-L$ac_zvbi_libraries -lzvbi";
    have_zvbi=yes;
  fi

  ])

  eval "$ac_cv_have_zvbi"
else
  have_zvbi=no
fi

AC_SUBST(ZVBI_INCLUDES)
AC_SUBST(ZVBI_LDFLAGS)
AC_SUBST(LIBZVBI)
])


AC_PATH_ZVBI

if test "$ac_zvbi_includes" = NO || test "$ac_zvbi_libraries" = NO; then
  ZVBIDIRS=
  AC_MSG_RESULT([not found.  Captioning support disabled.])
else
  ZVBIDIRS="yes"
  AC_MSG_RESULT([found.  Captioning support enabled.])
fi

AM_CONDITIONAL(include_ZVBIDIR, [test -n "$ZVBIDIRS"])

