Makefile.sphinx 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. # -*- makefile -*-
  2. # Makefile for Sphinx documentation
  3. #
  4. # You can set these variables from the command line.
  5. SPHINXBUILD = sphinx-build
  6. SPHINXOPTS =
  7. SPHINXDIRS = .
  8. _SPHINXDIRS = $(patsubst $(srctree)/Documentation/%/conf.py,%,$(wildcard $(srctree)/Documentation/*/conf.py))
  9. SPHINX_CONF = conf.py
  10. PAPER =
  11. BUILDDIR = $(obj)/output
  12. # User-friendly check for sphinx-build
  13. HAVE_SPHINX := $(shell if which $(SPHINXBUILD) >/dev/null 2>&1; then echo 1; else echo 0; fi)
  14. ifeq ($(HAVE_SPHINX),0)
  15. .DEFAULT:
  16. $(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.)
  17. @echo " SKIP Sphinx $@ target."
  18. else ifneq ($(DOCBOOKS),)
  19. # Skip Sphinx build if the user explicitly requested DOCBOOKS.
  20. .DEFAULT:
  21. @echo " SKIP Sphinx $@ target (DOCBOOKS specified)."
  22. else # HAVE_SPHINX
  23. # User-friendly check for pdflatex
  24. HAVE_PDFLATEX := $(shell if which xelatex >/dev/null 2>&1; then echo 1; else echo 0; fi)
  25. # Internal variables.
  26. PAPEROPT_a4 = -D latex_paper_size=a4
  27. PAPEROPT_letter = -D latex_paper_size=letter
  28. KERNELDOC = $(srctree)/scripts/kernel-doc
  29. KERNELDOC_CONF = -D kerneldoc_srctree=$(srctree) -D kerneldoc_bin=$(KERNELDOC)
  30. ALLSPHINXOPTS = $(KERNELDOC_CONF) $(PAPEROPT_$(PAPER)) $(SPHINXOPTS)
  31. # the i18n builder cannot share the environment and doctrees with the others
  32. I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
  33. # commands; the 'cmd' from scripts/Kbuild.include is not *loopable*
  34. loop_cmd = $(echo-cmd) $(cmd_$(1))
  35. # $2 sphinx builder e.g. "html"
  36. # $3 name of the build subfolder / e.g. "media", used as:
  37. # * dest folder relative to $(BUILDDIR) and
  38. # * cache folder relative to $(BUILDDIR)/.doctrees
  39. # $4 dest subfolder e.g. "man" for man pages at media/man
  40. # $5 reST source folder relative to $(srctree)/$(src),
  41. # e.g. "media" for the linux-tv book-set at ./Documentation/media
  42. quiet_cmd_sphinx = SPHINX $@ --> file://$(abspath $(BUILDDIR)/$3/$4);
  43. cmd_sphinx = $(MAKE) BUILDDIR=$(abspath $(BUILDDIR)) $(build)=Documentation/media all;\
  44. BUILDDIR=$(abspath $(BUILDDIR)) SPHINX_CONF=$(abspath $(srctree)/$(src)/$5/$(SPHINX_CONF)) \
  45. $(SPHINXBUILD) \
  46. -b $2 \
  47. -c $(abspath $(srctree)/$(src)) \
  48. -d $(abspath $(BUILDDIR)/.doctrees/$3) \
  49. -D version=$(KERNELVERSION) -D release=$(KERNELRELEASE) \
  50. $(ALLSPHINXOPTS) \
  51. $(abspath $(srctree)/$(src)/$5) \
  52. $(abspath $(BUILDDIR)/$3/$4);
  53. htmldocs:
  54. @$(foreach var,$(SPHINXDIRS),$(call loop_cmd,sphinx,html,$(var),,$(var)))
  55. latexdocs:
  56. ifeq ($(HAVE_PDFLATEX),0)
  57. $(warning The 'xelatex' command was not found. Make sure you have it installed and in PATH to produce PDF output.)
  58. @echo " SKIP Sphinx $@ target."
  59. else # HAVE_PDFLATEX
  60. @$(foreach var,$(SPHINXDIRS),$(call loop_cmd,sphinx,latex,$(var),latex,$(var)))
  61. endif # HAVE_PDFLATEX
  62. pdfdocs: latexdocs
  63. ifneq ($(HAVE_PDFLATEX),0)
  64. $(foreach var,$(SPHINXDIRS), $(MAKE) PDFLATEX=xelatex LATEXOPTS="-interaction=nonstopmode" -C $(BUILDDIR)/$(var)/latex)
  65. endif # HAVE_PDFLATEX
  66. epubdocs:
  67. @$(foreach var,$(SPHINXDIRS),$(call loop_cmd,sphinx,epub,$(var),epub,$(var)))
  68. xmldocs:
  69. @$(foreach var,$(SPHINXDIRS),$(call loop_cmd,sphinx,xml,$(var),xml,$(var)))
  70. # no-ops for the Sphinx toolchain
  71. sgmldocs:
  72. psdocs:
  73. mandocs:
  74. installmandocs:
  75. cleandocs:
  76. $(Q)rm -rf $(BUILDDIR)
  77. endif # HAVE_SPHINX
  78. dochelp:
  79. @echo ' Linux kernel internal documentation in different formats (Sphinx):'
  80. @echo ' htmldocs - HTML'
  81. @echo ' latexdocs - LaTeX'
  82. @echo ' pdfdocs - PDF'
  83. @echo ' epubdocs - EPUB'
  84. @echo ' xmldocs - XML'
  85. @echo ' cleandocs - clean all generated files'
  86. @echo
  87. @echo ' make SPHINXDIRS="s1 s2" [target] Generate only docs of folder s1, s2'
  88. @echo ' valid values for SPHINXDIRS are: $(_SPHINXDIRS)'
  89. @echo
  90. @echo ' make SPHINX_CONF={conf-file} [target] use *additional* sphinx-build'
  91. @echo ' configuration. This is e.g. useful to build with nit-picking config.'