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_elements.papersize=a4paper 64PAPEROPT_letter = -D latex_elements.papersize=letterpaper 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 = \ 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 107htmldocs: 108 @$(srctree)/scripts/sphinx-pre-install --version-check 109 @+$(foreach var,$(SPHINXDIRS),$(call loop_cmd,sphinx,html,$(var),,$(var))) 110 111htmldocs-redirects: $(srctree)/Documentation/.renames.txt 112 @tools/docs/gen-redirects.py --output $(BUILDDIR) < $< 113 114# If Rust support is available and .config exists, add rustdoc generated contents. 115# If there are any, the errors from this make rustdoc will be displayed but 116# won't stop the execution of htmldocs 117 118ifneq ($(wildcard $(srctree)/.config),) 119ifeq ($(CONFIG_RUST),y) 120 $(Q)$(MAKE) rustdoc || true 121endif 122endif 123 124texinfodocs: 125 @$(srctree)/scripts/sphinx-pre-install --version-check 126 @+$(foreach var,$(SPHINXDIRS),$(call loop_cmd,sphinx,texinfo,$(var),texinfo,$(var))) 127 128# Note: the 'info' Make target is generated by sphinx itself when 129# running the texinfodocs target define above. 130infodocs: texinfodocs 131 $(MAKE) -C $(BUILDDIR)/texinfo info 132 133linkcheckdocs: 134 @$(foreach var,$(SPHINXDIRS),$(call loop_cmd,sphinx,linkcheck,$(var),,$(var))) 135 136latexdocs: 137 @$(srctree)/scripts/sphinx-pre-install --version-check 138 @+$(foreach var,$(SPHINXDIRS),$(call loop_cmd,sphinx,latex,$(var),latex,$(var))) 139 140ifeq ($(HAVE_PDFLATEX),0) 141 142pdfdocs: 143 $(warning The '$(PDFLATEX)' command was not found. Make sure you have it installed and in PATH to produce PDF output.) 144 @echo " SKIP Sphinx $@ target." 145 146else # HAVE_PDFLATEX 147 148pdfdocs: DENY_VF = XDG_CONFIG_HOME=$(FONTS_CONF_DENY_VF) 149pdfdocs: latexdocs 150 @$(srctree)/scripts/sphinx-pre-install --version-check 151 $(foreach var,$(SPHINXDIRS), \ 152 $(MAKE) PDFLATEX="$(PDFLATEX)" LATEXOPTS="$(LATEXOPTS)" $(DENY_VF) -C $(BUILDDIR)/$(var)/latex || sh $(srctree)/scripts/check-variable-fonts.sh || exit; \ 153 mkdir -p $(BUILDDIR)/$(var)/pdf; \ 154 mv $(subst .tex,.pdf,$(wildcard $(BUILDDIR)/$(var)/latex/*.tex)) $(BUILDDIR)/$(var)/pdf/; \ 155 ) 156 157endif # HAVE_PDFLATEX 158 159epubdocs: 160 @$(srctree)/scripts/sphinx-pre-install --version-check 161 @+$(foreach var,$(SPHINXDIRS),$(call loop_cmd,sphinx,epub,$(var),epub,$(var))) 162 163xmldocs: 164 @$(srctree)/scripts/sphinx-pre-install --version-check 165 @+$(foreach var,$(SPHINXDIRS),$(call loop_cmd,sphinx,xml,$(var),xml,$(var))) 166 167endif # HAVE_SPHINX 168 169# The following targets are independent of HAVE_SPHINX, and the rules should 170# work or silently pass without Sphinx. 171 172refcheckdocs: 173 $(Q)cd $(srctree);scripts/documentation-file-ref-check 174 175cleandocs: 176 $(Q)rm -rf $(BUILDDIR) 177 178dochelp: 179 @echo ' Linux kernel internal documentation in different formats from ReST:' 180 @echo ' htmldocs - HTML' 181 @echo ' htmldocs-redirects - generate HTML redirects for moved pages' 182 @echo ' texinfodocs - Texinfo' 183 @echo ' infodocs - Info' 184 @echo ' latexdocs - LaTeX' 185 @echo ' pdfdocs - PDF' 186 @echo ' epubdocs - EPUB' 187 @echo ' xmldocs - XML' 188 @echo ' linkcheckdocs - check for broken external links' 189 @echo ' (will connect to external hosts)' 190 @echo ' refcheckdocs - check for references to non-existing files under' 191 @echo ' Documentation' 192 @echo ' cleandocs - clean all generated files' 193 @echo 194 @echo ' make SPHINXDIRS="s1 s2" [target] Generate only docs of folder s1, s2' 195 @echo ' valid values for SPHINXDIRS are: $(_SPHINXDIRS)' 196 @echo 197 @echo ' make SPHINX_CONF={conf-file} [target] use *additional* sphinx-build' 198 @echo ' configuration. This is e.g. useful to build with nit-picking config.' 199 @echo 200 @echo ' make DOCS_THEME={sphinx-theme} selects a different Sphinx theme.' 201 @echo 202 @echo ' make DOCS_CSS={a .css file} adds a DOCS_CSS override file for html/epub output.' 203 @echo 204 @echo ' Default location for the generated documents is Documentation/output' 205