# Makefile for Sphinx documentation
#

# You can set these variables from the command line.
SPHINXOPTS      =
SPHINXBUILD     = sphinx-build
BUILDDIRNAME    = site
BUILDDIR        = ../site
TARDIRNAME      = tar
TARDIR          = ../tar
SRCDIRNAME      = src
SRCDIR          = .
DOCTREEDIRNAME  = ../doctree

TIMEVERSION    := $(shell date +%Y-%m-%d-%H-%M-%S)

# User-friendly check for sphinx-build
ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1)
$(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from http://sphinx-doc.org/)
endif

TIMEVERSIONOPTS = -D timeversion="$(TIMEVERSION)"
ALLSPHINXOPTS   = -D timeversion="$(TIMEVERSION)" .
NOWARNINGS      = -Q

help:
	@echo "Please use \`make <target>' where <target> is one of"
	@echo "  help       to show this help"
	@echo "  html       to make standalone HTML files"
	@echo "  learning   to make clean and to make standalone HTML files in learning mode"
	@echo "  control    to make clean and to make standalone HTML files in assessing mode and in training mode"
	@echo "  tar        to archive $(BUILDDIR)/* and $(SRCDIR)/*"
	@echo "  clean      to remove $(BUILDDIR)/* and $(TARDIR)/* and *.*~"
	@echo "  all        to make clean; make html-learning; make tar"

all: learning tar

learning: clean html-learning

control: clean html-assessing html-replay

clean:
	@echo "\033[1;32mCleaning\033[0m"
	rm -rf $(BUILDDIR)/*
	rm -rf $(TARDIR)/*
	rm -rf $(DOCTREEDIRNAME)/*
	rm -f *.json *.js *~ 
	rm -f pyenibook.cfg
	rm -f data/aleadico_*.py
	@echo "\033[1;32m... done\033[0m"
	@echo

tar:
	@echo "\033[1;32mArchiving\033[0m"
	(cd ..; tar czf $(TARDIRNAME)/$(BUILDDIRNAME).tgz $(BUILDDIRNAME)/)
	(cd ..; tar --check-links --dereference -czf $(TARDIRNAME)/$(SRCDIRNAME).tgz $(SRCDIRNAME)/)
	@echo "\033[1;32m... done\033[0m The .tgz files are in $(TARDIR)/."
	@echo

link:
	ln -s ../../../../_lab/  lab
	ln -s ../../../../_fig/  fig
	ln -s ../../../../_prg/  prg
	ln -s ../../../../_data/ data

html:
	@echo "\033[1;32mLearning\033[0m" with Sphinx warnings
	rm -f pyenibook.cfg
	$(SPHINXBUILD) -b html -d $(DOCTREEDIRNAME) -D modeEnibook="learning" $(ALLSPHINXOPTS) $(BUILDDIR)/html
	rm -rf ../doctree
	@echo "\033[1;32m... done\033[0m The HTML pages are in $(BUILDDIR)/html."
	@echo

html-learning:
	@echo "\033[1;32mLearning\033[0m" without Sphinx warnings
	rm -f pyenibook.cfg
	$(SPHINXBUILD) -b html -d $(DOCTREEDIRNAME) -D modeEnibook="learning" $(NOWARNINGS) $(ALLSPHINXOPTS) $(BUILDDIR)/html
	rm -rf ../doctree
	@echo "\033[1;32m... done\033[0m The HTML pages are in $(BUILDDIR)/html."
	@echo

html-assessing:
	@echo "\033[1;32mAssessing\033[0m"
	rm -f pyenibook.cfg
	$(SPHINXBUILD) -b html -d $(DOCTREEDIRNAME) -D modeEnibook="assessing" $(NOWARNINGS) $(ALLSPHINXOPTS) $(BUILDDIR)/assessing/html
	bin/makeConfig.py assessing "$(TIMEVERSION)"
	rm -rf ../doctree
	@echo "\033[1;32m... done\033[0m The HTML pages are in $(BUILDDIR)/assessing/html."
	@echo

html-replay:
	@echo "\033[1;32mReplay\033[0m"
	rm -f pyenibook.cfg
	$(SPHINXBUILD) -b html -d $(DOCTREEDIRNAME) -D modeEnibook="training" $(NOWARNINGS) $(ALLSPHINXOPTS)  $(BUILDDIR)/replay/html
	bin/makeConfig.py replay "$(TIMEVERSION)"
	rm -rf ../doctree
	@echo "\033[1;32m... done\033[0m  The HTML pages are in $(BUILDDIR)/replay/html."
	@echo

