# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS    ?=
SPHINXBUILD   ?= sphinx-build
SOURCEDIR     = .
BUILDDIR      = _build

# Put it first so that "make" without argument is like "make help".
help:
	@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile full

# Build PDF first, then HTML so the PDF download link works in the online docs.
# Uses xelatex directly (twice for cross-references) to avoid requiring latexmk.
full:
	@$(SPHINXBUILD) -M latex "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
	@cd "$(BUILDDIR)/latex" && \
	    pdflatex -interaction=nonstopmode lhcb_ftcalib.tex > pdflatex1.log 2>&1 || (tail -50 pdflatex1.log && exit 1) && \
	    makeindex -s python.ist lhcb_ftcalib.idx && \
	    pdflatex -interaction=nonstopmode lhcb_ftcalib.tex > pdflatex2.log 2>&1 || (tail -50 pdflatex2.log && exit 1)
	@cp "$(BUILDDIR)/latex/lhcb_ftcalib.pdf" "$(SOURCEDIR)/lhcb_ftcalib.pdf"
	@$(SPHINXBUILD) -M html "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option.  $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
	@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
