dnl  This the autoconf script for the gimp-help-2 project.
dnl  The GPL version 2 applies to it which you may get from
dnl  http://www.gnu.org/.

AC_PREREQ(2.54)

m4_define([help_major_version], [0])
m4_define([help_minor_version], [7])

m4_define([help_version], [help_major_version.help_minor_version])

AC_INIT(gimp-help-2, [help_version])

AC_CONFIG_SRCDIR([src/gimp.xml])

AM_INIT_AUTOMAKE(no-define)


AC_PROG_INSTALL
AC_PROG_LN_S
AC_PROG_MAKE_SET


dnl  You can set the ALL_LINGUAS environment variable to
dnl  control what languages are build.

if test "x$ALL_LINGUAS" != "x"; then
  ALL_LINGUAS=$ALL_LINGUAS
else
  ALL_LINGUAS="cs de en fr sv zh_CN"
fi

AC_SUBST(ALL_LINGUAS)


dnl  The build of the HTML files is optional

AC_ARG_ENABLE(build,
              [  --enable-build          build the help files from XML (needs xsltproc)],, enable_build=no)

AM_CONDITIONAL(GIMP_HELP_BUILD, test "x$enable_build" = "xyes")

dnl Using convert for optimizing screenshots for the html version is
dnl optional

AC_ARG_ENABLE(convert,
              [  --enable-convert        optimize the PNGs for the Web in file size (needs convert)],, enable_convert=no)

AM_CONDITIONAL(USE_CONVERT, test "x$enable_convert" = "xyes")

dnl  Search the XSLT processor

AC_PATH_PROG(XSLTPROC, xsltproc)
if test -z "$XSLTPROC" && test "x$enable_build" = "xyes"; then
  AC_MSG_ERROR([
** Couldn't find xsltproc. You will need it to build the help files.
** If you want to install the prebuilt help files only, use --disable-build.
** See the file 'INSTALL' for more help.])
fi

dnl  Search for xmllint

AC_PATH_PROG(XMLLINT, xmllint)
if test -z "$XMLLINT" && test "x$enable_build" = "xyes"; then
  AC_MSG_WARN([Couldn't find xmllint, won't be able to validate the XML.])
fi

dnl Search for image magic convert

AC_PATH_PROG(CONVERT, convert)
if test -z "$CONVERT" && test "x$enable_convert" = "xyes"; then
  AC_MSG_ERROR([
** Coudn't find convert. You will need it to optimize the images for the
** web.])
fi

dnl  Optionally allow xsltproc to access DTDs over the network

AC_ARG_ENABLE(network,
              [  --enable-network        allow to fetch DTDs or entities over the network])

if test "x$enable_network" != "xyes"; then
  XSLTFLAGS='--nonet'
fi

AC_SUBST(XSLTFLAGS)


dnl  Default to the correct way of identifying stylesheets.
dnl  People need an XML catalog to resolve this to a local file.

STYLEBASE='http://docbook.sourceforge.net/release/xsl/current'

dnl  Allow to explicitely specify the stylesheet location
dnl  in case the XML catalog doesn't exist or is broken.

AC_ARG_WITH(xsl,
            [  --with-xsl=<basedir>    path to the base of the DocBook Modular Stylesheets])

if test "x$with_xsl" != "x"; then
  STYLEBASE=$with_xsl
  AC_CHECK_FILE($STYLEBASE/xhtml/docbook.xsl,,
    AC_MSG_ERROR([** Couldn't find docbook.xsl in $STYLEBASE/xhtml]))
fi

AC_SUBST(STYLEBASE)


dnl  We need the GIMP data directory to install the help files

AC_ARG_WITH(gimp,
  [  --without-gimp          skip check for gimp2, install into prefix])

if test "x$with_gimp" != "xno"; then
  PKG_CHECK_MODULES(GIMP, gimp-2.0,, [
AC_MSG_ERROR([
** Couldn't find a GIMP-2.0 installation. If you want to skip this check and
** install the help files to the configured prefix, use the --without-gimp
** configure option. Note that GIMP will then only find the help files if it
** is installed in the same prefix. See the file 'INSTALL' for more help.])
])

  GIMP_DATADIR=`$PKG_CONFIG --variable=gimpdatadir gimp-2.0`
else
  GIMP_DATADIR='${datadir}/gimp/2.0'
fi

AC_SUBST(GIMP_DATADIR)


AC_CONFIG_FILES([
Makefile
stylesheets/plainhtml.xsl
])

AC_OUTPUT

AC_MSG_RESULT([
 Rebuild the help files:         $enable_build
 Languages:                      $ALL_LINGUAS
 Installation prefix:            $GIMP_DATADIR
 Optimize PNGs for HTML files:   $enable_convert 
])
