# copyright (c) 2000 Sun Microsystems, Inc.

dnl Process this file with autoconf to produce a configure script.
AC_INIT(libs/error.c)

dnl ==========================================================================
dnl
dnl If you add a version number here, you *must* add an AC_SUBST line for
dnl it too, or it will never make it into the spec file!
dnl
dnl ==========================================================================

dnl ==========================================================================

dnl Checks for programs.
AC_PROG_AWK
AC_PROG_CC
AC_PROG_CPP
AC_PROG_INSTALL
AC_PROG_LN_S
AC_PROG_MAKE_SET

dnl Checks for libraries.

dnl Checks for header files.
AC_HEADER_STDC

AC_ISC_POSIX

AC_CANONICAL_SYSTEM

AM_CONFIG_HEADER(config.h)
AM_INIT_AUTOMAKE(scrollkeeper,0.3.6)
AM_PROG_LIBTOOL

ALL_LINGUAS="az ca da de el es fr hu it ja ko nb nl no pl pt_BR ru sk sl sv tr uk zh_TW"

dnl ====================================
dnl = Begin checks for typedefs, structures, and compiler characteristics.
dnl ====================================
AC_C_CONST
AC_C_INLINE
AC_TYPE_SIZE_T
dnl ====================================
dnl = End checks for typedefs, structures, and compiler characteristics.
dnl ====================================

dnl ====================================
dnl = Begin checks for library functions.
dnl ====================================
AC_FUNC_ALLOCA
AC_FUNC_MMAP
AC_CHECK_FUNCS(getcwd getwd putenv strdup)
dnl ====================================
dnl = End checks for library functions.
dnl ====================================

dnl ====================================
dnl = Begin tests for intltool
dnl ====================================
AC_PATH_PROG(INTLTOOL,intltool-extract,no)
if test x$INTLTOOL = xno; then
  AC_MSG_ERROR(Couldn't find intltool-extract. Please install the intltool package: ftp://ftp.gnome.org/pub/GNOME/stable/sources/intltool/)
fi
AC_MSG_CHECKING(intltool version)
intltool_version=`$INTLTOOL --version | awk 'NR==1{print $3;}'`
AC_MSG_RESULT($intltool_version)
intltool_version=`echo $intltool_version | awk -F. '{print $1 * 10000 + $2 * 100 + $3;}'`
if test 0$intltool_version -lt 804; then
        AC_MSG_ERROR(intltool 0.8.4 or later required)
fi
INTLTOOL_REQUIRED=0.8.4
AC_SUBST(INTLTOOL_REQUIRED)

AC_PROG_INTLTOOL
dnl ====================================
dnl = End tests for intltool
dnl ====================================

dnl ====================================
dnl = Begin tests for libxml2
dnl ====================================
AC_PATH_PROG(XML_CONFIG,xml2-config,no)
if test x$XML_CONFIG = xno; then
  AC_MSG_ERROR(Couldn't find xml2-config please install the libxml2 and libxml2-devel packages)
fi
AC_MSG_CHECKING(libxml2 version)
libxml2_version=`$XML_CONFIG --version | awk '{print $1;}'`
AC_MSG_RESULT($libxml2_version)
libxml2_version=`echo $libxml2_version | awk -F. '{print $1 * 10000 + $2 * 100 + $3;}'`
if test 0$libxml2_version -lt 20309; then
        AC_MSG_ERROR(libxml2 2.3.9 or later required)
fi
XML_LIBS=`$XML_CONFIG --libs`
XML_CFLAGS=`$XML_CONFIG --cflags`
AC_SUBST(XML_LIBS)
AC_SUBST(XML_CFLAGS)
LIBXML2_REQUIRED=2.3.9
AC_SUBST(LIBXML2_REQUIRED)
dnl ====================================
dnl = End tests for libxml2
dnl ====================================

dnl ====================================
dnl = Begin tests for libxslt
dnl ====================================
AC_PATH_PROG(XSLT_CONFIG,xslt-config,no)
if test x$XSLT_CONFIG = xno; then
  AC_MSG_ERROR(Couldn't find xslt-config please install the libxslt package)
fi
XSLT_LIBS=`$XSLT_CONFIG --libs`
XSLT_CFLAGS=`$XSLT_CONFIG --cflags`
AC_SUBST(XSLT_LIBS)
AC_SUBST(XSLT_CFLAGS)
dnl ====================================
dnl = End tests for libxslt
dnl ====================================

dnl ====================================
dnl = Begin tests for docbook-dtd412-xml
dnl ====================================
case "$host_os" in
   solaris*)
	HOST_TYPE=-DSOLARIS
	AC_SUBST(HOST_TYPE)
        ;;
   *)
	AC_MSG_CHECKING(for docbook-dtd412-xml)
	if xmlcatalog /etc/xml/catalog "-//OASIS//DTD DocBook XML V4.1.2//EN" | grep "No entry" >/dev/null ; then
		echo "* ERROR * "
		echo " "
		echo "Couldn't find the DocBook XML V4.1.2 DTD.  Please make sure that you have the docbook-dtd412-xml package installed. If it is installed, the package probably did not register the DTD in the catalog properly. Consult http://scrollkeeper.sourceforge.net/docbook.shtml for more information."
		echo " "
		AC_MSG_ERROR(DocBook XML V4.1.2 DTD not present in /etc/xml/catalog. Make sure docbook-dtd412-xml is installed and registers DTD in catalog.)
	fi
	AC_MSG_RESULT(found)
	;;
esac
dnl ====================================
dnl = End tests for docbook-dtd412-xml
dnl ====================================

AM_GNU_GETTEXT

dnl Turn on more warnings and make them errors for cvs version
dnl to force contributors to pay attention to warnings.
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="$CFLAGS \
        -Wall \
        -Wchar-subscripts -Wmissing-declarations -Wmissing-prototypes \
        -Wnested-externs -Wpointer-arith"

        for option in -Wsign-promo -Wno-sign-compare; do
                SAVE_CFLAGS="$CFLAGS"
                CFLAGS="$CFLAGS $VFS_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
                  VFS_CFLAGS="$VFS_CFLAGS $option"
                fi
                AC_MSG_RESULT($has_option)
                unset has_option
                unset SAVE_CFLAGS
        done
        unset option
fi

AC_MSG_RESULT(setting up partial database directory ...)
case "$host_os" in
   freebsd*)
	SCROLLKEEPER_PARTIAL_DB_DIR=db/scrollkeeper
	;;
   *)
        SCROLLKEEPER_PARTIAL_DB_DIR=lib/scrollkeeper
	;;
esac
AC_SUBST(SCROLLKEEPER_PARTIAL_DB_DIR)
AC_MSG_RESULT(partial database directory is $SCROLLKEEPER_PARTIAL_DB_DIR)

AC_OUTPUT(
libs/Makefile
libs/scrollkeeper.h
libuuid/Makefile
cl/Makefile
cl/src/Makefile
buildtools/Makefile
cl/templates/Makefile
extract/Makefile
extract/src/Makefile
extract/stylesheets/Makefile
scripts/scrollkeeper-config
scripts/scrollkeeper-get-content-list
scripts/scrollkeeper-get-extended-content-list
scripts/scrollkeeper-get-toc-from-id
scripts/scrollkeeper-get-toc-from-docpath
scripts/scrollkeeper-get-index-from-docpath
scripts/scrollkeeper-rebuilddb
scripts/Makefile
man/Makefile
man/man1/Makefile
man/man5/Makefile
man/man7/Makefile
man/man8/Makefile
config/Makefile
intl/Makefile
po/Makefile.in
doc/Makefile
doc/writing_scrollkeeper_omf_files/Makefile
doc/writing_scrollkeeper_omf_files/C/Makefile
Makefile
scrollkeeper.spec)

echo "

Scrollkeeper database directory: $localstatedir/$SCROLLKEEPER_PARTIAL_DB_DIR

"
