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 | |
| 12 | # Put it first so that "make" without argument is like "make help". |
| 13 | help: doc_venv |
Zack Williams | c6460c2 | 2019-12-18 14:54:43 -0700 | [diff] [blame^] | 14 | source $</bin/activate ; set -u ;\ |
Zack Williams | 071eda2 | 2019-05-15 18:19:51 -0700 | [diff] [blame] | 15 | $(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) |
| 16 | |
| 17 | .PHONY: help test lint reload Makefile |
| 18 | |
| 19 | # Create the virtualenv with all the tools installed |
| 20 | doc_venv: |
| 21 | virtualenv doc_venv ;\ |
Zack Williams | c6460c2 | 2019-12-18 14:54:43 -0700 | [diff] [blame^] | 22 | source $@/bin/activate ;\ |
Zack Williams | 071eda2 | 2019-05-15 18:19:51 -0700 | [diff] [blame] | 23 | pip install livereload ;\ |
| 24 | pip install -r requirements.txt |
| 25 | |
| 26 | # automatically reload changes in browser as they're made |
| 27 | reload: doc_venv |
Zack Williams | c6460c2 | 2019-12-18 14:54:43 -0700 | [diff] [blame^] | 28 | source $</bin/activate ; set -u ;\ |
Zack Williams | 071eda2 | 2019-05-15 18:19:51 -0700 | [diff] [blame] | 29 | sphinx-reload $(SOURCEDIR) |
| 30 | |
| 31 | # lint and link verification. linkcheck is part of sphinx |
| 32 | test: lint linkcheck |
| 33 | |
Zack Williams | c6460c2 | 2019-12-18 14:54:43 -0700 | [diff] [blame^] | 34 | lint: doc8 |
Zack Williams | 071eda2 | 2019-05-15 18:19:51 -0700 | [diff] [blame] | 35 | |
Zack Williams | c6460c2 | 2019-12-18 14:54:43 -0700 | [diff] [blame^] | 36 | doc8: doc_venv | $(OTHER_REPO_DOCS) |
| 37 | source $</bin/activate ; set -u ;\ |
| 38 | doc8 --max-line-length 119 \ |
| 39 | $$(find . -name \*.rst ! -path "*doc_venv*" ! -path "*vendor*") |
Zack Williams | 071eda2 | 2019-05-15 18:19:51 -0700 | [diff] [blame] | 40 | |
| 41 | # markdown linting |
| 42 | # currently not enabled, should be added to lint target |
| 43 | LINT_STYLE ?= mdl_strict.rb |
| 44 | md-lint: | $(OTHER_REPO_DOCS) |
| 45 | @echo "markdownlint(mdl) version: `mdl --version`" |
| 46 | @echo "style config:" |
| 47 | @echo "---" |
| 48 | @cat $(LINT_STYLE) |
| 49 | @echo "---" |
| 50 | mdl -s $(LINT_STYLE) `find -L $(SOURCEDIR) ! -path "./_doc_venv/*" ! -path "./_build/*" ! -path "./repos/*" ! -path "*vendor*" -name "*.md"` |
| 51 | |
| 52 | # clean up |
| 53 | clean: |
| 54 | rm -rf $(BUILDDIR) $(OTHER_REPO_DOCS) |
| 55 | |
| 56 | clean-all: clean |
| 57 | rm -rf doc_venv repos |
| 58 | |
| 59 | # Other repos with documentation to include. |
| 60 | # edit the `git_refs` file with the commit/tag/branch that you want to use |
| 61 | OTHER_REPO_DOCS ?= bbsim voltha-go voltha-openolt-adapter voltha-openonu-adapter voltha-protos |
| 62 | |
| 63 | # checkout the repos inside repos/ dir |
| 64 | repos: |
| 65 | mkdir repos |
| 66 | |
| 67 | # build directory paths in repos/* to perform 'git clone <repo>' into |
| 68 | CHECKOUT_REPOS = $(foreach repo,$(OTHER_REPO_DOCS),repos/$(repo)) |
| 69 | |
| 70 | # Host holding the git server |
| 71 | REPO_HOST ?= https://gerrit.opencord.org |
| 72 | |
| 73 | # For QA patchset validation - set SKIP_CHECKOUT to the repo name and |
| 74 | # pre-populate it under repos/ with the specific commit to being validated |
| 75 | SKIP_CHECKOUT ?= |
| 76 | |
| 77 | # clone (only if doesn't exist), then checkout ref in repos/* |
| 78 | $(CHECKOUT_REPOS): | repos |
| 79 | GIT_REF=`grep '^$(@F) ' git_refs | awk '{print $$3}'` ;\ |
| 80 | if [ ! -d '$@' ] ;\ |
| 81 | then git clone $(REPO_HOST)/$(@F) $@ ;\ |
| 82 | fi ;\ |
| 83 | if [ "$(SKIP_CHECKOUT)" = "$(@F)" ] ;\ |
| 84 | then echo "Skipping checkout of repo $(SKIP_CHECKOUT) as it's being tested" ;\ |
| 85 | else pushd $@ ;\ |
| 86 | git checkout $$GIT_REF ;\ |
| 87 | popd ;\ |
| 88 | fi |
| 89 | |
| 90 | # link subdirectories (if applicable) into main docs dir |
| 91 | $(OTHER_REPO_DOCS): | $(CHECKOUT_REPOS) |
| 92 | GIT_SUBDIR=`grep '^$@ ' git_refs | awk '{print $$2}'` ;\ |
| 93 | ln -s repos/$(@)$$GIT_SUBDIR $@ |
| 94 | |
| 95 | # generate a list of git checksums suitable for updating git_refs |
| 96 | freeze: repos |
| 97 | @for repo in $(OTHER_REPO_DOCS) ; do \ |
| 98 | GIT_SUBDIR=`grep "^$$repo " git_refs | awk '{print $$2}'` ;\ |
| 99 | cd "repos/$$repo" > /dev/null ;\ |
| 100 | HEAD_SHA=`git rev-parse HEAD` ;\ |
| 101 | printf "%-24s %-8s %-40s\n" $$repo $$GIT_SUBDIR $$HEAD_SHA ;\ |
| 102 | cd ../.. ;\ |
| 103 | done |
| 104 | |
| 105 | # Catch-all target: route all unknown targets to Sphinx using the new |
| 106 | # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). |
Zack Williams | c6460c2 | 2019-12-18 14:54:43 -0700 | [diff] [blame^] | 107 | %: doc_venv Makefile | $(OTHER_REPO_DOCS) |
| 108 | source $</bin/activate ; set -u ;\ |
Zack Williams | 071eda2 | 2019-05-15 18:19:51 -0700 | [diff] [blame] | 109 | $(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) |
| 110 | |