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

AC_INIT(src/Code222ea.cpp)

AM_INIT_AUTOMAKE([Chaos-Strikes-Back-for-Linux],9.6)
AM_CONFIG_HEADER(config.h)

AC_PATH_PROG(GLIB_CONFIG, glib-config, AC_ERROR("I need glib"))

dnl Linux will require the following parameters to compile
dnl correctly when used with gcc/g++.
C_COMPILER_QUIRCS="-D_LINUX -fwritable-strings -fsigned-char"
CXX_COMPILER_QUIRCS="-D_LINUX -fno-const-strings -fpermissive"
#-fms-extensions

## DEBUG/RELEASE selector
AC_ARG_ENABLE( release,
[ --enable-release Turn off debugging
[default=disable]],
	CFLAGS="$CFLAGS -D_NDEBUG -DG_DISABLE_ASSERT -O2 $C_COMPILER_QUIRCS"
	CXXFLAGS="$CXXFLAGS -D_NDEBUG -DG_DISABLE_ASSERT -O2 $C_COMPILER_QUIRCS $CXX_COMPILER_QUIRCS"
,
	CFLAGS="$CFLAGS -g -Wall $C_COMPILER_QUIRCS"
	CXXFLAGS="$CXXFLAGS -g -Wall $C_COMPILER_QUIRCS $CXX_COMPILER_QUIRCS"
)

## Compile with electric fence.
AC_ARG_ENABLE( efence,
[ --enable-efence Compile with electric fence
[default=disable]],
	LINK_EFENCE="-lefence"
,
	LINK_EFENCE=""
)AC_SUBST(LINK_EFENCE)

PKG_CHECK_MODULES(GLIB, glib >= 1.2.0 )

#AM_PATH_SDL(1.2.0,
#	CFLAGS="$CFLAGS $SDL_CFLAGS"; LIBS="$LIBS $SDL_LIBS",
#	AC_MSG_ERROR(SDL is not installed))                              
AC_PATH_PROG(SDL_CONFIG, sdl-config, AC_ERROR("I am in great need of SDL"))
#PKG_CHECK_MODULES(SDL_CONFIG, sdl >= 1.2.4 )

#AC_PATH_PROG(GTK_CONFIG, gtk-config, AC_ERROR("I need GTK"))
PKG_CHECK_MODULES(GTK_CONFIG, gtk >= 1.2 )

# PKG_CHECK_MODULES(CSL_CONFIG,csl >= 0.2 )
PKG_CHECK_MODULES(ESD_CONFIG,esound >= 0.2.24 )


## Dynamic windowsize or fixed.
AC_ARG_ENABLE( dynwinsize,
[ --enable-dynwinsize Turn on dynamic winsize (default and requires libHermes). [default=enable]],
	LINK_HERMES=""
,
	LINK_HERMES="-lHermes"
	CFLAGS="$CFLAGS -D_DYN_WINSIZE"
	CXXFLAGS="$CXXFLAGS -D_DYN_WINSIZE"
)
AC_SUBST(LINK_HERMES)
AC_TRY_RUN(
	[#include <Hermes.h>
	int main(void){
		if(!Hermes_Init())
			return -1;
		return 0;
	}]
	,AC_ERROR("I tried to use Hermes but failed. You need a dynamically linkable hermes library installed.")
	,
	,AC_ERROR("No cross-compilation is supported."))

AC_PROG_CC
AC_PROG_CXX

AM_PROG_LIBTOOL

AC_PROG_INSTALL

AC_OUTPUT([Makefile \
src/Makefile \
stamp.h])
