Charles Chan | fcfe890 | 2022-02-02 17:06:27 -0800 | [diff] [blame] | 1 | # SPDX-FileCopyrightText: 2021 Open Networking Foundation <info@opennetworking.org> |
| 2 | # SPDX-License-Identifier: Apache-2.0 |
| 3 | |
Zack Williams | 98fe232 | 2021-09-20 15:02:11 -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 |
Zack Williams | e100ab5 | 2022-03-05 09:07:57 -0700 | [diff] [blame] | 16 | VENV_NAME := venv-docs |
Zack Williams | 98fe232 | 2021-09-20 15:02:11 -0700 | [diff] [blame] | 17 | |
Zack Williams | e100ab5 | 2022-03-05 09:07:57 -0700 | [diff] [blame] | 18 | .PHONY: help Makefile test doc8 dict-check sort-dict license clean clean-all |
Zack Williams | 98fe232 | 2021-09-20 15:02:11 -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 | e100ab5 | 2022-03-05 09:07:57 -0700 | [diff] [blame] | 27 | python3 -m venv $@ ;\ |
Zack Williams | 98fe232 | 2021-09-20 15:02:11 -0700 | [diff] [blame] | 28 | source $@/bin/activate ;\ |
| 29 | pip install -r requirements.txt |
| 30 | |
Zack Williams | 98fe232 | 2021-09-20 15:02:11 -0700 | [diff] [blame] | 31 | # lint and link verification. linkcheck is part of sphinx |
Zack Williams | e100ab5 | 2022-03-05 09:07:57 -0700 | [diff] [blame] | 32 | test: license doc8 dict-check spelling linkcheck |
Zack Williams | 98fe232 | 2021-09-20 15:02:11 -0700 | [diff] [blame] | 33 | |
Zack Williams | e100ab5 | 2022-03-05 09:07:57 -0700 | [diff] [blame] | 34 | doc8: $(VENV_NAME) |
Zack Williams | 98fe232 | 2021-09-20 15:02:11 -0700 | [diff] [blame] | 35 | source $</bin/activate ; set -u ;\ |
Zack Williams | e100ab5 | 2022-03-05 09:07:57 -0700 | [diff] [blame] | 36 | doc8 --ignore-path $< --ignore-path _build --ignore-path LICENSES --max-line-length 119 |
Zack Williams | 98fe232 | 2021-09-20 15:02:11 -0700 | [diff] [blame] | 37 | |
Yi Tseng | d6e2377 | 2022-03-01 16:31:55 -0800 | [diff] [blame] | 38 | # Words in dict.txt must be in the correct alphabetical order and must not duplicated. |
Zack Williams | e100ab5 | 2022-03-05 09:07:57 -0700 | [diff] [blame] | 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 |
Yi Tseng | d6e2377 | 2022-03-01 16:31:55 -0800 | [diff] [blame] | 43 | |
Zack Williams | e100ab5 | 2022-03-05 09:07:57 -0700 | [diff] [blame] | 44 | sort-dict: |
| 45 | @sort -u < dict.txt > dict_sorted.txt |
| 46 | @mv dict_sorted.txt dict.txt |
Yi Tseng | d6e2377 | 2022-03-01 16:31:55 -0800 | [diff] [blame] | 47 | |
Zack Williams | 98fe232 | 2021-09-20 15:02:11 -0700 | [diff] [blame] | 48 | license: $(VENV_NAME) |
| 49 | source $</bin/activate ; set -u ;\ |
| 50 | reuse --version ;\ |
| 51 | reuse --root . lint |
| 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 | 015e174 | 2022-03-08 11:26:24 -0700 | [diff] [blame] | 61 | multiversion: $(VENV_NAME) Makefile |
Zack Williams | 98fe232 | 2021-09-20 15:02:11 -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 | e100ab5 | 2022-03-05 09:07:57 -0700 | [diff] [blame] | 68 | %: $(VENV_NAME) Makefile |
Zack Williams | 98fe232 | 2021-09-20 15:02:11 -0700 | [diff] [blame] | 69 | source $</bin/activate ; set -u ;\ |
| 70 | $(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) |