blob: 71ee034b331d49de3a141fccad814f83f041876d [file] [log] [blame]
Dave Wallace51a037d2021-11-06 10:59:22 -04001# Copyright (c) 2021 Cisco and/or its affiliates.
2# Licensed under the Apache License, Version 2.0 (the "License");
3# you may not use this file except in compliance with the License.
4# You may obtain a copy of the License at:
5#
6# http://www.apache.org/licenses/LICENSE-2.0
7#
8# Unless required by applicable law or agreed to in writing, software
9# distributed under the License is distributed on an "AS IS" BASIS,
10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11# See the License for the specific language governing permissions and
12# limitations under the License.
John DeNisco2d1a0432018-07-26 16:21:31 -040013#
Paul Vinciguerra340c15c2019-11-05 15:34:36 -050014# We support MacOS for docs generation
15ifeq ($(shell uname),Darwin)
16OS_ID = darwin
17endif
18
Nathan Skrzypczak9ad39c02021-08-19 11:38:06 +020019# These should be passed in by the root Makefile
20WS_ROOT ?= $(CURDIR)/..
21BR ?= $(WS_ROOT)/build-root
22DOCS_DIR ?= $(WS_ROOT)/docs
23
24VENV_DIR ?= $(DOCS_DIR)/venv
25SPHINX_SCRIPTS_DIR ?= $(WS_ROOT)/docs/scripts
26
Paul Vinciguerra340c15c2019-11-05 15:34:36 -050027# Work out the OS if we haven't already
28OS_ID ?= $(shell grep '^ID=' /etc/os-release | cut -f2- -d= | sed -e 's/\"//g')
Nathan Skrzypczak9ad39c02021-08-19 11:38:06 +020029OS_VERSION ?= $(shell grep '^VERSION_ID=' /etc/os-release | cut -f2- -d= | sed -e 's/\"//g')
30PIP_VERSION ?= $(shell grep 'PIP_VERSION=' ${WS_ROOT}/test/Makefile | cut -d'=' -f2)
31PIP_TOOLS_VERSION ?= $(shell grep 'PIP_TOOLS_VERSION=' ${WS_ROOT}/test/Makefile | cut -d'=' -f2)
32
33PYTHON ?= "python3"
Dave Wallace51a037d2021-11-06 10:59:22 -040034PYTHON_VERSION_OK := $(shell $(PYTHON) -c "exec('import sys\nif sys.hexversion >= 0x03070000: print(\"true\")\nelse: print(\"false\")')")
35ifneq ($(PYTHON_VERSION_OK),true)
36$(error "ERROR: docs build requires python version >= to 3.7")
37endif
Paul Vinciguerra340c15c2019-11-05 15:34:36 -050038
John DeNisco2d1a0432018-07-26 16:21:31 -040039# You can set these variables from the command line.
Nathan Skrzypczak9ad39c02021-08-19 11:38:06 +020040SPHINXOPTS = --keep-going -n -W
41SPHINXBUILD = sphinx-build
42SPHINXPROJ = fdio-vpp
43SOURCEDIR = .
44BUILDDIR = ${BR}/docs
45BUILDDIR_SRC = ${BUILDDIR}/src
46BUILDDIR_OUT = ${BUILDDIR}/html
47SCRIPTS_DIR = _scripts
48
John DeNisco2d1a0432018-07-26 16:21:31 -040049
50# Put it first so that "make" without argument is like "make help".
Nathan Skrzypczak9ad39c02021-08-19 11:38:06 +020051.PHONY: help
John DeNisco2d1a0432018-07-26 16:21:31 -040052help:
Nathan Skrzypczak9ad39c02021-08-19 11:38:06 +020053 @( \
54 . ${VENV_DIR}/bin/activate; \
55 $(SPHINXBUILD) --help ;\
56 )
John DeNisco2d1a0432018-07-26 16:21:31 -040057
Nathan Skrzypczak9ad39c02021-08-19 11:38:06 +020058.PHONY: checkdeps
59checkdeps:
Paul Vinciguerra340c15c2019-11-05 15:34:36 -050060 @echo "Checking whether dependencies for Docs are installed..."
61ifeq ($(OS_ID),ubuntu)
62 @set -e; inst=; \
63 for i in $(DOC_DEB_DEPENDS); do \
64 dpkg-query --show $$i >/dev/null 2>&1 || inst="$$inst $$i"; \
65 done; \
66 if [ "$$inst" ]; then \
67 sudo apt-get update; \
68 sudo apt-get $(CONFIRM) $(FORCE) install $$inst; \
69 fi
Paul Vinciguerra340c15c2019-11-05 15:34:36 -050070endif
Nathan Skrzypczak9ad39c02021-08-19 11:38:06 +020071
72.PHONY: spell
73spell: clean checkdeps venv ${BUILDDIR_SRC}
74 @( \
75 . ${VENV_DIR}/bin/activate; \
76 make -C ${SCRIPTS_DIR} generate && \
77 $(SPHINXBUILD) -b spelling $(SPHINXOPTS) $(BUILDDIR_SRC) $(BUILDDIR_OUT); \
78 )
79
80.PHONY: venv
81venv:
82 @( \
83 if [ ! -d ${VENV_DIR} ]; then \
84 ${PYTHON} -m venv ${VENV_DIR}; \
85 . ${VENV_DIR}/bin/activate; \
86 ${PYTHON} -m pip install pip==${PIP_VERSION}; \
87 ${PYTHON} -m pip install pip-tools==${PIP_TOOLS_VERSION}; \
88 ${PYTHON} -m pip install -r ${WS_ROOT}/test/requirements-3.txt; \
89 fi; \
90 )
91
92${BUILDDIR_SRC}:
93 @mkdir -p ${BUILDDIR_SRC}
94 @cp -r $(SOURCEDIR) ${BUILDDIR_SRC}
95 @cd ${BUILDDIR_SRC} && find . -type l -exec cp --remove-destination -L ${DOCS_DIR}/{} {} \;
96
97.PHONY: docs
98docs: clean venv ${BUILDDIR_SRC}
99 @( \
100 . ${VENV_DIR}/bin/activate; \
101 make -C ${SCRIPTS_DIR} generate && \
102 $(SPHINXBUILD) $(SPHINXOPTS) -b html $(BUILDDIR_SRC) $(BUILDDIR_OUT); \
103 )
104
105.PHONY: clean
106clean:
Dave Wallace78b4f4e2021-10-30 15:30:38 -0400107 @rm -rf $(BUILDDIR) ${VENV_DIR}
Nathan Skrzypczak9ad39c02021-08-19 11:38:06 +0200108 @make -C ${SCRIPTS_DIR} clean
109
110.PHONY: build
111build: docs