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)

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${kdelibsuff}
    ])

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${kdelibsuff} /usr/local/lib${kdelibsuff} /usr/local/zvbi/lib${kdelibsuff} $prefix/lib${kdelibsuff} $exec_prefix/lib${kdelibsuff} $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. VBI services disabled.])
else
  ZVBIDIRS="yes"
  AC_DEFINE(HAVE_ZVBI, 1, [If we have libzvbi])
  AC_MSG_RESULT([found. VBI services enabled.])
fi

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

AC_CHECK_LIB(zvbi, vbi_proxy_client_create, AC_DEFINE(HAVE_VBI_PROXY, 1, [If we have VBI proxy]))

dnl ------------------------------------------------------------------------
dnl Check for XRANDR
KDE_CHECK_LIB(Xrandr, XRRConfigCurrentConfiguration, 
    KDETV_LIBS="-lXrandr -lXrender $KDETV_LIBS",,
    -L/usr/X11R6/lib $X_LIBS $X_PRE_LIBS -lXrender -lXext -lX11 $X_EXTRA_LIBS)

if test $ac_cv_lib_Xrandr_XRRConfigCurrentConfiguration = yes; then
  AC_DEFINE(HAVE_XRANDR, 1, [If we have the X11 RANDR extension])
fi


dnl ------------------------------------------------------------------------
dnl Check for processor architecture
case "$target" in
    i?86-* | k?-*)
        AC_DEFINE([ARCH_X86],,[x86 architecture])
        AC_DEFINE([ARCH_386],,[386 architecture])
        ARCH_X86=yes
        ARCH_386=yes
        ARCH_X86_64=no
        ;;
    x86_64-*)
        AC_DEFINE([ARCH_X86],,[x86 architecture])
        AC_DEFINE([ARCH_X86_64],,[x86_64 architecture])
        ARCH_X86=yes
        ARCH_386=no
        ARCH_X86_64=yes
        ;;
    *)
        ARCH_X86=no
        ARCH_386=no
        ARCH_X86_64=no
        ;;
esac

AC_MSG_CHECKING(for X86 architecture)
AC_MSG_RESULT($ARCH_X86)
AM_CONDITIONAL(ARCH_X86, [test "$ARCH_X86" = "yes"])

USE_MMX_REGISTER=""
if test "$ARCH_X86" = "yes"; then
  KDE_CHECK_COMPILER_FLAG([mmmx], [USE_MMX_REGISTER="-mmmx"], )
fi
AC_SUBST([USE_MMX_REGISTER])

AC_MSG_CHECKING(for 386 architecture)
AC_MSG_RESULT($ARCH_386)
AM_CONDITIONAL(ARCH_386, [test "$ARCH_386" = "yes"])

AC_MSG_CHECKING(for X86_64 architecture)
AC_MSG_RESULT($ARCH_X86_64)
AM_CONDITIONAL(ARCH_X86_64, [test "$ARCH_X86_64" = "yes"])
