2019-12-03 17:54:04 +00:00
|
|
|
# -*- coding: utf-8; mode: makefile-gmake -*-
|
|
|
|
|
2020-03-15 16:01:36 +00:00
|
|
|
export DOCS_FOLDER DOCS_BUILD DOCS_DIST BOOKS_FOLDER BOOKS_DIST
|
|
|
|
|
2019-12-03 17:54:04 +00:00
|
|
|
# You can set these variables from the command line.
|
|
|
|
SPHINXOPTS ?=
|
|
|
|
SPHINXBUILD ?= $(PY_ENV_BIN)/sphinx-build
|
|
|
|
SPHINX_CONF ?= conf.py
|
|
|
|
|
2020-06-18 16:44:22 +00:00
|
|
|
DOCS_FOLDER = ./docs
|
2020-03-23 17:05:46 +00:00
|
|
|
DOCS_BUILD = ./$(LXC_ENV_FOLDER)build/docs
|
|
|
|
DOCS_DIST = ./$(LXC_ENV_FOLDER)dist/docs
|
2021-01-29 10:41:48 +00:00
|
|
|
GH_PAGES ?= build/gh-pages
|
2019-12-03 17:54:04 +00:00
|
|
|
|
2020-06-18 16:44:22 +00:00
|
|
|
BOOKS_FOLDER = ./docs
|
2020-03-23 17:05:46 +00:00
|
|
|
BOOKS_DIST = ./$(LXC_ENV_FOLDER)dist/books
|
2019-12-03 17:54:04 +00:00
|
|
|
|
|
|
|
ifeq ($(KBUILD_VERBOSE),1)
|
|
|
|
SPHINX_VERBOSE = "-v"
|
|
|
|
else
|
|
|
|
SPHINX_VERBOSE =
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
|
|
docs-help:
|
|
|
|
@echo 'makefile.sphinx:'
|
|
|
|
@echo ' docs-clean - clean intermediate doc objects'
|
|
|
|
@echo ' $(GH_PAGES) - create & upload github pages'
|
|
|
|
@echo ' sphinx-pdf - run sphinx latex & pdf targets'
|
2020-12-24 12:54:07 +00:00
|
|
|
@echo ''
|
2019-12-03 17:54:04 +00:00
|
|
|
@echo ' books/{name}.html : build only the HTML of document {name}'
|
|
|
|
@echo ' valid values for books/{name}.html are:'
|
|
|
|
@echo ' $(BOOKS_HTML)' | $(FMT)
|
|
|
|
@echo ' books/{name}.pdf : build only the PDF of document {name}'
|
|
|
|
@echo ' valid values for books/{name}.pdf are:'
|
|
|
|
@echo ' $(BOOKS_PDF) ' | $(FMT)
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# requirements
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
PHONY += msg-texlive texlive
|
|
|
|
|
|
|
|
ifeq ($(shell which xelatex >/dev/null 2>&1; echo $$?), 1)
|
|
|
|
texlive: msg-TeXLive
|
|
|
|
$(error The 'xelatex' command was not found)
|
|
|
|
else
|
|
|
|
texlive:
|
|
|
|
@:
|
|
|
|
endif
|
|
|
|
|
|
|
|
msg-texlive:
|
|
|
|
$(Q)echo "\n\
|
|
|
|
The TeX/PDF output and the *math* extension require TexLive and latexmk:\n\n\
|
|
|
|
Make sure you have a updated TeXLive with XeTeX engine installed, grab it\n\
|
|
|
|
it from https://www.tug.org/texlive or install it from your package manager.\n\n\
|
|
|
|
Install latexmk from your package manager or visit https://ctan.org/pkg/latexmk\n\n\
|
|
|
|
Sphinx-doc produce (Xe)LaTeX files which might use additional TeX-packages\n\
|
|
|
|
and fonts. To process these LaTeX files, a TexLive installation with the\n\
|
|
|
|
additional packages is required. On debian based OS these requirements\n\
|
|
|
|
are installed by::\n\n\
|
|
|
|
sudo -H apt-get install\n\
|
|
|
|
latexmk\n\
|
|
|
|
texlive-base texlive-xetex texlive-latex-recommended\n\
|
|
|
|
texlive-extra-utils dvipng ttf-dejavu\n"
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# commands
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
# $2 sphinx builder e.g. "html"
|
|
|
|
# $3 path where configuration file (conf.py) is located
|
|
|
|
# $4 sourcedir
|
|
|
|
# $5 dest subfolder e.g. "man" for man pages at $(DOCS_DIST)/man
|
|
|
|
|
|
|
|
quiet_cmd_sphinx = SPHINX $@ --> file://$(abspath $(DOCS_DIST)/$5)
|
|
|
|
cmd_sphinx = SPHINX_CONF=$(abspath $4/$(SPHINX_CONF))\
|
|
|
|
$(SPHINXBUILD) $(SPHINX_VERBOSE) $(SPHINXOPTS)\
|
|
|
|
-b $2 -c $3 -d $(DOCS_BUILD)/.doctrees $4 $(DOCS_DIST)/$5
|
|
|
|
|
|
|
|
quiet_cmd_sphinx_autobuild = SPHINX $@ --> file://$(abspath $(DOCS_DIST)/$5)
|
2020-10-29 12:31:11 +00:00
|
|
|
cmd_sphinx_autobuild = PATH="$(PY_ENV_BIN):$(PATH)" $(PY_ENV_BIN)/sphinx-autobuild $(SPHINX_VERBOSE) --open-browser --host 0.0.0.0 $(SPHINXOPTS)\
|
2019-12-03 17:54:04 +00:00
|
|
|
-b $2 -c $3 -d $(DOCS_BUILD)/.doctrees $4 $(DOCS_DIST)/$5
|
|
|
|
|
|
|
|
quiet_cmd_sphinx_clean = CLEAN $@
|
|
|
|
cmd_sphinx_clean = rm -rf $(DOCS_BUILD) $(DOCS_DIST) $(GH_PAGES)/* $(GH_PAGES)/.buildinfo
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# targets
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2020-06-18 16:44:22 +00:00
|
|
|
# build PDF of whole documentation in: $(DOCS_DIST)/pdf
|
2019-12-03 17:54:04 +00:00
|
|
|
|
|
|
|
PHONY += sphinx-pdf
|
|
|
|
sphinx-pdf: sphinx-latex
|
|
|
|
$(Q)cd $(DOCS_BUILD)/latex/; make all-pdf
|
|
|
|
$(Q)mkdir -p $(DOCS_DIST)/pdf
|
|
|
|
$(Q)cp $(DOCS_BUILD)/latex/*.pdf $(DOCS_DIST)/pdf
|
|
|
|
@echo "SPHINX *.pdf --> file://$(abspath $(DOCS_DIST)/pdf)"
|
|
|
|
|
|
|
|
PHONY += sphinx-latex
|
2020-12-24 12:54:07 +00:00
|
|
|
sphinx-latex: pyenvinstall texlive
|
2019-12-03 17:54:04 +00:00
|
|
|
$(SPHINXBUILD) $(SPHINX_VERBOSE) $(SPHINXOPTS)\
|
|
|
|
-b latex \
|
|
|
|
-c $(DOCS_FOLDER) \
|
|
|
|
-d $(DOCS_BUILD)/.doctrees \
|
|
|
|
$(DOCS_FOLDER) \
|
|
|
|
$(DOCS_BUILD)/latex
|
|
|
|
|
|
|
|
# Sphinx projects, we call them *books* (what is more common). Books are
|
|
|
|
# folders under $(BOOKS_FOLDER) containing a conf.py file. The HTML output goes
|
|
|
|
# to folder $(BOOKS_DIST)/<name> while PDF is placed (BOOKS_DIST)/<name>/pdf
|
|
|
|
|
|
|
|
BOOKS=$(patsubst $(BOOKS_FOLDER)/%/conf.py,books/%,$(wildcard $(BOOKS_FOLDER)/*/conf.py))
|
|
|
|
|
|
|
|
# fine grained targets
|
|
|
|
BOOKS_HTML = $(patsubst %,%.html,$(BOOKS))
|
|
|
|
BOOKS_CLEAN = $(patsubst %,%.clean,$(BOOKS))
|
|
|
|
BOOKS_LATEX = $(patsubst %,%.latex,$(BOOKS))
|
|
|
|
BOOKS_PDF = $(patsubst %,%.pdf,$(BOOKS))
|
|
|
|
BOOKS_LIVE = $(patsubst %,%.live,$(BOOKS))
|
|
|
|
|
|
|
|
$(BOOKS_DIST):
|
|
|
|
mkdir -p $(BOOKS_DIST)
|
|
|
|
|
|
|
|
PHONY += $(BOOKS_HTML)
|
2020-12-24 12:54:07 +00:00
|
|
|
$(BOOKS_HTML): pyenvinstall | $(BOOKS_DIST)
|
2019-12-03 17:54:04 +00:00
|
|
|
SPHINX_CONF=$(patsubst books/%.html,%,$@)/conf.py \
|
|
|
|
$(SPHINXBUILD) $(SPHINX_VERBOSE) $(SPHINXOPTS)\
|
|
|
|
-b html \
|
|
|
|
-c $(DOCS_FOLDER) \
|
|
|
|
-d $(DOCS_BUILD)/books/$(patsubst books/%.html,%,$@)/.doctrees \
|
2020-03-21 17:45:38 +00:00
|
|
|
$(BOOKS_FOLDER)/$(patsubst books/%.html,%,$@) \
|
2019-12-03 17:54:04 +00:00
|
|
|
$(BOOKS_DIST)/$(patsubst books/%.html,%,$@)
|
|
|
|
@echo "SPHINX $@ --> file://$(abspath $(BOOKS_DIST)/$(patsubst books/%.html,%,$@))"
|
|
|
|
|
|
|
|
PHONY += $(BOOKS_HTML)
|
2020-12-24 12:54:07 +00:00
|
|
|
$(BOOKS_LIVE): pyenvinstall | $(BOOKS_DIST)
|
2019-12-03 17:54:04 +00:00
|
|
|
PATH="$(PY_ENV_BIN):$(PATH)" \
|
|
|
|
SPHINX_CONF=$(patsubst books/%.live,%,$@)/conf.py \
|
|
|
|
$(PY_ENV_BIN)/sphinx-autobuild --poll -B --host 0.0.0.0 --port 8080 $(SPHINX_VERBOSE) $(SPHINXOPTS)\
|
|
|
|
-b html \
|
|
|
|
-c $(DOCS_FOLDER) \
|
|
|
|
-d $(DOCS_BUILD)/books/$(patsubst books/%.live,%,$@)/.doctrees \
|
2020-03-21 17:45:38 +00:00
|
|
|
$(BOOKS_FOLDER)/$(patsubst books/%.live,%,$@) \
|
2019-12-03 17:54:04 +00:00
|
|
|
$(BOOKS_DIST)/$(patsubst books/%.live,%,$@)
|
|
|
|
|
|
|
|
$(BOOKS_PDF): %.pdf : %.latex
|
|
|
|
$(Q)cd $(DOCS_BUILD)/latex/$(patsubst books/%.pdf,%,$@); make all-pdf
|
|
|
|
$(Q)mkdir -p $(BOOKS_DIST)/$(patsubst books/%.pdf,%,$@)/pdf
|
|
|
|
$(Q)cp -v $(DOCS_BUILD)/latex/$(patsubst books/%.pdf,%,$@)/*.pdf $(BOOKS_DIST)/$(patsubst books/%.pdf,%,$@)/pdf
|
|
|
|
@echo "SPHINX $@ --> file://$(abspath $(BOOKS_DIST)/$(patsubst books/%.pdf,%,$@))/pdf"
|
|
|
|
|
|
|
|
PHONY += $(BOOKS_LATEX)
|
2020-12-24 12:54:07 +00:00
|
|
|
$(BOOKS_LATEX): pyenvinstall | $(BOOKS_DIST)
|
2019-12-03 17:54:04 +00:00
|
|
|
SPHINX_CONF=$(patsubst books/%.latex,%,$@)/conf.py \
|
|
|
|
$(SPHINXBUILD) $(SPHINX_VERBOSE) $(SPHINXOPTS)\
|
|
|
|
-b latex \
|
|
|
|
-c $(DOCS_FOLDER) \
|
|
|
|
-d $(DOCS_BUILD)/books/$(patsubst books/%.latex,%,$@)/.doctrees \
|
2020-03-21 17:45:38 +00:00
|
|
|
$(BOOKS_FOLDER)/$(patsubst books/%.latex,%,$@) \
|
2019-12-03 17:54:04 +00:00
|
|
|
$(DOCS_BUILD)/latex/$(patsubst books/%.latex,%,$@)
|
|
|
|
@echo "SPHINX $@ --> file://$(abspath $(DOCS_BUILD)/latex/$(patsubst books/%.latex,%,$@))"
|
|
|
|
|
|
|
|
$(BOOKS_CLEAN):
|
|
|
|
$(Q)rm -rf $(BOOKS_DIST)/$(patsubst books/%.clean,%,$@) \
|
|
|
|
$(DOCS_BUILD)/books/$(patsubst books/%.clean,%,$@) \
|
|
|
|
$(DOCS_BUILD)/latex/$(patsubst books/%.clean,%,$@)
|
|
|
|
|
|
|
|
# github pages
|
2020-10-27 12:21:48 +00:00
|
|
|
PHONY += prepare-gh-pages
|
|
|
|
prepare-gh-pages:
|
|
|
|
cp -r $(DOCS_DIST)/* $(GH_PAGES)/
|
|
|
|
touch $(GH_PAGES)/.nojekyll
|
2021-01-29 10:41:48 +00:00
|
|
|
echo "<html><head><META http-equiv='refresh' content='0;URL=index.html'></head></html>" > $(GH_PAGES)/404.html
|
|
|
|
|
|
|
|
PHONY += gh-pages
|
|
|
|
gh-pages: docs-clean docs
|
|
|
|
- git worktree remove -f $(GH_PAGES) || exit 0
|
|
|
|
- git branch -D gh-pages || exit 0
|
|
|
|
git worktree add --no-checkout $(GH_PAGES) master
|
|
|
|
cd $(GH_PAGES); git checkout --orphan gh-pages && git rm -rfq .
|
2020-10-27 12:21:48 +00:00
|
|
|
$(MAKE) prepare-gh-pages
|
2019-12-03 17:54:04 +00:00
|
|
|
cd $(GH_PAGES);\
|
|
|
|
git add --all . ;\
|
2021-01-29 10:41:48 +00:00
|
|
|
git commit -q -m "make gh-pages: from $(shell git config --get remote.origin.url)@$(shell git rev-parse HEAD)" ;\
|
|
|
|
git push -f origin gh-pages
|
2019-12-03 17:54:04 +00:00
|
|
|
|
2020-10-27 12:21:48 +00:00
|
|
|
PHONY += travis-gh-pages
|
2021-01-29 10:41:48 +00:00
|
|
|
travis-gh-pages: docs-clean docs
|
2020-10-27 12:21:48 +00:00
|
|
|
rm -Rf $(GH_PAGES)
|
|
|
|
mkdir -p $(GH_PAGES)
|
|
|
|
$(MAKE) prepare-gh-pages
|
2019-12-13 11:58:46 +00:00
|
|
|
|
2019-12-03 17:54:04 +00:00
|
|
|
PHONY += docs-clean
|
|
|
|
docs-clean: $(BOOKS_CLEAN)
|
|
|
|
$(call cmd,sphinx_clean)
|
|
|
|
|
|
|
|
.PHONY: $(PHONY)
|