# 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.14)
AM_PROG_LIBTOOL
AC_PROG_INTLTOOL([0.28])

ALL_LINGUAS="am az be ca cs da de el es fr hu it ja kn ko nl no pl pt_BR ro ru sk sl sr sr@Latn sv tr uk vi zh_CN zh_TW"

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

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

dnl ====================================
dnl = Check for paths to search for OMF files.
dnl ====================================
AC_MSG_CHECKING(for --with-omfdirs)
AC_ARG_WITH(omfdirs, dnl
[  --with-omfdirs          colon-seperated paths to search for OMF files])

if test -z "$with_omfdirs"
then
        with_omfdirs="/usr/share/omf:/usr/local/share/omf:/opt/gnome/share/omf:/opt/gnome-2.0/share/omf:/opt/kde/omf"
fi
OMFDIRS=$with_omfdirs
AC_MSG_RESULT($OMFDIRS)
AC_SUBST(OMFDIRS)
dnl ====================================
dnl = End check for paths to search for OMF files.
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 20419; then
        AC_MSG_ERROR(libxml2 2.4.19 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.4.19
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 Some systems have the XML catalog in different locations from others
dnl (particularly those acting as servers for huge networked setups). Usually,
dnl /etc/xml/catalog is correct (and depending on $prefix is always wrong), but
dnl we allow customisation if it is wanted.
dnl

default_xml_catalog="/etc/xml/catalog"
AC_MSG_CHECKING(which XML catalog to use)
AC_ARG_WITH(xml-catalog,
   [AC_HELP_STRING([--with-xml-catalog], [The location of the system XML catalog])],
   [xml_catalog="$withval"],
   [xml_catalog="auto"])

   case "$xml_catalog" in
   yes | no)
      AC_MSG_ERROR([Specifying --with-xml-catalog requires a subdirectory as an argument.])
      ;;
   auto)
      XML_CATALOG=$default_xml_catalog
      ;;
   *)
      XML_CATALOG=$xml_catalog
   esac
AC_SUBST(XML_CATALOG)
AC_MSG_RESULT($XML_CATALOG)

dnl ====================================
dnl = Begin tests for DocBook XML DTD
dnl ====================================
case "$host_os" in
   solaris*)
	HOST_TYPE=-DSOLARIS
	AC_SUBST(HOST_TYPE)
        ;;
   *)
	AC_MSG_CHECKING(for DocBook XML DTD)
	db_found=
	for vers in 4.2 4.1.2; do
	   if xmlcatalog $XML_CATALOG "-//OASIS//DTD DocBook XML V$vers//EN" >/dev/null ; then
	      db_found=$vers
	      break
	   fi
	done
	if test -z $db_found; then
	   AC_MSG_ERROR(not found. Make sure you have the DocBook DTD installed and ensure that it is registered in $XML_CATALOG.)
	fi
	AC_MSG_RESULT(found version $vers)
	AC_DEFINE_UNQUOTED(DB_PUBLIC_ID, "-//OASIS//DTD DocBook XML V$db_found//EN", [Public identifier for the DocBook DTD])
	AC_DEFINE_UNQUOTED(DB_SYSTEM_ID, "http://www.oasis-open.org/docbook/xml/$db_found/docbookx.dtd", [System identifier for the DocBook DTD])
	;;
esac
dnl ====================================
dnl = End tests for DocBook XML DTD
dnl ====================================

AM_GNU_GETTEXT
AC_SUBST(LTLIBINTL)
AC_SUBST(LIBINTL)
GETTEXT_PACKAGE=scrollkeeper
AC_SUBST(GETTEXT_PACKAGE)

if test "x$prefix" = "xNONE"; then
   SKLOCALEDIR=$ac_default_prefix/${DATADIRNAME}/locale
else
   SKLOCALEDIR=$prefix/${DATADIRNAME}/locale
fi
AC_DEFINE_UNQUOTED(SCROLLKEEPERLOCALEDIR, "$SKLOCALEDIR", [The locale dir to use])

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

dnl
dnl The "partial database directory" is the last portion of the directory path
dnl to the Scrollkeeper database. The database will always go under
dnl $localstatedir (typically /var/), but the last bit is OS dependent. We
dnl make a few good guesses here and provide customisation as an option if all
dnl else fails.
dnl
AC_MSG_RESULT(setting up partial database directory ...)
default_partial_db_dir="lib/scrollkeeper"
AC_ARG_WITH(partial-db-dir,
   [AC_HELP_STRING([--with-partial-db-dir], [The subdirectory under localstatedir to put the scrollkeeper database (lib/scrollkeeper by default).])],
   [partial_db_dir="$withval"],
   [partial_db_dir="auto"])

   case "$partial_db_dir" in
   yes | no)
      AC_MSG_ERROR([Specifying the --with-partial-db-dir flag requires a subdirectory as an argument.])
      ;;
   auto)
      case "$host_os" in
      freebsd* | netbsd* | openbsd*)
   	SCROLLKEEPER_PARTIAL_DB_DIR=db/scrollkeeper
   	;;
      *)
        SCROLLKEEPER_PARTIAL_DB_DIR=lib/scrollkeeper
   	;;
      esac
      ;;
   *)
      SCROLLKEEPER_PARTIAL_DB_DIR=$partial_db_dir
      ;;
   esac
AC_SUBST(SCROLLKEEPER_PARTIAL_DB_DIR)
AC_MSG_RESULT(partial database directory is $SCROLLKEEPER_PARTIAL_DB_DIR)

AC_OUTPUT(
libs/Makefile
libuuid/Makefile
buildtools/Makefile
cl/Makefile
cl/src/Makefile
cl/templates/Makefile
extract/Makefile
extract/src/Makefile
extract/stylesheets/Makefile
extract/dtds/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/scrollkeeper.conf
config/Makefile
intl/Makefile
m4/Makefile
po/Makefile.in
doc/Makefile
doc/writing_scrollkeeper_omf_files/Makefile
doc/writing_scrollkeeper_omf_files/C/Makefile
Makefile
scrollkeeper.spec)

AC_MSG_NOTICE([
   Default OMF search paths (in $sysconfdir/scrollkeeper.conf):
      $OMFDIRS

   Scrollkeeper database directory:
      $localstatedir/$SCROLLKEEPER_PARTIAL_DB_DIR

   Now type 'make' to build scrollkeeper.])
