dnl Process this file with autoconf to produce a configure script.

AC_INIT(configure.in)
AC_CONFIG_SRCDIR(src/main.c)
AM_INIT_AUTOMAKE(dvd95, 1.6p0)
AM_MAINTAINER_MODE
AM_CONFIG_HEADER(config.h)

dnl Detect the canonical host and target build environment
AC_CANONICAL_SYSTEM

AC_ISC_POSIX
dnl
dnl warning flags; always add -Wall
dnl
CFLAGS="-Wall -O3"

AC_PROG_CC
AM_PROG_CC_STDC
AC_PROG_INSTALL
AC_PROG_LIBTOOL
AM_PROG_LIBTOOL
AC_PROG_INTLTOOL

AC_HEADER_STDC

pkg_modules="libgnomeui-2.0 libxml-2.0"
PKG_CHECK_MODULES(PACKAGE, [$pkg_modules])
AC_SUBST(PACKAGE_CFLAGS)
AC_SUBST(PACKAGE_LIBS)

GETTEXT_PACKAGE=dvd95
AC_SUBST(GETTEXT_PACKAGE)
AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE,"$GETTEXT_PACKAGE")

dnl Add the languages which your application supports here.
ALL_LINGUAS="en hu el cs pt_BR de et_EE nl es it"
AM_GLIB_GNU_GETTEXT

dnl
dnl Architecture specific instructions
dnl

dnl test endianess - important for libdvdread includes and bswap.h
AC_C_BIGENDIAN

case "$host_os" in
    darwin*)
    LIBS="-framework Cocoa -framework IOKit $LIBS"
       ;;
esac

AC_MSG_CHECKING([for build architecture])
have_x86cpu=false
have_x86_64cpu=false
have_ppccpu=false
case x"$host_cpu" in
  xi?86*|xk6*)
    have_x86cpu=true
    AC_MSG_RESULT([Intel Pentium architecture (IA32)])
    AC_DEFINE([ARCH_X86], 1, [Define if your machine is x86 based])
    ;;
  xx86_64*|xamd64*)
    have_x86_64cpu=true
    AC_MSG_RESULT([AMD64 architecture (AMD64)])
    AC_DEFINE([ARCH_X86_64], 1, [Define if your machine is AMD64 based])
    ;;
  xpowerpc*)
    have_ppccpu=true
    AC_MSG_RESULT([Mac PPC architecture (PPC)])
    AC_DEFINE([ARCH_PPC], 1, [Define if your machine is PPC based])
    ;;
  *)
    ;;
esac
AM_CONDITIONAL(ARCH_X86, test x"$have_x86cpu" = x"true")
AM_CONDITIONAL(ARCH_X86_64, test x"$have_x86_64cpu" = x"true")
AM_CONDITIONAL(ARCH_PPC, test x"$have_ppccpu" = x"true")


dnl x86 & x86_64 architectures

dnl MMX support
dnl
AC_ARG_ENABLE(mmx,
  AC_HELP_STRING([--enable-mmx],
    [enable MMX code portions (yes)]),
  [case "${enableval}" in
    yes) use_mmx=yes ;;
    no)  use_mmx=no ;;
    *) AC_MSG_ERROR(bad value ${enableval} for --enable-mmx) ;;
  esac],
  [if test x"$have_x86cpu" = x"true" -o x"$have_x86_64cpu" = x"true" ; then
    use_mmx=yes
  else
    use_mmx=no
  fi])

AC_MSG_CHECKING([if \$CC groks MMX inline assembly])
have_asm_mmx="no"
if test x"$use_mmx" = x"yes" ; then
  AC_TRY_COMPILE([],
    [void *p;asm volatile("packuswb %%mm1,%%mm2"::"r"(p));],
    [have_asm_mmx="yes"])
  if test x"$have_asm_mmx" = x"yes" ; then
    AC_DEFINE([HAVE_ASM_MMX], 1,
      [Define if your CPU understands ASM MMX instructions])
    AC_DEFINE([HAVE_MMX], 1,
      [Define if your CPU understands MMX instructions])
  fi
fi
AC_MSG_RESULT($have_asm_mmx)
AM_CONDITIONAL(HAVE_MMX, test x"$have_asm_mmx" = x"yes")
if test x"$have_asm_mmx" = x"no" ; then
  AC_MSG_WARN(*** All of mmx dependent parts will be disabled ***)
fi

dnl 3DNow support
dnl
AC_ARG_ENABLE(3dnow,
  AC_HELP_STRING([--enable-3dnow],
    [enable 3DNow code portions (yes)]),
  [case "${enableval}" in
    yes) use_3dnow=yes ;;
    no)  use_3dnow=no ;;
    *) AC_MSG_ERROR(bad value ${enableval} for --enable-3dnow) ;;
  esac],
  [if test x"$have_x86cpu" = x"true" -o x"$have_x86_64cpu" = x"true" ; then
    use_3dnow=yes
  else
    use_3dnow=no
  fi])
AC_MSG_CHECKING([for support of 3DNow in assembly code])
have_asm_3dnow="no"
if test x"$use_3dnow" = x"yes" ; then
  cat > conftest.S <<EOF
    .text

    pfmul %mm3, %mm4
EOF
  if $CC -c conftest.S ; then
    rm -f conftest.*
    AC_DEFINE([HAVE_ASM_3DNOW], 1,
      [Define if your CPU understands ASM 3DNow instructions])
    AC_DEFINE([HAVE_3DNOW], 1,
      [Define if your CPU understands 3DNow instructions])
    have_asm_3dnow="yes"
  else
    echo "configure: failed program was:" >&AC_FD_CC
    cat conftest.S >&AC_FD_CC
    rm -f conftest.*
  fi
fi
AC_MSG_RESULT($have_asm_3dnow)
AM_CONDITIONAL(HAVE_3DNOW, test x"$have_asm_3dnow" = x"yes")
if test x"$have_asm_3dnow" = x"no" ; then
  AC_MSG_WARN(*** All of 3DNow dependent parts will be disabled ***)
fi


dnl SSE support
dnl
AC_ARG_ENABLE(sse,
  AC_HELP_STRING([--enable-sse],
    [enable SSE code portions (yes)]),
  [case "${enableval}" in
    yes) use_sse=yes ;;
    no)  use_sse=no ;;
    *) AC_MSG_ERROR(bad value ${enableval} for --enable-sse) ;;
  esac],
  [if test x"$have_x86cpu" = x"true" -o x"$have_x86_64cpu" = x"true" ; then
    use_sse=yes
  else
    use_sse=no
  fi])
AC_MSG_CHECKING([if \$CC groks SSE inline assembly])
have_asm_sse="no"
if test x"$use_sse" = x"yes" ; then
  AC_TRY_COMPILE([],
    [void *p; asm volatile("movntps  %%xmm0, 0"::"r"(p));],
    [have_asm_sse=yes])
  if test x"$have_asm_sse" = x"yes" ; then
    AC_DEFINE([HAVE_ASM_SSE], 1,
      [Define if your CPU understands ASM SSE instructions])
    AC_DEFINE([HAVE_SSE], 1,
      [Define if your CPU understands SSE instructions])
  fi
fi
AC_MSG_RESULT($have_asm_sse)
AM_CONDITIONAL(HAVE_SSE, test x"$have_asm_sse" = x"yes")
if test x"$have_asm_sse" = x"no" ; then
  AC_MSG_WARN(*** All of sse dependent parts will be disabled ***)
fi


dnl SSE2 support
dnl
AC_ARG_ENABLE(sse2,
  AC_HELP_STRING([--enable-sse2],
    [enable SSE2 code portions (yes)]),
  [case "${enableval}" in
    yes) use_sse2=yes ;;
    no)  use_sse2=no ;;
    *) AC_MSG_ERROR(bad value ${enableval} for --enable-sse2) ;;
  esac],
  [if test x"$have_x86cpu" = x"true" -o x"$have_x86_64cpu" = x"true" ; then
    use_sse2=yes
  else
    use_sse2=no
  fi])
AC_MSG_CHECKING([if \$CC can handle SSE2 inline asm])
have_asm_sse2="no"
if test x"$use_sse2" = x"yes" ; then
  AC_TRY_COMPILE([],
    [void *p; asm volatile("movdqa  %%xmm2, %%xmm3"::"r"(p));],
    [have_asm_sse2=yes])
  if test x"$have_asm_sse2" = x"yes" ; then
    AC_DEFINE([HAVE_ASM_SSE2], 1,
      [Define if your CPU understands ASM SSE2 instructions])
    AC_DEFINE([HAVE_SSE2], 1,
      [Define if your CPU understands SSE2 instructions])
  fi
fi
AC_MSG_RESULT($have_asm_sse2)
AM_CONDITIONAL(HAVE_SSE2, test x"$have_asm_sse2" = x"yes")
if test x"$have_asm_sse2" = x"no" ; then
  AC_MSG_RESULT(*** All of sse2 dependent parts will be disabled ***)
fi

dnl
dnl libdvdread: check wich version to use
dnl
if test -d contrib/libdvdread ; then
	AC_MSG_NOTICE([Using built-in libdvdread !])
	LIBDVDREAD_CFLAGS="-I\$(top_srcdir)/contrib/libdvdread/src"
	LIBDVDREAD_LIBS="\$(top_builddir)/contrib/libdvdread/src/libdvdread.la"
	AC_SUBST(LIBDVDREAD_CFLAGS)
	AC_SUBST(LIBDVDREAD_LIBS)
else
	AC_CHECK_LIB(dvdread, DVDOpen,
		[	LIBDVDREAD_CFLAGS=""
			LIBDVDREAD_LIBS="-ldvdread"
			AC_SUBST(LIBDVDREAD_CFLAGS)
			AC_SUBST(LIBDVDREAD_LIBS)
		],
		AC_MSG_ERROR([libdvdread not found!]))
	AC_MSG_CHECKING([for dvdread/ifo_read.h])
	AC_TRY_COMPILE([#include <stdint.h>\n#include <dvdread/ifo_read.h>], ,
		AC_MSG_RESULT([yes]), 
		AC_MSG_RESULT([no]) 
		AC_MSG_ERROR([Header files for dvdread not found]))

	dnl Check libdvdread version (0.9.4 seems broken on FC9/10
	AC_LANG(C)
	AC_TRY_RUN([
	#include <inttypes.h>
	#include <dvdread/dvd_reader.h>
	#include <dvdread/ifo_types.h>
	#include <dvdread/ifo_read.h>
	#include <dvdread/nav_read.h>
	int main(void) { if (DVDREAD_VERSION < 904) return 1; return 0; }
	],,AC_MSG_ERROR(Unable to find libdvdread >= 0.9.4))
fi

dnl
dnl libauthor
dnl
LIBAUTHOR_CFLAGS="-I\$(top_srcdir)/dvdauthor"
LIBAUTHOR_LIBS="\$(top_builddir)/dvdauthor/libauthor.la"
AC_SUBST(LIBAUTHOR_CFLAGS)
AC_SUBST(LIBAUTHOR_LIBS)

dnl
dnl libmpeg2
dnl

AC_ARG_ENABLE(libmpeg2,
  AC_HELP_STRING([--disable-libmpeg2], [disable LIBMPEG2 support]),
  [have_libmpeg2="$enableval"], [have_libmpeg2="yes"])

if test x"$have_libmpeg2" != x"no"; then

AC_CHECK_LIB(mpeg2, mpeg2_init, , AC_MSG_ERROR([libmpeg2 not found!]))
AC_MSG_CHECKING([for mpeg2dec/mpeg2.h])
AC_TRY_COMPILE([#include <stdint.h>\n#include <mpeg2dec/mpeg2.h>], ,
	AC_MSG_RESULT([yes]), 
	AC_MSG_RESULT([no]) 
	AC_MSG_ERROR([Header files for libmpeg2 not found]))

AC_CHECK_LIB(mpeg2convert, mpeg2_convert, , AC_MSG_ERROR([libmpeg2convert not found!]))
AC_MSG_CHECKING([for mpeg2dec/mpeg2convert.h])
AC_TRY_COMPILE([#include <stdint.h>\n#include <mpeg2dec/mpeg2convert.h>], ,
	AC_MSG_RESULT([yes]), 
	AC_MSG_RESULT([no]) 
	AC_MSG_ERROR([Header files for libmpeg2convert not found]))

fi

dnl **************************************************************

AC_PATH_PROG(MPLAYER_PROG, mplayer)
if test x"$MPLAYER_PROG" = x; then
  AC_MSG_ERROR(Unable to find mplayer in the PATH. You need mplayer to use DVD95. Find it on http://www.mplayerhq.hu)
fi

dnl **************************************************************

AC_PATH_PROG(MENCODER_PROG, mencoder)
if test x"$MENCODER_PROG" = x; then
  AC_MSG_ERROR(Unable to find mencoder in the PATH. You need mencoder to use DVD95. Find it on http://www.mplayerhq.hu)
fi

dnl **************************************************************

AC_PATH_PROG(FFMPEG_PROG, ffmpeg)
if test x"$FFMPEG_PROG" = x; then
  AC_MSG_ERROR(Unable to find ffmpeg in the PATH. You need ffmpeg to use DVD95. Find it on http://www.ffmpeg.org/)
fi


AC_OUTPUT([
Makefile
src/Makefile
dvdauthor/Makefile
po/Makefile.in
])

