
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=3
MICRO_VERSION=3
INTERFACE_AGE=3
BINARY_AGE=3
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 Check for tools

AC_PROG_MAKE_SET
AC_PROG_CC
AC_PROG_CXX
AM_PROG_LIBTOOL
AC_PROG_INSTALL

dnl The alpha architecture needs special flags for binary portability
AC_CANONICAL_TARGET
case "$target" in
    alpha*-*-linux*)
        CFLAGS="$CFLAGS -mcpu=ev4 -Wa,-mall"
        ;;
esac

dnl SMPEG uses mmap() for file loading:
AC_FUNC_MMAP
if test x$ac_cv_func_mmap_fixed_mapped != xyes; then
    AC_MSG_ERROR(SMPEG requires mmap() for file loading)
fi

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

dnl Check for SDL mixer support
AC_ARG_ENABLE(mixer,
[  --enable-mixer          use the SDL sample mixer for audio [default=no]],
              , enable_mixer=no)
if test x$enable_mixer = xyes; then
    CFLAGS="$CFLAGS -DSDL_MIXER"
    LIBS="$LIBS -lSDL_mixer"
fi
AC_ARG_WITH(mixer-prefix,
[  --with-mixer-prefix=PFX   Prefix where SDL mixer is installed (optional)],
            mixer_prefix="$withval", mixer_prefix="")
if test x$mixer_prefix != x; then
    CFLAGS="$CFLAGS -I$mixer_prefix/include"
    LIBS="$LIBS -I$mixer_prefix/lib"
fi

dnl Add the parent directory for sub-make
CFLAGS="$CFLAGS -I.. -DNOCONTROLS"
CXXFLAGS="$CFLAGS"

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
    dnl FIXME:  Need a better test here...
    #AC_CHECK_HEADER(GL/gl.h, have_gl=yes)
    AC_CHECK_LIB(GL, glXCreateContext, have_gl=yes)
    #AC_CHECK_HEADER(GL/glu.h, have_glu=yes)
    AC_CHECK_LIB(GLU, gluOrtho2D, have_glu=yes)
fi
AM_CONDITIONAL(HAVE_MESA, test x$have_gl = xyes -a x$have_glu = xyes)

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

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.spec
])
