blob: a42320385df34eed57b2ece17e9f859ae1a92a2d [file] [log] [blame]
Mauro Carvalho Chehabcb43fb52017-05-14 11:50:01 -03001# -*- makefile -*-
2# Makefile for Sphinx documentation
3#
4
Shuah Khan18489292016-10-06 16:00:50 -06005subdir-y :=
Mauro Carvalho Chehabcb43fb52017-05-14 11:50:01 -03006
7# You can set these variables from the command line.
8SPHINXBUILD = sphinx-build
9SPHINXOPTS =
10SPHINXDIRS = .
11_SPHINXDIRS = $(patsubst $(srctree)/Documentation/%/conf.py,%,$(wildcard $(srctree)/Documentation/*/conf.py))
12SPHINX_CONF = conf.py
13PAPER =
14BUILDDIR = $(obj)/output
15PDFLATEX = xelatex
16LATEXOPTS = -interaction=batchmode
17
18# User-friendly check for sphinx-build
19HAVE_SPHINX := $(shell if which $(SPHINXBUILD) >/dev/null 2>&1; then echo 1; else echo 0; fi)
20
21ifeq ($(HAVE_SPHINX),0)
22
23.DEFAULT:
24 $(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.)
25 @echo " SKIP Sphinx $@ target."
26
27else # HAVE_SPHINX
28
29# User-friendly check for pdflatex
30HAVE_PDFLATEX := $(shell if which $(PDFLATEX) >/dev/null 2>&1; then echo 1; else echo 0; fi)
31
32# Internal variables.
33PAPEROPT_a4 = -D latex_paper_size=a4
34PAPEROPT_letter = -D latex_paper_size=letter
35KERNELDOC = $(srctree)/scripts/kernel-doc
36KERNELDOC_CONF = -D kerneldoc_srctree=$(srctree) -D kerneldoc_bin=$(KERNELDOC)
37ALLSPHINXOPTS = $(KERNELDOC_CONF) $(PAPEROPT_$(PAPER)) $(SPHINXOPTS)
38# the i18n builder cannot share the environment and doctrees with the others
39I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
40
41# commands; the 'cmd' from scripts/Kbuild.include is not *loopable*
42loop_cmd = $(echo-cmd) $(cmd_$(1)) || exit;
43
44# $2 sphinx builder e.g. "html"
45# $3 name of the build subfolder / e.g. "media", used as:
46# * dest folder relative to $(BUILDDIR) and
47# * cache folder relative to $(BUILDDIR)/.doctrees
48# $4 dest subfolder e.g. "man" for man pages at media/man
49# $5 reST source folder relative to $(srctree)/$(src),
50# e.g. "media" for the linux-tv book-set at ./Documentation/media
51
52quiet_cmd_sphinx = SPHINX $@ --> file://$(abspath $(BUILDDIR)/$3/$4)
53 cmd_sphinx = $(MAKE) BUILDDIR=$(abspath $(BUILDDIR)) $(build)=Documentation/media $2 && \
54 PYTHONDONTWRITEBYTECODE=1 \
55 BUILDDIR=$(abspath $(BUILDDIR)) SPHINX_CONF=$(abspath $(srctree)/$(src)/$5/$(SPHINX_CONF)) \
56 $(SPHINXBUILD) \
57 -b $2 \
58 -c $(abspath $(srctree)/$(src)) \
59 -d $(abspath $(BUILDDIR)/.doctrees/$3) \
60 -D version=$(KERNELVERSION) -D release=$(KERNELRELEASE) \
61 $(ALLSPHINXOPTS) \
62 $(abspath $(srctree)/$(src)/$5) \
63 $(abspath $(BUILDDIR)/$3/$4)
64
65htmldocs:
66 @+$(foreach var,$(SPHINXDIRS),$(call loop_cmd,sphinx,html,$(var),,$(var)))
67
68linkcheckdocs:
69 @$(foreach var,$(SPHINXDIRS),$(call loop_cmd,sphinx,linkcheck,$(var),,$(var)))
70
71latexdocs:
72 @+$(foreach var,$(SPHINXDIRS),$(call loop_cmd,sphinx,latex,$(var),latex,$(var)))
73
74ifeq ($(HAVE_PDFLATEX),0)
75
76pdfdocs:
77 $(warning The '$(PDFLATEX)' command was not found. Make sure you have it installed and in PATH to produce PDF output.)
78 @echo " SKIP Sphinx $@ target."
79
80else # HAVE_PDFLATEX
81
82pdfdocs: latexdocs
83 $(foreach var,$(SPHINXDIRS), $(MAKE) PDFLATEX=$(PDFLATEX) LATEXOPTS="$(LATEXOPTS)" -C $(BUILDDIR)/$(var)/latex || exit;)
84
85endif # HAVE_PDFLATEX
86
87epubdocs:
88 @+$(foreach var,$(SPHINXDIRS),$(call loop_cmd,sphinx,epub,$(var),epub,$(var)))
89
90xmldocs:
91 @+$(foreach var,$(SPHINXDIRS),$(call loop_cmd,sphinx,xml,$(var),xml,$(var)))
92
93endif # HAVE_SPHINX
94
95# The following targets are independent of HAVE_SPHINX, and the rules should
96# work or silently pass without Sphinx.
97
98# no-ops for the Sphinx toolchain
99sgmldocs:
100 @:
101psdocs:
102 @:
103mandocs:
104 @:
105installmandocs:
106 @:
107
108cleandocs:
109 $(Q)rm -rf $(BUILDDIR)
110 $(Q)$(MAKE) BUILDDIR=$(abspath $(BUILDDIR)) $(build)=Documentation/media clean
111
112dochelp:
113 @echo ' Linux kernel internal documentation in different formats from ReST:'
114 @echo ' htmldocs - HTML'
115 @echo ' latexdocs - LaTeX'
116 @echo ' pdfdocs - PDF'
117 @echo ' epubdocs - EPUB'
118 @echo ' xmldocs - XML'
119 @echo ' linkcheckdocs - check for broken external links (will connect to external hosts)'
120 @echo ' cleandocs - clean all generated files'
121 @echo
122 @echo ' make SPHINXDIRS="s1 s2" [target] Generate only docs of folder s1, s2'
123 @echo ' valid values for SPHINXDIRS are: $(_SPHINXDIRS)'
124 @echo
125 @echo ' make SPHINX_CONF={conf-file} [target] use *additional* sphinx-build'
126 @echo ' configuration. This is e.g. useful to build with nit-picking config.'