
dnl Process this file with autoconf to produce a configure script.
AC_INIT(README)

dnl Set various version strings - taken gratefully from the GTk sources
#
# Making releases:
#   MICRO_VERSION += 1;
#   INTERFACE_AGE += 1;
#   BINARY_AGE += 1;
# if any functions have been added, set INTERFACE_AGE to 0.
# if backwards compatibility has been broken,
# set BINARY_AGE and INTERFACE_AGE to 0.
#
MAJOR_VERSION=0
MINOR_VERSION=4
MICRO_VERSION=4
INTERFACE_AGE=3
BINARY_AGE=4
VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION

AC_SUBST(MAJOR_VERSION)
AC_SUBST(MINOR_VERSION)
AC_SUBST(MICRO_VERSION)
AC_SUBST(INTERFACE_AGE)
AC_SUBST(BINARY_AGE)
AC_SUBST(VERSION)

# libtool versioning
LT_RELEASE=$MAJOR_VERSION.$MINOR_VERSION
LT_CURRENT=`expr $MICRO_VERSION - $INTERFACE_AGE`
LT_REVISION=$INTERFACE_AGE
LT_AGE=`expr $BINARY_AGE - $INTERFACE_AGE`

AC_SUBST(LT_RELEASE)
AC_SUBST(LT_CURRENT)
AC_SUBST(LT_REVISION)
AC_SUBST(LT_AGE)

dnl Setup for automake
AM_INIT_AUTOMAKE(smpeg, $VERSION)

dnl Detect the canonical host and target build environment
AC_CANONICAL_HOST
AC_CANONICAL_TARGET

dnl Check for tools

AC_PROG_MAKE_SET
AC_PROG_CC
AC_PROG_CXX
AC_LIBTOOL_WIN32_DLL
AM_PROG_LIBTOOL
AC_PROG_INSTALL

dnl Work around the lack of certain typedefs.
AC_TYPE_SOCKLEN_T

dnl The alpha architecture needs special flags for binary portability
case "$target" in
    alpha*-*-linux*)
	if test x$ac_cv_prog_gcc = xyes; then
            CFLAGS="$CFLAGS -mcpu=ev4 -Wa,-mall"
        fi
        ;;
    sparc*-*-solaris*)
        LIBS="$LIBS -lsocket -lnsl"	
        ;;
    *-*-qnx*)
        LIBS="$LIBS -lsocket"
        ;;
    *-*-beos*)
        ac_default_prefix=/boot/develop/tools/gnupro
        ;;
    *-*-cygwin* | *-*-mingw32*)
        if test "$build" != "$target"; then # cross-compiling
            ac_default_prefix=/usr/local/cross-tools/i386-mingw32msvc
        fi
        ;;
esac

# Set runtime shared library paths as needed 

case "$target" in
    *-*-linux*)
	SMPEG_RLD_FLAGS="-Wl,-rpath,\${exec_prefix}/lib"
	;;
    *-*-freebsd*)
	SMPEG_RLD_FLAGS="-Wl,-rpath,\${exec_prefix}/lib"
	;;
    *-*-solaris*)
	SMPEG_RLD_FLAGS="-R\${exec_prefix}/lib"
	;;
esac

AC_SUBST(SMPEG_RLD_FLAGS)

dnl Add compiler-specific optimization flags

AC_ARG_ENABLE(debug,
[  --enable-debug          Disable aggressive optimizations [default=yes]],
              , enable_debug=yes)
if test x$enable_debug != xyes; then
    if test x$ac_cv_prog_gcc = xyes; then
        CFLAGS="$CFLAGS -fexpensive-optimizations -fomit-frame-pointer"
    fi
    case "$target" in
        i486-*-*)  # Yeah right. :)
            if test x$ac_cv_prog_gcc = xyes; then
                CFLAGS="$CFLAGS -march=486"
            fi
            ;;
        i?86-*-*)
            if test x$ac_cv_prog_gcc = xyes; then
                CFLAGS="$CFLAGS -march=pentium -mcpu=pentiumpro"
            fi
            ;;
    esac
fi

dnl Check for SDL
SDL_VERSION=1.2.0
AM_PATH_SDL($SDL_VERSION,
            :,
	    AC_MSG_ERROR([*** SDL version $SDL_VERSION not found!])
)
CFLAGS="$CFLAGS $SDL_CFLAGS"
LIBS="$LIBS $SDL_LIBS"

dnl See if we need to pass -lm for the math library
AC_CHECK_LIB(m, sqrt, LIBS="$LIBS -lm")

dnl Check for MMX support
AC_ARG_ENABLE(mmx,
[  --enable-mmx            enable MMX IDCT decoding routines [default=no]],
              , enable_mmx=no)
if test x$enable_mmx = xyes; then
    AC_MSG_CHECKING(for MMX optimizations)
    use_mmx=no
    case "$target" in
        i?86*)
            use_mmx=yes
            ;;
    esac
    AC_MSG_RESULT($use_mmx)

    if test x$use_mmx = xyes; then
        CFLAGS="$CFLAGS -DUSE_MMX"
    fi
fi

dnl Check for ATI vha support
AC_ARG_ENABLE(ati,
[  --enable-ati            enable ATI Rage128 hardware acceleration [default=no]],
              , enable_ati=no)
if test x$enable_ati = xyes; then
    use_ati=yes
    AC_CHECK_LIB(r128hap, ATIHAP_StartCCE, LIBS="$LIBS -lr128hap", use_ati=no)
    AC_CHECK_LIB(r128vha, VHA_Init, LIBS="$LIBS -lr128vha", use_ati=no)
    AC_CHECK_LIB(r128ov, CreateOVSurface, LIBS="$LIBS -lr128ov", use_ati=no)
    AC_MSG_CHECKING(for ATI Rage128 hardware acceleration)
    AC_MSG_RESULT($use_ati)

    if test x$use_ati = xyes; then
        CFLAGS="$CFLAGS -DUSE_ATI"
    fi
fi

dnl Check for system timestamp sync
AC_ARG_ENABLE(timestamp-sync,
[  --enable-timestamp-sync  enable system timestamp sync [default=yes]],
              , enable_timestamp_sync=no)
if test x$enable_timestamp_sync = xyes; then
	CFLAGS="$CFLAGS -DUSE_TIMESTAMP_SYNC"
fi

dnl Enable the use of the system thread
AC_ARG_ENABLE(threaded-system,
[  --enable-threaded-system enable system thread         [default=no]],
              , enable_threaded_system=no)
if test x$enable_threaded_system = xyes; then
	CFLAGS="$CFLAGS -DUSE_SYSTEM_THREAD"
fi

dnl Enable threaded audio
AC_ARG_ENABLE(threaded-audio,
[  --enable-threaded-audio  enable threaded audio        [default=yes]],
              , enable_threaded_audio=yes)
if test x$enable_threaded_audio = xyes; then
	CFLAGS="$CFLAGS -DTHREADED_AUDIO"
fi

dnl See if we can build the GTk player
AC_ARG_ENABLE(gtk_player,
[  --enable-gtk-player     build a GTk sample SMPEG player [default=yes]],
              , enable_gtk_player=yes)
have_gtk=no
if test x$enable_gtk_player = xyes; then
    AM_PATH_GTK(1.2.1, have_gtk=yes)
    if test x$have_gtk = xyes; then
        CFLAGS="$CFLAGS $GTK_CFLAGS"
    fi
    AC_SUBST(GTK_LIBS)
fi
AM_CONDITIONAL(HAVE_GTK, test x$have_gtk = xyes)

dnl See if we can build the Mesa player
AC_ARG_ENABLE(opengl_player,
[  --enable-opengl-player  build an OpenGL sample SMPEG player [default=yes]],
              , enable_opengl_player=yes)
have_glu=no
if test x$enable_opengl_player = xyes; then
    case "$target" in
        *-*-cygwin* | *-*-mingw32*)
            SYS_GL_LIBS="-lopengl32 -lglu32"
            ;;
        *-*-beos*)
            SYS_GL_LIBS="-lGL"
            ;;
        *-*-darwin*)
            SYS_GL_LIBS=""
            ;;
        *)
            AC_PATH_X
            AC_PATH_XTRA
            if test x$have_x = xyes; then
                CFLAGS="$CFLAGS $X_CFLAGS"
                SYS_GL_LIBS="$X_LIBS -lGL -lGLU"
            else
                SYS_GL_LIBS="-lGL -lGLU"
            fi
            ;;
    esac
    AC_MSG_CHECKING(for OpenGL support)
    have_opengl=no
    AC_TRY_COMPILE([
     #include <GL/gl.h>
     #include <GL/glu.h>
    ],[
    ],[
    have_opengl=yes
    ])
    AC_MSG_RESULT($have_opengl)
    if test x$have_opengl = xyes; then
        GL_LIBS="$SYS_GL_LIBS"
    else
        echo "*** The OpenGL movie player will not be built (missing GL or GLU)"
    fi
fi
AC_SUBST(GL_LIBS)
AM_CONDITIONAL(HAVE_OPENGL, test x$have_opengl = xyes)

dnl Disable assertions in release builds
AC_ARG_ENABLE(assertions,
[  --enable-assertions     Enable consistency checks in decoding [default=no]],
              , enable_assertions=no)
if test x$enable_assertions != xyes; then
    CFLAGS="$CFLAGS -DNDEBUG"
fi

dnl Add the source include directories
CFLAGS="$CFLAGS -I.. -DNOCONTROLS"
CFLAGS="$CFLAGS -I\$(top_srcdir) -I\$(top_srcdir)/audio -I\$(top_srcdir)/video"
CXXFLAGS="$CFLAGS"


dnl C++ flags are the same as the C flags
CXXFLAGS="$CFLAGS"
if test x$GCC = xyes; then
    # Check to see if options -fno-rtti -fno-exceptions are supported
    AC_MSG_CHECKING(if $CXX supports -fno-rtti -fno-exceptions)
    use_fnoexceptions=no
    save_CFLAGS="$CFLAGS"
    save_CC="$CC"
    CFLAGS="-fno-rtti -fno-exceptions"
    CC="$CXX"
    AC_TRY_COMPILE([
    ],[
    ],[
    use_fnoexceptions=yes
    ])
    AC_MSG_RESULT($use_fnoexceptions)
    if test x$use_fnoexceptions = xyes; then
        CXXFLAGS="$CXXFLAGS -fno-exceptions -fno-rtti"
    fi
    CC="$save_CC"
    CFLAGS="$save_CFLAGS"
fi


# Finally create all the generated files
AC_OUTPUT([
Makefile
audio/Makefile
video/Makefile
smpeg-config
smpeg.spec
])
