blob: d94af443d0323db8ce7038e74bad1665695ccedc [file] [log] [blame]
Zack Williams7f708f82020-07-07 12:18:20 -07001# Makefile for Sphinx documentation
2
Zack Williams44faef92022-03-08 22:07:49 -07003# SPDX-FileCopyrightText: © 2020 Open Networking Foundation <support@opennetworking.org>
4# SPDX-License-Identifier: Apache-2.0
5
Zack Williams7f708f82020-07-07 12:18:20 -07006# use bash for pushd/popd, and to fail quickly
7SHELL = bash -e -o pipefail
8
9# You can set these variables from the command line.
Zack Williams1ae109e2021-07-27 11:17:04 -070010SPHINXOPTS ?= -W
Zack Williams7f708f82020-07-07 12:18:20 -070011SPHINXBUILD ?= sphinx-build
12SOURCEDIR ?= .
13BUILDDIR ?= _build
14
Zack Williams7f708f82020-07-07 12:18:20 -070015# Create the virtualenv with all the tools installed
Zack Williams44faef92022-03-08 22:07:49 -070016VENV_NAME := venv-docs
17
18# Put it first so that "make" without argument runs "make help".
19help: $(VENV_NAME)
20 source ./$(VENV_NAME)/bin/activate ; set -u ;\
21 $(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
22
23.PHONY: help Makefile test doc8 dict-check sort-dict license clean clean-all
24
Zack Williams7f708f82020-07-07 12:18:20 -070025$(VENV_NAME):
Zack Williams44faef92022-03-08 22:07:49 -070026 python3 -m venv $@ ;\
27 source ./$@/bin/activate ;\
28 pip install -r requirements.txt
Zack Williams7f708f82020-07-07 12:18:20 -070029
Zack Williams44faef92022-03-08 22:07:49 -070030# test - check that local build will lint, spelling is correct, then
31# build the html site.
32test: license doc8 dict-check spelling linkcheck
Zack Williams7f708f82020-07-07 12:18:20 -070033
Zack Williams44faef92022-03-08 22:07:49 -070034# lint all .rst files
35doc8: $(VENV_NAME)
36 source ./$</bin/activate ; set -u;\
37 doc8 --ignore-path $< --ignore-path _build --ignore-path LICENSES --max-line-length 119
Zack Williams7f708f82020-07-07 12:18:20 -070038
Zack Williams44faef92022-03-08 22:07:49 -070039# Words in dict.txt must be in the correct alphabetical order and must not duplicated.
40dict-check: sort-dict
41 @set -u ;\
42 git diff --exit-code dict.txt && echo "dict.txt is sorted" && exit 0 || \
43 echo "dict.txt is unsorted or needs to be added to git index" ; exit 1
Zack Williams7f708f82020-07-07 12:18:20 -070044
Zack Williams44faef92022-03-08 22:07:49 -070045sort-dict:
46 @sort -u < dict.txt > dict_sorted.txt
47 @mv dict_sorted.txt dict.txt
Zack Williams7f708f82020-07-07 12:18:20 -070048
Zack Williams44faef92022-03-08 22:07:49 -070049license: $(VENV_NAME) ## Check license with the reuse tool
50 source ./$</bin/activate ; set -u ;\
Zack Williams7f708f82020-07-07 12:18:20 -070051 reuse --version ;\
52 reuse --root . lint
53
54# clean up
55clean:
Zack Williams44faef92022-03-08 22:07:49 -070056 rm -rf "$(BUILDDIR)"
Zack Williams7f708f82020-07-07 12:18:20 -070057
Zack Williams44faef92022-03-08 22:07:49 -070058# clean-all - delete the virtualenv too
Zack Williams7f708f82020-07-07 12:18:20 -070059clean-all: clean
Zack Williams44faef92022-03-08 22:07:49 -070060 rm -rf "$(VENV_NAME)"
Zack Williams7f708f82020-07-07 12:18:20 -070061
62# build multiple versions
Zack Williams44faef92022-03-08 22:07:49 -070063multiversion: $(VENV_NAME) Makefile
Zack Williams7f708f82020-07-07 12:18:20 -070064 source $</bin/activate ; set -u ;\
65 sphinx-multiversion "$(SOURCEDIR)" "$(BUILDDIR)/multiversion" $(SPHINXOPTS)
66 cp "$(SOURCEDIR)/_templates/meta_refresh.html" "$(BUILDDIR)/multiversion/index.html"
67
68# Catch-all target: route all unknown targets to Sphinx using the new
69# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
Zack Williams44faef92022-03-08 22:07:49 -070070%: $(VENV_NAME) Makefile
71 source ./$</bin/activate ; set -u;\
72 $(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)