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

AC_INIT(SDL_gfxPrimitives.c)
AC_CONFIG_MACRO_DIR([m4])

dnl SDL version required

SDL_VERSION=1.2.0
AC_SUBST(SDL_VERSION)

dnl Setup for automake

# 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=2
MINOR_VERSION=0
MICRO_VERSION=22
INTERFACE_AGE=0
BINARY_AGE=9
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 Detect the canonical host and target build environment
AC_CANONICAL_HOST
AC_CANONICAL_TARGET

AM_INIT_AUTOMAKE(SDL_gfx, $VERSION)

dnl Check for compilers
AC_LIBTOOL_WIN32_DLL
AM_PROG_LIBTOOL
AC_PROG_MAKE_SET
AC_PROG_CC
AC_PROG_CXX
AC_PROG_INSTALL

dnl Check for compiler environment
AC_C_CONST

dnl Set for C compiler by default
AC_LANG_C

dnl Setup target flagsw
case "$target" in
    *-*-cygwin* | *-*-mingw32*)
	CFLAGS="$CFLAGS -DWIN32"
        if test "$build" != "$target"; then # cross-compiling
            ac_default_prefix=/usr/local/cross-tools/i386-mingw32msvc
        fi
        ;;
    *)
	dnl nothing to do
        ;;
esac

dnl Figure out which math library to use
case "$target" in
    *-*-cygwin* | *-*-mingw32*)
        MATHLIB=""
        ;;
    *-*-beos* | *-*-haiku*)
        MATHLIB=""
        ;;
    *-*-darwin*)
        MATHLIB=""
        ;;
    *-*-aix*)
	MATHLIB="-lm"
        if test x$ac_cv_prog_gcc = xyes; then
            CFLAGS="-mthreads"
	fi
        ;;
    *)
        MATHLIB="-lm"
        AC_PATH_X
        AC_PATH_XTRA
        ;;
esac
AC_SUBST(MATHLIB)
LIBS="$LIBS $MATHLIB"

dnl Check for NASM (for x86 assembly blit routines)
AC_ARG_ENABLE(mmx,[  --enable-mmx            use mmx assembly on x86 [default=yes], disable this on non-x86 platforms],, enable_mmx=yes)

dnl MMX not used on 64-bit platforms, as `popa' and `pusha' are not supported
dnl in 64-bit mode.
AC_CHECK_SIZEOF([long])
if test "$ac_cv_sizeof_long" = "8"; then
       enable_mmx=no
fi
 
if test x$enable_mmx = xyes; then
 CFLAGS="$CFLAGS -O -DUSE_MMX"
fi

dnl Check for SDL
AM_PATH_SDL($SDL_VERSION,
            :,
	    AC_MSG_ERROR([*** SDL version $SDL_VERSION not found!])
)
CFLAGS="$CFLAGS $SDL_CFLAGS"
# Remove dependencies from 'sdl-config' not meant for us libraries:
SDL_LIBS=$(echo "$SDL_LIBS" | sed -e 's/-lmingw32//' -e 's/-lSDLmain//')
LIBS="$LIBS $SDL_LIBS"

# Finally create all the generated files
AC_OUTPUT([
Makefile
SDL_gfx.pc
])
