# -*- Autoconf -*-
#
# Copyright (C) 2011-2021 ABINIT Group (Yann Pouillon)
#
# This file is part of the ABINIT software package. For license information,
# please see the COPYING file in the top-level directory of the ABINIT source
# distribution.
#

# ---------------------------------------------------------------------------- #

#
# IMPORTANT NOTE
#
# Please DO NOT EDIT this file unless you REALLY know what you are doing.
# Everything is important, in particular the order of the various commands
# executed here. YOU HAVE BEEN WARNED !
#

# ---------------------------------------------------------------------------- #

#
# Autoconf & Automake startup
#

# Initialize Autoconf
AC_PREREQ(2.62)
AC_INIT([ABINIT-Documentation],[9.6.2],
  [https://bugs.launchpad.net/abinit/],[abinit-doc])
AC_REVISION([Autotools support for the ABINIT Documentation])
AC_CONFIG_AUX_DIR([config/gnu])
AC_CONFIG_MACRO_DIR([config/m4])
AC_CONFIG_SRCDIR([rules.am])

# ---------------------------------------------------------------------------- #

#
# Startup
#

# Initial setup
AC_CANONICAL_TARGET
AM_INIT_AUTOMAKE(1.10)

# Check for common programs
AC_PROG_MAKE_SET
AC_PROG_INSTALL
AC_PROG_LN_S
AC_PROG_SED
AC_PROG_AWK
AC_PROG_GREP

# Workaround for the "grep -e" issue on Solaris systems
AC_PROG_EGREP

# Workaround for the wrong path to install-sh on Mac systems
AX_PROG_MKDIR_P

# Option to test the absence of LaTeX
AC_ARG_ENABLE(portability-tests,
  AS_HELP_STRING([--enable-portability-tests],
    [Maintainer-only option to force build parameters (default: disabled)]))
test "${enable_portability_tests}" = "" && enable_portability_tests="no"


# ---------------------------------------------------------------------------- #

#
# Graphviz support
#

# Define options and environment variables
AC_ARG_VAR([GVDFLAGS],[Graphviz dot flags])
AC_SUBST(GVDFLAGS)

# Look for the compiler
AC_CHECK_PROGS(GRAPHVIZ_DOT,[dot])

# Check whether dot is able to output PDF
abi_gv_ok="no"
if test "${GRAPHVIZ_DOT}" != ""; then
  AC_MSG_CHECKING([whether dot (Graphviz) can create PDF documents])
  abi_gv_pdf=`${GRAPHVIZ_DOT} -Thelp 2>&1 | grep 'pdf'`
  test "${abi_gv_pdf}" != "" && abi_gv_ok="yes"
  AC_MSG_RESULT([${abi_gv_ok}])
fi

# ---------------------------------------------------------------------------- #

#
# LaTeX support
#

# Define options and environment variables
AC_ARG_VAR([TEXFLAGS],[LaTeX flags])
AC_SUBST(TEXFLAGS)
TEXFLAGS="${TEXFLAGS} -interaction=nonstopmode"

# Look for the compiler
AC_CHECK_PROGS(LATEX,[pdflatex xetex])

# ---------------------------------------------------------------------------- #

#
# Markdown support
#

# Define options and environment variables
AC_ARG_VAR([MDFLAGS],[Markdown flags])
AC_SUBST(MDFLAGS)

# Look for required utilities
AC_CHECK_PROGS(PERL,[perl perl6 perl5])
AC_CHECK_PROGS(MARKDOWN,[markdown])

# Make sure we can use markdown
if test "${MARKDOWN}" = ""; then
  AC_MSG_NOTICE([using internal version of Markdown])
  MARKDOWN='[$](top_srcdir)/config/util/markdown.pl'
  MARKDOWN="${PERL} ${MARKDOWN}"
fi

# ---------------------------------------------------------------------------- #

#
# Final adjustments
#

# Make sure LaTeX is usable
abi_latex_ok="no"
if test "${LATEX}" != ""; then
  if test "${abi_gv_ok}" = "yes"; then
    abi_latex_ok="yes"
  else
    AC_MSG_WARN([dot (Graphviz) cannot create PDF documents - disabling LaTeX])
  fi
fi

# Decide whether to test portability by disabling document builders
if test "${enable_portability_tests}" = "yes"; then
  abi_gv_ok="no"
  abi_latex_ok="no"
fi

# Set conditionals
AM_CONDITIONAL([DO_BUILD_GV], [test "${abi_gv_ok}" = "yes"])
AM_CONDITIONAL([DO_BUILD_TEX], [test "${abi_gv_ok}" = "yes" -a "${abi_latex_ok}" = "yes"])


# ---------------------------------------------------------------------------- #

#
# Output configuration
#

ABIDOC_OUTPUT
