blob: 8ccc8187f894d08442c9445b4f09c8c39d3a9ca3 [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
70else ifneq ("$(wildcard /etc/redhat-release)","")
71 @sudo yum install $(CONFIRM) $(DOC_RPM_DEPENDS)
72endif
Nathan Skrzypczak9ad39c02021-08-19 11:38:06 +020073
74.PHONY: spell
75spell: clean checkdeps venv ${BUILDDIR_SRC}
76 @( \
77 . ${VENV_DIR}/bin/activate; \
78 make -C ${SCRIPTS_DIR} generate && \
79 $(SPHINXBUILD) -b spelling $(SPHINXOPTS) $(BUILDDIR_SRC) $(BUILDDIR_OUT); \
80 )
81
82.PHONY: venv
83venv:
84 @( \
85 if [ ! -d ${VENV_DIR} ]; then \
86 ${PYTHON} -m venv ${VENV_DIR}; \
87 . ${VENV_DIR}/bin/activate; \
88 ${PYTHON} -m pip install pip==${PIP_VERSION}; \
89 ${PYTHON} -m pip install pip-tools==${PIP_TOOLS_VERSION}; \
90 ${PYTHON} -m pip install -r ${WS_ROOT}/test/requirements-3.txt; \
91 fi; \
92 )
93
94${BUILDDIR_SRC}:
95 @mkdir -p ${BUILDDIR_SRC}
96 @cp -r $(SOURCEDIR) ${BUILDDIR_SRC}
97 @cd ${BUILDDIR_SRC} && find . -type l -exec cp --remove-destination -L ${DOCS_DIR}/{} {} \;
98
99.PHONY: docs
100docs: clean venv ${BUILDDIR_SRC}
101 @( \
102 . ${VENV_DIR}/bin/activate; \
103 make -C ${SCRIPTS_DIR} generate && \
104 $(SPHINXBUILD) $(SPHINXOPTS) -b html $(BUILDDIR_SRC) $(BUILDDIR_OUT); \
105 )
106
107.PHONY: clean
108clean:
Dave Wallace78b4f4e2021-10-30 15:30:38 -0400109 @rm -rf $(BUILDDIR) ${VENV_DIR}
Nathan Skrzypczak9ad39c02021-08-19 11:38:06 +0200110 @make -C ${SCRIPTS_DIR} clean
111
112.PHONY: build
113build: docs