AC_INIT(atris.c)
dnl Setup for automake
AC_CANONICAL_TARGET
AM_INIT_AUTOMAKE(atris, 1.0.7)
AM_CONFIG_HEADER(config.h)

dnl Check for tools

AC_PROG_AWK
AC_PROG_CC
AC_PROG_INSTALL
AC_PROG_LN_S
AC_PROG_MAKE_SET

AC_CHECK_HEADERS(winsock.h)
AC_CHECK_HEADERS(sys/socket.h)
AC_CHECK_HEADERS(netinet/in.h,,[
    echo '*** Cannot find "netinet/in.h". Compilation may fail!'])
AC_CHECK_HEADERS(netdb.h,,[
    echo '*** Cannot find "netdb.h". Compilation may fail!'])
AC_CHECK_HEADERS(fcntl.h,,[
    echo '*** Cannot find "fcntl.h". Compilation may fail!'])
AC_CHECK_HEADERS(sys/time.h)
AC_CHECK_HEADERS(unistd.h,,[
    echo '*** Cannot find "unistd.h". Compilation may fail!'])
AC_HEADER_DIRENT
AC_HEADER_STDC

AC_C_CONST
AC_TYPE_SIZE_T
AC_HEADER_TIME
AC_STRUCT_TM

AC_FUNC_STRFTIME
AC_FUNC_VPRINTF
AC_CHECK_FUNCS(strdup,,[
    echo '*** Cannot find strdup() and we are too lazy to rewrite it.'
    exit])
AC_CHECK_FUNCS(strerror,,[
    echo '*** Cannot find strerror(). You will not get good error messages.'])
AC_CHECK_FUNCS(strchr)
AC_CHECK_FUNCS(strstr,,[
    echo '*** Cannot find strstr() and we are too lazy to rewrite it.'
    exit])
AC_CHECK_FUNCS(memcpy)

AC_CHECK_LIB(wsock32, libwsock32_a_iname)

AC_CHECK_FUNCS(select,,[
    echo '*** Cannot find select(). Networking will fail unless WinSock provies it!'])

case "$target" in
    *-*-mingw32*)
	GAME_INSTALLDIR="C:/Program\\ Files/$PACKAGE"
	CFLAGS="$CFLAGS -s"
	;;
    *)
	GAME_INSTALLDIR="\$(prefix)/games/$PACKAGE"
	;;
esac



AC_SUBST(GAME_INSTALLDIR)

dnl Check for SDL
SDL_VERSION=1.1.6
AM_PATH_SDL($SDL_VERSION,
            :,
	    AC_MSG_ERROR([*** SDL version $SDL_VERSION not found! Get it from http://www.libsdl.org ])
)
CFLAGS="$CFLAGS -Wall -Wimplicit -Wsign-compare -Wpointer-arith $SDL_CFLAGS -DATRIS_LIBDIR=\\\"$GAME_INSTALLDIR\\\""
LIBS="$LIBS $SDL_LIBS"

# Finally create all the generated files
AC_OUTPUT([
Makefile
graphics/Makefile
Docs/Makefile
styles/Makefile
.protos/Makefile
atris.spec
])

echo "
$PACKAGE $VERSION
Configuration:
--------------

 Source code location: ${srcdir}
 Compiler:	       ${CC} 
 Host System Type:     ${host}
 Libraries:            ${LIBS}
 Install path:         ${prefix}
 Game files:           ${GAME_INSTALLDIR}

 Now type 'make' to build $PACKAGE $VERSION.
"
