dnl
dnl NAME
dnl	configure.in - source file for configure script
dnl VERSION
dnl	$Id$
dnl CHANGELOG
dnl	$Log$
dnl

dnl ---------------------------------------------------------------------
dnl initial setup
dnl ---------------------------------------------------------------------
dnl update for autoconf-2.53

AC_INIT(coconut/cobject.h)
AC_CONFIG_AUX_DIR(./misc)
AM_INIT_AUTOMAKE(coconut,0.3.0)
AM_CONFIG_HEADER(./config.h)

VERSION_INFO=1:0:0
AC_SUBST(VERSION_INFO)

ORG_CFLAGS="$CFLAGS"
ORG_LIBS="$LIBS"

LIBS_LIST="/usr/gnome/lib /usr/gnu/lib /usr/X11R6/lib /usr/local/lib /opt/lib"
LIBS_DIR=""
for TESTLIB in $LIBS_LIST ; do
	if test -d $TESTLIB ; then
		LIBS_DIR="$LIBS_DIR -L$TESTLIB"
	fi
done
LIBS="$LIBS_DIR $LIBS"

ISODATE=`date +%Y-%m-%d`
AC_SUBST(ISODATE)

# AC_DISABLE_SHARED

dnl ---------------------------------------------------------------------
dnl check host configulation
dnl ---------------------------------------------------------------------
AC_CANONICAL_HOST

AC_CHECK_TYPE(u_int8_t, uint8_t)
AC_CHECK_TYPE(u_int16_t, uint16_t)
AC_CHECK_TYPE(u_int32_t, uint32_t)
AC_CHECK_TYPE(u_int64_t, uint64_t)
AC_CHECK_TYPE(ptrdiff_t, int )

dnl ---------------------------------------------------------------------
dnl check programs
dnl ---------------------------------------------------------------------
AC_PROG_APPLE_OBJECTIVE_C
AC_PROG_GNU_OBJECTIVE_C
AM_CONDITIONAL(HAVE_APPLE_OBJECTIVE_C, [test "X$HAVE_APPLE_OBJECTIVE_C" = "Xyes"])
AM_CONDITIONAL(HAVE_GNU_OBJECTIVE_C, [test "X$HAVE_GNU_OBJECTIVE_C" = "Xyes"])
AC_SUBST(OBJC)
AC_SUBST(OBJCFLAGS)
AC_SUBST(OBJCLIBS)
AC_SUBST(OBJCDEPMODE)

AC_PROG_INSTALL
AM_PROG_LIBTOOL
AC_SUBST(LIBTOOL_DEPS)

dnl ---------------------------------------------------------------------
dnl check library
dnl ---------------------------------------------------------------------
AC_CHECK_FUNCS(memmove memcpy memcmp bcopy bcmp)

AH_TEMPLATE(HAVE_GLIB_CONFIG, [Define when the glib package has been installed])
AM_PATH_GLIB_2_0(2.0.0)
AM_CONDITIONAL(COND_GLIB_CONFIG, [test "X${GLIB_CFLAGS}" != "X"])
if test "X$GLIB_CFLAGS" != "X" ; then
	AC_DEFINE(HAVE_GLIB_CONFIG)
fi
AC_SUBST(GLIB_CFLAGS)
AC_SUBST(GLIB_LIBS)

AH_TEMPLATE(HAVE_GTK_CONFIG, [Define when the gtk package has been installed])
AM_PATH_GTK_2_0(2.0.0)
AM_CONDITIONAL(COND_GTK_CONFIG, [test "X${GTK_CFLAGS}" != "X"])
if test "X$GTK_CFLAGS" != "X" ; then
	AC_DEFINE(HAVE_GTK_CONFIG)
fi
AC_SUBST(GTK_CFLAGS)
AC_SUBST(GTK_LIBS)

AH_TEMPLATE(HAVE_GL_PKG, [Define when the gtkglext package has been installed])
GL_PKG="gtkglext-0.0"
GL_REQUIRED_VERSION="0.3.1"
PKG_CHECK_MODULES(GL, $GL_PKG >= $GL_REQUIRED_VERSION, [echo "found"], [echo "gtkglext library was ignored"])
AM_CONDITIONAL(COND_GL_PKG, [test "X${GL_CFLAGS}" != "X"])
if test "X${GL_CFLAGS}" != "X" ; then
	GL_CFLAGS=`echo $GL_CFLAGS | sed 's/[ ][ ]*/ /g'`
	GL_LIBS=`echo $GL_LIBS | sed 's/[ ][ ]*/ /g'`
	AC_DEFINE(HAVE_GL_PKG)
fi
AC_SUBST(GL_CFLAGS)
AC_SUBST(GL_LIBS)

AH_TEMPLATE(HAVE_GNET_CONFIG, [Define when the gnet package has been installed])
AM_PATH_GNET(1.1.2)
AM_CONDITIONAL(COND_GNET_CONFIG, [test "X${GNET_CFLAGS}" != "X"])
if test "X$GNET_CFLAGS" != "X" ; then
	AC_DEFINE(HAVE_GNET_CONFIG)
fi
AC_SUBST(GNET_CFLAGS)
AC_SUBST(GNET_LIBS)

AH_TEMPLATE(HAVE_LIBPOPT, [Define when the popt package has been installed])
AC_SEARCH_AND_DEFINE_LIB(popt, poptGetContext, HAVE_LIBPOPT, POPT_LIBS, )
AM_CONDITIONAL(COND_LIBPOPT, test ["X${HAVE_LIBPOPT}" = "XYES"])
AC_SUBST(POPT_LIBS)

AH_TEMPLATE(HAVE_XML2_CONFIG, [Define when the libxml2 package has been installed])
AM_PATH_XML2
AM_CONDITIONAL(COND_LIBXML2_CONFIG, test ["X${XML_CFLAGS}" != "X"])
if test "X${XML_CFLAGS}" != "X" ; then
	AC_DEFINE(HAVE_XML2_CONFIG)
fi
AC_SUBST(XML_CFLAGS)
AC_SUBST(XML_LIBS)

dnl ---------------------------------------------------------------------
dnl check header files
dnl ---------------------------------------------------------------------
INCLUDE_DIR_LIST="/opt/sfw/include /usr/gnu/include /usr/gnome/include /usr/X11R6/include /usr/local/include /usr/include"

AC_HEADER_STDC
AC_CHECK_HEADERS(unistd.h obstack.h regex.h)
AM_CONDITIONAL(COND_OBSTACK_H, [test "X${HAVE_OBSTACK_H}" != "X"])
AM_CONDITIONAL(COND_REGEX_H, [test "X${HAVE_REGEX_H}" != "X"])

AC_SEARCH_AND_DEFINE_HEADER(popt.h, $INCLUDE_DIR_LIST, POPT_CFLAGS)
AC_SUBST(POPT_CFLAGS)

AC_CHECK_LIB(c, _obstack_begin, HAVE_OBSTACK_BEGIN="yes", HAVE_OBSTACK_BEGIN="")
AM_CONDITIONAL(COND_OBSTACK_BEGIN, [test "X$HAVE_OBSTACK_BEGIN" = "Xyes"])

dnl ---------------------------------------------------------------------
dnl finalize
dnl ---------------------------------------------------------------------
if test -z "$OBJCDEPMODE" ; then
	OBJCDEPMODE="$CCDEPMODE" ;
fi

CFLAGS="$ORG_CFLAGS"
CLIBS="$ORG_LIBS"

dnl OBJCFLAGS="$OBJCFLAGS $CFLAGS"
dnl OBJCLIBS="$OBJCLIBS $LIBS"
AC_SUBST(CFLAGS)
AC_SUBST(LIBS)

AC_CONFIG_FILES([
	Makefile 
	coconut/Makefile 
	coconut/gtk/Makefile
	coconut/gl/Makefile
	coconut/gnet/Makefile
	script/Makefile 
	script/coconut-config 
	script/test-and-compare 
	macros/Makefile 
	macros/coconut.m4 
	doc/Makefile 
	doc/coconut.texinfo 
	test/Makefile
])
AC_OUTPUT

/bin/sh ./misc/make_config_h.sh ./config.h ./coconut/dconfig.h

