AC_INIT(src/Makefile.am)

DEVHELP_VERSION=0.3

GLIB_REQUIRED=1.2.9
GTK_REQUIRED=1.2.9
GNOME_REQUIRED=1.2.8
GNOME_LIBS_REQUIRED=1.2.8
GNOME_PRINT_REQUIRED=0.29
GNOME_VFS_REQUIRED=1.0.1
GDK_PIXBUF_REQUIRED=0.11.0
LIBXML_REQUIRED=1.8.14
LIBGLADE_REQUIRED=0.16
GTKHTML_REQUIRED=0.10.0
ORBIT_REQUIRED=0.5.7
OAF_REQUIRED=0.6.5
BONOBO_REQUIRED=1.0.6
GCONF_REQUIRED=1.0.4

AC_SUBST(GLIB_REQUIRED)
AC_SUBST(GTK_REQUIRED)
AC_SUBST(GNOME_REQUIRED)
AC_SUBST(GNOME_LIBS_REQUIRED)
AC_SUBST(GNOME_PRINT_REQUIRED)
AC_SUBST(GNOME_VFS_REQUIRED)
AC_SUBST(GDK_PIXBUF_REQUIRED)
AC_SUBST(LIBXML_REQUIRED)
AC_SUBST(LIBGLADE_REQUIRED)
AC_SUBST(GTKHTML_REQUIRED)
AC_SUBST(ORBIT_REQUIRED)
AC_SUBST(OAF_REQUIRED)
AC_SUBST(BONOBO_REQUIRED)
AC_SUBST(GCONF_REQUIRED)

dnl VERSION_CANON(version)
dnl                     1

AC_DEFUN(VERSION_CANON, [`

	dnl Assumes that there are no more than 999 revisions at a level,
	dnl no more than three levels of revision.
	dnl
	dnl Any more than that, and test starts messing up the numeric
	dnl comparisons because its integers overflow, and there's no
	dnl way to do string comparisons in the shell.  Grr.
	dnl
	dnl Must come up with some way to fix this.

	echo "$1" |
	tr . '\012' |
	sed -e 's/^/000/' -e 's/^.*\(...\)/\1/' |
	tr -d '\012' |
	sed 's/$/000000000/
	     s/^\(.........\).*/\1/'
`])

dnl VERSION_INSIST(package, get-version-cmd, operator, want-version-var)
dnl                1        2                3         4

AC_DEFUN(VERSION_INSIST, [
	want_version=[$]$4

	case "$3" in
		">")	g_operator=-gt ;;
		">=")	g_operator=-ge ;;
		"<")	g_operator=-lt ;;
		"<=")	g_operator=-le ;;
		"=")	g_operator=-eq ;;
		"!=")	g_operator=-ne ;;
		*)	AC_ERROR(Unknown operator $3 in configure script) ;;
	esac

	AC_MSG_CHECKING(for $1 $3 [$want_version])

	if installed_version="`$2`"
	then
		AC_MSG_RESULT([$installed_version])
	else
		AC_ERROR($2 failed)
	fi

	if test "VERSION_CANON([$installed_version])" "$g_operator" \
		"VERSION_CANON([$want_version])"
	then
		:
		AC_SUBST($4)
	else
		AC_ERROR($1 version [$want_version] is required.)
	fi
])

AM_INIT_AUTOMAKE(devhelp, $DEVHELP_VERSION)
AM_CONFIG_HEADER(config.h)
AM_MAINTAINER_MODE

AM_PROG_XML_I18N_TOOLS

AM_SANITY_CHECK

AC_PROG_CC
AC_PROG_CPP
AC_ISC_POSIX
AC_HEADER_STDC
AC_ARG_PROGRAM
AM_PROG_LIBTOOL

#AM_ACLOCAL_INCLUDE(macros)

dnl ** GLIB **
dnl
AM_PATH_GLIB($GLIB_REQUIRED,,
AC_MSG_ERROR([
*** GLIB $GLIB_REQUIRED or better is required. The latest version of GLIB
*** is always available from ftp://ftp.gtk.org/.]))

dnl ** GTK **
dnl
AM_PATH_GTK($GTK_REQUIRED,,
AC_MSG_ERROR([
*** Gtk+ $GTK_REQUIRED or better is required. The latest version of GTK
*** is always available from ftp://ftp.gtk.org/.]))

AC_SUBST(GTK_REQUIRED)

dnl ** GNOME **
dnl
AM_PATH_GNOME($GNOME_REQUIRED,,AC_MSG_ERROR([*** GNOME $GNOME_REQUIRED or better is required.]), gtkhtml xml vfs bonobo print libglade)
AC_SUBST(GNOME_REQUIRED)

AC_PATH_PROG(GNOME_CONFIG,gnome-config,no)
if test x$GNOME_CONFIG = xno; then
  AC_MSG_ERROR(Couldn't find gnome-config. Please install the GNOME package)
fi
  
VERSION_INSIST(gnome-libs, $GNOME_CONFIG --version | awk '{print $2}', >=, GNOME_LIBS_REQUIRED)
VERSION_INSIST(xml, $GNOME_CONFIG --modversion xml | awk -F- '{print $2}', >=, LIBXML_REQUIRED)
VERSION_INSIST(gtkhtml, $GNOME_CONFIG --modversion gtkhtml | awk -F- '{print $2}', >=, GTKHTML_REQUIRED)
VERSION_INSIST(oaf, $GNOME_CONFIG --modversion oaf | awk -F- '{print $2}', >=, OAF_REQUIRED)
VERSION_INSIST(bonobo, $GNOME_CONFIG --modversion bonobo | awk -F- '{print $2}', >=, BONOBO_REQUIRED)
VERSION_INSIST(libglade, $GNOME_CONFIG --modversion libglade | awk -F- '{print $2}', >=, LIBGLADE_REQUIRED)

AC_SUBST(VFS_CFLAGS)
AC_SUBST(VFS_LIBS)
AC_SUBST(BONOBO_CFLAGS)
AC_SUBST(BONOBO_LIBS)
AC_SUBST(LIBXML_CFLAGS)
AC_SUBST(LIBXML_LIBS)
AC_SUBST(GTKHTML_CFLAGS)
AC_SUBST(GTKHTML_LIBS)
AC_SUBST(LIBGLADE_CFLAGS)
AC_SUBST(LIBGLADE_LIBS)

AM_PATH_ORBIT($ORBIT_REQUIRED,,AC_MSG_ERROR([ORBit $ORBIT_REQUIRED+ not installed or installation problem]))

IDL_FLAGS=`gnome-config --cflags idl`
AC_SUBST(IDL_FLAGS)

dnl GCONF
dnl 
AM_PATH_GCONF($GCONF_REQUIRED,,AC_MSG_ERROR([
*** gconf >= $GCONF_REQUIRED is required]),
gconf-gtk)

AC_ARG_ENABLE(install_schemas,
	[  --disable-install-schemas        Disable installation of the gconf schemas])
AM_CONDITIONAL(INSTALL_SCHEMAS, test x$enable_install_schemas != xno)

if test x$enable_install_schemas != xno; then
	AM_GCONF_SOURCE
fi
				 
# find the actual value for $prefix that we'll end up with
REAL_PREFIX=
if test "x$prefix" = "xNONE"; then
  REAL_PREFIX=$ac_default_prefix
else
  REAL_PREFIX=$prefix
fi

SYSCONFDIR_TMP="$sysconfdir"
old_prefix=$prefix
prefix=$REAL_PREFIX
EXPANDED_SYSCONFDIR=`eval echo $SYSCONFDIR_TMP`
prefix=$old_prefix
AC_SUBST(EXPANDED_SYSCONFDIR)

ALL_LINGUAS="de es fr it ja no pl ru sk sv zh_TW"
AM_GNOME_GETTEXT

AC_SUBST(CFLAGS)
AC_SUBST(CPPFLAGS)
AC_SUBST(LDFLAGS)

PREFIX=$prefix
AC_SUBST(PREFIX)

AC_OUTPUT([
Makefile
devhelp.spec
intl/Makefile
po/Makefile.in
src/Makefile
ui/Makefile
])
