Debian Codegraph @

doc/Makefile

raw
1 # Makefile for Sphinx documentation
2 #
3
4 # Note, due to a problem with python2/python3 parallel
5 # installability of sphinx (https://github.com/sphinx-doc/sphinx/issues/4375)
6 # we dont use the standard `sphinx-build` and `sphinx-apidoc` entry points.
7 #
8 # The following technique works as long as sphinx is installed for python3,
9 # regardless of the entry point which might be in /usr/bin or PATH.
10 #
11 # Since Sphinx 2.0 is planned to be Python 3-only, this workaround should not
12 # be needed once Spinx 2.0 is released, and we upgrade to it
13 #
14 SPHINXOPTS =
15 SPHINXBUILD = python3 -m sphinx
16 SPHINXAPIDOC = python3 -m sphinx.ext.apidoc
17 PAPER =
18 BUILDDIR = build
19
20 # Internal variables.
21 PAPEROPT_a4 = -D latex_paper_size=a4
22 PAPEROPT_letter = -D latex_paper_size=letter
23 ALLSPHINXOPTS = -W -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source
24 # the i18n builder cannot share the environment and doctrees with the others
25 I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source
26
27 # Set BST_FORCE_SESSION_REBUILD to force rebuild the docs
28 BST2HTML = $(CURDIR)/bst2html.py
29 BST2HTMLOPTS =
30 ifneq ($(strip $(BST_FORCE_SESSION_REBUILD)),)
31 BST2HTMLOPTS = --force
32 endif
33
34 # Help Python find buildstream and its plugins
35 PYTHONPATH=$(CURDIR)/..:$(CURDIR)/../src/buildstream/plugins
36
37
38 .PHONY: all clean templates templates-clean sessions sessions-prep sessions-clean badges badges-clean html devhelp
39
40 # Canned recipe for generating plugin api skeletons
41 # $1 = the plugin directory
42 # $2 = the output docs directory
43 #
44 # Explanation:
45 #
46 # Sphinx does not have any option for skipping documentation,
47 # we dont want to document plugin code because nobody uses that
48 # but we do want to use module-level docstrings in plugins in
49 # order to explain how plugins work.
50 #
51 # For this purpose, we replace sphinx-apidoc with a simple
52 # makefile rule which generates a template slightly differently
53 # from how sphinx does it, allowing us to get what we want
54 # from plugin documentation.
55 #
56 define plugin-doc-skeleton
57 @for file in $$(find ${1} -name "*.py" ! -name "_*.py"); do \
58 base=$$(basename $$file); \
59 module=${2}.$${base%.py}; \
60 modname=$${base%.py}; \
61 echo -n "Generating source/${2}/$${modname}.rst... "; \
62 sed -e "s|@@MODULE@@|$${module}|g" \
63 source/plugin.rsttemplate > \
64 source/${2}/$${modname}.rst.tmp && \
65 mv source/${2}/$${modname}.rst.tmp source/${2}/$${modname}.rst || exit 1; \
66 echo "Done."; \
67 done
68 endef
69
70
71 all: html devhelp
72
73 clean: templates-clean sessions-clean badges-clean
74 rm -rf build
75
76 ############################################################
77 # Plugin doc templates #
78 ############################################################
79
80 # Generate rst templates for the docs using a mix of sphinx-apidoc and
81 # our 'plugin-doc-skeleton' routine for plugin pages.
82 templates:
83 mkdir -p source/elements
84 mkdir -p source/sources
85 $(SPHINXAPIDOC) --force --separate --module-first --no-headings --no-toc -o source $(CURDIR)/../src/buildstream *_pb2*.py
86 $(call plugin-doc-skeleton,$(CURDIR)/../src/buildstream/plugins/elements,elements)
87 $(call plugin-doc-skeleton,$(CURDIR)/../src/buildstream/plugins/sources,sources)
88
89 templates-clean:
90 rm -rf source/elements
91 rm -rf source/sources
92
93 ############################################################
94 # Session captures #
95 ############################################################
96
97 # Stage the stored sessions into the place where they will
98 # be used in the build.
99 #
100 # This is separated so that the git tree does not become
101 # dirty as a result of a documentation build process - which
102 # messes up the docs version number and the version number
103 # printed in some command line output.
104 #
105 sessions-prep:
106 mkdir -p source/sessions
107 cp source/sessions-stored/*.html source/sessions
108
109 # bst2html is called unconditionally for every session file in SESSION_FILES.
110 #
111 # By default, this will generate the html fragments of colorized BuildStream terminal
112 # output only if the output html files don't yet exist.
113 #
114 # Specify BST_FORCE_SESSION_REBUILD=1 to force rebuild all session html files.
115 #
116 SESSION_FILES=$(wildcard sessions/*.run)
117 $(SESSION_FILES): sessions-prep
118
119 %.run:
120 PYTHONPATH=$(PYTHONPATH) $(BST2HTML) $(BST2HTMLOPTS) $@
121
122 sessions: $(SESSION_FILES)
123
124 sessions-clean:
125 rm -rf source/sessions
126
127
128 ############################################################
129 # Generate release badges and their redirecting html pages #
130 ############################################################
131 badges-clean:
132 rm -rf source/badges
133
134 badges:
135 mkdir -p source/badges
136 $(CURDIR)/badges.py > source/badges/release.svg
137 $(CURDIR)/badges.py --redirect > source/badges/release.html
138
139
140 ############################################################
141 # Main sphinx build #
142 ############################################################
143
144 # Targets which generate docs with sphinx build
145 #
146 #
147 html devhelp: templates sessions badges
148 @echo "Building $@..."
149 PYTHONPATH=$(PYTHONPATH) \
150 $(SPHINXBUILD) -b $@ $(ALLSPHINXOPTS) "$(BUILDDIR)/$@" \
151 $(wildcard source/*.rst) \
152 $(wildcard source/tutorial/*.rst) \
153 $(wildcard source/developing/*.rst) \
154 $(wildcard source/handling-files/*.rst) \
155 $(wildcard source/junctions/*.rst) \
156 $(wildcard source/examples/*.rst) \
157 $(wildcard source/elements/*.rst) \
158 $(wildcard source/sources/*.rst) \
159 $(wildcard source/hacking/*.rst)
160 @echo
161 @echo "Build of $@ finished, output: $(CURDIR)/$(BUILDDIR)/$@"
162 # Makefile for Sphinx documentation
163 #