/************************************************************
Copyright (C) 2004  Masahiko SAWAI 
************************************************************/


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

dnl  Checks for programs.
AC_PROG_RANLIB
AC_PROG_INSTALL

AC_CHECK_PROG([GCJ], [gcj], [gcj])


dnl AC_CONFIG_HEADER(config.h)
AC_CANONICAL_SYSTEM

AC_EXEEXT

dnl ############################################################
dnl initialize variable
dnl ############################################################

AC_SUBST(GCJFLAGS)
GCJFLAGS=""

CFLAGS=" -Wall"
LIBS=


dnl The alpha architecture needs special flags for binary portability
case "$target" in
	alpha*-*-linux*)
		CFLAGS="$CFLAGS -mcpu=ev4 -Wa,-mall"
		SYS_GL_LIBS="-lGL -lglut"
		;;
	*-*-beos*)
		ac_default_prefix=/boot/develop/tools/gnupro
		SYS_GL_LIBS="-lGL -lglut"
		;;
	*-*-cygwin* | *-*-mingw32*)
		SYS_GL_LIBS="-lopengl32 -lglut32"
		if test "$build" != "$target"; then # cross-compiling
			ac_default_prefix=/usr/local/cross-tools/i386-mingw32msvc
		fi
		;;
	*)
		AC_PATH_X
		AC_PATH_XTRA
		if test x$have_x = xyes; then
			SYS_GL_LIBS="$X_LIBS -lGL -lglut"
		else
			SYS_GL_LIBS="-lGL -lglut"
		fi
		;;
esac

case "$target" in
	*-*-cygwin*)
		CFLAGS="$CFLAGS -I/usr/include"
		GCJFLAGS="$GCJFLAGS -mno-cygwin"
		;;
esac

dnl ############################################################
dnl Checks for header files.
dnl ############################################################
AC_HEADER_STDC

dnl ############################################################
dnl Checks for libraries.
dnl ############################################################


dnl ##################################################
dnl check gl4gcj.
dnl ##################################################
GL4GCJ_PREFIX_DIRS="/usr /usr/local /opt"
AC_ARG_WITH(gl4gcj-prefix, 
	[  --with-gl4gcj-prefix=PREFIX Prefix where gl4gcj is install],
	[GL4GCJ_PREFIX_DIRS="$withval $GL4GCJ_PREFIX_DIRS"])

AC_SUBST(HAS_GL4GCJ)
AC_SUBST(GL4GCJ_CLASSPATH)
AC_SUBST(GL4GCJ_LDFLAGS)
AC_SUBST(GL4GCJ_LIBS)
for dir in $GL4GCJ_PREFIX_DIRS ; do
	AC_CHECK_FILE(
		["$dir/share/java/ext/gl4gcj.jar"], 
		[
			GL4GCJ_PREFIX_DIR="$dir" ;
			GL4GCJ_CLASSPATH="$dir/share/java/ext/gl4gcj.jar:$dir/share/java/ext/glut4gcj.jar";
			GL4GCJ_LDFLAGS="-L$dir/lib";
			HAS_GL4GCJ=yes;
			break;
		])
done;
if test -z "$GL4GCJ_PREFIX_DIR" ; then
	AC_CHECK_FILE(
		["../src/gl4gcj.jar"], 
		[
			GL4GCJ_CLASSPATH="../src/gl4gcj.jar:../src/glut4gcj.jar" 
			GL4GCJ_LDFLAGS="-L../src";
		],
		[AC_MSG_ERROR("gl4gcj.jar not found")])
fi
GL4GCJ_LIBS="-lglut4gcj -lgl4gcj $SYS_GL_LIBS";



dnl ##################################################
dnl set link flags
dnl ##################################################
if test "$enable_static" = yes; then
	LIBS="-static $LIBS"
fi

dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST

dnl ############################################################
dnl Set debug & optimize options in $CFLAGS and $OPT_FLAGS
dnl ############################################################
AC_ARG_ENABLE(debug,
	[  --enable-debug          include debugging code],
	[ enable_debug=$enableval ],
	[ enable_debug=no])


AC_SUBST(OPT_FLAGS)
AC_SUBST(STRIP_PROGRAM)
if test "$enable_debug" = yes; then
	OPT_FLAGS=""
	STRIP_PROGRAM="touch"
	CFLAGS="$CFLAGS -g "
else
	OPT_FLAGS="-O2"
	STRIP_PROGRAM="strip"
	CFLAGS="$CFLAGS -DNDEBUG "
fi


dnl ############################################################
dnl Search screensaver configuration files.
dnl ############################################################

AC_OUTPUT( Makefile )

