(rule
 (targets unreleased.rst)
 (deps (source_tree changelog))
 (action (with-stdout-to %{targets} (bash "cat changelog/00-title.rst changelog/*/*.rst"))))

(alias
 (name refman-deps)
 (deps
  ; We could use finer dependencies here so the build is faster:
  ;
  ; - vo files: generated by sphinx after parsing the doc, promoted,
  ; - Static files:
  ;   + %{bin:coqdoc} etc...
  ;   + config/coq_config.py
  ;   + tools/coqdoc/coqdoc.css
  (package coq-core)
  (package coq-stdlib)
  (source_tree sphinx)
  (source_tree tools/coqrst)
  unreleased.rst
  (env_var SPHINXWARNOPT)))

(rule
 (targets refman-html)
 (alias refman-html)
 (package coq-doc)
 ; Cannot use this deps alias because of ocaml/dune#3415
 ; (deps (alias refman-deps))
 ; EJGA: note this should've been fixed in dune master as of 05/03/2021
 (deps
  (package coq-core)
  (package coq-stdlib)
  (source_tree sphinx)
  (source_tree tools/coqrst)
  ../config/coq_config.py
  unreleased.rst
  (env_var SPHINXWARNOPT))
 (action
  (run env sphinx-build -q %{env:SPHINXWARNOPT=-W} -b html sphinx %{targets})))

(rule
 (targets refman-pdf)
 (alias refman-pdf)
 (package coq-doc)
 ; Cannot use this deps alias because of ocaml/dune#3415
 ; (deps (alias refman-deps))
 ; EJGA: note this should've been fixed in dune master as of 05/03/2021
 (deps
  (package coq-core)
  (package coq-stdlib)
  (source_tree sphinx)
  (source_tree tools/coqrst)
  unreleased.rst
  (env_var SPHINXWARNOPT))
 (action
  (progn
   (run env sphinx-build -q %{env:SPHINXWARNOPT=-W} -b latex sphinx %{targets})
   (chdir %{targets} (run make LATEXMKOPTS=-silent)))))

; Installable directories are not yet fully supported by Dune.  See
; ocaml/dune#1868.  Yet, this makes coq-doc.install a valid target to
; generate the whole Coq documentation.  And the result under
; _build/install/default/doc/coq-doc looks just right!

(install
 (files (refman-html as html/refman) (refman-pdf as pdf/refman))
 (section doc)
 (package coq-doc))

(documentation
 (package coq-doc))
