Dave Wallace | 51a037d | 2021-11-06 10:59:22 -0400 | [diff] [blame] | 1 | # 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 DeNisco | 2d1a043 | 2018-07-26 16:21:31 -0400 | [diff] [blame] | 13 | # |
Paul Vinciguerra | 340c15c | 2019-11-05 15:34:36 -0500 | [diff] [blame] | 14 | # We support MacOS for docs generation |
| 15 | ifeq ($(shell uname),Darwin) |
| 16 | OS_ID = darwin |
| 17 | endif |
| 18 | |
Nathan Skrzypczak | 9ad39c0 | 2021-08-19 11:38:06 +0200 | [diff] [blame] | 19 | # These should be passed in by the root Makefile |
| 20 | WS_ROOT ?= $(CURDIR)/.. |
| 21 | BR ?= $(WS_ROOT)/build-root |
| 22 | DOCS_DIR ?= $(WS_ROOT)/docs |
| 23 | |
Nathan Skrzypczak | 9ad39c0 | 2021-08-19 11:38:06 +0200 | [diff] [blame] | 24 | SPHINX_SCRIPTS_DIR ?= $(WS_ROOT)/docs/scripts |
| 25 | |
Paul Vinciguerra | 340c15c | 2019-11-05 15:34:36 -0500 | [diff] [blame] | 26 | # Work out the OS if we haven't already |
| 27 | OS_ID ?= $(shell grep '^ID=' /etc/os-release | cut -f2- -d= | sed -e 's/\"//g') |
Nathan Skrzypczak | 9ad39c0 | 2021-08-19 11:38:06 +0200 | [diff] [blame] | 28 | OS_VERSION ?= $(shell grep '^VERSION_ID=' /etc/os-release | cut -f2- -d= | sed -e 's/\"//g') |
| 29 | PIP_VERSION ?= $(shell grep 'PIP_VERSION=' ${WS_ROOT}/test/Makefile | cut -d'=' -f2) |
| 30 | PIP_TOOLS_VERSION ?= $(shell grep 'PIP_TOOLS_VERSION=' ${WS_ROOT}/test/Makefile | cut -d'=' -f2) |
| 31 | |
| 32 | PYTHON ?= "python3" |
Dave Wallace | 51a037d | 2021-11-06 10:59:22 -0400 | [diff] [blame] | 33 | PYTHON_VERSION_OK := $(shell $(PYTHON) -c "exec('import sys\nif sys.hexversion >= 0x03070000: print(\"true\")\nelse: print(\"false\")')") |
| 34 | ifneq ($(PYTHON_VERSION_OK),true) |
| 35 | $(error "ERROR: docs build requires python version >= to 3.7") |
| 36 | endif |
Paul Vinciguerra | 340c15c | 2019-11-05 15:34:36 -0500 | [diff] [blame] | 37 | |
John DeNisco | 2d1a043 | 2018-07-26 16:21:31 -0400 | [diff] [blame] | 38 | # You can set these variables from the command line. |
Nathan Skrzypczak | 9ad39c0 | 2021-08-19 11:38:06 +0200 | [diff] [blame] | 39 | SPHINXOPTS = --keep-going -n -W |
| 40 | SPHINXBUILD = sphinx-build |
| 41 | SPHINXPROJ = fdio-vpp |
Nathan Skrzypczak | 9ad39c0 | 2021-08-19 11:38:06 +0200 | [diff] [blame] | 42 | BUILDDIR = ${BR}/docs |
| 43 | BUILDDIR_SRC = ${BUILDDIR}/src |
| 44 | BUILDDIR_OUT = ${BUILDDIR}/html |
| 45 | SCRIPTS_DIR = _scripts |
Nathan Skrzypczak | 1e167a4 | 2022-03-25 12:06:51 +0100 | [diff] [blame] | 46 | VENV_DIR ?= $(BUILDDIR)/venv |
Nathan Skrzypczak | 9ad39c0 | 2021-08-19 11:38:06 +0200 | [diff] [blame] | 47 | |
John DeNisco | 2d1a043 | 2018-07-26 16:21:31 -0400 | [diff] [blame] | 48 | |
| 49 | # Put it first so that "make" without argument is like "make help". |
Nathan Skrzypczak | 9ad39c0 | 2021-08-19 11:38:06 +0200 | [diff] [blame] | 50 | .PHONY: help |
John DeNisco | 2d1a043 | 2018-07-26 16:21:31 -0400 | [diff] [blame] | 51 | help: |
Nathan Skrzypczak | 9ad39c0 | 2021-08-19 11:38:06 +0200 | [diff] [blame] | 52 | @( \ |
| 53 | . ${VENV_DIR}/bin/activate; \ |
| 54 | $(SPHINXBUILD) --help ;\ |
| 55 | ) |
John DeNisco | 2d1a043 | 2018-07-26 16:21:31 -0400 | [diff] [blame] | 56 | |
Nathan Skrzypczak | 9ad39c0 | 2021-08-19 11:38:06 +0200 | [diff] [blame] | 57 | .PHONY: venv |
| 58 | venv: |
| 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 Skrzypczak | 1e167a4 | 2022-03-25 12:06:51 +0100 | [diff] [blame] | 69 | .PHONY: spell |
| 70 | spell: venv |
| 71 | @( \ |
| 72 | . ${VENV_DIR}/bin/activate; \ |
| 73 | make -C ${SCRIPTS_DIR} generate && \ |
| 74 | $(SPHINXBUILD) -b spelling $(SPHINXOPTS) $(BUILDDIR_SRC) $(BUILDDIR_OUT); \ |
| 75 | ) |
| 76 | |
| 77 | .PHONY: rebuild-spell |
| 78 | rebuild-spell: clean spell |
Nathan Skrzypczak | 9ad39c0 | 2021-08-19 11:38:06 +0200 | [diff] [blame] | 79 | |
| 80 | .PHONY: docs |
Nathan Skrzypczak | 1e167a4 | 2022-03-25 12:06:51 +0100 | [diff] [blame] | 81 | docs: venv |
Nathan Skrzypczak | 9ad39c0 | 2021-08-19 11:38:06 +0200 | [diff] [blame] | 82 | @( \ |
| 83 | . ${VENV_DIR}/bin/activate; \ |
| 84 | make -C ${SCRIPTS_DIR} generate && \ |
| 85 | $(SPHINXBUILD) $(SPHINXOPTS) -b html $(BUILDDIR_SRC) $(BUILDDIR_OUT); \ |
| 86 | ) |
| 87 | |
Nathan Skrzypczak | 1e167a4 | 2022-03-25 12:06:51 +0100 | [diff] [blame] | 88 | .PHONY: rebuild |
| 89 | rebuild: clean docs |
| 90 | |
Nathan Skrzypczak | 9ad39c0 | 2021-08-19 11:38:06 +0200 | [diff] [blame] | 91 | .PHONY: clean |
| 92 | clean: |
Nathan Skrzypczak | 9ad39c0 | 2021-08-19 11:38:06 +0200 | [diff] [blame] | 93 | @make -C ${SCRIPTS_DIR} clean |
| 94 | |
| 95 | .PHONY: build |
| 96 | build: docs |