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

AC_PREREQ(2.54)

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

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


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

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

AC_SUBST(ALL_LINGUAS)


#  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")


#  Using convert for optimizing screenshots for the html version is 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")


#  Check for GNU make.

AC_MSG_CHECKING([whether ${MAKE-make} is GNU make])
if (${MAKE-make} --version) < /dev/null > /dev/null 2>&1; then
  if (${MAKE-make} --version) 2> /dev/null | grep GNU 2>&1 > /dev/null; then
    AC_MSG_RESULT(yes)
  else
    AC_MSG_RESULT(no)
    AC_MSG_WARN([
** It seems that the make utility is not GNU make. Since this project
** makes use of GNU make extensions, you may run into build problems.
** Please use GNU make if possible.
])
  fi
else
  AC_MSG_RESULT([${MAKE-make}not found])
fi

#  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


#  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


#  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


#  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)


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

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


#  Allow to explicitely specify the stylesheet location
#  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)


#  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 
])
