Zack Williams | ccaa38a | 2021-11-16 15:36:05 -0700 | [diff] [blame^] | 1 | # Makefile for Sphinx documentation |
| 2 | |
| 3 | # use bash for pushd/popd, and to fail quickly |
| 4 | SHELL = bash -e -o pipefail |
| 5 | |
| 6 | # You can set these variables from the command line. |
| 7 | SPHINXOPTS ?= -W |
| 8 | SPHINXBUILD ?= sphinx-build |
| 9 | SOURCEDIR ?= . |
| 10 | BUILDDIR ?= _build |
| 11 | |
| 12 | # name of python virtualenv that is used to run commands |
| 13 | VENV_NAME := venv-docs |
| 14 | |
| 15 | .PHONY: help test lint doc8 reload Makefile prep |
| 16 | |
| 17 | # Put it first so that "make" without argument is like "make help". |
| 18 | help: $(VENV_NAME) |
| 19 | source $</bin/activate ; set -u ;\ |
| 20 | $(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) |
| 21 | |
| 22 | # Create the virtualenv with all the tools installed |
| 23 | $(VENV_NAME): |
| 24 | python3 -m venv $(VENV_NAME) ;\ |
| 25 | source $@/bin/activate ;\ |
| 26 | pip install -r requirements.txt |
| 27 | |
| 28 | # automatically reload changes in browser as they're made |
| 29 | reload: $(VENV_NAME) |
| 30 | source $</bin/activate ; set -u ;\ |
| 31 | sphinx-reload $(SOURCEDIR) |
| 32 | |
| 33 | # lint and link verification. linkcheck is part of sphinx |
| 34 | test: lint spelling linkcheck |
| 35 | |
| 36 | lint: doc8 |
| 37 | |
| 38 | doc8: $(VENV_NAME) | $(OTHER_REPO_DOCS) |
| 39 | source $</bin/activate ; set -u ;\ |
| 40 | doc8 --max-line-length 119 \ |
| 41 | $$(find . -name \*.rst ! -path "*venv*" ! -path "*vendor*" ! -path "*repos*" ) |
| 42 | |
| 43 | # clean up |
| 44 | clean: |
| 45 | rm -rf $(BUILDDIR) |
| 46 | |
| 47 | clean-all: clean |
| 48 | rm -rf $(VENV_NAME) |
| 49 | |
| 50 | # build multiple versions |
| 51 | multiversion: $(VENV_NAME) Makefile | prep $(OTHER_REPO_DOCS) |
| 52 | source $</bin/activate ; set -u ;\ |
| 53 | sphinx-multiversion "$(SOURCEDIR)" "$(BUILDDIR)/multiversion" $(SPHINXOPTS) |
| 54 | cp "$(SOURCEDIR)/_templates/meta_refresh.html" "$(BUILDDIR)/multiversion/index.html" |
| 55 | |
| 56 | # Catch-all target: route all unknown targets to Sphinx using the new |
| 57 | # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). |
| 58 | %: $(VENV_NAME) Makefile | $(OTHER_REPO_DOCS) $(STATIC_DOCS) |
| 59 | source $</bin/activate ; set -u ;\ |
| 60 | $(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) |