diff options
author | Markus Heiser <markus.heiser@darmarIT.de> | 2016-08-13 10:12:42 -0400 |
---|---|---|
committer | Jonathan Corbet <corbet@lwn.net> | 2016-08-14 13:51:51 -0400 |
commit | 606b9ac81a63ab3adb7e61206b9ae34ee186a89d (patch) | |
tree | 8ff0fcf5ec5d762a0ad7fc7e05fbbeb8d17f6801 | |
parent | 3eb6cd6834c356f40e1633a0ced4ff9a4c59936b (diff) |
doc-rst: generic way to build only sphinx sub-folders
Add a generic way to build only a reST sub-folder with or
without a individual *build-theme*.
* control *sub-folders* by environment SPHINXDIRS
* control *build-theme* by environment SPHINX_CONF
Folders with a conf.py file, matching $(srctree)/Documentation/*/conf.py
can be build and distributed *stand-alone*. E.g. to compile only the
html of 'media' and 'gpu' folder use::
make SPHINXDIRS="media gpu" htmldocs
To use an additional sphinx-build configuration (*build-theme*) set the
name of the configuration file to SPHINX_CONF. E.g. to compile only the
html of 'media' with the *nit-picking* build use::
make SPHINXDIRS=media SPHINX_CONF=conf_nitpick.py htmldocs
With this, the Documentation/conf.py is read first and updated with the
configuration values from the Documentation/media/conf_nitpick.py.
Signed-off-by: Markus Heiser <markus.heiser@darmarIT.de>
Signed-off-by: Jonathan Corbet <corbet@lwn.net>
-rw-r--r-- | Documentation/DocBook/Makefile | 7 | ||||
-rw-r--r-- | Documentation/Makefile.sphinx | 43 | ||||
-rw-r--r-- | Documentation/conf.py | 7 | ||||
-rw-r--r-- | Documentation/sphinx/load_config.py | 32 |
4 files changed, 82 insertions, 7 deletions
diff --git a/Documentation/DocBook/Makefile b/Documentation/DocBook/Makefile index 64460a897f56..a91c96522379 100644 --- a/Documentation/DocBook/Makefile +++ b/Documentation/DocBook/Makefile | |||
@@ -22,9 +22,15 @@ ifeq ($(DOCBOOKS),) | |||
22 | # Skip DocBook build if the user explicitly requested no DOCBOOKS. | 22 | # Skip DocBook build if the user explicitly requested no DOCBOOKS. |
23 | .DEFAULT: | 23 | .DEFAULT: |
24 | @echo " SKIP DocBook $@ target (DOCBOOKS=\"\" specified)." | 24 | @echo " SKIP DocBook $@ target (DOCBOOKS=\"\" specified)." |
25 | else | ||
26 | ifneq ($(SPHINXDIRS),) | ||
25 | 27 | ||
28 | # Skip DocBook build if the user explicitly requested a sphinx dir | ||
29 | .DEFAULT: | ||
30 | @echo " SKIP DocBook $@ target (SPHINXDIRS specified)." | ||
26 | else | 31 | else |
27 | 32 | ||
33 | |||
28 | ### | 34 | ### |
29 | # The build process is as follows (targets): | 35 | # The build process is as follows (targets): |
30 | # (xmldocs) [by docproc] | 36 | # (xmldocs) [by docproc] |
@@ -221,6 +227,7 @@ silent_gen_xml = : | |||
221 | echo "</programlisting>") > $@ | 227 | echo "</programlisting>") > $@ |
222 | 228 | ||
223 | endif # DOCBOOKS="" | 229 | endif # DOCBOOKS="" |
230 | endif # SPHINDIR=... | ||
224 | 231 | ||
225 | ### | 232 | ### |
226 | # Help targets as used by the top-level makefile | 233 | # Help targets as used by the top-level makefile |
diff --git a/Documentation/Makefile.sphinx b/Documentation/Makefile.sphinx index fc29e08085aa..ea0664cece12 100644 --- a/Documentation/Makefile.sphinx +++ b/Documentation/Makefile.sphinx | |||
@@ -5,6 +5,9 @@ | |||
5 | # You can set these variables from the command line. | 5 | # You can set these variables from the command line. |
6 | SPHINXBUILD = sphinx-build | 6 | SPHINXBUILD = sphinx-build |
7 | SPHINXOPTS = | 7 | SPHINXOPTS = |
8 | SPHINXDIRS = . | ||
9 | _SPHINXDIRS = $(patsubst $(srctree)/Documentation/%/conf.py,%,$(wildcard $(srctree)/Documentation/*/conf.py)) | ||
10 | SPHINX_CONF = conf.py | ||
8 | PAPER = | 11 | PAPER = |
9 | BUILDDIR = $(obj)/output | 12 | BUILDDIR = $(obj)/output |
10 | 13 | ||
@@ -33,30 +36,50 @@ PAPEROPT_a4 = -D latex_paper_size=a4 | |||
33 | PAPEROPT_letter = -D latex_paper_size=letter | 36 | PAPEROPT_letter = -D latex_paper_size=letter |
34 | KERNELDOC = $(srctree)/scripts/kernel-doc | 37 | KERNELDOC = $(srctree)/scripts/kernel-doc |
35 | KERNELDOC_CONF = -D kerneldoc_srctree=$(srctree) -D kerneldoc_bin=$(KERNELDOC) | 38 | KERNELDOC_CONF = -D kerneldoc_srctree=$(srctree) -D kerneldoc_bin=$(KERNELDOC) |
36 | ALLSPHINXOPTS = -D version=$(KERNELVERSION) -D release=$(KERNELRELEASE) -d $(BUILDDIR)/.doctrees $(KERNELDOC_CONF) $(PAPEROPT_$(PAPER)) -c $(srctree)/$(src) $(SPHINXOPTS) $(srctree)/$(src) | 39 | ALLSPHINXOPTS = $(KERNELDOC_CONF) $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) |
37 | # the i18n builder cannot share the environment and doctrees with the others | 40 | # the i18n builder cannot share the environment and doctrees with the others |
38 | I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . | 41 | I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . |
39 | 42 | ||
40 | quiet_cmd_sphinx = SPHINX $@ | 43 | # commands; the 'cmd' from scripts/Kbuild.include is not *loopable* |
41 | cmd_sphinx = $(MAKE) BUILDDIR=$(BUILDDIR) $(build)=Documentation/media all; BUILDDIR=$(BUILDDIR) $(SPHINXBUILD) -b $2 $(ALLSPHINXOPTS) $(BUILDDIR)/$2 | 44 | loop_cmd = $(echo-cmd) $(cmd_$(1)) |
45 | |||
46 | # $2 sphinx builder e.g. "html" | ||
47 | # $3 name of the build subfolder / e.g. "media", used as: | ||
48 | # * dest folder relative to $(BUILDDIR) and | ||
49 | # * cache folder relative to $(BUILDDIR)/.doctrees | ||
50 | # $4 dest subfolder e.g. "man" for man pages at media/man | ||
51 | # $5 reST source folder relative to $(srctree)/$(src), | ||
52 | # e.g. "media" for the linux-tv book-set at ./Documentation/media | ||
53 | |||
54 | quiet_cmd_sphinx = SPHINX $@ --> file://$(abspath $(BUILDDIR)/$3/$4); | ||
55 | cmd_sphinx = $(MAKE) BUILDDIR=$(abspath $(BUILDDIR)) $(build)=Documentation/media all;\ | ||
56 | BUILDDIR=$(abspath $(BUILDDIR)) SPHINX_CONF=$(abspath $(srctree)/$(src)/$5/$(SPHINX_CONF)) \ | ||
57 | $(SPHINXBUILD) \ | ||
58 | -b $2 \ | ||
59 | -c $(abspath $(srctree)/$(src)) \ | ||
60 | -d $(abspath $(BUILDDIR)/.doctrees/$3) \ | ||
61 | -D version=$(KERNELVERSION) -D release=$(KERNELRELEASE) \ | ||
62 | $(ALLSPHINXOPTS) \ | ||
63 | $(abspath $(srctree)/$(src)/$5) \ | ||
64 | $(abspath $(BUILDDIR)/$3/$4); | ||
42 | 65 | ||
43 | htmldocs: | 66 | htmldocs: |
44 | $(call cmd,sphinx,html) | 67 | @$(foreach var,$(SPHINXDIRS),$(call loop_cmd,sphinx,html,$(var),,$(var))) |
45 | 68 | ||
46 | pdfdocs: | 69 | pdfdocs: |
47 | ifeq ($(HAVE_PDFLATEX),0) | 70 | ifeq ($(HAVE_PDFLATEX),0) |
48 | $(warning The 'pdflatex' command was not found. Make sure you have it installed and in PATH to produce PDF output.) | 71 | $(warning The 'pdflatex' command was not found. Make sure you have it installed and in PATH to produce PDF output.) |
49 | @echo " SKIP Sphinx $@ target." | 72 | @echo " SKIP Sphinx $@ target." |
50 | else # HAVE_PDFLATEX | 73 | else # HAVE_PDFLATEX |
51 | $(call cmd,sphinx,latex) | 74 | @$(call loop_cmd,sphinx,latex,.,latex,.)) |
52 | $(Q)$(MAKE) -C $(BUILDDIR)/latex | 75 | $(Q)$(MAKE) -C $(BUILDDIR)/latex |
53 | endif # HAVE_PDFLATEX | 76 | endif # HAVE_PDFLATEX |
54 | 77 | ||
55 | epubdocs: | 78 | epubdocs: |
56 | $(call cmd,sphinx,epub) | 79 | @$(foreach var,$(SPHINXDIRS),$(call loop_cmd,sphinx,epub,$(var),epub,$(var))) |
57 | 80 | ||
58 | xmldocs: | 81 | xmldocs: |
59 | $(call cmd,sphinx,xml) | 82 | @$(foreach var,$(SPHINXDIRS),$(call loop_cmd,sphinx,xml,$(var),xml,$(var))) |
60 | 83 | ||
61 | # no-ops for the Sphinx toolchain | 84 | # no-ops for the Sphinx toolchain |
62 | sgmldocs: | 85 | sgmldocs: |
@@ -76,3 +99,9 @@ dochelp: | |||
76 | @echo ' epubdocs - EPUB' | 99 | @echo ' epubdocs - EPUB' |
77 | @echo ' xmldocs - XML' | 100 | @echo ' xmldocs - XML' |
78 | @echo ' cleandocs - clean all generated files' | 101 | @echo ' cleandocs - clean all generated files' |
102 | @echo | ||
103 | @echo ' make SPHINXDIRS="s1 s2" [target] Generate only docs of folder s1, s2' | ||
104 | @echo ' valid values for SPHINXDIRS are: $(_SPHINXDIRS)' | ||
105 | @echo | ||
106 | @echo ' make SPHINX_CONF={conf-file} [target] use *additional* sphinx-build' | ||
107 | @echo ' configuration. This is e.g. useful to build with nit-picking config.' | ||
diff --git a/Documentation/conf.py b/Documentation/conf.py index 827dafc515b1..43e41ed74584 100644 --- a/Documentation/conf.py +++ b/Documentation/conf.py | |||
@@ -19,6 +19,7 @@ import os | |||
19 | # add these directories to sys.path here. If the directory is relative to the | 19 | # add these directories to sys.path here. If the directory is relative to the |
20 | # documentation root, use os.path.abspath to make it absolute, like shown here. | 20 | # documentation root, use os.path.abspath to make it absolute, like shown here. |
21 | sys.path.insert(0, os.path.abspath('sphinx')) | 21 | sys.path.insert(0, os.path.abspath('sphinx')) |
22 | from load_config import loadConfig | ||
22 | 23 | ||
23 | # -- General configuration ------------------------------------------------ | 24 | # -- General configuration ------------------------------------------------ |
24 | 25 | ||
@@ -421,3 +422,9 @@ pdf_documents = [ | |||
421 | # line arguments. | 422 | # line arguments. |
422 | kerneldoc_bin = '../scripts/kernel-doc' | 423 | kerneldoc_bin = '../scripts/kernel-doc' |
423 | kerneldoc_srctree = '..' | 424 | kerneldoc_srctree = '..' |
425 | |||
426 | # ------------------------------------------------------------------------------ | ||
427 | # Since loadConfig overwrites settings from the global namespace, it has to be | ||
428 | # the last statement in the conf.py file | ||
429 | # ------------------------------------------------------------------------------ | ||
430 | loadConfig(globals()) | ||
diff --git a/Documentation/sphinx/load_config.py b/Documentation/sphinx/load_config.py new file mode 100644 index 000000000000..301a21aa4f63 --- /dev/null +++ b/Documentation/sphinx/load_config.py | |||
@@ -0,0 +1,32 @@ | |||
1 | # -*- coding: utf-8; mode: python -*- | ||
2 | # pylint: disable=R0903, C0330, R0914, R0912, E0401 | ||
3 | |||
4 | import os | ||
5 | import sys | ||
6 | from sphinx.util.pycompat import execfile_ | ||
7 | |||
8 | # ------------------------------------------------------------------------------ | ||
9 | def loadConfig(namespace): | ||
10 | # ------------------------------------------------------------------------------ | ||
11 | |||
12 | u"""Load an additional configuration file into *namespace*. | ||
13 | |||
14 | The name of the configuration file is taken from the environment | ||
15 | ``SPHINX_CONF``. The external configuration file extends (or overwrites) the | ||
16 | configuration values from the origin ``conf.py``. With this you are able to | ||
17 | maintain *build themes*. """ | ||
18 | |||
19 | config_file = os.environ.get("SPHINX_CONF", None) | ||
20 | if (config_file is not None | ||
21 | and os.path.normpath(namespace["__file__"]) != os.path.normpath(config_file) ): | ||
22 | config_file = os.path.abspath(config_file) | ||
23 | |||
24 | if os.path.isfile(config_file): | ||
25 | sys.stdout.write("load additional sphinx-config: %s\n" % config_file) | ||
26 | config = namespace.copy() | ||
27 | config['__file__'] = config_file | ||
28 | execfile_(config_file, config) | ||
29 | del config['__file__'] | ||
30 | namespace.update(config) | ||
31 | else: | ||
32 | sys.stderr.write("WARNING: additional sphinx-config not found: %s\n" % config_file) | ||