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

######## Setup for automake
AM_CONDITIONAL(MIXER_INCLUDED, test -d ./src/mixer )
    
NAME="bumprace"
SDL_VERSION=1.1.5
AM_INIT_AUTOMAKE($NAME, 1.45)

######## Detect the canonical host and target build environment
AC_CANONICAL_HOST
AC_CANONICAL_TARGET

######## Check for tools
AC_PROG_CC
AC_PROG_INSTALL
AC_PROG_RANLIB

######## Check for compiler environment
AC_C_CONST

######## Figure out which math library to use
case "$target" in
    *-*-mingw32*)
        MATHLIB=""
        ;;
    *-*-beos*)
        MATHLIB=""
        ;;
    *)
        MATHLIB="-lm"
	AC_CHECK_LIB(m, main, , AC_MSG_ERROR(Your system is missing libm (mathlib)!))
        ;;
esac
AC_SUBST(MATHLIB)

######## Check for SDL
AM_PATH_SDL($SDL_VERSION,
            :,
	    AC_MSG_ERROR([*** SDL version $SDL_VERSION not found!])
)

######## Check for other libs
AC_CHECK_LIB(jpeg, main, , AC_MSG_ERROR(Your system is missing libjpeg!))

#Commented out because of a bug in the SuSE 6.2
#AC_CHECK_LIB(png, main, , AC_MSG_ERROR(Your system is missing libpng!))

AC_CHECK_LIB(SDL_mixer, main, SOUND="-lSDL_mixer";CFLAGS="$CFLAGS -DSOUND")

######## Set compiler flags and libraries
CFLAGS="$CFLAGS $SDL_CFLAGS -DDATADIR=\\\"$datadir/bumprace\\\""
LIBS="$LIBS $SDL_LIBS -ljpeg -lpng $SOUND -lz -lSDL"

######## Check for headers
AC_CHECK_HEADERS(png.h, , AC_MSG_ERROR(Your system is missing png.h ! You will probably have to install the png-devel package))
AC_CHECK_HEADERS(jpeglib.h, , AC_MSG_ERROR(Your system is missing jpeglib.h ! You will probably have to install the jpeg-devel package))

######## Finally create all the generated files
AC_OUTPUT([
Makefile
src/Makefile
data/Makefile
data/gfx/Makefile
data/sound/Makefile
])
