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=1
MINOR_VERSION=2
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 Detect the canonical host and target build environment
AC_CANONICAL_HOST
AC_CANONICAL_TARGET

dnl Setup for automake
AM_INIT_AUTOMAKE(SDL_image, $VERSION)
AM_MAINTAINER_MODE

dnl Check for tools

AC_LIBTOOL_WIN32_DLL
AM_PROG_LIBTOOL
LIBTOOL="$LIBTOOL --preserve-dup-deps"
AC_SUBST(LIBTOOL)
AC_PROG_MAKE_SET
AC_PROG_CC
AC_C_INLINE
AC_PROG_INSTALL

dnl Check for a valid PSPSDK installation
CheckPSPSDK()
{
    AC_CHECK_PROG(psp_config, psp-config, psp-config, no)
    if test x$psp_config = xno; then
        AC_MSG_ERROR(Couldn't locate psp-config.)
    fi

    AC_MSG_CHECKING(for PSPSDK)
    pspsdk_path=`$psp_config --pspsdk-path`
    if test ! -d $pspsdk_path -o -z $pspsdk_path; then
        AC_MSG_RESULT(not found)
        AC_MSG_ERROR(Couldn't locate PSPSDK.)
    fi
    AC_MSG_RESULT($pspsdk_path)

    # Compile SDL with -G0 to disable the $gp register.
    CFLAGS="$CFLAGS -G0 -I\"${pspsdk_path}/include\""
    BUILD_PREFIX="psp-"
}

dnl The alpha architecture needs special flags for binary portability
case "$target" in
    alpha*-*-linux*)
        CFLAGS="$CFLAGS -mcpu=ev4 -Wa,-mall"
        ;;
    *-*-beos*)
        ac_default_prefix=/boot/develop/tools/gnupro
        ;;
    *-*-cygwin* | *-*-mingw32*)
        if test "$build" != "$target"; then # cross-compiling
            # Default cross-compile location
            ac_default_prefix=/usr/local/cross-tools/i386-mingw32msvc
        else
            # Look for the location of the tools and install there
            if [ "$BUILD_PREFIX" != "" ]; then
                ac_default_prefix=$BUILD_PREFIX
            fi
        fi
        ;;
    *-psp-*)
       	ARCH=psp
       	CheckPSPSDK
       	;;
esac

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

dnl Check command-line options
AC_ARG_ENABLE(bmp,
[  --enable-bmp            support loading BMP images [default=yes]],
              , enable_bmp=yes)
if test x$enable_bmp = xyes; then
    CFLAGS="$CFLAGS -DLOAD_BMP"
fi
AC_ARG_ENABLE(gif,
[  --enable-gif            support loading GIF images [default=yes]],
              , enable_gif=yes)
if test x$enable_gif = xyes; then
    CFLAGS="$CFLAGS -DLOAD_GIF"
fi
AC_ARG_ENABLE(jpg,
[  --enable-jpg            support loading JPG images [default=yes]],
              , enable_jpg=yes)
if test x$enable_jpg = xyes; then
    AC_CHECK_LIB(jpeg, jpeg_CreateDecompress, have_libjpeg=yes)
    if test x$have_libjpeg = xyes; then
        CFLAGS="$CFLAGS -DLOAD_JPG"
        IMG_LIBS="$IMG_LIBS -ljpeg"
    else
        AC_MSG_WARN([
*** Unable to find JPEG library (http://www.ijg.org/)
])
        AC_MSG_WARN([JPG image loading disabled])
    fi
fi
AC_ARG_ENABLE(lbm,
[  --enable-lbm            support loading LBM images [default=yes]],
              , enable_lbm=yes)
if test x$enable_lbm = xyes; then
    CFLAGS="$CFLAGS -DLOAD_LBM"
fi
AC_ARG_ENABLE(pcx,
[  --enable-pcx            support loading PCX images [default=yes]],
              , enable_pcx=yes)
if test x$enable_pcx = xyes; then
    CFLAGS="$CFLAGS -DLOAD_PCX"
fi
AC_ARG_ENABLE(png,
[  --enable-png            support loading PNG images [default=yes]],
              , enable_png=yes)
if test x$enable_png = xyes; then
    AC_CHECK_LIB(png, png_create_read_struct, have_libpng=yes, , -lz)
    if test x$have_libpng != xyes; then
        AC_MSG_WARN([
*** Unable to find PNG library (http://www.libpng.org/pub/png/libpng.html)
])
    fi
    AC_CHECK_LIB(z, uncompress, have_libz=yes)
    if test x$have_libz != xyes; then
        AC_MSG_WARN([
*** Unable to find Zlib library (http://www.gzip.org/zlib/)
])
    fi
    if test x$have_libpng = xyes -a x$have_libz = xyes; then
        CFLAGS="$CFLAGS -DLOAD_PNG"
        IMG_LIBS="$IMG_LIBS -lpng -lz"
    else
        AC_MSG_WARN([PNG image loading disabled])
    fi
fi
AC_ARG_ENABLE(pnm,
[  --enable-pnm            support loading PNM images [default=yes]],
              , enable_pnm=yes)
if test x$enable_pnm = xyes; then
    CFLAGS="$CFLAGS -DLOAD_PNM"
fi
AC_ARG_ENABLE(tga,
[  --enable-tga            support loading TGA images [default=yes]],
              , enable_tga=yes)
if test x$enable_tga = xyes; then
    CFLAGS="$CFLAGS -DLOAD_TGA"
fi
AC_ARG_ENABLE(tif,
[  --enable-tif            support loading TIFF images [default=no]],
              , enable_tif=no)
if test x$enable_tif = xyes; then
    AC_CHECK_LIB(tiff, TIFFClientOpen, have_libtiff=yes)
    if test x$have_libtiff = xyes; then
        CFLAGS="$CFLAGS -DLOAD_TIF"
        IMG_LIBS="$IMG_LIBS -ltiff"
    else
        AC_MSG_WARN([
*** Unable to find Tiff library (ftp://ftp.sgi.com/graphics/tiff/)
])
        AC_MSG_WARN([TIF image loading disabled])
    fi
fi
AC_ARG_ENABLE(xcf,
[  --enable-xcf            support loading XCF images [default=no]],
              , enable_xcf=no)
if test x$enable_xcf = xyes; then
    CFLAGS="$CFLAGS -DLOAD_XCF"
fi
AC_ARG_ENABLE(xpm,
[  --enable-xpm            support loading XPM images [default=yes]],
              , enable_xpm=yes)
if test x$enable_xpm = xyes; then
    CFLAGS="$CFLAGS -DLOAD_XPM"
fi
AC_SUBST(IMG_LIBS)

# Finally create all the generated files
AC_OUTPUT([
Makefile
SDL_image.spec
SDL_image.qpg
])