xref: /linux/Documentation/Makefile (revision 7e8a8143ecc3940dbc3664b24b132ec7420d1053)
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      =
26SPHINX_CONF   = conf.py
27PAPER         =
28BUILDDIR      = $(obj)/output
29PDFLATEX      = xelatex
30LATEXOPTS     = -interaction=batchmode -no-shell-escape
31
32PYTHONPYCACHEPREFIX ?= $(abspath $(BUILDDIR)/__pycache__)
33
34# Wrapper for sphinx-build
35
36BUILD_WRAPPER = $(srctree)/tools/docs/sphinx-build-wrapper
37
38# For denylisting "variable font" files
39# Can be overridden by setting as an env variable
40FONTS_CONF_DENY_VF ?= $(HOME)/deny-vf
41
42# User-friendly check for sphinx-build
43HAVE_SPHINX := $(shell if which $(SPHINXBUILD) >/dev/null 2>&1; then echo 1; else echo 0; fi)
44
45ifeq ($(HAVE_SPHINX),0)
46
47.DEFAULT:
48	$(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.)
49	@echo
50	@$(srctree)/tools/docs/sphinx-pre-install
51	@echo "  SKIP    Sphinx $@ target."
52
53else # HAVE_SPHINX
54
55# Common documentation targets
56mandocs infodocs texinfodocs latexdocs epubdocs xmldocs pdfdocs linkcheckdocs:
57	$(Q)@$(srctree)/tools/docs/sphinx-pre-install --version-check
58	+$(Q)$(PYTHON3) $(BUILD_WRAPPER) $@ \
59		--sphinxdirs="$(SPHINXDIRS)" --conf="$(SPHINX_CONF)" \
60		--builddir="$(BUILDDIR)" --deny-vf=$(FONTS_CONF_DENY_VF) \
61		--theme=$(DOCS_THEME) --css=$(DOCS_CSS) --paper=$(PAPER)
62
63# Special handling for pdfdocs
64ifneq ($(shell which $(PDFLATEX) >/dev/null 2>&1; echo $$?),0)
65pdfdocs:
66	$(warning The '$(PDFLATEX)' command was not found. Make sure you have it installed and in PATH to produce PDF output.)
67	@echo "  SKIP    Sphinx $@ target."
68endif
69
70htmldocs-redirects: $(srctree)/Documentation/.renames.txt
71	@tools/docs/gen-redirects.py --output $(BUILDDIR) < $<
72
73# HTML main logic is identical to other targets. However, if rust is enabled,
74# an extra step at the end is required to generate rustdoc.
75htmldocs:
76	$(Q)@$(srctree)/tools/docs/sphinx-pre-install --version-check
77	+$(Q)$(PYTHON3) $(BUILD_WRAPPER) $@ \
78		--sphinxdirs="$(SPHINXDIRS)" --conf="$(SPHINX_CONF)" \
79		--builddir="$(BUILDDIR)" \
80		--theme=$(DOCS_THEME) --css=$(DOCS_CSS) --paper=$(PAPER)
81# If Rust support is available and .config exists, add rustdoc generated contents.
82# If there are any, the errors from this make rustdoc will be displayed but
83# won't stop the execution of htmldocs
84
85ifneq ($(wildcard $(srctree)/.config),)
86ifeq ($(CONFIG_RUST),y)
87	$(Q)$(MAKE) rustdoc || true
88endif
89endif
90
91endif # HAVE_SPHINX
92
93# The following targets are independent of HAVE_SPHINX, and the rules should
94# work or silently pass without Sphinx.
95
96refcheckdocs:
97	$(Q)cd $(srctree);scripts/documentation-file-ref-check
98
99cleandocs:
100	$(Q)rm -rf $(BUILDDIR)
101
102# Used only on help
103_SPHINXDIRS   = $(sort $(patsubst $(srctree)/Documentation/%/index.rst,%,$(wildcard $(srctree)/Documentation/*/index.rst)))
104
105dochelp:
106	@echo  ' Linux kernel internal documentation in different formats from ReST:'
107	@echo  '  htmldocs        - HTML'
108	@echo  '  htmldocs-redirects - generate HTML redirects for moved pages'
109	@echo  '  texinfodocs     - Texinfo'
110	@echo  '  infodocs        - Info'
111	@echo  '  mandocs         - Man pages'
112	@echo  '  latexdocs       - LaTeX'
113	@echo  '  pdfdocs         - PDF'
114	@echo  '  epubdocs        - EPUB'
115	@echo  '  xmldocs         - XML'
116	@echo  '  linkcheckdocs   - check for broken external links'
117	@echo  '                    (will connect to external hosts)'
118	@echo  '  refcheckdocs    - check for references to non-existing files under'
119	@echo  '                    Documentation'
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.'
127	@echo
128	@echo  '  make DOCS_THEME={sphinx-theme} selects a different Sphinx theme.'
129	@echo
130	@echo  '  make DOCS_CSS={a .css file} adds a DOCS_CSS override file for html/epub output.'
131	@echo
132	@echo  '  make PAPER={a4|letter} Specifies the paper size used for LaTeX/PDF output.'
133	@echo
134	@echo  '  make FONTS_CONF_DENY_VF={path} sets a deny list to block variable Noto CJK fonts'
135	@echo  '  for PDF build. See tools/docs/lib/latex_fonts.py for more details'
136	@echo
137	@echo  '  Default location for the generated documents is Documentation/output'
138