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 |
| 70 | else ifneq ("$(wildcard /etc/redhat-release)","") |
| 71 | @sudo yum install $(CONFIRM) $(DOC_RPM_DEPENDS) |
| 72 | endif |
Nathan Skrzypczak | 9ad39c0 | 2021-08-19 11:38:06 +0200 | [diff] [blame] | 73 | |
| 74 | .PHONY: spell |
| 75 | spell: 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 |
| 83 | venv: |
| 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 |
| 100 | docs: 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 |
| 108 | clean: |
Dave Wallace | 78b4f4e | 2021-10-30 15:30:38 -0400 | [diff] [blame] | 109 | @rm -rf $(BUILDDIR) ${VENV_DIR} |
Nathan Skrzypczak | 9ad39c0 | 2021-08-19 11:38:06 +0200 | [diff] [blame] | 110 | @make -C ${SCRIPTS_DIR} clean |
| 111 | |
| 112 | .PHONY: build |
| 113 | build: docs |