dnl Process this file with autoconf to produce a configure script.
AC_INIT(idl/oaf.idl)

OAF_MAJOR_VERSION=0
OAF_MINOR_VERSION=6
OAF_MICRO_VERSION=10
OAF_VERSION="$OAF_MAJOR_VERSION.$OAF_MINOR_VERSION.$OAF_MICRO_VERSION"
AM_INIT_AUTOMAKE(oaf, $OAF_VERSION)
AC_SUBST(OAF_MAJOR_VERSION)
AC_SUBST(OAF_MINOR_VERSION)
AC_SUBST(OAF_MICRO_VERSION)

dnl Specify a header configuration file
AM_CONFIG_HEADER(config.h)

dnl Initialize maintainer mode
AM_MAINTAINER_MODE

dnl Initialize libtool
AM_DISABLE_STATIC
AM_PROG_LIBTOOL

AM_PROG_XML_I18N_TOOLS


dnl Build time sanity check
AM_SANITY_CHECK

dnl Checks for programs.
AC_PROG_CC
AM_PROG_LEX
AC_PROG_YACC
AC_PROG_INSTALL
AC_PROG_LN_S
AC_PROG_MAKE_SET
AC_ISC_POSIX

dnl internationalization support
ALL_LINGUAS="az bg da de el es eu fi fr ga gl hu it ja ko nl nn no pl pt pt_BR ro ru sk sl sv ta tr uk zh_CN zh_TW"
AM_GNU_OAF_GETTEXT


dnl Checks for libraries.
AM_PATH_GLIB(1.2.0,,
AC_MSG_ERROR([
*** GLIB 1.2.0 or better is required. The latest version of GLIB
*** is always available from ftp://ftp.gtk.org/.]), gmodule)

AM_PATH_ORBIT(0.5.1,,AC_MSG_ERROR([ORBit not installed or installation problem]))
AC_DEFINE(HAVE_ORB_ORBIT_H)

dnl Check for ORBit > 0.5.1 (CORBA_Object_create_request is prototyped
dnl in orb/dii.h in the "new" ORBit, but not ORBit 0.5.1, so #defining
dnl it to nothing results in a compile error iff we have the new ORBit.)
saved_CFLAGS="$CFLAGS"
saved_LDFLAGS="$LDFLAGS"
CFLAGS="$CFLAGS $ORBIT_CFLAGS"
LDFLAGS="$LDFLAGS $ORBIT_LDFLAGS"
AC_TRY_COMPILE([
#define CORBA_Object_create_request
#include <orb/dii.h>
],[], AC_MSG_ERROR([You need a newer version of ORBit. See the README.]), :)
CFLAGS="$saved_CFLAGS"
LDFLAGS="$saved_LDFLAGS"

APP_LIBS=""
AC_SUBST(APP_LIBS)

dnl	
dnl Locate the xml library
dnl
AC_CHECK_PROG(XML_CONFIG, xml-config, xml-config)
if test "$XML_CONFIG" != "" 
then
  XML_LIBS="`$XML_CONFIG --libs`"
  XML_CFLAGS="`$XML_CONFIG --cflags`"
  XML_VERSION="`$XML_CONFIG --version`"
else
  AC_MSG_ERROR(Can't find gnome-xml library.)
fi

case $XML_VERSION in
1.*) ;;
2.*) AC_MSG_ERROR(libxml 2.x detected; OAF requires libxml 1.x) ;;
*) AC_MSG_ERROR(unrecognized version of libxml detected; OAF requires libxml 1.x) ;;
esac;

AC_SUBST(XML_LIBS)
AC_SUBST(XML_CFLAGS)

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 = end gtk-doc stuff
dnl ======================


AC_CHECK_LIB(popt, poptDupArgv,,
AC_MSG_ERROR([You must have popt 1.5 or newer to compile oaf.]))

dnl Checks for header files.
AC_HEADER_DIRENT
AC_HEADER_STDC
AC_CHECK_HEADERS(fcntl.h unistd.h alloca.h malloc.h)

dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST

dnl Checks for library functions
AC_CHECK_FUNCS(select strcspn strdup strtol snprintf usleep nanosleep unsetenv)

dnl declare --enable-* args

oaf_debug_default=no;

AC_ARG_ENABLE(oaf-debug, [  --enable-oaf-debug=[no/yes] turn on debugging [default=$oaf_debug_default]],enable_oaf_debug=$enableval,enable_oaf_debug=$debug_default)

if test "x$enable_oaf_debug" = "xyes"; then
	AC_DEFINE(OAF_DEBUG)
fi

dnl turn warnings into errors to enforce clean code



AC_ARG_ENABLE(more-warnings,
[  --enable-more-warnings  Maximum compiler warnings],
set_more_warnings="$enableval",[
if test -f $srcdir/CVSVERSION; then
	set_more_warnings=yes
else
	set_more_warnings=no
fi
])

if test "$GCC" = "yes" -a "$set_more_warnings" != "no"; then
	echo "enable compile warnings = $set_more_warnings"
	CFLAGS="\
	-Wall \
	-Wchar-subscripts -Wmissing-declarations -Wmissing-prototypes \
	-Wnested-externs -Wpointer-arith \
	-Werror \
	$CFLAGS"

	for option in -Wsign-promo -Wno-sign-compare; do
		SAVE_CFLAGS="$CFLAGS"
		CFLAGS="$CFLAGS $option"
		AC_MSG_CHECKING([whether gcc understands $option])
		AC_TRY_COMPILE([], [],
			has_option=yes,
			has_option=no,)
		CFLAGS="$SAVE_CFLAGS"
		if test $has_option = yes; then
		  CFLAGS="$CFLAGS $option"
		fi
		AC_MSG_RESULT($has_option)
		unset has_option
		unset SAVE_CFLAGS
	done
	unset option
fi

AC_PATH_PROG(PERL_PATH, perl)
if test -n "$PERL_PATH"; then
	OAF_SLAY=oaf-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
fi
AC_SUBST(PERL_PATH)
AC_SUBST(OAF_SLAY)
AC_SUBST(PS_PATH)
AC_SUBST(IF_BSD_PS)
AC_SUBST(IF_POSIX_PS)

AC_OUTPUT([
Makefile
oaf.spec
idl/Makefile
docs/Makefile
api-docs/Makefile
liboaf/Makefile
liboaf/liboaf-version.h
oafd/Makefile
test/Makefile
test/oaf-slay
utils/Makefile
intl/Makefile
po/Makefile.in
oaf-config
oafConf.sh
oafd/OAF_naming-service.oaf
],
[sed -e "/POTFILES =/r po/POTFILES" po/Makefile.in > po/Makefile])
