Jani Nikula | 22cba31 | 2016-05-19 15:14:05 +0300 | [diff] [blame] | 1 | # -*- makefile -*- |
| 2 | # Makefile for Sphinx documentation |
| 3 | # |
| 4 | |
| 5 | # You can set these variables from the command line. |
| 6 | SPHINXBUILD = sphinx-build |
| 7 | SPHINXOPTS = |
Markus Heiser | 606b9ac | 2016-08-13 16:12:42 +0200 | [diff] [blame] | 8 | SPHINXDIRS = . |
| 9 | _SPHINXDIRS = $(patsubst $(srctree)/Documentation/%/conf.py,%,$(wildcard $(srctree)/Documentation/*/conf.py)) |
| 10 | SPHINX_CONF = conf.py |
Jani Nikula | 22cba31 | 2016-05-19 15:14:05 +0300 | [diff] [blame] | 11 | PAPER = |
| 12 | BUILDDIR = $(obj)/output |
Jani Nikula | 1171a28 | 2016-11-02 10:38:43 +0200 | [diff] [blame] | 13 | PDFLATEX = xelatex |
Jani Nikula | eaed1b2 | 2016-11-02 13:20:15 +0200 | [diff] [blame] | 14 | LATEXOPTS = -interaction=batchmode |
Jani Nikula | 22cba31 | 2016-05-19 15:14:05 +0300 | [diff] [blame] | 15 | |
| 16 | # User-friendly check for sphinx-build |
| 17 | HAVE_SPHINX := $(shell if which $(SPHINXBUILD) >/dev/null 2>&1; then echo 1; else echo 0; fi) |
| 18 | |
| 19 | ifeq ($(HAVE_SPHINX),0) |
| 20 | |
| 21 | .DEFAULT: |
| 22 | $(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.) |
| 23 | @echo " SKIP Sphinx $@ target." |
| 24 | |
Jani Nikula | 6387872 | 2016-07-01 15:24:44 +0300 | [diff] [blame] | 25 | else ifneq ($(DOCBOOKS),) |
| 26 | |
| 27 | # Skip Sphinx build if the user explicitly requested DOCBOOKS. |
| 28 | .DEFAULT: |
| 29 | @echo " SKIP Sphinx $@ target (DOCBOOKS specified)." |
| 30 | |
Jani Nikula | 22cba31 | 2016-05-19 15:14:05 +0300 | [diff] [blame] | 31 | else # HAVE_SPHINX |
| 32 | |
Jani Nikula | f907ba9 | 2016-08-10 18:54:08 +0300 | [diff] [blame] | 33 | # User-friendly check for pdflatex |
Jani Nikula | 1171a28 | 2016-11-02 10:38:43 +0200 | [diff] [blame] | 34 | HAVE_PDFLATEX := $(shell if which $(PDFLATEX) >/dev/null 2>&1; then echo 1; else echo 0; fi) |
Jani Nikula | 22cba31 | 2016-05-19 15:14:05 +0300 | [diff] [blame] | 35 | |
| 36 | # Internal variables. |
| 37 | PAPEROPT_a4 = -D latex_paper_size=a4 |
| 38 | PAPEROPT_letter = -D latex_paper_size=letter |
Jani Nikula | 24dcdeb | 2016-05-20 11:51:47 +0300 | [diff] [blame] | 39 | KERNELDOC = $(srctree)/scripts/kernel-doc |
| 40 | KERNELDOC_CONF = -D kerneldoc_srctree=$(srctree) -D kerneldoc_bin=$(KERNELDOC) |
Markus Heiser | 606b9ac | 2016-08-13 16:12:42 +0200 | [diff] [blame] | 41 | ALLSPHINXOPTS = $(KERNELDOC_CONF) $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) |
Jani Nikula | 22cba31 | 2016-05-19 15:14:05 +0300 | [diff] [blame] | 42 | # the i18n builder cannot share the environment and doctrees with the others |
| 43 | I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . |
| 44 | |
Markus Heiser | 606b9ac | 2016-08-13 16:12:42 +0200 | [diff] [blame] | 45 | # commands; the 'cmd' from scripts/Kbuild.include is not *loopable* |
Ben Hutchings | 85bd902 | 2017-01-31 00:18:34 +0000 | [diff] [blame] | 46 | loop_cmd = $(echo-cmd) $(cmd_$(1)) || exit; |
Markus Heiser | 606b9ac | 2016-08-13 16:12:42 +0200 | [diff] [blame] | 47 | |
| 48 | # $2 sphinx builder e.g. "html" |
| 49 | # $3 name of the build subfolder / e.g. "media", used as: |
| 50 | # * dest folder relative to $(BUILDDIR) and |
| 51 | # * cache folder relative to $(BUILDDIR)/.doctrees |
| 52 | # $4 dest subfolder e.g. "man" for man pages at media/man |
| 53 | # $5 reST source folder relative to $(srctree)/$(src), |
| 54 | # e.g. "media" for the linux-tv book-set at ./Documentation/media |
| 55 | |
Jani Nikula | c855696 | 2016-11-02 10:56:31 +0200 | [diff] [blame] | 56 | quiet_cmd_sphinx = SPHINX $@ --> file://$(abspath $(BUILDDIR)/$3/$4) |
Ben Hutchings | 85bd902 | 2017-01-31 00:18:34 +0000 | [diff] [blame] | 57 | cmd_sphinx = $(MAKE) BUILDDIR=$(abspath $(BUILDDIR)) $(build)=Documentation/media $2 && \ |
Jani Nikula | 2a0f403 | 2017-01-31 20:18:05 +0200 | [diff] [blame] | 58 | PYTHONDONTWRITEBYTECODE=1 \ |
Markus Heiser | 606b9ac | 2016-08-13 16:12:42 +0200 | [diff] [blame] | 59 | BUILDDIR=$(abspath $(BUILDDIR)) SPHINX_CONF=$(abspath $(srctree)/$(src)/$5/$(SPHINX_CONF)) \ |
| 60 | $(SPHINXBUILD) \ |
| 61 | -b $2 \ |
| 62 | -c $(abspath $(srctree)/$(src)) \ |
| 63 | -d $(abspath $(BUILDDIR)/.doctrees/$3) \ |
| 64 | -D version=$(KERNELVERSION) -D release=$(KERNELRELEASE) \ |
| 65 | $(ALLSPHINXOPTS) \ |
| 66 | $(abspath $(srctree)/$(src)/$5) \ |
Ben Hutchings | 85bd902 | 2017-01-31 00:18:34 +0000 | [diff] [blame] | 67 | $(abspath $(BUILDDIR)/$3/$4) |
Jani Nikula | 22cba31 | 2016-05-19 15:14:05 +0300 | [diff] [blame] | 68 | |
| 69 | htmldocs: |
Ben Hutchings | 4b0b0d9 | 2017-01-31 00:18:56 +0000 | [diff] [blame] | 70 | @+$(foreach var,$(SPHINXDIRS),$(call loop_cmd,sphinx,html,$(var),,$(var))) |
Jani Nikula | 22cba31 | 2016-05-19 15:14:05 +0300 | [diff] [blame] | 71 | |
Rémy Léone | 62924fd | 2017-02-15 13:16:35 +0100 | [diff] [blame] | 72 | linkcheckdocs: |
| 73 | @$(foreach var,$(SPHINXDIRS),$(call loop_cmd,sphinx,linkcheck,$(var),,$(var))) |
| 74 | |
Mauro Carvalho Chehab | d565127 | 2016-08-18 11:53:39 -0300 | [diff] [blame] | 75 | latexdocs: |
Ben Hutchings | 4b0b0d9 | 2017-01-31 00:18:56 +0000 | [diff] [blame] | 76 | @+$(foreach var,$(SPHINXDIRS),$(call loop_cmd,sphinx,latex,$(var),latex,$(var))) |
Jani Nikula | 207fc55 | 2016-11-02 11:13:19 +0200 | [diff] [blame] | 77 | |
Jani Nikula | f907ba9 | 2016-08-10 18:54:08 +0300 | [diff] [blame] | 78 | ifeq ($(HAVE_PDFLATEX),0) |
Jani Nikula | 207fc55 | 2016-11-02 11:13:19 +0200 | [diff] [blame] | 79 | |
| 80 | pdfdocs: |
Jani Nikula | 1171a28 | 2016-11-02 10:38:43 +0200 | [diff] [blame] | 81 | $(warning The '$(PDFLATEX)' command was not found. Make sure you have it installed and in PATH to produce PDF output.) |
Jani Nikula | 22cba31 | 2016-05-19 15:14:05 +0300 | [diff] [blame] | 82 | @echo " SKIP Sphinx $@ target." |
Jani Nikula | 207fc55 | 2016-11-02 11:13:19 +0200 | [diff] [blame] | 83 | |
Jani Nikula | f907ba9 | 2016-08-10 18:54:08 +0300 | [diff] [blame] | 84 | else # HAVE_PDFLATEX |
Mauro Carvalho Chehab | d565127 | 2016-08-18 11:53:39 -0300 | [diff] [blame] | 85 | |
| 86 | pdfdocs: latexdocs |
Ben Hutchings | 85bd902 | 2017-01-31 00:18:34 +0000 | [diff] [blame] | 87 | $(foreach var,$(SPHINXDIRS), $(MAKE) PDFLATEX=$(PDFLATEX) LATEXOPTS="$(LATEXOPTS)" -C $(BUILDDIR)/$(var)/latex || exit;) |
Jani Nikula | 1171a28 | 2016-11-02 10:38:43 +0200 | [diff] [blame] | 88 | |
Jani Nikula | f907ba9 | 2016-08-10 18:54:08 +0300 | [diff] [blame] | 89 | endif # HAVE_PDFLATEX |
Jani Nikula | 22cba31 | 2016-05-19 15:14:05 +0300 | [diff] [blame] | 90 | |
| 91 | epubdocs: |
Ben Hutchings | 4b0b0d9 | 2017-01-31 00:18:56 +0000 | [diff] [blame] | 92 | @+$(foreach var,$(SPHINXDIRS),$(call loop_cmd,sphinx,epub,$(var),epub,$(var))) |
Jani Nikula | 22cba31 | 2016-05-19 15:14:05 +0300 | [diff] [blame] | 93 | |
| 94 | xmldocs: |
Ben Hutchings | 4b0b0d9 | 2017-01-31 00:18:56 +0000 | [diff] [blame] | 95 | @+$(foreach var,$(SPHINXDIRS),$(call loop_cmd,sphinx,xml,$(var),xml,$(var))) |
Jani Nikula | 22cba31 | 2016-05-19 15:14:05 +0300 | [diff] [blame] | 96 | |
Jani Nikula | c892925 | 2017-01-30 18:58:15 +0200 | [diff] [blame] | 97 | endif # HAVE_SPHINX |
| 98 | |
| 99 | # The following targets are independent of HAVE_SPHINX, and the rules should |
| 100 | # work or silently pass without Sphinx. |
| 101 | |
Jani Nikula | 22cba31 | 2016-05-19 15:14:05 +0300 | [diff] [blame] | 102 | # no-ops for the Sphinx toolchain |
| 103 | sgmldocs: |
Jim Davis | c33dea1 | 2017-02-10 17:06:50 -0700 | [diff] [blame] | 104 | @: |
Jani Nikula | 22cba31 | 2016-05-19 15:14:05 +0300 | [diff] [blame] | 105 | psdocs: |
Jim Davis | c33dea1 | 2017-02-10 17:06:50 -0700 | [diff] [blame] | 106 | @: |
Jani Nikula | 22cba31 | 2016-05-19 15:14:05 +0300 | [diff] [blame] | 107 | mandocs: |
Jim Davis | c33dea1 | 2017-02-10 17:06:50 -0700 | [diff] [blame] | 108 | @: |
Jani Nikula | 22cba31 | 2016-05-19 15:14:05 +0300 | [diff] [blame] | 109 | installmandocs: |
Jim Davis | c33dea1 | 2017-02-10 17:06:50 -0700 | [diff] [blame] | 110 | @: |
Jani Nikula | 22cba31 | 2016-05-19 15:14:05 +0300 | [diff] [blame] | 111 | |
| 112 | cleandocs: |
| 113 | $(Q)rm -rf $(BUILDDIR) |
Markus Heiser | 7cabd5a | 2017-01-31 10:57:41 +0100 | [diff] [blame] | 114 | $(Q)$(MAKE) BUILDDIR=$(abspath $(BUILDDIR)) $(build)=Documentation/media clean |
Jani Nikula | 22cba31 | 2016-05-19 15:14:05 +0300 | [diff] [blame] | 115 | |
Jani Nikula | ebc88ef | 2016-06-22 15:41:48 +0300 | [diff] [blame] | 116 | dochelp: |
| 117 | @echo ' Linux kernel internal documentation in different formats (Sphinx):' |
| 118 | @echo ' htmldocs - HTML' |
Mauro Carvalho Chehab | d565127 | 2016-08-18 11:53:39 -0300 | [diff] [blame] | 119 | @echo ' latexdocs - LaTeX' |
Jani Nikula | ebc88ef | 2016-06-22 15:41:48 +0300 | [diff] [blame] | 120 | @echo ' pdfdocs - PDF' |
| 121 | @echo ' epubdocs - EPUB' |
| 122 | @echo ' xmldocs - XML' |
Rémy Léone | 62924fd | 2017-02-15 13:16:35 +0100 | [diff] [blame] | 123 | @echo ' linkcheckdocs - check for broken external links (will connect to external hosts)' |
Jani Nikula | ebc88ef | 2016-06-22 15:41:48 +0300 | [diff] [blame] | 124 | @echo ' cleandocs - clean all generated files' |
Markus Heiser | 606b9ac | 2016-08-13 16:12:42 +0200 | [diff] [blame] | 125 | @echo |
| 126 | @echo ' make SPHINXDIRS="s1 s2" [target] Generate only docs of folder s1, s2' |
| 127 | @echo ' valid values for SPHINXDIRS are: $(_SPHINXDIRS)' |
| 128 | @echo |
| 129 | @echo ' make SPHINX_CONF={conf-file} [target] use *additional* sphinx-build' |
| 130 | @echo ' configuration. This is e.g. useful to build with nit-picking config.' |