# This Makefile creates PasDoc generated documentation for PasDoc itself.
# Documentation is created in subdirectories named after pasdoc's --format
# names (html/, latex/ etc.)
#
# Targets:
#
#   html latex pdf dvi ps html-latex htmlhelp rtf
#     Make documentation in requested format.
#
#   clean
#     Delete all generated documentation.
#
#   public
#     Generate documentation in all formats that we want to show
#     on https://pasdoc.github.io/autodoc/ .
#
#   upload
#     Copy documentation generated by `public'
#     to ../../../pasdoc.github.io/docs/ .
#     This assumes you have cloned
#     https://github.com/pasdoc/pasdoc.github.io alongside pasdoc repo.
#     After pushing this repo it will be visible on
#     https://pasdoc.github.io/autodoc/ .
#
# Some hints:
#   To completely remake all documentation for
#   https://pasdoc.github.io/autodoc/
#   just call `make clean public upload'
#   then in ../../../pasdoc.github.io/ to GIT commit + push with new docs.

# Making documentation ----------------------------------------

# Name of pasdoc binary. Remember that you can override it at
# make's command-line, like `make PASDOC=my_pasdoc'
PASDOC=pasdoc

# These options will be passed to every pasdoc invocation,
# i.e. for every output format.
PASDOC_OPTIONS=--include ../component \
  ../component/*.pas ../component/tipue/*.pas \
  ../console/*.pas \
  -DFPC -DVER2 -DPASDOC \
  --title "PasDoc's autodoc" --write-uses-list  --auto-abstract \
  --introduction=introduction.txt

GRAPHVIZ_COMMANDS=dot -Grankdir=LR -Tjpg -oGVClasses.jpg GVClasses.dot; \
                  dot -Grankdir=LR -Tjpg -oGVUses.jpg GVUses.dot

# These options will be passed only when making docs in format that
# supports including graphviz graphs.
PASDOC_GRAPHVIZ_OPTIONS=--graphviz-classes --graphviz-uses \
  --link-gv-classes jpg --link-gv-uses jpg

# How to call hhc (html help compiler) ?
# Default value means that it must be available on path.
# As usual, remember you can override it at make's command-line.
HHC=hhc

.PHONY: html latex pdf dvi ps html-latex clean htmlhelp rtf

html:
	mkdir -p html/
	$(PASDOC) $(PASDOC_OPTIONS) $(PASDOC_GRAPHVIZ_OPTIONS) \
	  --output=html/ --use-tipue-search
	cd html/; $(GRAPHVIZ_COMMANDS)

# Ignore exit code from hhc (it's always 1 ???)
htmlhelp:
	mkdir -p htmlhelp/
	$(PASDOC) $(PASDOC_OPTIONS) $(PASDOC_GRAPHVIZ_OPTIONS) \
	  --format=htmlhelp --output=htmlhelp/
	cd htmlhelp/; $(GRAPHVIZ_COMMANDS)
	-cd htmlhelp/; $(HHC) docs.hhp

# Just shortcuts
latex: latex/docs.tex
pdf: latex/docs.pdf
dvi: latex/docs.dvi
ps: latex/docs.ps
html-latex: latex/docs.html
rtf: latex2rtf/docs.rtf

latex/docs.tex:
	mkdir -p latex/
	$(PASDOC) $(PASDOC_OPTIONS) \
	  --format=latex --output=latex/

# (Yes, I must do `cd latex' before calling pdflatex, I can't simply call
# `pdflatex latex/docs.tex' because then many output files of pdflatex
# would be placed in current dir)
latex/docs.pdf: latex/docs.tex
	cd latex; pdflatex --file-line-error-style -interaction=nonstopmode docs.tex
	cd latex; pdflatex --file-line-error-style -interaction=nonstopmode docs.tex

latex/docs.dvi: latex/docs.tex
	cd latex; latex --file-line-error-style -interaction=nonstopmode docs.tex
	cd latex; latex --file-line-error-style -interaction=nonstopmode docs.tex

latex/docs.ps: latex/docs.dvi
	cd latex; dvips docs.dvi -o docs.ps

# When working htlatex overrides latex/docs.dvi with a version
# that is not really a useful to browse (it's only for htlatex internals).
# That's why I `rm' it afterwards.
#
# As far as I understand how htlatex works, it's not needed to run
# htlatex twice (like it's needed with pdflatex and latex).
latex/docs.html: latex/docs.tex
	cd latex; htlatex docs.tex
	rm latex/docs.dvi

latex2rtf/docs.tex:
	mkdir -p latex2rtf/
	$(PASDOC) $(PASDOC_OPTIONS) \
	  --format=latex2rtf --output=latex2rtf/

# I must have latex/docs.tex as a prerequisite, to run latex over it
# to generate docs.aux file. Then I can use latex/docs.aux file with latex2rtf
# so that latex2rtf can make appropriate links.
latex2rtf/docs.rtf: latex2rtf/docs.tex latex/docs.tex
	cd latex/; latex --file-line-error-style -interaction=nonstopmode docs.tex
	cd latex2rtf/; latex2rtf -a ../latex/docs.aux docs.tex

clean:
	rm -Rf html/ latex/ latex2rtf/ htmlhelp/ html_by_pasdoc_gui/

# ------------------------------------------------------------
# Making and uploading autodoc for https://pasdoc.github.io/autodoc/

.PHONY:	public upload

public: html pdf latex

OUTPUT_DIR:=../../../pasdoc.github.io/docs/
AUTODOC_DIR:=$(OUTPUT_DIR)autodoc/

upload:
	rm -Rf $(AUTODOC_DIR)
	mkdir -p $(AUTODOC_DIR) $(AUTODOC_DIR)latex/
	cp -Rf html/ $(AUTODOC_DIR)
	cp -Rf latex/docs.pdf $(AUTODOC_DIR)latex/
	cp -Rf latex/docs.tex $(AUTODOC_DIR)latex/

# eof ------------------------------------------------------------
