blob: 9f209357113fc73b7a581f833928b0fd491c2034 [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
Nathan Skrzypczak9ad39c02021-08-19 11:38:06 +020024SPHINX_SCRIPTS_DIR ?= $(WS_ROOT)/docs/scripts
25
Paul Vinciguerra340c15c2019-11-05 15:34:36 -050026# Work out the OS if we haven't already
27OS_ID ?= $(shell grep '^ID=' /etc/os-release | cut -f2- -d= | sed -e 's/\"//g')
Nathan Skrzypczak9ad39c02021-08-19 11:38:06 +020028OS_VERSION ?= $(shell grep '^VERSION_ID=' /etc/os-release | cut -f2- -d= | sed -e 's/\"//g')
29PIP_VERSION ?= $(shell grep 'PIP_VERSION=' ${WS_ROOT}/test/Makefile | cut -d'=' -f2)
30PIP_TOOLS_VERSION ?= $(shell grep 'PIP_TOOLS_VERSION=' ${WS_ROOT}/test/Makefile | cut -d'=' -f2)
31
32PYTHON ?= "python3"
Dave Wallace51a037d2021-11-06 10:59:22 -040033PYTHON_VERSION_OK := $(shell $(PYTHON) -c "exec('import sys\nif sys.hexversion >= 0x03070000: print(\"true\")\nelse: print(\"false\")')")
34ifneq ($(PYTHON_VERSION_OK),true)
35$(error "ERROR: docs build requires python version >= to 3.7")
36endif
Paul Vinciguerra340c15c2019-11-05 15:34:36 -050037
John DeNisco2d1a0432018-07-26 16:21:31 -040038# You can set these variables from the command line.
Nathan Skrzypczak9ad39c02021-08-19 11:38:06 +020039SPHINXOPTS = --keep-going -n -W
40SPHINXBUILD = sphinx-build
41SPHINXPROJ = fdio-vpp
Nathan Skrzypczak9ad39c02021-08-19 11:38:06 +020042BUILDDIR = ${BR}/docs
43BUILDDIR_SRC = ${BUILDDIR}/src
44BUILDDIR_OUT = ${BUILDDIR}/html
45SCRIPTS_DIR = _scripts
Nathan Skrzypczak1e167a42022-03-25 12:06:51 +010046VENV_DIR ?= $(BUILDDIR)/venv
Nathan Skrzypczak9ad39c02021-08-19 11:38:06 +020047
John DeNisco2d1a0432018-07-26 16:21:31 -040048
49# Put it first so that "make" without argument is like "make help".
Nathan Skrzypczak9ad39c02021-08-19 11:38:06 +020050.PHONY: help
John DeNisco2d1a0432018-07-26 16:21:31 -040051help:
Nathan Skrzypczak9ad39c02021-08-19 11:38:06 +020052 @( \
53 . ${VENV_DIR}/bin/activate; \
54 $(SPHINXBUILD) --help ;\
55 )
John DeNisco2d1a0432018-07-26 16:21:31 -040056
Nathan Skrzypczak9ad39c02021-08-19 11:38:06 +020057.PHONY: venv
58venv:
59 @( \
60 if [ ! -d ${VENV_DIR} ]; then \
61 ${PYTHON} -m venv ${VENV_DIR}; \
62 . ${VENV_DIR}/bin/activate; \
63 ${PYTHON} -m pip install pip==${PIP_VERSION}; \
64 ${PYTHON} -m pip install pip-tools==${PIP_TOOLS_VERSION}; \
65 ${PYTHON} -m pip install -r ${WS_ROOT}/test/requirements-3.txt; \
66 fi; \
67 )
68
Nathan Skrzypczak1e167a42022-03-25 12:06:51 +010069.PHONY: spell
70spell: venv
71 @( \
72 . ${VENV_DIR}/bin/activate; \
Renato Botelho do Couto893daca2024-06-05 18:11:46 +000073 $(MAKE) -C ${SCRIPTS_DIR} generate && \
Nathan Skrzypczak1e167a42022-03-25 12:06:51 +010074 $(SPHINXBUILD) -b spelling $(SPHINXOPTS) $(BUILDDIR_SRC) $(BUILDDIR_OUT); \
75 )
76
77.PHONY: rebuild-spell
78rebuild-spell: clean spell
Nathan Skrzypczak9ad39c02021-08-19 11:38:06 +020079
80.PHONY: docs
Nathan Skrzypczak1e167a42022-03-25 12:06:51 +010081docs: venv
Nathan Skrzypczak9ad39c02021-08-19 11:38:06 +020082 @( \
83 . ${VENV_DIR}/bin/activate; \
Renato Botelho do Couto893daca2024-06-05 18:11:46 +000084 $(MAKE) -C ${SCRIPTS_DIR} generate && \
Nathan Skrzypczak9ad39c02021-08-19 11:38:06 +020085 $(SPHINXBUILD) $(SPHINXOPTS) -b html $(BUILDDIR_SRC) $(BUILDDIR_OUT); \
86 )
87
Nathan Skrzypczak1e167a42022-03-25 12:06:51 +010088.PHONY: rebuild
89rebuild: clean docs
90
Nathan Skrzypczak9ad39c02021-08-19 11:38:06 +020091.PHONY: clean
92clean:
Renato Botelho do Couto893daca2024-06-05 18:11:46 +000093 @$(MAKE) -C ${SCRIPTS_DIR} clean
Nathan Skrzypczak9ad39c02021-08-19 11:38:06 +020094
95.PHONY: build
96build: docs