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

AC_INIT(configure.in)
AM_INIT_AUTOMAKE(rcalc, 0.3.99)
AM_MAINTAINER_MODE
AM_CONFIG_HEADER(config.h)

AC_ISC_POSIX
AC_PROG_CC
AM_PROG_CC_STDC
AC_HEADER_STDC
AC_PROG_RANLIB

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

dnl Checks for library functions.
AC_TYPE_SIGNAL
AC_FUNC_VPRINTF

dnl
dnl READLINE_HOOK (script-if-readline-found, failflag)
dnl
dnl If failflag is "failure", script aborts due to lack of GNU readline
dnl 
dnl Check for availability of the GNU readline library

AC_DEFUN([READLINE_HOOK],[
	TERMCAP_LIB="-ltermcap"
	AC_CHECK_LIB(readline,readline, [READLINE_LIB="-lreadline"],
		AC_MSG_ERROR(Readline library not found),
		$TERMCAP_LIB )
	READLINE_LIBS="$TERMCAP_LIB $READLINE_LIB"
	AC_SUBST(READLINE_LIBS)
])

AC_DEFUN([READLINE_CHECK], [
	READLINE_HOOK([],failure)
])

READLINE_CHECK
GNOME_COMPILE_WARNINGS

ADDITIONAL_LIBS=
pkg_modules=

AC_ARG_ENABLE([compiled-functions],
              [  --enable-compiled-functions      compile user-defined functions (default: disabled)],
              [try_functions="$enableval"],
	      [try_functions="no"])

dnl echo "try_functions $try_functions"

if test x$try_functions = xyes || test x$try_functions = xauto; then
   dnl echo "trying functions"
	functions_msg=yes
   pkg_modules="gmodule-2.0"
	AC_DEFINE(USE_COMPILED_FUNCTIONS,1,[Compile user-defined functions]) 
else
   dnl echo "not trying functions"
   functions_msg=no
fi

AC_ARG_ENABLE([gnome-support],
              [  --disable-gnome-support build only the text interface (default: use gnome)],
              [gnome_support="$enableval"],
	      [gnome_support="yes"])

dnl echo "gnome_support $gnome_support"

if test x$gnome_support = xyes; then
	pkg_modules="$pkg_modules libgnomeui-2.0 libzvt-2.0"
	conditional_gnome="true"
else
	echo "Don't use GNOME support."
	AC_DEFINE(RCALC_TEXT_ONLY,1,[Don't build GNOME-based UI])
	pkg_modules="$pkg_modules glib-2.0"
	conditional_gnome="false"
fi

AM_CONDITIONAL(USE_GNOME2,  test x$conditional_gnome = xtrue)

PKG_CHECK_MODULES(PACKAGE, [$pkg_modules])
AC_SUBST(PACKAGE_CFLAGS)
AC_SUBST(PACKAGE_LIBS)
AC_SUBST(ADDITIONAL_LIBS)
	
GETTEXT_PACKAGE=rcalc
AC_SUBST(GETTEXT_PACKAGE)
AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE,"$GETTEXT_PACKAGE")

dnl Add the languages which your application supports here.
ALL_LINGUAS="en_GB de fr es it af"
AM_GLIB_GNU_GETTEXT

AC_OUTPUT([
Makefile
src/Makefile
src/engine/Makefile
src/gnome/Makefile
src/console/Makefile
po/Makefile.in
doc/Makefile
doc/C/Makefile
doc/en_GB/Makefile
doc/de/Makefile
doc/fr/Makefile
doc/es/Makefile
doc/it/Makefile
doc/af/Makefile
rpm/Makefile
],
[sed -e "/POTFILES =/r po/POTFILES" po/Makefile.in > po/Makefile])

