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

AC_INIT(configure.in)

AM_PROG_XML_I18N_TOOLS

GCONF_REQUIRED=1.0.4
GDK_PIXBUF_REQUIRED=0.10.1
GLIB_REQUIRED=1.2.9
LIBGLADE_REQUIRED=0.13
GNOME_LIBS_REQUIRED=1.2.11
GNOME_REQUIRED=1.2.8
GNOME_VFS_REQUIRED=1.0.1
GTK_REQUIRED=1.2.9
LIBXML_REQUIRED=1.8.14
OAF_REQUIRED=0.6.5
ORBIT_REQUIRED=0.5.7
MOZILLA_REQUIRED=0.9.8
SCROLLKEEPER_REQUIRED=0.1.4

AC_SUBST(SCROLLKEEPER_REQUIRED)
AC_SUBST(GNOME_VFS_REQUIRED)
AC_SUBST(LIBXML_REQUIRED)
AC_SUBST(ORBIT_REQUIRED)
AC_SUBST(LIBGLADE_REQUIRED)
AC_SUBST(GNOME_LIBS_REQUIRED)
AC_SUBST(MOZILLA_REQUIRED)

AC_ENABLE_SHARED(yes)
AC_ENABLE_STATIC(no)

dnl detect common typos (near the top of the file so we see the error sooner)
AC_DEFUN(GALEON_TYPO,if test "${$1+set}" = set; then AC_MSG_ERROR(use --$2); fi)
GALEON_TYPO(with_mozilla_lib, with-mozilla-libs)
GALEON_TYPO(with_mozilla_include, with-mozilla-includes)

AM_INIT_AUTOMAKE(galeon, 1.0.3)
AM_CONFIG_HEADER(config.h)
AM_PROG_LIBTOOL
dnl not sure what GNOME_INTERFACE_VERSION is supposed to be, but autogen.sh
dnl checks it so I guess it must mean something ...
if test -z "$GNOME_INTERFACE_VERSION" -a -z "`echo "$ACLOCAL_FLAGS" | grep macros 2> /dev/null`" ; then
	ACLOCAL_FLAGS="-I hack-macros $ACLOCAL_FLAGS"
fi
ACLOCAL="$ACLOCAL $ACLOCAL_FLAGS"

AC_ISC_POSIX
AC_PROG_CC
AC_PROG_CXX
AM_PROG_CC_STDC
AC_HEADER_STDC

dnl ORBit
AM_PATH_ORBIT

dnl Checks for libraries.
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/.]))
AC_SUBST(GLIB_REQUIRED)

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)

_gnome_modules="gdk_pixbuf vfs libglade gnome gnomeui oaf xml glib gtk"

AC_ARG_ENABLE(applet,
	[  --enable-applet        Enable gnome panel applet])

if test "x$enable_applet" = "xyes"; then
  AC_DEFINE(ENABLE_APPLET)
  _gnome_modules="$_gnome_modules applets"
fi

dnl ******************************
dnl gnome-file-selector checking
dnl ******************************

use_gnome_file_selector=no
dnl AC_ARG_ENABLE(gnome-file-selector, [  --enable-gnome-file-selector
dnl			  Use the GNOME_FileSelector bonobo component])

dnl AC_MSG_CHECKING(if GNOME_FileSelector component is wanted)
dnl if test "x$enable_gnome_file_selector" = "xyes"; then
dnl  AC_DEFINE(ENABLE_GNOME_FILE_SELECTOR)
dnl  _gnome_modules="$_gnome_modules bonobox"
dnl fi
dnl AC_MSG_RESULT($enable_gnome_file_selector)
AM_CONDITIONAL(ENABLE_GNOME_FILE_SELECTOR, test "x$enable_gnome_file_selector" = "xyes")

dnl ******************************
dnl filters dialog checking
dnl ******************************

use_filters_dialog=no
AC_ARG_ENABLE(filters-dialog, [  --enable-filters-dialog
			  Build the experimental per-site filtering system])

AC_MSG_CHECKING(if we want the filtering system)
if test "x$enable_filters_dialog" = "xyes"; then
  AC_DEFINE(ENABLE_EXPERIMENTAL_FILTERS)
fi
AC_MSG_RESULT($enable_filters_dialog)
AM_CONDITIONAL(ENABLE_EXPERIMENTAL_FILTERS, test "x$enable_filters_dialog" = "xyes")

AC_DEFUN(GALEON_PATH_GNOME,
[dnl 
dnl Get the cflags and libraries from the gnome-config script
dnl
AC_ARG_WITH(gnome-prefix,[  --with-gnome-prefix=PFX   Prefix where GNOME is installed (optional)],
            gnome_config_prefix="$withval", gnome_config_prefix="")
AC_ARG_WITH(gnome-exec-prefix,[  --with-gnome-exec-prefix=PFX Exec prefix where GNOME is installed (optional)],
            gnome_config_exec_prefix="$withval", gnome_config_exec_prefix="")

  if test x$gnome_config_exec_prefix != x ; then
     gnome_config_args="$gnome_config_args --exec-prefix=$gnome_config_exec_prefix"
     if test x${GNOME_CONFIG+set} != xset ; then
        GNOME_CONFIG=$gnome_config_exec_prefix/bin/gnome-config
     fi
  fi
  if test x$gnome_config_prefix != x ; then
     gnome_config_args="$gnome_config_args --prefix=$gnome_config_prefix"
     if test x${GNOME_CONFIG+set} != xset ; then
        GNOME_CONFIG=$gnome_config_prefix/bin/gnome-config
     fi
  fi

  AC_PATH_PROG(GNOME_CONFIG, gnome-config, no)
  min_gnome_version=ifelse([$1], , 1.1.0, $1)

  AC_MSG_CHECKING(for GNOME - version >= $min_gnome_version)
  no_gnome=""
  if test "$GNOME_CONFIG" = "no" ; then
    no_gnome=yes
  else
    GNOME_CFLAGS="`$GNOME_CONFIG $gnome_config_args --cflags gnome`"
    GNOME_LIBS="`$GNOME_CONFIG $gnome_config_args --libs gnome`"
    GNOMEUI_CFLAGS="`$GNOME_CONFIG $gnome_config_args --cflags gnomeui`"
    GNOMEUI_LIBS="`$GNOME_CONFIG $gnome_config_args --libs gnomeui`"

    gnome_config_major_version=`$GNOME_CONFIG $gnome_config_args --version | \
           sed 's/[[^0-9]]*\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\1/'`
    gnome_config_minor_version=`$GNOME_CONFIG $gnome_config_args --version | \
           sed 's/[[^0-9]]*\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\2/'`
    gnome_config_micro_version=`$GNOME_CONFIG $gnome_config_args --version | \
           sed 's/[[^0-9]]*\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\3/'`
    needed_major_version=`echo $min_gnome_version | \
           sed 's/[[^0-9]]*\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\1/'`
    needed_minor_version=`echo $min_gnome_version | \
           sed 's/[[^0-9]]*\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\2/'`
    needed_micro_version=`echo $min_gnome_version | \
           sed 's/[[^0-9]]*\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\3/'`

    if test $gnome_config_major_version -lt $needed_major_version; then
	ifelse([$3], , :, [$3])
	no_gnome=yes
    elif test $gnome_config_major_version = $needed_major_version; then
	if test -n "$needed_minor_version" -a $gnome_config_minor_version -lt $needed_minor_version; then
		ifelse([$3], , :, [$3])
		no_gnome=yes
	elif test -n "$needed_minor_version" -a $gnome_config_minor_version = $needed_minor_version; then
		if test -n "$needed_micro_version" -a $gnome_config_micro_version -lt $needed_micro_version; then
			ifelse([$3], , :, [$3])
			no_gnome=yes
		fi
	fi
    fi
  fi
  AC_SUBST(GNOME_CFLAGS)
  AC_SUBST(GNOME_LIBS)
  AC_SUBST(GNOMEUI_CFLAGS)
  AC_SUBST(GNOMEUI_LIBS)

  if test "x$no_gnome" = x ; then
     AC_MSG_RESULT(yes)
     ifelse([$2], , :, [$2])     
  else
     AC_MSG_RESULT(no)
     if test "$GNOME_CONFIG" = "no" ; then
       echo "*** The gnome-config script installed by GNOME could not be found"
       echo "*** If GNOME was installed in PREFIX, make sure PREFIX/bin is in"
       echo "*** your path, or set the GNOME_CONFIG environment variable to the"
       echo "*** full path to gnome-config."
     else
	:
     fi
     GNOME_CFLAGS=""
     GNOME_LIBS=""
     ifelse([$3], , :, [$3])
  fi

  tmp_gnome_libdir=`$GNOME_CONFIG $gnome_config_args --libdir`
  if test -n "$4"; then
	AC_MSG_CHECKING([for additional GNOME modules])
  fi
  for module in $4 ""; do
	gnome_m4_notfound=no
	if test "$module" = zvt; then
	  ZVT_LIBS="`$GNOME_CONFIG $gnome_config_args --libs zvt`"
	  AC_SUBST(ZVT_LIBS)
	elif test "$module" = gtk; then
	  GTK_CFLAGS="`$GNOME_CONFIG $gnome_config_args --cflags gtk`"
	  GTK_LIBS="`$GNOME_CONFIG $gnome_config_args --libs gtk`"
	  AC_SUBST(GTK_CFLAGS)
	  AC_SUBST(GTK_LIBS)
	elif test "$module" = "glib"; then
	  GLIB_CFLAGS="`$GNOME_CONFIG $gnome_config_args --cflags glib`"
	  GLIB_LIBS="`$GNOME_CONFIG $gnome_config_args --libs glib`"
	  AC_SUBST(GLIB_CFLAGS)
	  AC_SUBST(GLIB_LIBS)
	elif test "$module" = "oaf"; then
	  OAF_CFLAGS="`$GNOME_CONFIG $gnome_config_args --cflags oaf`"
	  OAF_LIBS="`$GNOME_CONFIG $gnome_config_args --libs oaf`"
	  AC_SUBST(OAF_CFLAGS)
	  AC_SUBST(OAF_LIBS)
	elif test "$module" = "gnorba"; then
	  GNORBA_CFLAGS="`$GNOME_CONFIG $gnome_config_args --cflags gnorba`"
	  GNORBA_LIBS="`$GNOME_CONFIG $gnome_config_args --libs gnorba`"
	  AC_SUBST(GNORBA_CFLAGS)
	  AC_SUBST(GNORBA_LIBS)
	elif test -n "$module"; then
	  if $GNOME_CONFIG $gnome_config_args --cflags $module >/dev/null 2>&1; then
		tmp_bsnom=`echo $module | tr a-z A-Z`
		eval $tmp_bsnom'_CFLAGS'=\"`$GNOME_CONFIG $gnome_config_args --cflags $module`\"
		eval $tmp_bsnom'_LIBS'=\"`$GNOME_CONFIG $gnome_config_args --libs $module`\"
	  else
	  	AC_MSG_RESULT([*** $module library is not installed])
	  	ifelse([$3], , :, [$3])
		gnome_m4_notfound=yes
	  fi
	fi
	if test "$gnome_m4_notfound" = no; then
	  echo $ac_n " $module" 1>&6
	fi
  done
  if test -n "$4"; then
	AC_MSG_RESULT([])
  fi
])

dnl gnome, including gnome-vfs
GALEON_PATH_GNOME($GNOME_REQUIRED,,AC_MSG_ERROR([
*** GNOME $GNOME_REQUIRED or better is required.
*** gdk-pixbuf $GDK_PIXBUF_REQUIRED or better is required.
*** gnome-vfs $GNOME_VFS_REQUIRED or better is required.
*** libglade $LIBGLADE_REQUIRED or better is required.
*** libxml $LIBXML_REQUIRED or better is required.
*** oaf $OAF_REQUIRED or better is required.
*** libpanel-applet is required (unless --disable-applet is used)]),
$_gnome_modules)
AC_SUBST(GNOME_REQUIRED)

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

AM_PATH_OAF($OAF_REQUIRED)
AC_SUBST(OAF_REQUIRED)

AC_PATH_PROG(XML_CONFIG,xml-config,no)
if test x$XML_CONFIG = xno; then
  AC_MSG_ERROR(Couldn't find xml-config please install the gnome-xml package)
fi

XML_VERSION="`$XML_CONFIG --version`"
case "$XML_VERSION" in
	1.*)
		:
	;;

	*)
		AC_ERROR(Galeon needs gnome-xml version 1.x not $XML_VERSION)
	;;
esac

AM_PATH_GDK_PIXBUF($GDK_PIXBUF_REQUIRED,,
AC_MSG_ERROR([*** gdk_pixbuf $GDK_PIXBUF_REQUIRED or better is required.]))
AC_SUBST(GDK_PIXBUF_REQUIRED)

dnl Scrollkeeper
AC_PATH_PROG(SCROLLKEEPER_CONFIG, scrollkeeper-config,no)
if test x$SCROLLKEEPER_CONFIG = xno; then
  AC_MSG_RESULT(Couldn't find scrollkeeper-config. Please install the scrollkeeper package)
  DISABLE_SCROLLKEEPER=1
  AC_SUBST(DISABLE_SCROLLKEEPER)
fi

dnl Flags for libraries that galeon depends on
GALEON_DEPENDENCY_CFLAGS="`$GNOME_CONFIG --cflags $_gnome_modules`"
GALEON_DEPENDENCY_LIBS="`$GNOME_CONFIG --libs $_gnome_modules`"
GALEON_XPCOM_DEPENDENCY_LIBS="`$GNOME_CONFIG --libs gnome gnomeui`"

dnl Xinerama
AC_CHECK_HEADER(X11/extensions/Xinerama.h,
  AC_DEFINE(HAVE_XINERAMA)
  GALEON_DEPENDENCY_LIBS="$GALEON_DEPENDENCY_LIBS -lXinerama")
AC_MSG_RESULT($have_xinerama)

AC_SUBST(GALEON_DEPENDENCY_CFLAGS)
AC_SUBST(GALEON_DEPENDENCY_LIBS)
AC_SUBST(GALEON_XPCOM_DEPENDENCY_LIBS)

dnl setup OS specific variables
OS_ARCH=`uname -s`

USE_PTHREADS=
_PTHREAD_CFLAGS=""
_PTHREAD_LDFLAGS=""
case "$OS_ARCH" in
	NetBSD)
		;;
	FreeBSD)
		USE_PTHREADS=1
		_PTHREAD_CFLAGS="-pthread -D_THREAD_SAFE"
		_PTHREAD_LDFLAGS="";;
	*)
		USE_PTHREADS=1
		_PTHREAD_LDFLAGS="-lpthread";;
esac
AC_SUBST(_PTHREAD_CFLAGS)
AC_SUBST(_PTHREAD_LDFLAGS)

dnl ====================================
dnl = Setup gconf schemas installation
dnl ====================================

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

dnl ====================================
dnl = End setup gconf schemas installation
dnl ====================================

dnl $1 = regex search prefix
dnl $2 = version string to parse
dnl $3 = name of var to set result
AC_DEFUN(GALEON_PARSE_VERSION,[
	_gpv_pfx=$1
	_gpv_vstr=$2
	# Solaris sed doesn't recognize \+, so use \{1,\} instead
	[_gpv_ver=`echo $_gpv_vstr | sed -n 's/^'${_gpv_pfx}'\([0-9]\{1,\}\)\.\([0-9]\{1,\}\)\.\([0-9]\{1,\}\).*$/\1*16777216+\2*65536+\3*256/p'`]
	if test -z "$_gpv_ver" ; then
		[_gpv_ver=`echo $_gpv_vstr | sed -n 's/^'${_gpv_pfx}'\([0-9]\{1,\}\)\.\([0-9]\{1,\}\).*$/\1*16777216+\2*65536/p'`]
	fi
	if test -n ["`echo $_gpv_vstr | sed -n 's/^'${_gpv_pfx}'[0-9.]\{1,\}+.*$/true/p'`"] ; then
		_gpv_ver="${_gpv_ver}+1"
	fi
	
	if test -z "$_gpv_ver" ; then 
		_gpv_ver="0"
	fi
	$3=`awk "BEGIN{ print $_gpv_ver; exit 0 }"`

])

dnl $1 = version int to parse
AC_DEFUN(GALEON_VERSION_RESULT,[
	# Solaris awk requires exit 0 to exit correctly instead of hanging
	_gvr_ver=$1
	[_gvr_ver_str=`awk "BEGIN{ a = int($_gvr_ver / 16777216); b = int($_gvr_ver / 65536 % 256); c = int($_gvr_ver / 256 % 256); d = int($_gvr_ver % 256); plus[0]=\"\"; plus[1]=\"+\"; printf \"%d.%d.%d%s\n\", a, b, c, plus[d]; exit 0 }"`]
	AC_MSG_RESULT($_gvr_ver_str)
])

dnl Test gcc version
if test "x$GCC" = "xyes"; then
	VER=`gcc --version`
	AC_MSG_CHECKING(for gcc version)
	GALEON_PARSE_VERSION("",$VER,GCC_VERSION)
	GALEON_VERSION_RESULT($GCC_VERSION)
else
	GCC_VERSION=0
fi

AC_DEFINE_UNQUOTED(GCC_VERSION, $GCC_VERSION)

dnl Nautilus CREDITS 
dnl ====================================
dnl = Detection of mozilla libraries 
dnl ====================================

BUILD_MOZILLA_COMPONENT=
MOZILLA_COMPONENT_CFLAGS=
MOZILLA_COMPONENT_LDFLAGS=
MOZILLA_COMPONENT_LIBS=

_mozilla_lib_place=/usr/lib/mozilla
_mozilla_include_place=/usr/include/mozilla

dnl Hackery to find Ximian'd libs without extra flags -- MattA 30/6/2001
if test -f /usr/lib/mozilla/chrome/embed.jar ; then
	_mozilla_lib_place=/usr/lib/mozilla
elif test -f /usr/lib/mozilla-0.9.3/defaults/pref/all.js ; then
	_mozilla_lib_place=/usr/lib/mozilla-0.9.3
elif test -f /usr/lib/mozilla-0.9.4/defaults/pref/all.js ; then
	_mozilla_lib_place=/usr/lib/mozilla-0.9.4
fi

dnl Add a flag to override the default mozilla lib dir
AC_ARG_WITH(mozilla-libs,
	[  --with-mozilla-libs     Set mozilla 'lib' place ],
	[ _mozilla_lib_place="$withval" ])

dnl Add a flag to override the default mozilla include dir
AC_ARG_WITH(mozilla-includes,
	[  --with-mozilla-includes Set mozilla 'include' place ],
	[ _mozilla_include_place="$withval" ])

dnl Add a flag to override the default nspr include dir
dnl Also check /usr/include/nspr if not found in mozilla/nspr
AC_ARG_WITH(nspr-includes,
	[  --with-nspr-includes    Set nspr 'include' place ],
	[ _nspr_include_place="$withval" ],
	[ 
		_nspr_include_place="$_mozilla_include_place/nspr"
		if test ! -d "$_nspr_include_place"; then
			_nspr_include_place="/usr/include/nspr"
		fi
	])

dnl Add a flag to override the default mozilla home dir
AC_ARG_WITH(mozilla-home,
	[  --with-mozilla-home     Set mozilla 'home' place ],
	[ _mozilla_home_place="$withval" ],
	[ _mozilla_home_place="$_mozilla_lib_place" ])


_mozilla_nspr_libs=
_mozilla_plc_libs=
_mozilla_plds_libs=
_mozilla_xpcom_libs=
_mozilla_gtk_moz_embed_libs=
_mozilla_gtk_super_win_libs=

dnl Save flags and compiler
_save_cflags="$CFLAGS"
_save_ldflags="$LDFLAGS"
_save_cc="$CC"

dnl Hack flags to find the mozilla stuff
CFLAGS="$_save_cflags -I$_mozilla_include_place"
LDFLAGS="$_save_ldflags -L$_mozilla_lib_place"

dnl Check for nspr and friends
AC_CHECK_LIB(nspr4, PR_Init, [_mozilla_nspr_libs="-lnspr4"],[],[$_PTHREAD_LDFLAGS])
LDFLAGS="$LDFLAGS $_mozilla_nspr_libs"
AC_CHECK_LIB(plc4, PL_strcmp, [_mozilla_plc_libs="-lplc4"],[],[$_PTHREAD_LDFLAGS -lnspr4])
AC_CHECK_LIB(plds4, PL_NewHashTable, [_mozilla_plds_libs="-lplds4"],[],[$_PTHREAD_LDFLAGS -lnspr4])

_mozilla_all_nspr_flags="$_mozilla_nspr_libs $_mozilla_plc_libs $_mozilla_plds_libs"

dnl Now check for the evil c++ ones "by hand"
CC="g++"

LDFLAGS="$_save_ldflags -L$_mozilla_lib_place $_mozilla_all_nspr_flags -lxpcom"
AC_MSG_CHECKING(for xpcom)
AC_CACHE_VAL(have_xpcom,
 [AC_TRY_COMPILE([extern "C" int NS_RegistryGetFactory(void**);]
                 [],
                 [NS_RegistryGetFactory(0); return 0;],
                 [have_xpcom=true],
                 [have_xpcom=false])])
if test "$have_xpcom" = "true" ; then
  _mozilla_xpcom_libs="-lxpcom"
  AC_MSG_RESULT(yes)
else
  AC_MSG_RESULT(no)
fi  

dnl The next two are pure from evil
CC="$_save_cc"

dnl gtk superwin library
LDFLAGS="$_save_ldflags -L$_mozilla_lib_place $_mozilla_all_nspr_flags -lgtksuperwin"
AC_CHECK_LIB(gtksuperwin, gdk_superwin_get_type, [_mozilla_gtk_super_win_libs="-lgtksuperwin"],[],[$_PTHREAD_LDFLAGS])

dnl gtk moz embed library
LDFLAGS="$_save_ldflags -L$_mozilla_lib_place $_mozilla_all_nspr_flags -lgtkembedmoz $_mozilla_xpcom_libs $_mozilla_gtk_super_win_libs"
AC_CHECK_LIB(gtkembedmoz, gtk_moz_embed_get_type, [_mozilla_gtk_moz_embed_libs="-lgtkembedmoz"])

dnl Restore the flags and compiler
CFLAGS="$_save_cflags"
LDFLAGS="$_save_ldflags"
CC="$_save_cc"

dnl Now make sure all the libraries are good
AC_MSG_CHECKING(for Mozilla)

CC="g++"
dnl hacky check for the g++ headers location
AC_TRY_COMPILE([#include <g++/string>]
	[],
      	[],
       	[STRING_HEADER="\"g++/string\""
	AC_DEFINE_UNQUOTED(STRING_HEADER, $STRING_HEADER)
	])
AC_TRY_COMPILE([#include <g++-2/string>]
	[],
      	[],
       	[STRING_HEADER="\"g++-2/string\""
	AC_DEFINE_UNQUOTED(STRING_HEADER, $STRING_HEADER)
	])
AC_TRY_COMPILE([#include <g++-3/string>]
	[],
      	[],
       	[STRING_HEADER="\"g++-3/string\""
	AC_DEFINE_UNQUOTED(STRING_HEADER, $STRING_HEADER)
	])
CC="$_save_cc"


if test -n "$_mozilla_nspr_libs" -a \
	-n "$_mozilla_plc_libs" -a \
	-n "$_mozilla_plds_libs" -a \
	-n "$_mozilla_xpcom_libs" -a \
	-n "$_mozilla_gtk_super_win_libs" -a \
	-n "$_mozilla_gtk_moz_embed_libs"
then
	AC_MSG_RESULT(yes)
	found_mozilla=true

	MOZILLA_COMPONENT_CFLAGS="-I$_mozilla_include_place -I$_nspr_include_place"

	MOZILLA_COMPONENT_LDFLAGS=-L$_mozilla_lib_place

	MOZILLA_COMPONENT_LIBS="$_mozilla_gtk_moz_embed_libs $_mozilla_gtk_super_win_libs $_mozilla_xpcom_libs $_mozilla_nspr_libs $_mozilla_plc_libs $_mozilla_plds_libs $_mozilla_filelocprovider_libs"

	MOZILLA_INCLUDE_ROOT=$_mozilla_include_place

	AC_SUBST(MOZILLA_INCLUDE_ROOT)
	AC_SUBST(MOZILLA_COMPONENT_CFLAGS)
	AC_SUBST(MOZILLA_COMPONENT_LDFLAGS)
	AC_SUBST(MOZILLA_COMPONENT_LIBS)
	MOZILLA_HOME="$_mozilla_home_place"
	AC_SUBST(MOZILLA_HOME)
else
	AC_MSG_RESULT(no)
	found_mozilla=false
fi

dnl
dnl EVIL1:
dnl
dnl The mozilla milestone version checks aren't so evil anymore, or even
dnl very ugly.
dnl
dnl EVIL2:
dnl
dnl The DEBUG check is a most evil hack.  The problem im trying to solve
dnl is that we dont know whether the mozilla binaries we are using are built
dnl in debug mode or not (DEBUG).  We need to know this so that we set
dnl appropiate compile flags in the mozilla component.  Otherwise we get 
dnl undefined symbols.  Specifically, the undefined symbols are some
dnl destrcutors (nsCOMPtr_base::~nsCOMPtr_base) which are implemented only
dnl if the debug flag DEBUG is set a certain way.

if test "x$found_mozilla" = "xtrue"
then
dnl EVIL2:
	_xpcom_lib=$_mozilla_lib_place/libxpcom.so
	_symbol="nsCOMPtr_base::~nsCOMPtr_base"
	_num_symbols=`nm $_xpcom_lib 2> /dev/null | wc -l`

	if test $_num_symbols -ne 0
	then
		# Solaris nm doesn't recognize --demangle, so use -C
		nm -C $_xpcom_lib | grep $_symbol > /dev/null 2>&1

		if test $? -eq 1
		then
			MOZILLA_COMPONENT_DEBUG_FLAGS="-DDEBUG"
		fi
	fi

	AC_SUBST(MOZILLA_COMPONENT_DEBUG_FLAGS)

dnl EVIL1:

	AC_MSG_CHECKING(Mozilla version)

	if test -f $_mozilla_lib_place/defaults/pref/all.js ; then
		_user_agent=`grep useragent.misc $_mozilla_lib_place/defaults/pref/all.js`
	else
		_user_agent=`grep useragent.misc $MOZILLA_HOME/defaults/pref/all.js`
	fi

	GALEON_PARSE_VERSION(".*rv:", $_user_agent, MOZILLA_VERSION)
	GALEON_VERSION_RESULT($MOZILLA_VERSION)
	AC_DEFINE_UNQUOTED(MOZILLA_VERSION, $MOZILLA_VERSION)
	
dnl 590592 = 0x90300
	if test "$MOZILLA_VERSION" -lt 590592 ;	then
		found_mozilla=false
	fi
fi
if test "x$found_mozilla" != "xtrue" ; then
	AC_MSG_ERROR([
	*** Mozilla $MOZILLA_VERSION is required 
	*** A package for $MOZILLA_VERSION is available here:
	*** http://ftp.mozilla.org/pub/mozilla/releases/mozilla$MOZILLA_VERSION/.])

fi

AC_ARG_ENABLE(xpcom_shared_lib,
	[  --enable-xpcom-shared-lib   Build galeon xpcom modules like a shared library])
if test "x$enable_xpcom_shared_lib" = "xyes" ; then
AC_DEFINE(XPCOM_SHARED_LIB)
fi

AM_CONDITIONAL(XPCOM_SHARED_LIB, test "x$enable_xpcom_shared_lib" = "xyes")

dnl ====================================
dnl = End mozilla hacks
dnl ====================================

dnl Add the languages which your application supports here.
ALL_LINGUAS="az bg ca cs da de el es et fi fr gl hr hu it ja ko lt ms nl nn no pl pt pt_BR ro ru sk sl sv ta tr uk wa zh_CN zh_TW"
AM_GNU_GETTEXT

dnl Set PACKAGE_LOCALE_DIR in config.h.
if test "x${prefix}" = "xNONE"; then
  AC_DEFINE_UNQUOTED(PACKAGE_LOCALE_DIR, "${ac_default_prefix}/${DATADIRNAME}/locale")
else
  AC_DEFINE_UNQUOTED(PACKAGE_LOCALE_DIR, "${prefix}/${DATADIRNAME}/locale")
fi

AC_ARG_ENABLE(cpp-rtti,
	[  --enable-cpp-rtti       Enable C++ RTTI (for cvs gcc)],,
	enable_cpp_rtti=no)

if test "x$enable_cpp_rtti" = "xno"; then
  CXXFLAGS="-fno-rtti $CXXFLAGS"
fi

dnl ******************************
dnl gtk-doc
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 ** GCC FLAGS ********************************************************
dnl *********************************************************************

dnl Only use warning flags if we have gcc
if test "x$GCC" = "xyes"; then
	if test -z "`echo "$CFLAGS" | grep "\-Wall" 2> /dev/null`" ; then
		CFLAGS="$CFLAGS -Wall"
	fi
dnl -W generates way too many unused parameter warnings, ick.
dnl	if test -z "`echo "$CFLAGS" | grep "\-W\>" 2> /dev/null`" ; then
dnl		CFLAGS="$CFLAGS -W"
dnl	fi
	if test -z "`echo "$CFLAGS" | grep "\-Wmissing-declarations" 2> /dev/null`" ; then
		CFLAGS="$CFLAGS -Wmissing-declarations"
	fi
	dnl Could add some more here if we wanted to
fi

dnl Only use warning flags if we have g++
if test "x$GXX" = "xyes"; then
	if test -z "`echo "$CXXFLAGS" | grep "\-Wall" 2> /dev/null`" ; then
		CXXFLAGS="$CXXFLAGS -Wall"
	fi
dnl	if test -z "`echo "$CXXFLAGS" | grep "\-W\>" 2> /dev/null`" ; then
dnl		CXXFLAGS="$CXXFLAGS -W"
dnl	fi
	if test -z "`echo "$CXXFLAGS" | grep "\-Wmissing-declarations" 2> /dev/null`" ; then
		CXXFLAGS="$CXXFLAGS -Wmissing-declarations"
	fi
fi

AC_OUTPUT([
galeon.spec
Makefile
src/Makefile
src/mozilla/Makefile
src/npl/Makefile
src/galeon
intl/Makefile
po/Makefile.in
spinners/Makefile
spinners/pipeon/Makefile
spinners/galeon/Makefile
spinners/crashcut/Makefile
themes/Makefile
themes/GnomeLarge/Makefile
themes/Micro/Makefile
themes/Remembrance/Makefile
ui/Makefile
doc/Makefile
doc/C/Makefile
omf-install/Makefile
sounds/Makefile
galeon.schemas
galeon-config-tool
],
[chmod +x src/galeon
chmod +x galeon-config-tool])


