blob: ed5398309adf1949ae0c5799461421728fd88b1a [file] [log] [blame]
Joey Armstrong36592e32022-11-28 09:00:28 -05001# -*- makefile -*-
2# -----------------------------------------------------------------------
3# Copyright 2022 Open Networking Foundation
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16# -----------------------------------------------------------------------
Zack Williams071eda22019-05-15 18:19:51 -070017# Makefile for Sphinx documentation
18
Joey Armstrong36592e32022-11-28 09:00:28 -050019.DEFAULT_GOAL := help
20
21TOP ?= .
22MAKEDIR ?= $(TOP)/makefiles
23
24$(if $(VERBOSE),$(eval export VERBOSE=$(VERBOSE))) # visible to include(s)
25
26##--------------------##
27##---] INCLUDES [---##
28##--------------------##
29include $(MAKEDIR)/consts.mk
30include $(MAKEDIR)/help/include.mk
31include $(MAKEDIR)/patches/include.mk
32include $(MAKEDIR)/help/variables.mk
Zack Williams071eda22019-05-15 18:19:51 -070033
34# You can set these variables from the command line.
35SPHINXOPTS ?=
36SPHINXBUILD ?= sphinx-build
37SOURCEDIR ?= .
38BUILDDIR ?= _build
39
Zack Williams88df4742019-12-20 08:24:47 -070040# Other repos with documentation to include.
41# edit the `git_refs` file with the commit/tag/branch that you want to use
Andrea Campanellac18d1182021-09-10 12:01:38 +020042OTHER_REPO_DOCS ?= bbsim cord-tester ofagent-go openolt voltctl voltha-openolt-adapter voltha-openonu-adapter-go voltha-protos voltha-system-tests device-management-interface voltha-helm-charts
Zack Williams88df4742019-12-20 08:24:47 -070043
Joey Armstrong36592e32022-11-28 09:00:28 -050044ifdef NO_OTHER_REPO_DOCS
45 # Inhibit pulling in external repos.
46 # python 3.10+ patching not supported by all repos yet.
47 OTHER_REPO_DOCS := $(null)
48endif
49
Zack Williams16042b62020-03-29 22:03:16 -070050# Static docs, built by other means (usually robot framework)
51STATIC_DOCS := _static/voltha-system-tests _static/cord-tester
52
53# name of python virtualenv that is used to run commands
54VENV_NAME := venv_docs
Zack Williams071eda22019-05-15 18:19:51 -070055
Zack Williams88df4742019-12-20 08:24:47 -070056.PHONY: help test lint reload Makefile prep
Zack Williams071eda22019-05-15 18:19:51 -070057
Zack Williams16042b62020-03-29 22:03:16 -070058# Put it first so that "make" without argument is like "make help".
Joey Armstrong36592e32022-11-28 09:00:28 -050059help :: $(VENV_NAME)
60 @ echo
61 @ source $</bin/activate ; set -u ;\
Zack Williams16042b62020-03-29 22:03:16 -070062 $(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
63
Joey Armstrong36592e32022-11-28 09:00:28 -050064# -----------------------------------------------------------------------
Zack Williams071eda22019-05-15 18:19:51 -070065# Create the virtualenv with all the tools installed
Joey Armstrong36592e32022-11-28 09:00:28 -050066# -----------------------------------------------------------------------
Zack Williams16042b62020-03-29 22:03:16 -070067$(VENV_NAME):
Joey Armstrong36592e32022-11-28 09:00:28 -050068 @echo
69 @echo "============================="
70 @echo "Installing python virtual env"
71 @echo "============================="
72 virtualenv -p python3 $@ ;\
73 source ./$@/bin/activate ;\
74 python -m pip install -r requirements.txt
75ifndef NO_PATCH
76 @echo
77 @echo "========================================"
78 @echo "Applying python 3.10.x migration patches"
79 @echo "========================================"
80 ./patches/python_310_migration.sh '--venv' "$@" 'apply'
81endif
Zack Williams071eda22019-05-15 18:19:51 -070082
83# automatically reload changes in browser as they're made
Zack Williams16042b62020-03-29 22:03:16 -070084reload: $(VENV_NAME)
Zack Williamsc6460c22019-12-18 14:54:43 -070085 source $</bin/activate ; set -u ;\
Zack Williams071eda22019-05-15 18:19:51 -070086 sphinx-reload $(SOURCEDIR)
87
88# lint and link verification. linkcheck is part of sphinx
89test: lint linkcheck
Joey Armstrong36592e32022-11-28 09:00:28 -050090# doctest
91# coverage
92# linkcheck
Zack Williamsc6460c22019-12-18 14:54:43 -070093lint: doc8
Zack Williams071eda22019-05-15 18:19:51 -070094
Zack Williams16042b62020-03-29 22:03:16 -070095doc8: $(VENV_NAME) | $(OTHER_REPO_DOCS)
Zack Williamsc6460c22019-12-18 14:54:43 -070096 source $</bin/activate ; set -u ;\
97 doc8 --max-line-length 119 \
Zack Williams16042b62020-03-29 22:03:16 -070098 $$(find . -name \*.rst ! -path "*venv*" ! -path "*vendor*" ! -path "*repos*" )
Zack Williams071eda22019-05-15 18:19:51 -070099
100# markdown linting
101# currently not enabled, should be added to lint target
102LINT_STYLE ?= mdl_strict.rb
103md-lint: | $(OTHER_REPO_DOCS)
104 @echo "markdownlint(mdl) version: `mdl --version`"
105 @echo "style config:"
106 @echo "---"
107 @cat $(LINT_STYLE)
108 @echo "---"
Zack Williams16042b62020-03-29 22:03:16 -0700109 mdl -s $(LINT_STYLE) `find -L $(SOURCEDIR) ! -path "./_$(VENV_NAME)/*" ! -path "./_build/*" ! -path "./repos/*" ! -path "*vendor*" -name "*.md"`
Zack Williams071eda22019-05-15 18:19:51 -0700110
111# clean up
112clean:
Joey Armstrong36592e32022-11-28 09:00:28 -0500113 $(RM) -r $(BUILDDIR) $(OTHER_REPO_DOCS) $(STATIC_DOCS)
Zack Williams071eda22019-05-15 18:19:51 -0700114
Joey Armstrong36592e32022-11-28 09:00:28 -0500115clean-all sterile: clean
116 $(RM) -r $(VENV_NAME) repos
Zack Williams071eda22019-05-15 18:19:51 -0700117
Zack Williams071eda22019-05-15 18:19:51 -0700118# checkout the repos inside repos/ dir
119repos:
120 mkdir repos
121
122# build directory paths in repos/* to perform 'git clone <repo>' into
123CHECKOUT_REPOS = $(foreach repo,$(OTHER_REPO_DOCS),repos/$(repo))
124
125# Host holding the git server
126REPO_HOST ?= https://gerrit.opencord.org
127
128# For QA patchset validation - set SKIP_CHECKOUT to the repo name and
129# pre-populate it under repos/ with the specific commit to being validated
130SKIP_CHECKOUT ?=
131
Zack Williams88df4742019-12-20 08:24:47 -0700132# clone (only if doesn't exist)
Zack Williams071eda22019-05-15 18:19:51 -0700133$(CHECKOUT_REPOS): | repos
Zack Williams071eda22019-05-15 18:19:51 -0700134 if [ ! -d '$@' ] ;\
135 then git clone $(REPO_HOST)/$(@F) $@ ;\
Zack Williams071eda22019-05-15 18:19:51 -0700136 fi
137
Zack Williams33085522020-02-28 11:41:01 -0700138# checkout correct ref if not under test, then copy subdirectories into main
Zack Williams17e34022019-12-20 13:51:54 -0700139# docs dir
Zack Williams071eda22019-05-15 18:19:51 -0700140$(OTHER_REPO_DOCS): | $(CHECKOUT_REPOS)
Zack Williams88df4742019-12-20 08:24:47 -0700141 if [ "$(SKIP_CHECKOUT)" != "$@" ] ;\
142 then GIT_REF=`grep '^$@ ' git_refs | awk '{print $$3}'` ;\
Zack Williams6c1703f2019-12-20 15:31:58 -0700143 cd "repos/$@" && git checkout $$GIT_REF ;\
Zack Williams88df4742019-12-20 08:24:47 -0700144 fi
Zack Williams17e34022019-12-20 13:51:54 -0700145 GIT_SUBDIR=`grep '^$@ ' git_refs | awk '{print $$2}'` ;\
Zack Williams33085522020-02-28 11:41:01 -0700146 cp -r repos/$(@)$$GIT_SUBDIR $@ ;\
Zack Williams071eda22019-05-15 18:19:51 -0700147
Andrea Campanella92bd59b2020-01-30 17:26:32 +0100148# Build Robot documentation in voltha-system-tests and copy it into _static.
149_static/voltha-system-tests: | $(OTHER_REPO_DOCS)
150 make -C voltha-system-tests gendocs
151 mkdir -p $@
152 cp -r voltha-system-tests/gendocs/* $@
153
Andy Bavier39d67b12020-02-27 16:08:52 -0700154# Build Robot documentation in cord-tester and copy it into _static.
155_static/cord-tester: | $(OTHER_REPO_DOCS)
156 make -C cord-tester gendocs
157 mkdir -p $@
158 cp -r cord-tester/gendocs/* $@
159
Zack Williams071eda22019-05-15 18:19:51 -0700160# generate a list of git checksums suitable for updating git_refs
161freeze: repos
162 @for repo in $(OTHER_REPO_DOCS) ; do \
163 GIT_SUBDIR=`grep "^$$repo " git_refs | awk '{print $$2}'` ;\
Zack Williams6c1703f2019-12-20 15:31:58 -0700164 cd "repos/$$repo" > /dev/null ;\
Zack Williams071eda22019-05-15 18:19:51 -0700165 HEAD_SHA=`git rev-parse HEAD` ;\
166 printf "%-24s %-8s %-40s\n" $$repo $$GIT_SUBDIR $$HEAD_SHA ;\
Zack Williams6c1703f2019-12-20 15:31:58 -0700167 cd ../.. ;\
Zack Williams071eda22019-05-15 18:19:51 -0700168 done
169
Zack Williams16042b62020-03-29 22:03:16 -0700170# build multiple versions
171multiversion: $(VENV_NAME) Makefile | prep $(OTHER_REPO_DOCS)
Zack Williams88df4742019-12-20 08:24:47 -0700172 source $</bin/activate ; set -u ;\
Zack Williams16042b62020-03-29 22:03:16 -0700173 sphinx-multiversion "$(SOURCEDIR)" "$(BUILDDIR)/multiversion" $(SPHINXOPTS)
174 cp "$(SOURCEDIR)/_templates/meta_refresh.html" "$(BUILDDIR)/multiversion/index.html"
Zack Williams88df4742019-12-20 08:24:47 -0700175
Zack Williams16042b62020-03-29 22:03:16 -0700176# prep target - used in sphinx-multiversion to properly link
177prep: | $(OTHER_REPO_DOCS) $(STATIC_DOCS)
Andy Bavier5dee6ae2020-01-29 16:03:40 -0700178
Zack Williams071eda22019-05-15 18:19:51 -0700179# Catch-all target: route all unknown targets to Sphinx using the new
180# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
Joey Armstrong36592e32022-11-28 09:00:28 -0500181# %: $(VENV_NAME) Makefile | $(OTHER_REPO_DOCS) $(STATIC_DOCS)
182
183include $(MAKEDIR)/voltha/docs-catchall-targets.mk
184$(voltha-docs-catchall): $(VENV_NAME) Makefile | $(OTHER_REPO_DOCS) $(STATIC_DOCS)
185 @echo " ** CATCHALL: $@"
Zack Williamsc6460c22019-12-18 14:54:43 -0700186 source $</bin/activate ; set -u ;\
Zack Williams071eda22019-05-15 18:19:51 -0700187 $(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
Joey Armstrong36592e32022-11-28 09:00:28 -0500188
189include $(MAKEDIR)/help/trailer.mk
190
191# [EOF]