blob: c37b9ae8a94fca1b4bb93dcaec4b67c3915445ad [file] [log] [blame]
John DeNisco2d1a0432018-07-26 16:21:31 -04001# Minimal makefile for Sphinx documentation
2#
Paul Vinciguerra340c15c2019-11-05 15:34:36 -05003# We support MacOS for docs generation
4ifeq ($(shell uname),Darwin)
5OS_ID = darwin
6endif
7
Nathan Skrzypczak9ad39c02021-08-19 11:38:06 +02008# These should be passed in by the root Makefile
9WS_ROOT ?= $(CURDIR)/..
10BR ?= $(WS_ROOT)/build-root
11DOCS_DIR ?= $(WS_ROOT)/docs
12
13VENV_DIR ?= $(DOCS_DIR)/venv
14SPHINX_SCRIPTS_DIR ?= $(WS_ROOT)/docs/scripts
15
Paul Vinciguerra340c15c2019-11-05 15:34:36 -050016# Work out the OS if we haven't already
17OS_ID ?= $(shell grep '^ID=' /etc/os-release | cut -f2- -d= | sed -e 's/\"//g')
Nathan Skrzypczak9ad39c02021-08-19 11:38:06 +020018OS_VERSION ?= $(shell grep '^VERSION_ID=' /etc/os-release | cut -f2- -d= | sed -e 's/\"//g')
19PIP_VERSION ?= $(shell grep 'PIP_VERSION=' ${WS_ROOT}/test/Makefile | cut -d'=' -f2)
20PIP_TOOLS_VERSION ?= $(shell grep 'PIP_TOOLS_VERSION=' ${WS_ROOT}/test/Makefile | cut -d'=' -f2)
21
22PYTHON ?= "python3"
Paul Vinciguerra340c15c2019-11-05 15:34:36 -050023
John DeNisco2d1a0432018-07-26 16:21:31 -040024# You can set these variables from the command line.
Nathan Skrzypczak9ad39c02021-08-19 11:38:06 +020025SPHINXOPTS = --keep-going -n -W
26SPHINXBUILD = sphinx-build
27SPHINXPROJ = fdio-vpp
28SOURCEDIR = .
29BUILDDIR = ${BR}/docs
30BUILDDIR_SRC = ${BUILDDIR}/src
31BUILDDIR_OUT = ${BUILDDIR}/html
32SCRIPTS_DIR = _scripts
33
John DeNisco2d1a0432018-07-26 16:21:31 -040034
35# Put it first so that "make" without argument is like "make help".
Nathan Skrzypczak9ad39c02021-08-19 11:38:06 +020036.PHONY: help
John DeNisco2d1a0432018-07-26 16:21:31 -040037help:
Nathan Skrzypczak9ad39c02021-08-19 11:38:06 +020038 @( \
39 . ${VENV_DIR}/bin/activate; \
40 $(SPHINXBUILD) --help ;\
41 )
John DeNisco2d1a0432018-07-26 16:21:31 -040042
Nathan Skrzypczak9ad39c02021-08-19 11:38:06 +020043.PHONY: checkdeps
44checkdeps:
Paul Vinciguerra340c15c2019-11-05 15:34:36 -050045 @echo "Checking whether dependencies for Docs are installed..."
46ifeq ($(OS_ID),ubuntu)
47 @set -e; inst=; \
48 for i in $(DOC_DEB_DEPENDS); do \
49 dpkg-query --show $$i >/dev/null 2>&1 || inst="$$inst $$i"; \
50 done; \
51 if [ "$$inst" ]; then \
52 sudo apt-get update; \
53 sudo apt-get $(CONFIRM) $(FORCE) install $$inst; \
54 fi
55else ifneq ("$(wildcard /etc/redhat-release)","")
56 @sudo yum install $(CONFIRM) $(DOC_RPM_DEPENDS)
57endif
Nathan Skrzypczak9ad39c02021-08-19 11:38:06 +020058
59.PHONY: spell
60spell: clean checkdeps venv ${BUILDDIR_SRC}
61 @( \
62 . ${VENV_DIR}/bin/activate; \
63 make -C ${SCRIPTS_DIR} generate && \
64 $(SPHINXBUILD) -b spelling $(SPHINXOPTS) $(BUILDDIR_SRC) $(BUILDDIR_OUT); \
65 )
66
67.PHONY: venv
68venv:
69 @( \
70 if [ ! -d ${VENV_DIR} ]; then \
71 ${PYTHON} -m venv ${VENV_DIR}; \
72 . ${VENV_DIR}/bin/activate; \
73 ${PYTHON} -m pip install pip==${PIP_VERSION}; \
74 ${PYTHON} -m pip install pip-tools==${PIP_TOOLS_VERSION}; \
75 ${PYTHON} -m pip install -r ${WS_ROOT}/test/requirements-3.txt; \
76 fi; \
77 )
78
79${BUILDDIR_SRC}:
80 @mkdir -p ${BUILDDIR_SRC}
81 @cp -r $(SOURCEDIR) ${BUILDDIR_SRC}
82 @cd ${BUILDDIR_SRC} && find . -type l -exec cp --remove-destination -L ${DOCS_DIR}/{} {} \;
83
84.PHONY: docs
85docs: clean venv ${BUILDDIR_SRC}
86 @( \
87 . ${VENV_DIR}/bin/activate; \
88 make -C ${SCRIPTS_DIR} generate && \
89 $(SPHINXBUILD) $(SPHINXOPTS) -b html $(BUILDDIR_SRC) $(BUILDDIR_OUT); \
90 )
91
92.PHONY: clean
93clean:
Dave Wallace78b4f4e2021-10-30 15:30:38 -040094 @rm -rf $(BUILDDIR) ${VENV_DIR}
Nathan Skrzypczak9ad39c02021-08-19 11:38:06 +020095 @make -C ${SCRIPTS_DIR} clean
96
97.PHONY: build
98build: docs
99