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 |
| 16 | VENV_NAME := venv-docs |
| 17 | |
| 18 | .PHONY: help test lint doc8 reload Makefile prep |
| 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): |
| 27 | python3 -m venv $(VENV_NAME) ;\ |
| 28 | source $@/bin/activate ;\ |
| 29 | pip install -r requirements.txt |
| 30 | |
| 31 | # automatically reload changes in browser as they're made |
| 32 | reload: $(VENV_NAME) |
| 33 | source $</bin/activate ; set -u ;\ |
| 34 | sphinx-reload $(SOURCEDIR) |
| 35 | |
| 36 | # lint and link verification. linkcheck is part of sphinx |
| 37 | test: lint spelling linkcheck |
| 38 | |
| 39 | lint: doc8 |
| 40 | |
| 41 | doc8: $(VENV_NAME) | $(OTHER_REPO_DOCS) |
| 42 | source $</bin/activate ; set -u ;\ |
| 43 | doc8 --max-line-length 119 \ |
| 44 | $$(find . -name \*.rst ! -path "*venv*" ! -path "*vendor*" ! -path "*repos*" ) |
| 45 | |
| 46 | license: $(VENV_NAME) |
| 47 | source $</bin/activate ; set -u ;\ |
| 48 | reuse --version ;\ |
| 49 | reuse --root . lint |
| 50 | |
| 51 | # clean up |
| 52 | clean: |
| 53 | rm -rf $(BUILDDIR) |
| 54 | |
| 55 | clean-all: clean |
| 56 | rm -rf $(VENV_NAME) |
| 57 | |
| 58 | # build multiple versions |
| 59 | multiversion: $(VENV_NAME) Makefile | prep $(OTHER_REPO_DOCS) |
| 60 | source $</bin/activate ; set -u ;\ |
| 61 | sphinx-multiversion "$(SOURCEDIR)" "$(BUILDDIR)/multiversion" $(SPHINXOPTS) |
| 62 | cp "$(SOURCEDIR)/_templates/meta_refresh.html" "$(BUILDDIR)/multiversion/index.html" |
| 63 | |
| 64 | # Catch-all target: route all unknown targets to Sphinx using the new |
| 65 | # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). |
| 66 | %: $(VENV_NAME) Makefile | $(OTHER_REPO_DOCS) $(STATIC_DOCS) |
| 67 | source $</bin/activate ; set -u ;\ |
| 68 | $(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) |