xref: /linux/Documentation/Makefile (revision 8d2b0853add1d7534dc0794e3c8e0b9e8c4ec640)
1# -*- makefile -*-
2# Makefile for Sphinx documentation
3#
4
5# for cleaning
6subdir- := devicetree/bindings
7
8ifneq ($(MAKECMDGOALS),cleandocs)
9# Check for broken documentation file references
10ifeq ($(CONFIG_WARN_MISSING_DOCUMENTS),y)
11$(shell $(srctree)/scripts/documentation-file-ref-check --warn)
12endif
13
14# Check for broken ABI files
15ifeq ($(CONFIG_WARN_ABI_ERRORS),y)
16$(shell $(srctree)/scripts/get_abi.py --dir $(srctree)/Documentation/ABI validate)
17endif
18endif
19
20# You can set these variables from the command line.
21SPHINXBUILD   = sphinx-build
22SPHINXOPTS    =
23SPHINXDIRS    = .
24DOCS_THEME    =
25DOCS_CSS      =
26_SPHINXDIRS   = $(sort $(patsubst $(srctree)/Documentation/%/index.rst,%,$(wildcard $(srctree)/Documentation/*/index.rst)))
27SPHINX_CONF   = conf.py
28PAPER         =
29BUILDDIR      = $(obj)/output
30PDFLATEX      = xelatex
31LATEXOPTS     = -interaction=batchmode -no-shell-escape
32
33# For denylisting "variable font" files
34# Can be overridden by setting as an env variable
35FONTS_CONF_DENY_VF ?= $(HOME)/deny-vf
36
37ifeq ($(findstring 1, $(KBUILD_VERBOSE)),)
38SPHINXOPTS    += "-q"
39endif
40
41# User-friendly check for sphinx-build
42HAVE_SPHINX := $(shell if which $(SPHINXBUILD) >/dev/null 2>&1; then echo 1; else echo 0; fi)
43
44ifeq ($(HAVE_SPHINX),0)
45
46.DEFAULT:
47	$(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.)
48	@echo
49	@$(srctree)/scripts/sphinx-pre-install
50	@echo "  SKIP    Sphinx $@ target."
51
52else # HAVE_SPHINX
53
54# User-friendly check for pdflatex and latexmk
55HAVE_PDFLATEX := $(shell if which $(PDFLATEX) >/dev/null 2>&1; then echo 1; else echo 0; fi)
56HAVE_LATEXMK := $(shell if which latexmk >/dev/null 2>&1; then echo 1; else echo 0; fi)
57
58ifeq ($(HAVE_LATEXMK),1)
59	PDFLATEX := latexmk -$(PDFLATEX)
60endif #HAVE_LATEXMK
61
62# Internal variables.
63PAPEROPT_a4     = -D latex_paper_size=a4
64PAPEROPT_letter = -D latex_paper_size=letter
65ALLSPHINXOPTS   = -D kerneldoc_srctree=$(srctree) -D kerneldoc_bin=$(KERNELDOC)
66ALLSPHINXOPTS   += $(PAPEROPT_$(PAPER)) $(SPHINXOPTS)
67ifneq ($(wildcard $(srctree)/.config),)
68ifeq ($(CONFIG_RUST),y)
69	# Let Sphinx know we will include rustdoc
70	ALLSPHINXOPTS   +=  -t rustdoc
71endif
72endif
73# the i18n builder cannot share the environment and doctrees with the others
74I18NSPHINXOPTS  = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
75
76# commands; the 'cmd' from scripts/Kbuild.include is not *loopable*
77loop_cmd = $(echo-cmd) $(cmd_$(1)) || exit;
78
79# $2 sphinx builder e.g. "html"
80# $3 name of the build subfolder / e.g. "userspace-api/media", used as:
81#    * dest folder relative to $(BUILDDIR) and
82#    * cache folder relative to $(BUILDDIR)/.doctrees
83# $4 dest subfolder e.g. "man" for man pages at userspace-api/media/man
84# $5 reST source folder relative to $(src),
85#    e.g. "userspace-api/media" for the linux-tv book-set at ./Documentation/userspace-api/media
86
87PYTHONPYCACHEPREFIX ?= $(abspath $(BUILDDIR)/__pycache__)
88
89quiet_cmd_sphinx = SPHINX  $@ --> file://$(abspath $(BUILDDIR)/$3/$4)
90      cmd_sphinx = $(MAKE) BUILDDIR=$(abspath $(BUILDDIR)) $(build)=Documentation/userspace-api/media $2 && \
91	PYTHONPYCACHEPREFIX="$(PYTHONPYCACHEPREFIX)" \
92	BUILDDIR=$(abspath $(BUILDDIR)) SPHINX_CONF=$(abspath $(src)/$5/$(SPHINX_CONF)) \
93	$(PYTHON3) $(srctree)/scripts/jobserver-exec \
94	$(CONFIG_SHELL) $(srctree)/Documentation/sphinx/parallel-wrapper.sh \
95	$(SPHINXBUILD) \
96	-b $2 \
97	-c $(abspath $(src)) \
98	-d $(abspath $(BUILDDIR)/.doctrees/$3) \
99	-D version=$(KERNELVERSION) -D release=$(KERNELRELEASE) \
100	$(ALLSPHINXOPTS) \
101	$(abspath $(src)/$5) \
102	$(abspath $(BUILDDIR)/$3/$4) && \
103	if [ "x$(DOCS_CSS)" != "x" ]; then \
104		cp $(if $(patsubst /%,,$(DOCS_CSS)),$(abspath $(srctree)/$(DOCS_CSS)),$(DOCS_CSS)) $(BUILDDIR)/$3/_static/; \
105	fi
106
107YNL_INDEX:=$(srctree)/Documentation/networking/netlink_spec/index.rst
108YNL_RST_DIR:=$(srctree)/Documentation/networking/netlink_spec
109YNL_YAML_DIR:=$(srctree)/Documentation/netlink/specs
110YNL_TOOL:=$(srctree)/tools/net/ynl/pyynl/ynl_gen_rst.py
111
112YNL_RST_FILES_TMP := $(patsubst %.yaml,%.rst,$(wildcard $(YNL_YAML_DIR)/*.yaml))
113YNL_RST_FILES := $(patsubst $(YNL_YAML_DIR)%,$(YNL_RST_DIR)%, $(YNL_RST_FILES_TMP))
114
115$(YNL_INDEX): $(YNL_RST_FILES)
116	$(Q)$(YNL_TOOL) -o $@ -x
117
118$(YNL_RST_DIR)/%.rst: $(YNL_YAML_DIR)/%.yaml $(YNL_TOOL)
119	$(Q)$(YNL_TOOL) -i $< -o $@
120
121htmldocs texinfodocs latexdocs epubdocs xmldocs: $(YNL_INDEX)
122
123htmldocs:
124	@$(srctree)/scripts/sphinx-pre-install --version-check
125	@+$(foreach var,$(SPHINXDIRS),$(call loop_cmd,sphinx,html,$(var),,$(var)))
126
127# If Rust support is available and .config exists, add rustdoc generated contents.
128# If there are any, the errors from this make rustdoc will be displayed but
129# won't stop the execution of htmldocs
130
131ifneq ($(wildcard $(srctree)/.config),)
132ifeq ($(CONFIG_RUST),y)
133	$(Q)$(MAKE) rustdoc || true
134endif
135endif
136
137texinfodocs:
138	@$(srctree)/scripts/sphinx-pre-install --version-check
139	@+$(foreach var,$(SPHINXDIRS),$(call loop_cmd,sphinx,texinfo,$(var),texinfo,$(var)))
140
141# Note: the 'info' Make target is generated by sphinx itself when
142# running the texinfodocs target define above.
143infodocs: texinfodocs
144	$(MAKE) -C $(BUILDDIR)/texinfo info
145
146linkcheckdocs:
147	@$(foreach var,$(SPHINXDIRS),$(call loop_cmd,sphinx,linkcheck,$(var),,$(var)))
148
149latexdocs:
150	@$(srctree)/scripts/sphinx-pre-install --version-check
151	@+$(foreach var,$(SPHINXDIRS),$(call loop_cmd,sphinx,latex,$(var),latex,$(var)))
152
153ifeq ($(HAVE_PDFLATEX),0)
154
155pdfdocs:
156	$(warning The '$(PDFLATEX)' command was not found. Make sure you have it installed and in PATH to produce PDF output.)
157	@echo "  SKIP    Sphinx $@ target."
158
159else # HAVE_PDFLATEX
160
161pdfdocs: DENY_VF = XDG_CONFIG_HOME=$(FONTS_CONF_DENY_VF)
162pdfdocs: latexdocs
163	@$(srctree)/scripts/sphinx-pre-install --version-check
164	$(foreach var,$(SPHINXDIRS), \
165	   $(MAKE) PDFLATEX="$(PDFLATEX)" LATEXOPTS="$(LATEXOPTS)" $(DENY_VF) -C $(BUILDDIR)/$(var)/latex || sh $(srctree)/scripts/check-variable-fonts.sh || exit; \
166	   mkdir -p $(BUILDDIR)/$(var)/pdf; \
167	   mv $(subst .tex,.pdf,$(wildcard $(BUILDDIR)/$(var)/latex/*.tex)) $(BUILDDIR)/$(var)/pdf/; \
168	)
169
170endif # HAVE_PDFLATEX
171
172epubdocs:
173	@$(srctree)/scripts/sphinx-pre-install --version-check
174	@+$(foreach var,$(SPHINXDIRS),$(call loop_cmd,sphinx,epub,$(var),epub,$(var)))
175
176xmldocs:
177	@$(srctree)/scripts/sphinx-pre-install --version-check
178	@+$(foreach var,$(SPHINXDIRS),$(call loop_cmd,sphinx,xml,$(var),xml,$(var)))
179
180endif # HAVE_SPHINX
181
182# The following targets are independent of HAVE_SPHINX, and the rules should
183# work or silently pass without Sphinx.
184
185refcheckdocs:
186	$(Q)cd $(srctree);scripts/documentation-file-ref-check
187
188cleandocs:
189	$(Q)rm -f $(YNL_INDEX) $(YNL_RST_FILES)
190	$(Q)rm -rf $(BUILDDIR)
191	$(Q)$(MAKE) BUILDDIR=$(abspath $(BUILDDIR)) $(build)=Documentation/userspace-api/media clean
192
193dochelp:
194	@echo  ' Linux kernel internal documentation in different formats from ReST:'
195	@echo  '  htmldocs        - HTML'
196	@echo  '  texinfodocs     - Texinfo'
197	@echo  '  infodocs        - Info'
198	@echo  '  latexdocs       - LaTeX'
199	@echo  '  pdfdocs         - PDF'
200	@echo  '  epubdocs        - EPUB'
201	@echo  '  xmldocs         - XML'
202	@echo  '  linkcheckdocs   - check for broken external links'
203	@echo  '                    (will connect to external hosts)'
204	@echo  '  refcheckdocs    - check for references to non-existing files under'
205	@echo  '                    Documentation'
206	@echo  '  cleandocs       - clean all generated files'
207	@echo
208	@echo  '  make SPHINXDIRS="s1 s2" [target] Generate only docs of folder s1, s2'
209	@echo  '  valid values for SPHINXDIRS are: $(_SPHINXDIRS)'
210	@echo
211	@echo  '  make SPHINX_CONF={conf-file} [target] use *additional* sphinx-build'
212	@echo  '  configuration. This is e.g. useful to build with nit-picking config.'
213	@echo
214	@echo  '  make DOCS_THEME={sphinx-theme} selects a different Sphinx theme.'
215	@echo
216	@echo  '  make DOCS_CSS={a .css file} adds a DOCS_CSS override file for html/epub output.'
217	@echo
218	@echo  '  Default location for the generated documents is Documentation/output'
219