blob: e145e4db508bc6a45ed598f0cb3564893d0bc026 [file] [log] [blame]
Mauro Carvalho Chehabcb43fb52017-05-14 11:50:01 -03001# -*- makefile -*-
2# Makefile for Sphinx documentation
3#
4
Rob Herring4f0e3a52018-09-06 13:26:07 -05005subdir-y := devicetree/bindings/
Mauro Carvalho Chehabcb43fb52017-05-14 11:50:01 -03006
Mauro Carvalho Chehabb1663d72019-06-04 09:26:27 -03007# Check for broken documentation file references
8ifeq ($(CONFIG_WARN_MISSING_DOCUMENTS),y)
9$(shell $(srctree)/scripts/documentation-file-ref-check --warn)
10endif
11
Mauro Carvalho Chehabcb43fb52017-05-14 11:50:01 -030012# You can set these variables from the command line.
13SPHINXBUILD = sphinx-build
14SPHINXOPTS =
15SPHINXDIRS = .
16_SPHINXDIRS = $(patsubst $(srctree)/Documentation/%/conf.py,%,$(wildcard $(srctree)/Documentation/*/conf.py))
17SPHINX_CONF = conf.py
18PAPER =
19BUILDDIR = $(obj)/output
20PDFLATEX = xelatex
21LATEXOPTS = -interaction=batchmode
22
23# User-friendly check for sphinx-build
24HAVE_SPHINX := $(shell if which $(SPHINXBUILD) >/dev/null 2>&1; then echo 1; else echo 0; fi)
25
26ifeq ($(HAVE_SPHINX),0)
27
28.DEFAULT:
29 $(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.)
Mauro Carvalho Chehab92a037f2017-07-16 19:08:06 -030030 @echo
Jonathan Corbet6c01edd2019-05-31 10:02:11 -060031 @$(srctree)/scripts/sphinx-pre-install
Mauro Carvalho Chehabcb43fb52017-05-14 11:50:01 -030032 @echo " SKIP Sphinx $@ target."
33
34else # HAVE_SPHINX
35
Mauro Carvalho Chehabcf085082019-05-29 20:09:31 -030036export SPHINXOPTS = $(shell perl -e 'open IN,"sphinx-build --version 2>&1 |"; while (<IN>) { if (m/([\d\.]+)/) { print "-jauto" if ($$1 >= "1.7") } ;} close IN')
37
Mauro Carvalho Chehab28f7c992019-03-30 10:45:58 -030038# User-friendly check for pdflatex and latexmk
Mauro Carvalho Chehabcb43fb52017-05-14 11:50:01 -030039HAVE_PDFLATEX := $(shell if which $(PDFLATEX) >/dev/null 2>&1; then echo 1; else echo 0; fi)
Mauro Carvalho Chehab28f7c992019-03-30 10:45:58 -030040HAVE_LATEXMK := $(shell if which latexmk >/dev/null 2>&1; then echo 1; else echo 0; fi)
41
42ifeq ($(HAVE_LATEXMK),1)
43 PDFLATEX := latexmk -$(PDFLATEX)
44endif #HAVE_LATEXMK
Mauro Carvalho Chehabcb43fb52017-05-14 11:50:01 -030045
46# Internal variables.
47PAPEROPT_a4 = -D latex_paper_size=a4
48PAPEROPT_letter = -D latex_paper_size=letter
49KERNELDOC = $(srctree)/scripts/kernel-doc
50KERNELDOC_CONF = -D kerneldoc_srctree=$(srctree) -D kerneldoc_bin=$(KERNELDOC)
51ALLSPHINXOPTS = $(KERNELDOC_CONF) $(PAPEROPT_$(PAPER)) $(SPHINXOPTS)
52# the i18n builder cannot share the environment and doctrees with the others
53I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
54
55# commands; the 'cmd' from scripts/Kbuild.include is not *loopable*
56loop_cmd = $(echo-cmd) $(cmd_$(1)) || exit;
57
58# $2 sphinx builder e.g. "html"
59# $3 name of the build subfolder / e.g. "media", used as:
60# * dest folder relative to $(BUILDDIR) and
61# * cache folder relative to $(BUILDDIR)/.doctrees
62# $4 dest subfolder e.g. "man" for man pages at media/man
63# $5 reST source folder relative to $(srctree)/$(src),
64# e.g. "media" for the linux-tv book-set at ./Documentation/media
65
66quiet_cmd_sphinx = SPHINX $@ --> file://$(abspath $(BUILDDIR)/$3/$4)
67 cmd_sphinx = $(MAKE) BUILDDIR=$(abspath $(BUILDDIR)) $(build)=Documentation/media $2 && \
68 PYTHONDONTWRITEBYTECODE=1 \
69 BUILDDIR=$(abspath $(BUILDDIR)) SPHINX_CONF=$(abspath $(srctree)/$(src)/$5/$(SPHINX_CONF)) \
70 $(SPHINXBUILD) \
71 -b $2 \
72 -c $(abspath $(srctree)/$(src)) \
73 -d $(abspath $(BUILDDIR)/.doctrees/$3) \
74 -D version=$(KERNELVERSION) -D release=$(KERNELRELEASE) \
75 $(ALLSPHINXOPTS) \
76 $(abspath $(srctree)/$(src)/$5) \
77 $(abspath $(BUILDDIR)/$3/$4)
78
79htmldocs:
Jonathan Corbet18e15722019-06-04 07:55:49 -060080 @$(srctree)/scripts/sphinx-pre-install --version-check
Mauro Carvalho Chehabcb43fb52017-05-14 11:50:01 -030081 @+$(foreach var,$(SPHINXDIRS),$(call loop_cmd,sphinx,html,$(var),,$(var)))
82
83linkcheckdocs:
84 @$(foreach var,$(SPHINXDIRS),$(call loop_cmd,sphinx,linkcheck,$(var),,$(var)))
85
86latexdocs:
Jonathan Corbet18e15722019-06-04 07:55:49 -060087 @$(srctree)/scripts/sphinx-pre-install --version-check
Mauro Carvalho Chehabcb43fb52017-05-14 11:50:01 -030088 @+$(foreach var,$(SPHINXDIRS),$(call loop_cmd,sphinx,latex,$(var),latex,$(var)))
89
90ifeq ($(HAVE_PDFLATEX),0)
91
92pdfdocs:
93 $(warning The '$(PDFLATEX)' command was not found. Make sure you have it installed and in PATH to produce PDF output.)
94 @echo " SKIP Sphinx $@ target."
95
96else # HAVE_PDFLATEX
97
98pdfdocs: latexdocs
Jonathan Corbet18e15722019-06-04 07:55:49 -060099 @$(srctree)/scripts/sphinx-pre-install --version-check
Mauro Carvalho Chehab28f7c992019-03-30 10:45:58 -0300100 $(foreach var,$(SPHINXDIRS), $(MAKE) PDFLATEX="$(PDFLATEX)" LATEXOPTS="$(LATEXOPTS)" -C $(BUILDDIR)/$(var)/latex || exit;)
Mauro Carvalho Chehabcb43fb52017-05-14 11:50:01 -0300101
102endif # HAVE_PDFLATEX
103
104epubdocs:
Jonathan Corbet18e15722019-06-04 07:55:49 -0600105 @$(srctree)/scripts/sphinx-pre-install --version-check
Mauro Carvalho Chehabcb43fb52017-05-14 11:50:01 -0300106 @+$(foreach var,$(SPHINXDIRS),$(call loop_cmd,sphinx,epub,$(var),epub,$(var)))
107
108xmldocs:
Jonathan Corbet18e15722019-06-04 07:55:49 -0600109 @$(srctree)/scripts/sphinx-pre-install --version-check
Mauro Carvalho Chehabcb43fb52017-05-14 11:50:01 -0300110 @+$(foreach var,$(SPHINXDIRS),$(call loop_cmd,sphinx,xml,$(var),xml,$(var)))
111
112endif # HAVE_SPHINX
113
114# The following targets are independent of HAVE_SPHINX, and the rules should
115# work or silently pass without Sphinx.
116
Jani Nikulae8939222017-10-09 18:26:15 +0300117refcheckdocs:
118 $(Q)cd $(srctree);scripts/documentation-file-ref-check
119
Mauro Carvalho Chehabcb43fb52017-05-14 11:50:01 -0300120cleandocs:
121 $(Q)rm -rf $(BUILDDIR)
122 $(Q)$(MAKE) BUILDDIR=$(abspath $(BUILDDIR)) $(build)=Documentation/media clean
123
124dochelp:
125 @echo ' Linux kernel internal documentation in different formats from ReST:'
126 @echo ' htmldocs - HTML'
127 @echo ' latexdocs - LaTeX'
128 @echo ' pdfdocs - PDF'
129 @echo ' epubdocs - EPUB'
130 @echo ' xmldocs - XML'
131 @echo ' linkcheckdocs - check for broken external links (will connect to external hosts)'
Jani Nikulae8939222017-10-09 18:26:15 +0300132 @echo ' refcheckdocs - check for references to non-existing files under Documentation'
Mauro Carvalho Chehabcb43fb52017-05-14 11:50:01 -0300133 @echo ' cleandocs - clean all generated files'
134 @echo
135 @echo ' make SPHINXDIRS="s1 s2" [target] Generate only docs of folder s1, s2'
136 @echo ' valid values for SPHINXDIRS are: $(_SPHINXDIRS)'
137 @echo
138 @echo ' make SPHINX_CONF={conf-file} [target] use *additional* sphinx-build'
139 @echo ' configuration. This is e.g. useful to build with nit-picking config.'
Shuah Khan9effc8f2017-10-02 17:44:18 -0600140 @echo
141 @echo ' Default location for the generated documents is Documentation/output'