Makefile 7.8 KB

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