# 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 http://pasdoc.sourceforge.net/autodoc/.
#
#   upload
#     Upload documentation generated by `public'
#     to http://pasdoc.sourceforge.net/autodoc/.
#     Of course you need to have sourceforge account and sufficient privileges
#     on sourceforge web server to do this (you need to be a pasdoc developer).
#     It uses scp program. You will be asked for password (more than once)
#     unless you configured ssh keys for your sourceforge account,
#     so configuring ssh keys is really advised.
#     You should override SF_USERNAME variable at command-line to your
#     username on sourceforge.
#
#     Note that scp displays progress meter on output, if you don't want this
#     (e.g. because you run "make" into Emacs compilation buffer)
#     you can pass option `-q' to scp, calling make like this
#     `make upload SCP_OPTIONS=-q SF_USERNAME=my_user_name'
#
#     For the sake of other pasdoc developers that would like
#     to also be able to execute `make upload' to upload freshest
#     version of autodoc, this target makes sure the uploaded files
#     are writeable by the group `pasdoc', so other pasdoc developers
#     may override them.
#
# Some hints:
#   To completely remake all documentation for
#   http://pasdoc.sourceforge.net/autodoc/
#   just call `make clean public upload SF_USERNAME=my_user_name'

# 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 \
  --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 http://pasdoc.sourceforge.net/autodoc/

# html-latex format output used to be included here too,
# but honestly htlatex is too bad to show publicly.
# Besides htlatex is broken on my system right now :)
# If you want to restore html-latex for public autodoc demo,
# add to the upload target
#	scp $(SCP_OPTIONS) latex/docs.html $(SF_CONNECT)latex/
#	scp $(SCP_OPTIONS) latex/docs.css $(SF_CONNECT)latex/

.PHONY:	public upload

public: html pdf latex

# Override this at command-line to your username,
# like `make upload SF_USERNAME=my_user_name'
SF_USERNAME=kambi

SF_HOST=web.sourceforge.net
SF_PATH=/home/project-web/pasdoc/htdocs/autodoc/

SF_CONNECT=$(SF_USERNAME),pasdoc@$(SF_HOST):$(SF_PATH)

SCP_OPTIONS=

upload:
	scp $(SCP_OPTIONS) -r html/ $(SF_CONNECT)
	scp $(SCP_OPTIONS) latex/docs.pdf $(SF_CONNECT)latex/
	scp $(SCP_OPTIONS) latex/docs.tex $(SF_CONNECT)latex/
# Not required anymore: with new SF shell, I'm logging in with ",pasdoc"
# in username, so the files will already be owned by "pasdoc" group by default.
#	../../tests/scripts/ssh_chmod_writeable_by_pasdoc.sh \
#	  $(SF_USERNAME),pasdoc $(SF_PATH)

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