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

dnl Setup for automake
AM_INIT_AUTOMAKE(OpenGL-intro, 1.1.1)

dnl Detect the canonical host and target build environment
AC_CANONICAL_HOST
AC_CANONICAL_TARGET

dnl Check for tools

AC_PROG_CC

dnl Check for compiler environment

AC_C_CONST

dnl Figure out which math library to use
case "$target" in
    *-*-cygwin* | *-*-mingw32*)
        MATHLIB=""
        SYS_GL_LIBS="-lopengl32 -lglu32"
        ;;
    *-*-beos*)
        MATHLIB=""
        SYS_GL_LIBS="-lGL"
        ;;
    *-*-darwin*)
        MATHLIB=""
        SYS_GL_LIBS=""
        ;;
    *)
        MATHLIB="-lm"
        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_SUBST(MATHLIB)

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 Check for OpenGL
AC_MSG_CHECKING(for OpenGL support)
have_opengl=no
AC_TRY_COMPILE([
 #include "SDL_opengl.h"
],[
],[
have_opengl=yes
])
AC_MSG_RESULT($have_opengl)
if test x$have_opengl = xyes; then
    CFLAGS="$CFLAGS -DHAVE_OPENGL"
    GL_LIBS="$SYS_GL_LIBS"
else
    AC_MSG_ERROR(Unable to find OpenGL headers and libraries)
fi
AC_SUBST(GL_LIBS)

dnl Look for a working SDL_mixer library
AC_CHECK_LIB(SDL_mixer, Mix_LoadMUS, have_SDL_mixer=yes)
if test x$have_SDL_mixer = xyes; then
    CFLAGS="$CFLAGS -DSOUND"
    SOUND_LIBS="-lSDL_mixer"
fi
AC_SUBST(SOUND_LIBS)

# Finally create all the generated files
AC_OUTPUT([
Makefile
Data06/Makefile
Data07/Makefile
Data08/Makefile
Data09/Makefile
Data10/Makefile
Data11/Makefile
Data12/Makefile
Data16/Makefile
Data17/Makefile
Data18/Makefile
Data19/Makefile
Data20/Makefile
Data21/Makefile
Data22/Makefile
Data23/Makefile
Data24/Makefile
Data25/Makefile
Data26/Makefile
Data27/Makefile
Data28/Makefile
Data29/Makefile
Data30/Makefile
])
