Skip to content

Commit 22cba31

Browse files
committed
Documentation/sphinx: add basic working Sphinx configuration and build
Add basic configuration and makefile to build documentation from any .rst files under Documentation using Sphinx. For starters, there's just the placeholder index.rst. At the top level Makefile, hook Sphinx documentation targets alongside (but independent of) the DocBook toolchain, having both be run on the various 'make *docs' targets. All Sphinx processing is placed into Documentation/Makefile.sphinx. Both that and the Documentation/DocBook/Makefile are now expected to handle all the documentation targets, explicitly ignoring them if they're not relevant for that particular toolchain. The changes to the existing DocBook Makefile are kept minimal. There is graceful handling of missing Sphinx and rst2pdf (which is needed for pdf output) by checking for the tool and python module, respectively, with informative messages to the user. If the Read the Docs theme (sphinx_rtd_theme) is available, use it, but otherwise gracefully fall back to the Sphinx default theme, with an informative message to the user, and slightly less pretty HTML output. Sphinx can now handle htmldocs, pdfdocs (if rst2pdf is available), epubdocs and xmldocs targets. The output documents are written into per output type subdirectories under Documentation/output. Finally, you can pass options to sphinx-build using the SPHINXBUILD make variable. For example, 'make SPHINXOPTS=-v htmldocs' for more verbose output from Sphinx. This is based on the original work by Jonathan Corbet, but he probably wouldn't recognize this as his own anymore. Signed-off-by: Jani Nikula <[email protected]>
1 parent 86ae2e3 commit 22cba31

File tree

5 files changed

+478
-5
lines changed

5 files changed

+478
-5
lines changed

Documentation/DocBook/Makefile

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,6 @@ PDF_METHOD = $(prefer-db2x)
3333
PS_METHOD = $(prefer-db2x)
3434

3535

36-
###
37-
# The targets that may be used.
38-
PHONY += xmldocs sgmldocs psdocs pdfdocs htmldocs mandocs installmandocs cleandocs
39-
4036
targets += $(DOCBOOKS)
4137
BOOKS := $(addprefix $(obj)/,$(DOCBOOKS))
4238
xmldocs: $(BOOKS)
@@ -63,6 +59,9 @@ installmandocs: mandocs
6359
sort -k 2 -k 1 | uniq -f 1 | sed -e 's: :/:' | \
6460
xargs install -m 644 -t /usr/local/man/man9/
6561

62+
# no-op for the DocBook toolchain
63+
epubdocs:
64+
6665
###
6766
#External programs used
6867
KERNELDOCXMLREF = $(srctree)/scripts/kernel-doc-xml-ref

Documentation/Makefile.sphinx

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# -*- makefile -*-
2+
# Makefile for Sphinx documentation
3+
#
4+
5+
# You can set these variables from the command line.
6+
SPHINXBUILD = sphinx-build
7+
SPHINXOPTS =
8+
PAPER =
9+
BUILDDIR = $(obj)/output
10+
11+
# User-friendly check for sphinx-build
12+
HAVE_SPHINX := $(shell if which $(SPHINXBUILD) >/dev/null 2>&1; then echo 1; else echo 0; fi)
13+
14+
ifeq ($(HAVE_SPHINX),0)
15+
16+
.DEFAULT:
17+
$(warning The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed and in PATH, or set the SPHINXBUILD make variable to point to the full path of the '$(SPHINXBUILD)' executable.)
18+
@echo " SKIP Sphinx $@ target."
19+
20+
else # HAVE_SPHINX
21+
22+
# User-friendly check for rst2pdf
23+
HAVE_RST2PDF := $(shell if python -c "import rst2pdf" >/dev/null 2>&1; then echo 1; else echo 0; fi)
24+
25+
# Internal variables.
26+
PAPEROPT_a4 = -D latex_paper_size=a4
27+
PAPEROPT_letter = -D latex_paper_size=letter
28+
ALLSPHINXOPTS = -d $(BUILDDIR)/.doctrees $(PAPEROPT_$(PAPER)) -c $(srctree)/$(src) $(SPHINXOPTS) $(srctree)/$(src)
29+
# the i18n builder cannot share the environment and doctrees with the others
30+
I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
31+
32+
quiet_cmd_sphinx = SPHINX $@
33+
cmd_sphinx = $(SPHINXBUILD) -b $2 $(ALLSPHINXOPTS) $(BUILDDIR)/$2
34+
35+
htmldocs:
36+
$(call cmd,sphinx,html)
37+
38+
pdfdocs:
39+
ifeq ($(HAVE_RST2PDF),0)
40+
$(warning The Python 'rst2pdf' module was not found. Make sure you have the module installed to produce PDF output.)
41+
@echo " SKIP Sphinx $@ target."
42+
else # HAVE_RST2PDF
43+
$(call cmd,sphinx,pdf)
44+
endif # HAVE_RST2PDF
45+
46+
epubdocs:
47+
$(call cmd,sphinx,epub)
48+
49+
xmldocs:
50+
$(call cmd,sphinx,xml)
51+
52+
# no-ops for the Sphinx toolchain
53+
sgmldocs:
54+
psdocs:
55+
mandocs:
56+
installmandocs:
57+
58+
cleandocs:
59+
$(Q)rm -rf $(BUILDDIR)
60+
61+
endif # HAVE_SPHINX

0 commit comments

Comments
 (0)