Zack Williams | 7d058a9 | 2022-03-08 14:50:08 -0700 | [diff] [blame] | 1 | # SPDX-FileCopyrightText: 2021 Open Networking Foundation <info@opennetworking.org> |
| 2 | # SPDX-License-Identifier: Apache-2.0 |
| 3 | |
Zack Williams | ccaa38a | 2021-11-16 15:36:05 -0700 | [diff] [blame] | 4 | # Makefile for Sphinx documentation |
| 5 | |
| 6 | # use bash for pushd/popd, and to fail quickly |
| 7 | SHELL = bash -e -o pipefail |
| 8 | |
| 9 | # You can set these variables from the command line. |
| 10 | SPHINXOPTS ?= -W |
| 11 | SPHINXBUILD ?= sphinx-build |
| 12 | SOURCEDIR ?= . |
| 13 | BUILDDIR ?= _build |
| 14 | |
| 15 | # name of python virtualenv that is used to run commands |
| 16 | VENV_NAME := venv-docs |
| 17 | |
Zack Williams | 7d058a9 | 2022-03-08 14:50:08 -0700 | [diff] [blame] | 18 | .PHONY: help Makefile test doc8 dict-check sort-dict license clean clean-all |
Zack Williams | ccaa38a | 2021-11-16 15:36:05 -0700 | [diff] [blame] | 19 | |
| 20 | # Put it first so that "make" without argument is like "make help". |
| 21 | help: $(VENV_NAME) |
| 22 | source $</bin/activate ; set -u ;\ |
| 23 | $(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) |
| 24 | |
| 25 | # Create the virtualenv with all the tools installed |
| 26 | $(VENV_NAME): |
Zack Williams | 7d058a9 | 2022-03-08 14:50:08 -0700 | [diff] [blame] | 27 | python3 -m venv $@ ;\ |
Zack Williams | ccaa38a | 2021-11-16 15:36:05 -0700 | [diff] [blame] | 28 | source $@/bin/activate ;\ |
| 29 | pip install -r requirements.txt |
| 30 | |
Zack Williams | ccaa38a | 2021-11-16 15:36:05 -0700 | [diff] [blame] | 31 | # lint and link verification. linkcheck is part of sphinx |
Zack Williams | 7d058a9 | 2022-03-08 14:50:08 -0700 | [diff] [blame] | 32 | test: license doc8 dict-check spelling linkcheck |
Zack Williams | ccaa38a | 2021-11-16 15:36:05 -0700 | [diff] [blame] | 33 | |
Zack Williams | 7d058a9 | 2022-03-08 14:50:08 -0700 | [diff] [blame] | 34 | doc8: $(VENV_NAME) |
Zack Williams | ccaa38a | 2021-11-16 15:36:05 -0700 | [diff] [blame] | 35 | source $</bin/activate ; set -u ;\ |
Zack Williams | 7d058a9 | 2022-03-08 14:50:08 -0700 | [diff] [blame] | 36 | doc8 --ignore-path $< --ignore-path _build --ignore-path LICENSES --max-line-length 119 |
| 37 | |
| 38 | # Words in dict.txt must be in the correct alphabetical order and must not duplicated. |
| 39 | dict-check: sort-dict |
| 40 | @set -u ;\ |
| 41 | git diff --exit-code dict.txt && echo "dict.txt is sorted" && exit 0 || \ |
| 42 | echo "dict.txt is unsorted or needs to be added to git index" ; exit 1 |
| 43 | |
| 44 | sort-dict: |
| 45 | @sort -u < dict.txt > dict_sorted.txt |
| 46 | @mv dict_sorted.txt dict.txt |
| 47 | |
| 48 | license: $(VENV_NAME) |
| 49 | source $</bin/activate ; set -u ;\ |
| 50 | reuse --version ;\ |
| 51 | reuse --root . lint |
Zack Williams | ccaa38a | 2021-11-16 15:36:05 -0700 | [diff] [blame] | 52 | |
| 53 | # clean up |
| 54 | clean: |
| 55 | rm -rf $(BUILDDIR) |
| 56 | |
| 57 | clean-all: clean |
| 58 | rm -rf $(VENV_NAME) |
| 59 | |
| 60 | # build multiple versions |
Zack Williams | 7d058a9 | 2022-03-08 14:50:08 -0700 | [diff] [blame] | 61 | multiversion: $(VENV_NAME) Makefile |
Zack Williams | ccaa38a | 2021-11-16 15:36:05 -0700 | [diff] [blame] | 62 | source $</bin/activate ; set -u ;\ |
| 63 | sphinx-multiversion "$(SOURCEDIR)" "$(BUILDDIR)/multiversion" $(SPHINXOPTS) |
| 64 | cp "$(SOURCEDIR)/_templates/meta_refresh.html" "$(BUILDDIR)/multiversion/index.html" |
| 65 | |
| 66 | # Catch-all target: route all unknown targets to Sphinx using the new |
| 67 | # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). |
Zack Williams | 7d058a9 | 2022-03-08 14:50:08 -0700 | [diff] [blame] | 68 | %: $(VENV_NAME) Makefile |
Zack Williams | ccaa38a | 2021-11-16 15:36:05 -0700 | [diff] [blame] | 69 | source $</bin/activate ; set -u ;\ |
| 70 | $(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) |