From c2923b038386b2143f1af6518aea2a8c49a9a014 Mon Sep 17 00:00:00 2001
From: Houtan Bastani <houtan@dynare.org>
Date: Mon, 19 Feb 2018 15:00:13 +0100
Subject: [PATCH] build system: integrate documentation

---
 .gitignore           | 12 ++++++++
 Makefile.am          |  2 +-
 configure.ac         | 28 ++++++++++++++++--
 doc/Makefile.am      |  5 ++++
 license.txt          |  5 ++++
 m4/ax_latex_class.m4 | 68 ++++++++++++++++++++++++++++++++++++++++++++
 m4/ax_latex_test.m4  | 56 ++++++++++++++++++++++++++++++++++++
 7 files changed, 173 insertions(+), 3 deletions(-)
 create mode 100644 doc/Makefile.am
 create mode 100644 m4/ax_latex_class.m4
 create mode 100644 m4/ax_latex_test.m4

diff --git a/.gitignore b/.gitignore
index 433a53ad..ee858849 100644
--- a/.gitignore
+++ b/.gitignore
@@ -48,3 +48,15 @@ ar-lib
 
 # macOS stuff
 .DS_Store
+
+# Doc rules
+*.pdf
+*.aux
+*.log
+*.nav
+*.out
+*.snm
+*.toc
+*.vrb
+!/doc/macroprocessor/new-design.pdf
+!/doc/macroprocessor/old-design.pdf
diff --git a/Makefile.am b/Makefile.am
index c6125521..b086f007 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,4 +1,4 @@
-SUBDIRS = src
+SUBDIRS = src doc
 
 ACLOCAL_AMFLAGS = -I m4
 
diff --git a/configure.ac b/configure.ac
index ddb93126..e0457b96 100755
--- a/configure.ac
+++ b/configure.ac
@@ -80,9 +80,23 @@ AC_DEFINE([BOOST_NO_HASH], [], [Don't use deprecated STL hash structures])
 AC_CHECK_PROG([DOXYGEN], [doxygen], [doxygen])
 AM_CONDITIONAL([HAVE_DOXYGEN], [test "x$DOXYGEN" != "x"])
 
+AC_CHECK_PROG([PDFLATEX], [pdflatex], [pdflatex])
+AM_CONDITIONAL([HAVE_PDFLATEX], [test "x$PDFLATEX" != "x"])
+
+AC_CHECK_PROG([BIBTEX], [bibtex], [bibtex])
+AM_CONDITIONAL([HAVE_BIBTEX], [test "x$BIBTEX" != "x"])
+
+if test "x$PDFLATEX" != "x" -a "x$BIBTEX" != "x"; then
+  AX_LATEX_CLASS([beamer], [ax_latex_have_beamer])
+fi
+AM_CONDITIONAL([HAVE_BEAMER], [test "x$ax_latex_have_beamer" = "xyes"])
+
 AC_CONFIG_FILES([Makefile
                  src/Makefile
                  src/macro/Makefile
+                 doc/Makefile
+                 doc/preprocessor/Makefile
+                 doc/macroprocessor/Makefile
 ])
 
 if test "x$DOXYGEN" != "x"; then
@@ -91,15 +105,25 @@ else
   BUILD_DYNARE_PREPROC_DOC="no (missing doxygen)"
 fi
 
+
+if test "x$PDFLATEX" != "x" -a "x$ax_latex_have_beamer" = "xyes"; then
+  BUILD_BEAMER_DOC="yes"
+else
+  BUILD_BEAMER_DOC="no (missing one of: pdflatex, beamer)"
+fi
+
 AC_MSG_NOTICE([
 
 The Dynare Preprocessor is now configured to build...
 
 Binaries (with "make")
- Dynare preprocessor:                   yes
+ Dynare preprocessor:                         yes
+
+PDF documentation (with "make pdf"):
+ Preprocessor & Macroprocessor presentations: $BUILD_BEAMER_DOC
 
 HTML documentation (with "make html"):
- Dynare preprocessor developer doc:     $BUILD_DYNARE_PREPROC_DOC
+ Dynare preprocessor developer doc:           $BUILD_DYNARE_PREPROC_DOC
 
 ])
 
diff --git a/doc/Makefile.am b/doc/Makefile.am
new file mode 100644
index 00000000..975d8715
--- /dev/null
+++ b/doc/Makefile.am
@@ -0,0 +1,5 @@
+SUBDIRS = preprocessor macroprocessor
+
+PDF_TARGETS =
+
+pdf-local: $(PDF_TARGETS)
diff --git a/license.txt b/license.txt
index bfa79484..52292c1a 100644
--- a/license.txt
+++ b/license.txt
@@ -21,6 +21,11 @@ Copyright: 2008 Thomas Porschberg <thomas@randspringer.de>
            2009 Peter Adolphs
 License: permissive-autoconf
 
+Files: m4/ax_latex_class.m4 m4/ax_tex_test.m4
+Copyright: 2008 Boretti Mathieu <boretti@eig.unige.ch>
+           2009 Dynare Team
+License: LGPL-2.1+
+
 License: GPL-3+
  Dynare is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
diff --git a/m4/ax_latex_class.m4 b/m4/ax_latex_class.m4
new file mode 100644
index 00000000..0c1a9519
--- /dev/null
+++ b/m4/ax_latex_class.m4
@@ -0,0 +1,68 @@
+# ===========================================================================
+#         http://www.nongnu.org/autoconf-archive/ax_latex_class.html
+# ===========================================================================
+#
+# OBSOLETE MACRO
+#
+#   Deprecated because of licensing issues. The Lesser GPL imposes licensing
+#   restrictions on the generated configure script unless it is augmented
+#   with an Autoconf Exception clause.
+#
+# SYNOPSIS
+#
+#   AX_LATEX_CLASS(CLASSNAME,VARIABLETOSET[,ACTION-IF-FOUND[,ACTION-IF-NOT-FOUND]])
+#
+# DESCRIPTION
+#
+#   This macros test is class CLASSNAME exists and work and set
+#   VARIABLETOSET to yes or no If ACTION-IF-FOUND (and ACTION-IF-NOT-FOUND)
+#   are set, do the correct action
+#
+# LICENSE
+#
+#   Copyright (c) 2008 Boretti Mathieu <boretti@eig.unige.ch>
+#   Copyright (c) 2009 Dynare Team
+#
+#   This library is free software; you can redistribute it and/or modify it
+#   under the terms of the GNU Lesser General Public License as published by
+#   the Free Software Foundation; either version 2.1 of the License, or (at
+#   your option) any later version.
+#
+#   This library is distributed in the hope that it will be useful, but
+#   WITHOUT ANY WARRANTY; without even the implied warranty of
+#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
+#   General Public License for more details.
+#
+#   You should have received a copy of the GNU Lesser General Public License
+#   along with this library. If not, see <http://www.gnu.org/licenses/>.
+
+AC_DEFUN([AX_LATEX_CLASS],[
+AC_CACHE_CHECK([for usability of class $1],[ac_cv_latex_class_]translit($1,[-],[_]),[
+AX_LATEX_TEST([\documentclass{$1}
+\begin{document}
+\end{document}],[ac_cv_latex_class_]translit($1,[-],[_]))
+])
+$2=$[ac_cv_latex_class_]translit($1,[-],[_]) ; export $2;
+AC_SUBST($2)
+ifelse($#,2,[],$#,3,[
+    if test "[$]$2" = "yes" ;
+    then
+        $3
+    fi
+],$#,4,[
+    ifelse($3,[],[
+        if test "[$]$2" = "no" ;
+        then
+            $4
+        fi
+    ],[
+        if test "[$]$2" = "yes" ;
+        then
+            $3
+        else
+            $4
+        fi
+    ])
+])
+
+])
diff --git a/m4/ax_latex_test.m4 b/m4/ax_latex_test.m4
new file mode 100644
index 00000000..4d5b73a3
--- /dev/null
+++ b/m4/ax_latex_test.m4
@@ -0,0 +1,56 @@
+# ===========================================================================
+#          http://www.nongnu.org/autoconf-archive/ax_latex_test.html
+# ===========================================================================
+#
+# OBSOLETE MACRO
+#
+#   Deprecated because of licensing issues. The Lesser GPL imposes licensing
+#   restrictions on the generated configure script unless it is augmented
+#   with an Autoconf Exception clause.
+#
+# SYNOPSIS
+#
+#   AX_LATEX_TEST(FILEDATA,VARIABLETOSET,[NOCLEAN])
+#
+# DESCRIPTION
+#
+#   This macros execute the latex application with FILEDATA as input and set
+#   VARIABLETOSET the yes or no depending of the result if NOCLEAN is set,
+#   the folder used for the test is not delete after testing.
+#
+#   The macro assumes that the variable PDFLATEX is set.
+#
+# LICENSE
+#
+#   Copyright (c) 2008 Boretti Mathieu <boretti@eig.unige.ch>
+#   Copyright (c) 2009 Dynare Team
+#
+#   This library is free software; you can redistribute it and/or modify it
+#   under the terms of the GNU Lesser General Public License as published by
+#   the Free Software Foundation; either version 2.1 of the License, or (at
+#   your option) any later version.
+#
+#   This library is distributed in the hope that it will be useful, but
+#   WITHOUT ANY WARRANTY; without even the implied warranty of
+#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
+#   General Public License for more details.
+#
+#   You should have received a copy of the GNU Lesser General Public License
+#   along with this library. If not, see <http://www.gnu.org/licenses/>.
+
+AC_DEFUN([AX_LATEX_TEST],[
+rm -rf conftest.dir/.acltx
+AS_MKDIR_P([conftest.dir/.acltx])
+cd conftest.dir/.acltx
+m4_ifval([$2],[$2="no"; export $2;])
+cat > conftest.tex << ACLEOF
+$1
+ACLEOF
+cat conftest.tex | $PDFLATEX 2>&1 1>output m4_ifval([$2],[&& $2=yes])
+cd ..
+cd ..
+sed 's/^/| /' conftest.dir/.acltx/conftest.tex >&5
+echo "$as_me:$LINENO: executing cat conftest.tex | $PDFLATEX" >&5
+sed 's/^/| /' conftest.dir/.acltx/output >&5
+m4_ifval([$3],,[rm -rf conftest.dir/.acltx])
+])
-- 
GitLab