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

dnl Detect the canonical target build environment
AC_CANONICAL_HOST
AC_CANONICAL_TARGET

dnl Setup for automake
AM_INIT_AUTOMAKE(Maelstrom, 3.0.6)

dnl Check for tools

AC_PROG_MAKE_SET
AC_PROG_CC
AC_PROG_CXX
AC_PROG_RANLIB
AC_PROG_INSTALL

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

dnl Figure out which math and networking libraries to use
case "$target" in
    *-*-mingw32*)
        MATHLIB=""
        INETLIB="-lwsock32"
        ;;
    *-*-beos*)
        MATHLIB=""
        INETLIB=""
        ;;
    *-*-darwin*)
        MATHLIB=""
        INETLIB=""
        ;;
    *)
        MATHLIB="-lm"
        INETLIB=""
        ;;
esac
AC_SUBST(MATHLIB)
AC_SUBST(INETLIB)

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 SDL_net
AC_CHECK_LIB(SDL_net, SDLNet_Init, have_SDL_net=yes)
if test x$have_SDL_net = xyes; then
    LIBS="$LIBS -lSDL_net"
else
    AC_MSG_ERROR([*** Can't find the SDL_net library
The SDL_net library can be found at:
http://www.devolution.com/~slouken/SDL/projects/SDL_net/
])
fi

dnl Check for RSA checksum authentication
AC_MSG_CHECKING(for RSA checksum authentication)
if test -d $HOME/RSA; then
    CFLAGS="$CFLAGS -DUSE_CHECKSUM -I$HOME/RSA/source"
    LIBS="$LIBS $HOME/RSA/install/rsaref.a"
    use_checksum=yes
else
    use_checksum=no
fi
AC_MSG_RESULT($use_checksum)

dnl Add the include directories for the object libraries
CFLAGS="$CFLAGS -I\$(top_srcdir)"
CFLAGS="$CFLAGS -I\$(top_srcdir)/netlogic"
CFLAGS="$CFLAGS -I\$(top_srcdir)/screenlib"
CFLAGS="$CFLAGS -I\$(top_srcdir)/maclib"

dnl Set up the icon object file, for Mingw32
case "$target" in
    *-*-mingw32*)
        cp ico_o ico.o
	ICONOBJ="ico.o"
        ;;
    *)
	ICONOBJ=""
        ;;
esac
AC_SUBST(ICONOBJ)

dnl Set up the game data install directory
case "$target" in
    *-*-mingw32*)
        GAME_INSTALLDIR="."
	ICONOBJ="ico.o"
        ;;
    *-*-beos*)
        ac_default_prefix=/boot/beos
        GAME_INSTALLDIR="\$(prefix)/games/$PACKAGE"
        ;;
    *)
        GAME_INSTALLDIR="\$(prefix)/games/$PACKAGE"
        ;;
esac
AC_SUBST(GAME_INSTALLDIR)
CFLAGS="$CFLAGS -DLIBDIR=\\\"$GAME_INSTALLDIR\\\""

dnl C++ flags are the same as the C flags
CXXFLAGS="$CXXFLAGS $CFLAGS"

# Finally create all the generated files
AC_OUTPUT([
Makefile
netlogic/Makefile
screenlib/Makefile
maclib/Makefile
Images/Makefile
Docs/Makefile
Maelstrom.spec
])
