dnl Process this file with autoconf to produce a configure script.
dnl
dnl COPYRIGHT (c) 2020 The Fellowship of SML/NJ (http://www.smlnj.org)
dnl All rights reserved.
dnl
dnl This the configuration script for autoconf version 2.60+.

AC_INIT([smlnj-lib-doc],[1.0],[],[],[http://smlnj.org])

AC_PREREQ(2.60)
AC_COPYRIGHT([[COPYRIGHT (c) 2020 The Fellowship of SML/NJ (http://www.smlnj.org)]])
AC_CONFIG_SRCDIR(src/JSON/json-lib.adoc)
AC_CONFIG_AUX_DIR(config)
AC_CONFIG_MACRO_DIR(config)

dnl
dnl get host information
dnl
AC_CANONICAL_HOST

dnl check for standard programs
dnl
AC_PROG_INSTALL
AC_PROG_MAKE_SET

dnl
dnl directory paths
dnl
case "$host_os" in
  mingw32)
    ROOT_DIR=`pwd -W`
  ;;
  *)
    ROOT_DIR=`pwd`
  ;;
esac
SMLNJ_ROOT=$ROOT_DIR/../..
SRC_DIR=$ROOT_DIR/src
OUT_DIR=$ROOT_DIR/doc
WEB_OUT_DIR=$ROOT_DIR/htdocs
MK_DIR=$ROOT_DIR/mk
SRC_CONFIG_DIR=$SRC_DIR/config
SRC_STYLES_DIR=$SRC_DIR/styles

AC_SUBST(ROOT_DIR)
AC_SUBST(OUT_DIR)
AC_SUBST(WEB_OUT_DIR)
AC_SUBST(SRC_DIR)
AC_SUBST(MK_DIR)
AC_SUBST(SRC_CONFIG_DIR)
AC_SUBST(SRC_STYLES_DIR)

dnl
dnl ******************** get SML/NJ release number and date ********************
dnl
SMLNJ_DATE=`date "+%B %d, %Y"`

AC_ARG_WITH([version],
  AC_HELP_STRING([--with-version], ["specify the SML/NJ release version"]),
  [SMLNJ_VERSION=$withval],
  [SMLNJ_VERSION=none])
if test x"$SMLNJ_VERSION" = xnone ; then
  if test -r $SMLNJ_ROOT/config/version ; then
    SMLNJ_VERSION=`cat $SMLNJ_ROOT/config/version`
    AC_MSG_NOTICE(["SML/NJ release version: $SMLNJ_VERSION"])
  else
    SMLNJ_VERSION="working"
    AC_MSG_NOTICE(["SML/NJ working version"])
  fi
fi
AC_SUBST(SMLNJ_VERSION)

AC_ARG_WITH([date],
  AC_HELP_STRING([--with-date], ["specify the SML/NJ release date"]),
  [SMLNJ_DATE=$withval],
  [SMLNJ_DATE=none])
if test x"$SMLNJ_DATE" = xnone ; then
  if test x"$SMLNJ_VERSION" = xworking ; then
    #
    # for working versions, we just use the current date
    #
    SMLNJ_DATE=`date "+%B %d, %Y"`
  else
    if test -r $SMLNJ_ROOT/config/releasedate ; then
      SMLNJ_DATE=`cat $SMLNJ_ROOT/config/releasedate`
    else
      SMLNJ_DATE=`date "+%B %d, %Y"`
    fi
  fi
fi
AC_MSG_NOTICE(["SML/NJ release date: $SMLNJ_DATE"])
AC_SUBST(SMLNJ_DATE)

dnl
dnl ******************** check for asciidoctor ********************
dnl
AC_PATH_PROGS([ASCIIDOCTOR], [asciidoctor], [none])

if test x"$ASCIIDOCTOR" = xnone ; then
  AC_MSG_ERROR([documentation generation requires asciidoctor])
fi

AC_SUBST(ASCIIDOCTOR)

dnl
dnl ******************** check for latexmk ********************
dnl
AC_PATH_PROGS([LATEXMK], [latexmk], [none])

if test x"$LATEXMK" = xnone ; then
  AC_MSG_ERROR([documentation generation requires latexmk (from texlive)])
fi

AC_SUBST(LATEXMK)

dnl
dnl ******************** write output ********************
dnl
AC_CONFIG_FILES(
dnl ***** Makefiles *****
  mk/doc-rules.gmk:config/doc-rules_gmk.in
  src/Makefile
)

AC_OUTPUT
