m4_define([bonobo_major_version],[2])
m4_define([bonobo_minor_version],[20])
m4_define([bonobo_micro_version],[2])
m4_define([bonobo_version],[bonobo_major_version.bonobo_minor_version.bonobo_micro_version])

AC_INIT([libbonobo],[bonobo_version],[http://bugzilla.gnome.org/enter_bug.cgi?product=bonobo&component=libbonobo])

AC_CONFIG_SRCDIR([bonobo/bonobo-moniker.h])
AC_CONFIG_HEADERS([config.h])

AM_INIT_AUTOMAKE([1.9 foreign no-dist-gzip dist-bzip2])

BONOBO_MAJOR_VERSION=bonobo_major_version
BONOBO_MINOR_VERSION=bonobo_minor_version
BONOBO_MICRO_VERSION=bonobo_micro_version
AC_SUBST([BONOBO_MAJOR_VERSION])
AC_SUBST([BONOBO_MINOR_VERSION])
AC_SUBST([BONOBO_MICRO_VERSION])

AM_MAINTAINER_MODE

LIBBONOBO_LT_VERSION_INFO='-version-info 0:0:0'
AC_SUBST(LIBBONOBO_LT_VERSION_INFO)
BONOBO_ACTIVATION_LT_VERSION_INFO='-version-info 4:0:0'
AC_SUBST(BONOBO_ACTIVATION_LT_VERSION_INFO)

AC_CANONICAL_HOST
case "$host" in
  *-*-cygwin*)
    os_win32=no
    SOPREFIX=cyg
    ;;
  *-*-mingw*)
    os_win32=yes
    SOPREFIX=lib
    # Autoconf also puts stuff in configure to set PATH_SEPARATOR, but
    # if you run the configure script with a Cygwin shell, it gets set
    # to ":" while we do want the semicolon here.
    SEARCHPATHSEP=";"
    ;;
  *)
    os_win32=no
    SOPREFIX=lib
    SEARCHPATHSEP=":"
    ;;
esac

AM_CONDITIONAL(OS_WIN32, [test $os_win32 = yes])

AC_SUBST(SOPREFIX)
AC_SUBST(SEARCHPATHSEP)

if test "$os_win32" = "yes"; then
  if test x$enable_static = xyes -o x$enable_static = x; then
    AC_MSG_WARN([Disabling static library build, must build as DLL on Windows.])
    enable_static=no
  fi
  if test x$enable_shared = xno; then
    AC_MSG_WARN([Enabling shared library build, must build as DLL on Windows.])
  fi
  enable_shared=yes
fi

AC_ISC_POSIX
AC_PROG_CC

AM_PROG_LEX
if [[ "$LEX" != "flex" ]]; then
        AC_MSG_ERROR([flex is required to build bonobo-activation])
fi
AC_SUBST(LFLAGS)
AC_STDC_HEADERS
AC_PROG_INSTALL
AC_PROG_LN_S
AC_PROG_MAKE_SET
AC_LIBTOOL_WIN32_DLL
AM_PROG_LIBTOOL
AC_PROG_YACC
AC_CHECK_FUNCS(bind_textdomain_codeset)

# ****
# i18n
# ****

IT_PROG_INTLTOOL([0.35.0])

GETTEXT_PACKAGE=libbonobo-2.0
AC_SUBST(GETTEXT_PACKAGE)
AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE,"$GETTEXT_PACKAGE",[gettext package name])

AM_GLIB_GNU_GETTEXT

GNOME_COMMON_INIT
GNOME_COMPILE_WARNINGS

dnl Checks for library functions
AC_CHECK_FUNCS(usleep nanosleep sigaction setsid)

dnl Checks for headers
AC_CHECK_HEADERS(sys/wait.h syslog.h)

#
# Start of pkg-config checks
#
ORBIT_VERSION=2.11.2
GLIB_VERSION=2.8.0

PKG_CHECK_MODULES(LIBBONOBO, \
	ORBit-2.0 >= $ORBIT_VERSION \
	ORBit-CosNaming-2.0 >= $ORBIT_VERSION \
	gmodule-2.0 >= 2.0.1 \
	glib-2.0 >= $GLIB_VERSION \
	gobject-2.0 >= $GLIB_VERSION \
	gthread-2.0 >= $GLIB_VERSION)
AC_SUBST(LIBBONOBO_CFLAGS)
AC_SUBST(LIBBONOBO_LIBS)

PKG_CHECK_MODULES(SERVER, \
	gmodule-2.0 >= 2.0.1 \
	ORBit-2.0 >= 2.4.0 \
	ORBit-CosNaming-2.0 >= 2.4.0 \
	libxml-2.0 >= 2.4.20)
AC_SUBST(SERVER_LIBS)
AC_SUBST(SERVER_CFLAGS)

# orbit-idl
ORBIT_IDL="`$PKG_CONFIG --variable=orbit_idl ORBit-2.0`"
AC_SUBST(ORBIT_IDL)

# popt
AC_CHECK_LIB(popt, poptStrippedArgv, POPT_LIBS=-lpopt, AC_MSG_ERROR([You must have popt version 1.5 or greater installed.]))
AC_SUBST(POPT_LIBS)
AC_CHECK_HEADER(popt.h,,AC_MSG_ERROR([Failed to find popt.h - you may have to adjust your environment]))

PKG_CHECK_MODULES(GTHREAD, gthread-2.0 >= $GLIB_VERSION)

# checks for working GThread
# Aware: "make check" fails with --disable-threads
AC_ARG_ENABLE(threads,
	      AC_HELP_STRING([--disable-threads],
			     [Disable multithread support @<:@default=enabled@:>@]),
	      enable_threads="$enableval", enable_threads=yes)

if test x$enable_threads != xno; then
  AC_MSG_CHECKING([for working gthread-2.0 support])
  libbonobo_save_CFLAGS=$CFLAGS
  libbonobo_save_LIBS=$LIBS
  CFLAGS="$CFLAGS $GTHREAD_CFLAGS"
  LIBS="$LIBS $GTHREAD_LIBS"
  AC_TRY_RUN([#include <glib/gthread.h>
		int main (void) {
			if (!g_thread_supported()) g_thread_init(NULL);
			return NULL == g_mutex_new(); }],
	AC_MSG_RESULT(yes),[
		AC_MSG_RESULT(no)
		AC_MSG_ERROR(
			[No working gthread-2.0 support found, using --disable-threads IS DISCOURAGED])
	]
  )
  CFLAGS=$libbonobo_save_CFLAGS
  LIBS=$libbonobo_save_LIBS
  AC_DEFINE(HAVE_GTHREADS,,[whether we use gthreads])
fi

# Checks for Apple Darwin

AC_CHECK_FUNC(_NSGetEnviron, have_ns_getenviron=yes)
if test x$have_ns_getenviron = xyes; then
  AC_DEFINE(HAVE_NSGETENVIRON, 1, [whether we have _NSGetEnviron])
fi
AC_CHECK_HEADER(crt_externs.h, have_crt_externs=yes)
if test x$have_crt_externs = xyes; then
  AC_DEFINE(HAVE_CRT_EXTERNS_H, 1, [whether we have crt_externs.h])
fi

# glib-genmarshal
AC_PATH_PROG(GLIB_GENMARSHAL, glib-genmarshal)

GTK_DOC_CHECK([1.0])

AC_ARG_ENABLE(debug,
	      AC_HELP_STRING([--enable-debug],
			     [Enable debugging code @<:@default=disabled@:>@]),
	      enable_debug="$enableval", enable_debug=no)

if test x$enable_debug = xyes; then
  AC_DEFINE(G_ENABLE_DEBUG, 1, [Defined if debugging code should be compiled])
fi

AC_ARG_ENABLE(bonobo-activation-debug,
	      AC_HELP_STRING([--enable-bonobo-activation-debug],
			     [turn on debugging @<:@default=no@:>@]),
	      enable_bonobo_activation_debug=$enableval, enable_bonobo_activation_debug=no)

if test "x$enable_bonobo_activation_debug" = "xyes"; then
	AC_DEFINE(BONOBO_ACTIVATION_DEBUG, 1,
                  [whether to compile with bonobo activation debugging])
fi

AC_PATH_PROG(PERL_PATH, perl)
if test -n "$PERL_PATH"; then
	BONOBO_SLAY=bonobo-slay
	AC_PATH_PROG(PS_PATH, ps)
	AC_CACHE_CHECK([for POSIX ps], ac_cv_prog_ps_posix, [
		USER=${USER:-${LOGNAME:-`logname`}}
		if $PS_PATH -U $USER -opid,args >/dev/null 2>&1; then
			ac_cv_prog_ps_posix=yes
		else
			ac_cv_prog_ps_posix=no
		fi
	])
	if test "$ac_cv_prog_ps_posix" = yes; then
		IF_BSD_PS=#
	else
		IF_POSIX_PS=#
	fi

	case "$target_os" in
		cygwin*)
			IF_BSD_PS=#
			IF_POSIX_PS=#
			;;
		*)
			IF_CYGWIN_PS=#
			;;
	esac

fi
AC_SUBST(PERL_PATH)
AC_SUBST(BONOBO_SLAY)
AC_SUBST(PS_PATH)
AC_SUBST(IF_BSD_PS)
AC_SUBST(IF_POSIX_PS)
AC_SUBST(IF_CYGWIN_PS)

# *****************************************************************************
# *****************************************************************************

AC_CONFIG_FILES([
Makefile
libbonobo-zip
po/Makefile.in
idl/Makefile
bonobo/Makefile
bonobo/libbonobo-2.0.pc
bonobo/libbonobo-2.0-uninstalled.pc
bonobo-activation/Makefile
bonobo-activation/bonobo-activation-2.0.pc
bonobo-activation/bonobo-activation-2.0-uninstalled.pc
bonobo-activation/bonobo-activation-version.h
activation-server/Makefile
monikers/Makefile
samples/Makefile
samples/echo/Makefile
utils/Makefile
utils/bonobo-slay
tests/Makefile
tests/test-activation/Makefile
tests/models/Makefile
doc/Makefile
doc/api/Makefile
doc/api/figures/Makefile
doc/activation/Makefile
doc/activation-api/Makefile
])

AC_OUTPUT

echo ""
echo "bonobo configuration summary:"
echo "============================="
echo ""

echo "\
	Threads                  : $enable_threads
	Debug                    : $enable_debug
	Bonobo activation debug  : $enable_bonobo_activation_debug"

echo ""