e dnl Initialization

AC_INIT(src/gtkhtml.c)
AM_CONFIG_HEADER(config.h)

PACKAGE=gtkhtml

GTKHTML_RELEASE=1.1
AC_DEFINE_UNQUOTED(GTKHTML_RELEASE, "${GTKHTML_RELEASE}")
AC_SUBST(GTKHTML_RELEASE)

GTKHTML_RELEASE_STRING=${PACKAGE}-${GTKHTML_RELEASE}
AC_DEFINE_UNQUOTED(GTKHTML_RELEASE_STRING, "${GTKHTML_RELEASE_STRING}")
AC_SUBST(GTKHTML_RELEASE_STRING)

dnl because intltool has an extremely broken way of getting the
dnl GETTEXT_PACKAGE name we cannot do variable substitution here
dnl so we have to hard code it instead.
dnl GETTEXT_PACKAGE=${GTKHTML_RELEASE_STRING}
GETTEXT_PACKAGE=gtkhtml-1.1
AC_SUBST(GETTEXT_PACKAGE)

GNOME_EXPLICIT_TRANSLATION_DOMAIN=${GTKHTML_RELEASE_STRING}
AC_DEFINE_UNQUOTED(GNOME_EXPLICIT_TRANSLATION_DOMAIN, "${GNOME_EXPLICIT_TRANSLATION_DOMAIN}")

AM_INIT_AUTOMAKE($PACKAGE, $GTKHTML_RELEASE.9)

EDITOR_API_VERSION=1.1
AC_DEFINE_UNQUOTED(EDITOR_API_VERSION, "${EDITOR_API_VERSION}")
AC_SUBST(EDITOR_API_VERSION)

AM_MAINTAINER_MODE
AM_ACLOCAL_INCLUDE(macros)

GNOME_INIT

AC_PROG_CC
AC_ISC_POSIX
AC_HEADER_STDC
AM_PROG_XML_I18N_TOOLS
AM_PROG_LIBTOOL

GNOME_COMPILE_WARNINGS

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

ALL_LINGUAS="az ca cs da de el es et eu fi fr gl hu it ja ko lt lv ms nl nn no pl pt pt_BR ru sk sl sv tr uk vi zh_CN zh_TW"
AM_GNOME_GETTEXT

dnl ******************************
dnl * This check function was stolen from red-carpet who stole it from
dnl * evolution or something.
dnl ******************************

AC_DEFUN(HTML_REQUIRE_LIB, [
  dispname="$1"
  dispvers="$2"
  pkgname="$3"

  AC_MSG_CHECKING(for $dispname >= $dispvers)
  cmpvers=`echo $dispvers | awk -F. '{ print $[]1 * 1000000 + $[]2 * 10000 + $[]3 * 100 + $[]4;}'`
  if gnome-config --libs $pkgname > /dev/null 2>&1; then
    pkgvers=`gnome-config --modversion $pkgname | sed -e 's/^[[^0-9]]*//'`
  else
    pkgvers=not
  fi

  AC_MSG_RESULT($pkgvers found)

  pkgvers=`echo $pkgvers | awk -F. '{ print $[]1 * 1000000 + $[]2 * 10000 + $[]3 * 100 + $[]4;}'`

  if test "$pkgvers" -lt $cmpvers; then
    AC_MSG_ERROR([
""
"You need $dispname $dispvers or later to build $PACKAGE."])
  fi
])

dnl ******************************
dnl Gnome App Lib checking
dnl ******************************

HTML_REQUIRE_LIB(Gnome App libraries (GAL), 0.20.1.99, gal)

dnl ******************************
dnl GnomePrint checking
dnl ******************************

HTML_REQUIRE_LIB(Gnome print libraries, 0.29.0, print)

dnl ******************************
dnl gdk-pixbuf checks.
dnl *****************************

HTML_REQUIRE_LIB(GdkPixbuf, 0.8.0, gdk_pixbuf)

dnl ******************************
dnl --enable XIM switch
dnl ******************************

AC_ARG_ENABLE(xim, [  --enable-xim            support XIM [default=yes]],, enable_xim="yes")

if test "x$enable_xim" = "xyes"; then
	BACKUP_LDFLAGS=$LDFLAGS
	LDFLAGS="$LDFLAGS `gtk-config --libs`"
	AC_CHECK_FUNC(gdk_im_begin, AC_DEFINE(GTK_HTML_USE_XIM), AC_MSG_RESULT(Gtk lacks XIM support => GtkHTML will be build without XIM support))
	LDFLAGS=$BACKUP_LDFLAGS
fi

dnl *****************************
dnl GNU regex checking
dnl *****************************

AC_CHECK_FUNC(re_compile_pattern, AC_DEFINE(HAVE_GNU_REGEX))

dnl *****************************
dnl soup checks (for testgtkhtml)
dnl *****************************

have_soup=false
AC_MSG_CHECKING(for soup >= 0.7)
if gnome-config --libs soup > /dev/null 2>&1; then
	vers=`gnome-config --modversion soup | sed -e "s/soup-//" | \
		awk 'BEGIN { FS = "."; } { printf "%d", $1 * 1000 + $2;}'`

	if test "$vers" -ge 7; then
		AC_MSG_RESULT([found])

		SOUP_CFLAGS="`gnome-config --cflags soup`"
		SOUP_LIBS="`gnome-config --libs soup`"

		have_soup=true
	else
		AC_MSG_RESULT(not found)
	fi
else
	AC_MSG_RESULT(not found)
fi

if $have_soup ; then
	AC_DEFINE(HAVE_SOUP)
else
	AC_MSG_WARN([\`testgtkhtml' will not be built.])
fi

AC_SUBST(SOUP_CFLAGS)
AC_SUBST(SOUP_LIBS)
AM_CONDITIONAL(SOUP, test x$have_soup = xtrue)

dnl libghttp checks.
have_ghttp=false
AC_MSG_CHECKING(for libghttp >= 1.0)
if gnome-config --libs ghttp > /dev/null 2>&1; then
	vers=`gnome-config --modversion ghttp | sed -e "s/ghttp-//" | \
		awk 'BEGIN { FS = "."; } { printf "%d", $1 * 1000 + $2;}'`

	if test "$vers" -ge 1000; then
		AC_MSG_RESULT([found])

		GHTTP_CFLAGS="`gnome-config --cflags ghttp`"
		GHTTP_LIBS="`gnome-config --libs ghttp`"

		have_ghttp=true
	else
		AC_MSG_RESULT(not found)
	fi
else
	AC_MSG_RESULT(not found)
fi

if $have_ghttp ; then
	AC_DEFINE(HAVE_GHTTP)
else
	AC_MSG_WARN([\`ebrowser' will not be built.])
fi

AC_SUBST(GHTTP_CFLAGS)
AC_SUBST(GHTTP_LIBS)
AM_CONDITIONAL(GHTTP, test x$have_ghttp = xtrue)

dnl Bonobo checks.

try_bonobo=true
bonobo=
bonobo_msg=no
have_bonobo=false

AC_ARG_WITH(bonobo,
	[--{with,without}-bonobo   Compile with Bonobo support or without it],
	if test x$withval = xno; then
		try_bonobo=false
	fi
	if test x$withval = xyes; then
		try_bonobo=true
	fi
)

if $try_bonobo; then
	AC_MSG_CHECKING(for Bonobo >= 0.32)

	if gnome-config --libs bonobox > /dev/null 2>&1; then
		vers=`gnome-config --modversion bonobo | sed -e "s/bonobo-//" | \
			awk 'BEGIN { FS = "."; } { printf "%d", $1 * 1000 + $2;}'`
		if test "$vers" -ge 32; then
			bonobo_ok=true
		else
			bonobo_ok=false
		fi
	else
		bonobo_ok=false
	fi
	
	if $bonobo_ok; then
		AC_MSG_RESULT([found ("$vers")])
		AC_DEFINE(ENABLE_BONOBO)
		have_bonobo=true
		if gnome-config --libs bonobox > /dev/null 2>&1; then
			bonobo=bonobox
		else
			bonobo=bonobo
		fi
		bonobo_msg=yes
	else
		AC_MSG_RESULT([not found
***************
*** WARNING ***  gtkhtml will be build without HTML Editor component
***************  which is required for Evolution])
	fi
fi

AM_CONDITIONAL(BONOBO, $have_bonobo)

dnl Check if Bonobo is OAFized
AC_MSG_CHECKING(if Bonobo uses OAF)
if ( gnome-config --libs bonobo | grep oaf ) > /dev/null 2>&1 ; then
	using_oaf="yes"
	AC_DEFINE(USING_OAF)
else
	using_oaf="no"
fi

AC_MSG_RESULT("$using_oaf")

AM_CONDITIONAL(USING_OAF, test "x$using_oaf" = "xyes")

dnl ******************
dnl gconf checks
dnl ******************

try_gconf=true
have_gconf=false

AC_ARG_WITH(gconf,
	[--{with,without}-gconf    Compile with Gconf support or without it],
	if test x$withval = xno; then
		try_gconf=false
	fi
	if test x$withval = xyes; then
		try_gconf=true
	fi
)

GCONF_CFLAGS=""
GCONF_LIBS=""
if $try_gconf; then
	AC_MSG_CHECKING([for gconf])
	if gconf-config --version > /dev/null 2>&1; then
		gconf_ver=`gconf-config --version`
		vers=`echo ${gconf_ver} | awk 'BEGIN { FS = "."; } { print $1 * 1000000 + $2 * 1000 + $3;}'`
		if test "$vers" -ge 1000007; then
			have_gconf=true
			GCONF_CFLAGS="`gconf-config --cflags gconf-gtk` -DGTKHTML_HAVE_GCONF"
			GCONF_LIBS="`gconf-config --libs gconf-gtk`"
			AC_MSG_RESULT([found ($gconf_ver)])
		else
		        AC_MSG_ERROR(You need at least GConf 1.0.7 for this version of GtkHTML)
		fi
	else
		have_gconf=false
		AC_MSG_RESULT([not found, gtkhtml will be built without gconf support])
	fi
fi
AC_SUBST(GCONF_CFLAGS)
AC_SUBST(GCONF_LIBS)

dnl **********************************
dnl Setup extra GNOME library flags.
dnl **********************************

EXTRA_GNOME_LIBS=`gnome-config --libs gnomeui gdk_pixbuf print gal $bonobo libglade oaf`
EXTRA_GNOME_CFLAGS=`gnome-config --cflags gnomeui gdk_pixbuf print gal $bonobo libglade oaf`

AC_SUBST(EXTRA_GNOME_LIBS)
AC_SUBST(EXTRA_GNOME_CFLAGS)

dnl **********************************
dnl gtkhtmlConf.sh stuff.
dnl **********************************

GTKHTML_LIBDIR="-L${libdir}"
GTKHTML_INCLUDEDIR="-I${includedir}/$GTKHTML_RELEASE_STRING"
GTKHTML_INCLUDEDIR="$GTKHTML_INCLUDEDIR `$GNOME_CONFIG --cflags gdk_pixbuf print gal` $GCONF_CFLAGS"
GTKHTML_LIBS="`$GNOME_CONFIG --libs gdk_pixbuf print gal` $GCONF_LIBS"
GTKHTML_DATADIR="${datadir}/${GTKHTML_RELEASE_STRING}/"

AC_SUBST(GTKHTML_LIBDIR)
AC_SUBST(GTKHTML_INCLUDEDIR)
AC_SUBST(GTKHTML_LIBS)
AC_SUBST(GTKHTML_DATADIR)

dnl ****************************
dnl gtk-doc stuff
dnl ****************************

AC_CHECK_PROG(GTKDOC, gtkdoc-mkdb, true, false)
AM_CONDITIONAL(HAVE_GTK_DOC, $GTKDOC)
AC_SUBST(HAVE_GTK_DOC)

dnl Let people disable the gtk-doc stuff.
AC_ARG_ENABLE(gtk-doc, [  --enable-gtk-doc  Use gtk-doc to build documentation [default=auto]], enable_gtk_doc="$enableval", enable_gtk_doc=auto)

if test x$enable_gtk_doc = xauto ; then
  if test x$GTKDOC = xtrue ; then
    enable_gtk_doc=yes
  else
    enable_gtk_doc=no
  fi
fi

dnl NOTE: We need to use a separate automake conditional for this
dnl       to make this work with the tarballs.
AM_CONDITIONAL(ENABLE_GTK_DOC, test x$enable_gtk_doc = xyes)

dnl **********************************
dnl Library version information.
dnl **********************************
 
dnl Increment the following if the interface has additions, changes,
dnl removals.
GTKHTML_CURRENT=3

dnl Increment any time the source changes; set to 0 if you
dnl increment CURRENT.
GTKHTML_REVISION=4

dnl Increment if any interfaces have been added; set to 0
dnl if any interfaces have been removed. removal has 
dnl precedence over adding, so set to 0 if both happened.
GTKHTML_AGE=0

AC_SUBST(GTKHTML_CURRENT)
AC_SUBST(GTKHTML_REVISION)
AC_SUBST(GTKHTML_AGE)

dnl ******************************
dnl shlib factory
dnl ******************************

AC_ARG_ENABLE(shlib-factory, [  --enable-shlib-factory  build editor factory as shared library [default=no]],shlib_factory="$enableval", shlib_factory="no")

if test "x$shlib_factory" = "xyes"; then
	GNOME_GTKHTML_EDITOR_SHLIB=1
	GNOME_GTKHTML_EDITOR_TYPE="shlib"
	GNOME_GTKHTML_EDITOR_LOCATION="libgnome-gtkhtml-editor-${EDITOR_API_VERSION}.so"
	AC_DEFINE(GNOME_GTKHTML_EDITOR_SHLIB)
else
	GNOME_GTKHTML_EDITOR_LOCATION="gnome-gtkhtml-editor-${EDITOR_API_VERSION}"
	GNOME_GTKHTML_EDITOR_TYPE="exe"
fi

AC_SUBST(GNOME_GTKHTML_EDITOR_TYPE)
AC_SUBST(GNOME_GTKHTML_EDITOR_LOCATION)
AM_CONDITIONAL(EDITOR_SHLIB, test x$shlib_factory = xyes)

dnl **************
dnl Done.
dnl **************

AC_OUTPUT([ po/Makefile.in m4/Makefile  po/Makefile.in 
Makefile
gtkhtml.spec
gtkhtml-1.1.pc
po/Makefile.in
macros/Makefile
src/Makefile
doc/Makefile
art/Makefile
capplet/Makefile
components/Makefile
components/html-editor/Makefile
components/html-editor/GNOME_GtkHTML_Editor.oaf.in
components/ebrowser/Makefile
components/http-storage-module/Makefile
])

echo -n "

Configuration:

	GConf support:			"
if test x${have_gconf} = xtrue; then echo "yes"; else echo "no"; fi
echo "	XIM support:			$enable_xim
	Editor component type:		${GNOME_GTKHTML_EDITOR_TYPE}
"

