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 | |
| 24 | VENV_DIR ?= $(DOCS_DIR)/venv |
| 25 | SPHINX_SCRIPTS_DIR ?= $(WS_ROOT)/docs/scripts |
| 26 | |
Paul Vinciguerra | 340c15c | 2019-11-05 15:34:36 -0500 | [diff] [blame] | 27 | # Work out the OS if we haven't already |
| 28 | 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] | 29 | OS_VERSION ?= $(shell grep '^VERSION_ID=' /etc/os-release | cut -f2- -d= | sed -e 's/\"//g') |
| 30 | PIP_VERSION ?= $(shell grep 'PIP_VERSION=' ${WS_ROOT}/test/Makefile | cut -d'=' -f2) |
| 31 | PIP_TOOLS_VERSION ?= $(shell grep 'PIP_TOOLS_VERSION=' ${WS_ROOT}/test/Makefile | cut -d'=' -f2) |
| 32 | |
| 33 | PYTHON ?= "python3" |
Dave Wallace | 51a037d | 2021-11-06 10:59:22 -0400 | [diff] [blame] | 34 | PYTHON_VERSION_OK := $(shell $(PYTHON) -c "exec('import sys\nif sys.hexversion >= 0x03070000: print(\"true\")\nelse: print(\"false\")')") |
| 35 | ifneq ($(PYTHON_VERSION_OK),true) |
| 36 | $(error "ERROR: docs build requires python version >= to 3.7") |
| 37 | endif |
Paul Vinciguerra | 340c15c | 2019-11-05 15:34:36 -0500 | [diff] [blame] | 38 | |
John DeNisco | 2d1a043 | 2018-07-26 16:21:31 -0400 | [diff] [blame] | 39 | # You can set these variables from the command line. |
Nathan Skrzypczak | 9ad39c0 | 2021-08-19 11:38:06 +0200 | [diff] [blame] | 40 | SPHINXOPTS = --keep-going -n -W |
| 41 | SPHINXBUILD = sphinx-build |
| 42 | SPHINXPROJ = fdio-vpp |
| 43 | SOURCEDIR = . |
| 44 | BUILDDIR = ${BR}/docs |
| 45 | BUILDDIR_SRC = ${BUILDDIR}/src |
| 46 | BUILDDIR_OUT = ${BUILDDIR}/html |
| 47 | SCRIPTS_DIR = _scripts |
| 48 | |
John DeNisco | 2d1a043 | 2018-07-26 16:21:31 -0400 | [diff] [blame] | 49 | |
| 50 | # Put it first so that "make" without argument is like "make help". |
Nathan Skrzypczak | 9ad39c0 | 2021-08-19 11:38:06 +0200 | [diff] [blame] | 51 | .PHONY: help |
John DeNisco | 2d1a043 | 2018-07-26 16:21:31 -0400 | [diff] [blame] | 52 | help: |
Nathan Skrzypczak | 9ad39c0 | 2021-08-19 11:38:06 +0200 | [diff] [blame] | 53 | @( \ |
| 54 | . ${VENV_DIR}/bin/activate; \ |
| 55 | $(SPHINXBUILD) --help ;\ |
| 56 | ) |
John DeNisco | 2d1a043 | 2018-07-26 16:21:31 -0400 | [diff] [blame] | 57 | |
Nathan Skrzypczak | 9ad39c0 | 2021-08-19 11:38:06 +0200 | [diff] [blame] | 58 | .PHONY: checkdeps |
| 59 | checkdeps: |
Paul Vinciguerra | 340c15c | 2019-11-05 15:34:36 -0500 | [diff] [blame] | 60 | @echo "Checking whether dependencies for Docs are installed..." |
| 61 | ifeq ($(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 Vinciguerra | 340c15c | 2019-11-05 15:34:36 -0500 | [diff] [blame] | 70 | endif |
Nathan Skrzypczak | 9ad39c0 | 2021-08-19 11:38:06 +0200 | [diff] [blame] | 71 | |
| 72 | .PHONY: spell |
| 73 | spell: 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 |
| 81 | venv: |
| 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 |
| 98 | docs: 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 |
| 106 | clean: |
Dave Wallace | 78b4f4e | 2021-10-30 15:30:38 -0400 | [diff] [blame] | 107 | @rm -rf $(BUILDDIR) ${VENV_DIR} |
Nathan Skrzypczak | 9ad39c0 | 2021-08-19 11:38:06 +0200 | [diff] [blame] | 108 | @make -C ${SCRIPTS_DIR} clean |
| 109 | |
| 110 | .PHONY: build |
| 111 | build: docs |