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