Zack Williams | 071eda2 | 2019-05-15 18:19:51 -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 ?= |
| 8 | SPHINXBUILD ?= sphinx-build |
| 9 | SOURCEDIR ?= . |
| 10 | BUILDDIR ?= _build |
| 11 | |
Zack Williams | 88df474 | 2019-12-20 08:24:47 -0700 | [diff] [blame] | 12 | # Other repos with documentation to include. |
| 13 | # edit the `git_refs` file with the commit/tag/branch that you want to use |
Zack Williams | 16042b6 | 2020-03-29 22:03:16 -0700 | [diff] [blame^] | 14 | OTHER_REPO_DOCS ?= bbsim cord-tester ofagent-go openolt voltctl voltha-openolt-adapter voltha-openonu-adapter voltha-protos voltha-system-tests |
Zack Williams | 88df474 | 2019-12-20 08:24:47 -0700 | [diff] [blame] | 15 | |
Zack Williams | 16042b6 | 2020-03-29 22:03:16 -0700 | [diff] [blame^] | 16 | # Static docs, built by other means (usually robot framework) |
| 17 | STATIC_DOCS := _static/voltha-system-tests _static/cord-tester |
| 18 | |
| 19 | # name of python virtualenv that is used to run commands |
| 20 | VENV_NAME := venv_docs |
Zack Williams | 071eda2 | 2019-05-15 18:19:51 -0700 | [diff] [blame] | 21 | |
Zack Williams | 88df474 | 2019-12-20 08:24:47 -0700 | [diff] [blame] | 22 | .PHONY: help test lint reload Makefile prep |
Zack Williams | 071eda2 | 2019-05-15 18:19:51 -0700 | [diff] [blame] | 23 | |
Zack Williams | 16042b6 | 2020-03-29 22:03:16 -0700 | [diff] [blame^] | 24 | # Put it first so that "make" without argument is like "make help". |
| 25 | help: $(VENV_NAME) |
| 26 | source $</bin/activate ; set -u ;\ |
| 27 | $(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) |
| 28 | |
Zack Williams | 071eda2 | 2019-05-15 18:19:51 -0700 | [diff] [blame] | 29 | # Create the virtualenv with all the tools installed |
Zack Williams | 16042b6 | 2020-03-29 22:03:16 -0700 | [diff] [blame^] | 30 | $(VENV_NAME): |
| 31 | virtualenv -p python3 $(VENV_NAME) ;\ |
Zack Williams | c6460c2 | 2019-12-18 14:54:43 -0700 | [diff] [blame] | 32 | source $@/bin/activate ;\ |
Zack Williams | 071eda2 | 2019-05-15 18:19:51 -0700 | [diff] [blame] | 33 | pip install -r requirements.txt |
| 34 | |
| 35 | # automatically reload changes in browser as they're made |
Zack Williams | 16042b6 | 2020-03-29 22:03:16 -0700 | [diff] [blame^] | 36 | reload: $(VENV_NAME) |
Zack Williams | c6460c2 | 2019-12-18 14:54:43 -0700 | [diff] [blame] | 37 | source $</bin/activate ; set -u ;\ |
Zack Williams | 071eda2 | 2019-05-15 18:19:51 -0700 | [diff] [blame] | 38 | sphinx-reload $(SOURCEDIR) |
| 39 | |
| 40 | # lint and link verification. linkcheck is part of sphinx |
| 41 | test: lint linkcheck |
| 42 | |
Zack Williams | c6460c2 | 2019-12-18 14:54:43 -0700 | [diff] [blame] | 43 | lint: doc8 |
Zack Williams | 071eda2 | 2019-05-15 18:19:51 -0700 | [diff] [blame] | 44 | |
Zack Williams | 16042b6 | 2020-03-29 22:03:16 -0700 | [diff] [blame^] | 45 | doc8: $(VENV_NAME) | $(OTHER_REPO_DOCS) |
Zack Williams | c6460c2 | 2019-12-18 14:54:43 -0700 | [diff] [blame] | 46 | source $</bin/activate ; set -u ;\ |
| 47 | doc8 --max-line-length 119 \ |
Zack Williams | 16042b6 | 2020-03-29 22:03:16 -0700 | [diff] [blame^] | 48 | $$(find . -name \*.rst ! -path "*venv*" ! -path "*vendor*" ! -path "*repos*" ) |
Zack Williams | 071eda2 | 2019-05-15 18:19:51 -0700 | [diff] [blame] | 49 | |
| 50 | # markdown linting |
| 51 | # currently not enabled, should be added to lint target |
| 52 | LINT_STYLE ?= mdl_strict.rb |
| 53 | md-lint: | $(OTHER_REPO_DOCS) |
| 54 | @echo "markdownlint(mdl) version: `mdl --version`" |
| 55 | @echo "style config:" |
| 56 | @echo "---" |
| 57 | @cat $(LINT_STYLE) |
| 58 | @echo "---" |
Zack Williams | 16042b6 | 2020-03-29 22:03:16 -0700 | [diff] [blame^] | 59 | mdl -s $(LINT_STYLE) `find -L $(SOURCEDIR) ! -path "./_$(VENV_NAME)/*" ! -path "./_build/*" ! -path "./repos/*" ! -path "*vendor*" -name "*.md"` |
Zack Williams | 071eda2 | 2019-05-15 18:19:51 -0700 | [diff] [blame] | 60 | |
| 61 | # clean up |
| 62 | clean: |
Zack Williams | 16042b6 | 2020-03-29 22:03:16 -0700 | [diff] [blame^] | 63 | rm -rf $(BUILDDIR) $(OTHER_REPO_DOCS) $(STATIC_DOCS) |
Zack Williams | 071eda2 | 2019-05-15 18:19:51 -0700 | [diff] [blame] | 64 | |
| 65 | clean-all: clean |
Zack Williams | 16042b6 | 2020-03-29 22:03:16 -0700 | [diff] [blame^] | 66 | rm -rf $(VENV_NAME) repos |
Zack Williams | 071eda2 | 2019-05-15 18:19:51 -0700 | [diff] [blame] | 67 | |
Zack Williams | 071eda2 | 2019-05-15 18:19:51 -0700 | [diff] [blame] | 68 | # checkout the repos inside repos/ dir |
| 69 | repos: |
| 70 | mkdir repos |
| 71 | |
| 72 | # build directory paths in repos/* to perform 'git clone <repo>' into |
| 73 | CHECKOUT_REPOS = $(foreach repo,$(OTHER_REPO_DOCS),repos/$(repo)) |
| 74 | |
| 75 | # Host holding the git server |
| 76 | REPO_HOST ?= https://gerrit.opencord.org |
| 77 | |
| 78 | # For QA patchset validation - set SKIP_CHECKOUT to the repo name and |
| 79 | # pre-populate it under repos/ with the specific commit to being validated |
| 80 | SKIP_CHECKOUT ?= |
| 81 | |
Zack Williams | 88df474 | 2019-12-20 08:24:47 -0700 | [diff] [blame] | 82 | # clone (only if doesn't exist) |
Zack Williams | 071eda2 | 2019-05-15 18:19:51 -0700 | [diff] [blame] | 83 | $(CHECKOUT_REPOS): | repos |
Zack Williams | 071eda2 | 2019-05-15 18:19:51 -0700 | [diff] [blame] | 84 | if [ ! -d '$@' ] ;\ |
| 85 | then git clone $(REPO_HOST)/$(@F) $@ ;\ |
Zack Williams | 071eda2 | 2019-05-15 18:19:51 -0700 | [diff] [blame] | 86 | fi |
| 87 | |
Zack Williams | 3308552 | 2020-02-28 11:41:01 -0700 | [diff] [blame] | 88 | # checkout correct ref if not under test, then copy subdirectories into main |
Zack Williams | 17e3402 | 2019-12-20 13:51:54 -0700 | [diff] [blame] | 89 | # docs dir |
Zack Williams | 071eda2 | 2019-05-15 18:19:51 -0700 | [diff] [blame] | 90 | $(OTHER_REPO_DOCS): | $(CHECKOUT_REPOS) |
Zack Williams | 88df474 | 2019-12-20 08:24:47 -0700 | [diff] [blame] | 91 | if [ "$(SKIP_CHECKOUT)" != "$@" ] ;\ |
| 92 | then GIT_REF=`grep '^$@ ' git_refs | awk '{print $$3}'` ;\ |
Zack Williams | 6c1703f | 2019-12-20 15:31:58 -0700 | [diff] [blame] | 93 | cd "repos/$@" && git checkout $$GIT_REF ;\ |
Zack Williams | 88df474 | 2019-12-20 08:24:47 -0700 | [diff] [blame] | 94 | fi |
Zack Williams | 17e3402 | 2019-12-20 13:51:54 -0700 | [diff] [blame] | 95 | GIT_SUBDIR=`grep '^$@ ' git_refs | awk '{print $$2}'` ;\ |
Zack Williams | 3308552 | 2020-02-28 11:41:01 -0700 | [diff] [blame] | 96 | cp -r repos/$(@)$$GIT_SUBDIR $@ ;\ |
Zack Williams | 071eda2 | 2019-05-15 18:19:51 -0700 | [diff] [blame] | 97 | |
Andrea Campanella | 92bd59b | 2020-01-30 17:26:32 +0100 | [diff] [blame] | 98 | # Build Robot documentation in voltha-system-tests and copy it into _static. |
| 99 | _static/voltha-system-tests: | $(OTHER_REPO_DOCS) |
| 100 | make -C voltha-system-tests gendocs |
| 101 | mkdir -p $@ |
| 102 | cp -r voltha-system-tests/gendocs/* $@ |
| 103 | |
Andy Bavier | 39d67b1 | 2020-02-27 16:08:52 -0700 | [diff] [blame] | 104 | # Build Robot documentation in cord-tester and copy it into _static. |
| 105 | _static/cord-tester: | $(OTHER_REPO_DOCS) |
| 106 | make -C cord-tester gendocs |
| 107 | mkdir -p $@ |
| 108 | cp -r cord-tester/gendocs/* $@ |
| 109 | |
Zack Williams | 071eda2 | 2019-05-15 18:19:51 -0700 | [diff] [blame] | 110 | # generate a list of git checksums suitable for updating git_refs |
| 111 | freeze: repos |
| 112 | @for repo in $(OTHER_REPO_DOCS) ; do \ |
| 113 | GIT_SUBDIR=`grep "^$$repo " git_refs | awk '{print $$2}'` ;\ |
Zack Williams | 6c1703f | 2019-12-20 15:31:58 -0700 | [diff] [blame] | 114 | cd "repos/$$repo" > /dev/null ;\ |
Zack Williams | 071eda2 | 2019-05-15 18:19:51 -0700 | [diff] [blame] | 115 | HEAD_SHA=`git rev-parse HEAD` ;\ |
| 116 | printf "%-24s %-8s %-40s\n" $$repo $$GIT_SUBDIR $$HEAD_SHA ;\ |
Zack Williams | 6c1703f | 2019-12-20 15:31:58 -0700 | [diff] [blame] | 117 | cd ../.. ;\ |
Zack Williams | 071eda2 | 2019-05-15 18:19:51 -0700 | [diff] [blame] | 118 | done |
| 119 | |
Zack Williams | 16042b6 | 2020-03-29 22:03:16 -0700 | [diff] [blame^] | 120 | # build multiple versions |
| 121 | multiversion: $(VENV_NAME) Makefile | prep $(OTHER_REPO_DOCS) |
Zack Williams | 88df474 | 2019-12-20 08:24:47 -0700 | [diff] [blame] | 122 | source $</bin/activate ; set -u ;\ |
Zack Williams | 16042b6 | 2020-03-29 22:03:16 -0700 | [diff] [blame^] | 123 | sphinx-multiversion "$(SOURCEDIR)" "$(BUILDDIR)/multiversion" $(SPHINXOPTS) |
| 124 | cp "$(SOURCEDIR)/_templates/meta_refresh.html" "$(BUILDDIR)/multiversion/index.html" |
Zack Williams | 88df474 | 2019-12-20 08:24:47 -0700 | [diff] [blame] | 125 | |
Zack Williams | 16042b6 | 2020-03-29 22:03:16 -0700 | [diff] [blame^] | 126 | # prep target - used in sphinx-multiversion to properly link |
| 127 | prep: | $(OTHER_REPO_DOCS) $(STATIC_DOCS) |
Andy Bavier | 5dee6ae | 2020-01-29 16:03:40 -0700 | [diff] [blame] | 128 | |
Zack Williams | 071eda2 | 2019-05-15 18:19:51 -0700 | [diff] [blame] | 129 | # Catch-all target: route all unknown targets to Sphinx using the new |
| 130 | # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). |
Zack Williams | 16042b6 | 2020-03-29 22:03:16 -0700 | [diff] [blame^] | 131 | %: $(VENV_NAME) Makefile | $(OTHER_REPO_DOCS) $(STATIC_DOCS) |
Zack Williams | c6460c2 | 2019-12-18 14:54:43 -0700 | [diff] [blame] | 132 | source $</bin/activate ; set -u ;\ |
Zack Williams | 071eda2 | 2019-05-15 18:19:51 -0700 | [diff] [blame] | 133 | $(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) |