From d573ff1507ac5ac0904d7baf1a0d1ce59c757cf4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien@dynare.org>
Date: Mon, 18 Sep 2023 14:52:55 +0200
Subject: [PATCH] CI: build documentation using Meson

---
 .gitlab-ci.yml     | 16 +++++++---------
 macOS/build.sh     | 22 ++++++++--------------
 windows/build.sh   | 22 +++++++++-------------
 windows/dynare.nsi |  4 ++--
 4 files changed, 26 insertions(+), 38 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 2e3f40ca84..60d4b2bf3b 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -41,14 +41,12 @@ build_binaries:
 build_doc:
   stage: build
   script:
-    - autoreconf -si
-    - ./configure --disable-matlab --disable-octave PACKAGE_VERSION=$VERSION PACKAGE_STRING="dynare $VERSION"
-    - make -j $(nproc) pdf html
+    - meson rewrite kwargs set project / version "$VERSION"
+    - meson setup -Dbuild_for=octave build-doc
+    - meson compile -v -C build-doc doc
   artifacts:
     paths:
-      - doc/manual/build/
-      - doc/**/*.pdf
-      - preprocessor/doc/*/*.pdf
+      - build-doc/
     expire_in: 3 days
 
 pkg_source:
@@ -187,9 +185,9 @@ deploy_manual_unstable:
   dependencies:
     - build_doc
   script:
-    - rm -rf doc/manual/build/html/_static/mathjax
-    - ln -s /usr/share/javascript/mathjax doc/manual/build/html/_static/mathjax
-    - rsync --recursive --links --delete doc/manual/build/html/ /srv/www.dynare.org/manual-unstable/
+    - rm -rf build-doc/dynare-manual.html/_static/mathjax
+    - ln -s /usr/share/javascript/mathjax build-doc/dynare-manual.html/_static/mathjax
+    - rsync --recursive --links --delete build-doc/dynare-manual.html/ /srv/www.dynare.org/manual-unstable/
 
 deploy_snapshot_unstable:
   stage: deploy
diff --git a/macOS/build.sh b/macOS/build.sh
index 30e8c7abe3..38e5cf9172 100755
--- a/macOS/build.sh
+++ b/macOS/build.sh
@@ -76,7 +76,7 @@ QUADMATH_DIR=$(mktemp -d)
 ln -s /usr/local/opt/gcc/lib/gcc/$GCC_VERSION/libquadmath.a $QUADMATH_DIR
 
 ##
-## Compile Dynare doc, preprocessor, mex for MATLAB < 2018a
+## Compile Dynare preprocessor, mex for MATLAB < 2018a
 ##
 ## NB: In Homebrew, -static-libgfortran is implied by -static-libgcc (see “gfortran -dumpspecs”)
 ## NB2: We use the hack for libquadmath in LDFLAGS
@@ -96,13 +96,12 @@ cd "$ROOTDIR"
   --with-slicot="$LIB64"/Slicot/with-underscore \
   --disable-octave \
   --with-matlab=/Applications/MATLAB_R2016b.app
-if [[ -z $CI ]]; then
-    # If not in Gitlab CI, clean the source and build the doc
-    make clean
-    make -j"$NTHREADS" pdf html
-fi
 make -j"$NTHREADS"
 
+if [[ -z $CI ]]; then
+    echo "Building out of GitLab CI is not supported, documentation support needs to be fixed" 2>&1
+    exit 1
+fi
 
 ##
 ## Create package
@@ -140,14 +139,9 @@ cp -p  "$ROOTDIR"/scripts/dynare.el                                  "$PKGFILES"
 cp -pr "$ROOTDIR"/contrib/ms-sbvar/TZcode/MatlabFiles                "$PKGFILES"/contrib/ms-sbvar/TZcode
 cp -pr "$ROOTDIR"/contrib/jsonlab                                    "$PKGFILES"/contrib
 
-cp     "$ROOTDIR"/doc/*.pdf                                          "$PKGFILES"/doc
-cp     "$ROOTDIR"/doc/gsa/gsa.pdf                                    "$PKGFILES"/doc
-cp     "$ROOTDIR"/doc/parallel/parallel.pdf                          "$PKGFILES"/doc
-cp     "$ROOTDIR"/doc/dseries-and-reporting/dseriesReporting.pdf     "$PKGFILES"/doc
-cp     "$ROOTDIR"/preprocessor/doc/preprocessor/preprocessor.pdf     "$PKGFILES"/doc
-cp     "$ROOTDIR"/preprocessor/doc/macroprocessor/macroprocessor.pdf "$PKGFILES"/doc
-cp     "$ROOTDIR"/doc/manual/build/latex/dynare-manual.pdf           "$PKGFILES"/doc
-cp -r  "$ROOTDIR"/doc/manual/build/html                              "$PKGFILES"/doc/dynare-manual.html
+cp     "$ROOTDIR"/build-doc/*.pdf                                    "$PKGFILES"/doc
+cp     "$ROOTDIR"/build-doc/preprocessor/doc/*.pdf                   "$PKGFILES"/doc
+cp -r  "$ROOTDIR"/build-doc/dynare-manual.html                       "$PKGFILES"/doc
 
 mkdir -p                                                             "$PKGFILES"/matlab/modules/dseries/externals/x13/macOS/64
 cp -p  "$ROOTDIR"/macOS/deps/lib64/x13as/x13as                       "$PKGFILES"/matlab/modules/dseries/externals/x13/macOS/64
diff --git a/windows/build.sh b/windows/build.sh
index d2c858f6d1..54224e67e5 100755
--- a/windows/build.sh
+++ b/windows/build.sh
@@ -85,11 +85,6 @@ cd ..
 	    --disable-matlab \
 	    PACKAGE_VERSION="$VERSION" \
 	    PACKAGE_STRING="dynare $VERSION"
-if [[ -z $CI ]]; then
-    # If not in Gitlab CI, clean the source and build the doc
-    make clean
-    make -j"$NTHREADS" pdf html
-fi
 make -j"$NTHREADS"
 x86_64-w64-mingw32-strip preprocessor/src/dynare-preprocessor.exe
 x86_64-w64-mingw32-strip matlab/preprocessor64/dynare_m.exe
@@ -185,6 +180,11 @@ done < "$ROOT_DIRECTORY"/deps/versions.mk
 # shellcheck disable=SC1117
 echo -e "function v = supported_octave_version\nv=\"${OCTAVE_VERSION}\";\nend" > ../matlab/supported_octave_version.m
 
+if [[ -z $CI ]]; then
+    echo "Building out of GitLab CI is not supported, documentation support needs to be fixed" 2>&1
+    exit 1
+fi
+
 ## Create Windows installer
 makensis -DVERSION="$VERSION" dynare.nsi
 mkdir -p exe
@@ -218,14 +218,10 @@ cp -p windows/deps/lib64/x13as/x13as.exe "$ZIPDIR"/matlab/modules/dseries/extern
 cp -pr examples "$ZIPDIR"
 mkdir -p "$ZIPDIR"/scripts
 cp -p scripts/dynare.el "$ZIPDIR"/scripts
-mkdir -p "$ZIPDIR"/doc/dynare-manual.html
-cp -pr doc/manual/build/html/* "$ZIPDIR"/doc/dynare-manual.html
-cp -p doc/*.pdf "$ZIPDIR"/doc
-cp -p doc/manual/build/latex/dynare-manual.pdf "$ZIPDIR"/doc
-cp -p preprocessor/doc/macroprocessor/macroprocessor.pdf "$ZIPDIR"/doc
-cp -p doc/parallel/parallel.pdf "$ZIPDIR"/doc
-cp -p preprocessor/doc/preprocessor/preprocessor.pdf "$ZIPDIR"/doc
-cp -p doc/gsa/gsa.pdf "$ZIPDIR"/doc
+mkdir -p "$ZIPDIR"/doc
+cp -p build-doc/*.pdf "$ZIPDIR"/doc
+cp -p build-doc/preprocessor/doc/*.pdf "$ZIPDIR"/doc
+cp -pr build-doc/dynare-manual.html "$ZIPDIR"/doc
 
 cd "$TMP_DIRECTORY"
 
diff --git a/windows/dynare.nsi b/windows/dynare.nsi
index 76b1ecfbd8..348cc53e15 100644
--- a/windows/dynare.nsi
+++ b/windows/dynare.nsi
@@ -112,10 +112,10 @@ SectionEnd
 
 Section "Documentation and examples"
  SetOutPath $INSTDIR\doc
- File ..\doc\manual\build\latex\dynare-manual.pdf ..\doc\guide.pdf ..\doc\bvar-a-la-sims.pdf ..\doc\dr.pdf ..\doc\sylvester.pdf ..\doc\tl.pdf ..\preprocessor\doc\macroprocessor\macroprocessor.pdf ..\preprocessor\doc\preprocessor\preprocessor.pdf ..\doc\parallel\parallel.pdf ..\doc\gsa\gsa.pdf ..\doc\dseries-and-reporting\dseriesReporting.pdf
+ File ..\build-doc\dynare-manual.pdf ..\build-doc\guide.pdf ..\build-doc\bvar-a-la-sims.pdf ..\build-doc\dr.pdf ..\build-doc\sylvester.pdf ..\build-doc\tl.pdf ..\build-doc\preprocessor\doc\macroprocessor.pdf ..\build-doc\preprocessor\doc\preprocessor.pdf ..\build-doc\parallel.pdf ..\build-doc\gsa.pdf ..\build-doc\dseriesReporting.pdf
 
  SetOutPath $INSTDIR\doc\dynare-manual.html
- File /r ..\doc\manual\build\html\*
+ File /r ..\build-doc\dynare-manual.html\*
 
  SetOutPath $INSTDIR\examples
  File ..\examples\*.mod ..\examples\*.m
-- 
GitLab