blob: ca4a3acdb9c27d1bd167f0d767f92ddaa22a3cdc [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
Paul Vinciguerraa26f5442020-03-11 13:28:27 -040024DOC_DEB_DEPENDS = enchant
25DOC_RPM_DEPENDS = enchant
John DeNisco2d1a0432018-07-26 16:21:31 -040026
27# You can set these variables from the command line.
Nathan Skrzypczak9ad39c02021-08-19 11:38:06 +020028SPHINXOPTS = --keep-going -n -W
29SPHINXBUILD = sphinx-build
30SPHINXPROJ = fdio-vpp
31SOURCEDIR = .
32BUILDDIR = ${BR}/docs
33BUILDDIR_SRC = ${BUILDDIR}/src
34BUILDDIR_OUT = ${BUILDDIR}/html
35SCRIPTS_DIR = _scripts
36
John DeNisco2d1a0432018-07-26 16:21:31 -040037
38# Put it first so that "make" without argument is like "make help".
Nathan Skrzypczak9ad39c02021-08-19 11:38:06 +020039.PHONY: help
John DeNisco2d1a0432018-07-26 16:21:31 -040040help:
Nathan Skrzypczak9ad39c02021-08-19 11:38:06 +020041 @( \
42 . ${VENV_DIR}/bin/activate; \
43 $(SPHINXBUILD) --help ;\
44 )
John DeNisco2d1a0432018-07-26 16:21:31 -040045
Nathan Skrzypczak9ad39c02021-08-19 11:38:06 +020046.PHONY: checkdeps
47checkdeps:
Paul Vinciguerra340c15c2019-11-05 15:34:36 -050048 @echo "Checking whether dependencies for Docs are installed..."
49ifeq ($(OS_ID),ubuntu)
50 @set -e; inst=; \
51 for i in $(DOC_DEB_DEPENDS); do \
52 dpkg-query --show $$i >/dev/null 2>&1 || inst="$$inst $$i"; \
53 done; \
54 if [ "$$inst" ]; then \
55 sudo apt-get update; \
56 sudo apt-get $(CONFIRM) $(FORCE) install $$inst; \
57 fi
58else ifneq ("$(wildcard /etc/redhat-release)","")
59 @sudo yum install $(CONFIRM) $(DOC_RPM_DEPENDS)
60endif
Nathan Skrzypczak9ad39c02021-08-19 11:38:06 +020061
62.PHONY: spell
63spell: clean checkdeps venv ${BUILDDIR_SRC}
64 @( \
65 . ${VENV_DIR}/bin/activate; \
66 make -C ${SCRIPTS_DIR} generate && \
67 $(SPHINXBUILD) -b spelling $(SPHINXOPTS) $(BUILDDIR_SRC) $(BUILDDIR_OUT); \
68 )
69
70.PHONY: venv
71venv:
72 @( \
73 if [ ! -d ${VENV_DIR} ]; then \
74 ${PYTHON} -m venv ${VENV_DIR}; \
75 . ${VENV_DIR}/bin/activate; \
76 ${PYTHON} -m pip install pip==${PIP_VERSION}; \
77 ${PYTHON} -m pip install pip-tools==${PIP_TOOLS_VERSION}; \
78 ${PYTHON} -m pip install -r ${WS_ROOT}/test/requirements-3.txt; \
79 fi; \
80 )
81
82${BUILDDIR_SRC}:
83 @mkdir -p ${BUILDDIR_SRC}
84 @cp -r $(SOURCEDIR) ${BUILDDIR_SRC}
85 @cd ${BUILDDIR_SRC} && find . -type l -exec cp --remove-destination -L ${DOCS_DIR}/{} {} \;
86
87.PHONY: docs
88docs: clean venv ${BUILDDIR_SRC}
89 @( \
90 . ${VENV_DIR}/bin/activate; \
91 make -C ${SCRIPTS_DIR} generate && \
92 $(SPHINXBUILD) $(SPHINXOPTS) -b html $(BUILDDIR_SRC) $(BUILDDIR_OUT); \
93 )
94
95.PHONY: clean
96clean:
97 @rm -rf $(BUILDDIR)
98 @make -C ${SCRIPTS_DIR} clean
99
100.PHONY: build
101build: docs
102