| 1 |
# Makefile for Sphinx documentation |
| 2 |
# |
| 3 |
|
| 4 |
# You can set these variables from the command line. |
| 5 |
SPHINXOPTS = -W |
| 6 |
SPHINXBUILD = sphinx-build |
| 7 |
PAPER = |
| 8 |
BUILDDIR = build |
| 9 |
|
| 10 |
# Internal variables. |
| 11 |
PAPEROPT_a4 = -D latex_paper_size=a4 |
| 12 |
PAPEROPT_letter = -D latex_paper_size=letter |
| 13 |
ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source |
| 14 |
# the i18n builder cannot share the environment and doctrees with the others |
| 15 |
I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source |
| 16 |
|
| 17 |
# Fix for when python is mapped to python2 not python3 |
| 18 |
# This is an issue in the sphinx-build script provided in the default install |
| 19 |
# because it uses the generic python env, so we need to have a copy of this script |
| 20 |
# but with an explicit call to python3. |
| 21 |
# |
| 22 |
# Why python3? We are using some features of sphinx that are only implemented |
| 23 |
# currently in python3 |
| 24 |
# |
| 25 |
PYV=$(shell python -c "import sys;t='{v[0]}'.format(v=list(sys.version_info[:2]));sys.stdout.write(t)") |
| 26 |
|
| 27 |
ifeq ($(PYV), 2) |
| 28 |
SPHINXBUILD = ./sphinx-build3 |
| 29 |
endif |
| 30 |
|
| 31 |
.PHONY: all clean templates html devhelp |
| 32 |
|
| 33 |
# Canned recipe for generating plugin api skeletons |
| 34 |
# $1 = the plugin directory |
| 35 |
# $2 = the output docs directory |
| 36 |
# |
| 37 |
# Explanation: |
| 38 |
# |
| 39 |
# Sphinx does not have any option for skipping documentation, |
| 40 |
# we don't want to document plugin code because nobody uses that |
| 41 |
# but we do want to use module-level docstrings in plugins in |
| 42 |
# order to explain how plugins work. |
| 43 |
# |
| 44 |
# For this purpose, we replace sphinx-apidoc with a simple |
| 45 |
# makefile rule which generates a template slightly differently |
| 46 |
# from how sphinx does it, allowing us to get what we want |
| 47 |
# from plugin documentation. |
| 48 |
# |
| 49 |
define plugin-doc-skeleton |
| 50 |
@for file in $$(find ${1}/${2} -name "*.py" ! -name "_*"); do \ |
| 51 |
base=$$(basename $$file); \ |
| 52 |
module=${2}.$${base%.py}; \ |
| 53 |
modname=$${base%.py}; \ |
| 54 |
echo -n "Generating source/${2}/$${modname}.rst... "; \ |
| 55 |
sed -e "s|@@MODULENAME@@|$${modname}|g" \ |
| 56 |
-e "s|@@MODULE@@|$${module}|g" \ |
| 57 |
source/plugin.rsttemplate > \ |
| 58 |
source/${2}/$${modname}.rst.tmp && \ |
| 59 |
mv source/${2}/$${modname}.rst.tmp source/${2}/$${modname}.rst || exit 1; \ |
| 60 |
echo "Done."; \ |
| 61 |
done |
| 62 |
endef |
| 63 |
|
| 64 |
# We set PYTHONPATH here because source/conf.py sys.modules hacks don't seem to help sphinx-build import the plugins |
| 65 |
all: html devhelp |
| 66 |
|
| 67 |
clean: templates-clean |
| 68 |
rm -rf build |
| 69 |
|
| 70 |
# Generate rst templates for the docs using a mix of sphinx-apidoc and |
| 71 |
# our 'plugin-doc-skeleton' routine for plugin pages. |
| 72 |
templates: |
| 73 |
mkdir -p source/elements |
| 74 |
mkdir -p source/sources |
| 75 |
mkdir -p source/sourcemirrors |
| 76 |
$(call plugin-doc-skeleton,$(CURDIR)/../src/buildstream_plugins,elements) |
| 77 |
$(call plugin-doc-skeleton,$(CURDIR)/../src/buildstream_plugins,sources) |
| 78 |
$(call plugin-doc-skeleton,$(CURDIR)/../src/buildstream_plugins,sourcemirrors) |
| 79 |
|
| 80 |
templates-clean: |
| 81 |
rm -rf source/elements |
| 82 |
rm -rf source/sources |
| 83 |
rm -rf source/sourcemirrors |
| 84 |
|
| 85 |
# Targets which generate docs with sphinx build |
| 86 |
# |
| 87 |
# |
| 88 |
html devhelp: templates |
| 89 |
@echo "Building $@..." |
| 90 |
$(SPHINXBUILD) -b $@ $(ALLSPHINXOPTS) "$(BUILDDIR)/$@" \ |
| 91 |
$(wildcard source/*.rst) \ |
| 92 |
$(wildcard source/elements/*.rst) \ |
| 93 |
$(wildcard source/sources/*.rst) \ |
| 94 |
$(wildcard source/sourcemirrors/*.rst) |
| 95 |
@echo |
| 96 |
@echo "Build of $@ finished, output: $(CURDIR)/$(BUILDDIR)/$@" |
| 97 |
|
| 98 |
testy: |
| 99 |
@echo "Using $(SPHINXBUILD)" |
| 100 |
@echo "Py is $(PYV)" |