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 |
| 13 | |
| 14 | # User-friendly check for sphinx-build |
| 15 | HAVE_SPHINX := $(shell if which $(SPHINXBUILD) >/dev/null 2>&1; then echo 1; else echo 0; fi) |
| 16 | |
| 17 | ifeq ($(HAVE_SPHINX),0) |
| 18 | |
| 19 | .DEFAULT: |
| 20 | $(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.) |
| 21 | @echo " SKIP Sphinx $@ target." |
| 22 | |
Jani Nikula | 6387872 | 2016-07-01 15:24:44 +0300 | [diff] [blame] | 23 | else ifneq ($(DOCBOOKS),) |
| 24 | |
| 25 | # Skip Sphinx build if the user explicitly requested DOCBOOKS. |
| 26 | .DEFAULT: |
| 27 | @echo " SKIP Sphinx $@ target (DOCBOOKS specified)." |
| 28 | |
Jani Nikula | 22cba31 | 2016-05-19 15:14:05 +0300 | [diff] [blame] | 29 | else # HAVE_SPHINX |
| 30 | |
Jani Nikula | f907ba9 | 2016-08-10 18:54:08 +0300 | [diff] [blame] | 31 | # User-friendly check for pdflatex |
Mauro Carvalho Chehab | a682ec4 | 2016-08-16 13:25:39 -0300 | [diff] [blame] | 32 | HAVE_PDFLATEX := $(shell if which xelatex >/dev/null 2>&1; then echo 1; else echo 0; fi) |
Jani Nikula | 22cba31 | 2016-05-19 15:14:05 +0300 | [diff] [blame] | 33 | |
| 34 | # Internal variables. |
| 35 | PAPEROPT_a4 = -D latex_paper_size=a4 |
| 36 | PAPEROPT_letter = -D latex_paper_size=letter |
Jani Nikula | 24dcdeb | 2016-05-20 11:51:47 +0300 | [diff] [blame] | 37 | KERNELDOC = $(srctree)/scripts/kernel-doc |
| 38 | KERNELDOC_CONF = -D kerneldoc_srctree=$(srctree) -D kerneldoc_bin=$(KERNELDOC) |
Markus Heiser | 606b9ac | 2016-08-13 16:12:42 +0200 | [diff] [blame] | 39 | ALLSPHINXOPTS = $(KERNELDOC_CONF) $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) |
Jani Nikula | 22cba31 | 2016-05-19 15:14:05 +0300 | [diff] [blame] | 40 | # the i18n builder cannot share the environment and doctrees with the others |
| 41 | I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . |
| 42 | |
Markus Heiser | 606b9ac | 2016-08-13 16:12:42 +0200 | [diff] [blame] | 43 | # commands; the 'cmd' from scripts/Kbuild.include is not *loopable* |
| 44 | loop_cmd = $(echo-cmd) $(cmd_$(1)) |
| 45 | |
| 46 | # $2 sphinx builder e.g. "html" |
| 47 | # $3 name of the build subfolder / e.g. "media", used as: |
| 48 | # * dest folder relative to $(BUILDDIR) and |
| 49 | # * cache folder relative to $(BUILDDIR)/.doctrees |
| 50 | # $4 dest subfolder e.g. "man" for man pages at media/man |
| 51 | # $5 reST source folder relative to $(srctree)/$(src), |
| 52 | # e.g. "media" for the linux-tv book-set at ./Documentation/media |
| 53 | |
| 54 | quiet_cmd_sphinx = SPHINX $@ --> file://$(abspath $(BUILDDIR)/$3/$4); |
| 55 | cmd_sphinx = $(MAKE) BUILDDIR=$(abspath $(BUILDDIR)) $(build)=Documentation/media all;\ |
| 56 | BUILDDIR=$(abspath $(BUILDDIR)) SPHINX_CONF=$(abspath $(srctree)/$(src)/$5/$(SPHINX_CONF)) \ |
| 57 | $(SPHINXBUILD) \ |
| 58 | -b $2 \ |
| 59 | -c $(abspath $(srctree)/$(src)) \ |
| 60 | -d $(abspath $(BUILDDIR)/.doctrees/$3) \ |
| 61 | -D version=$(KERNELVERSION) -D release=$(KERNELRELEASE) \ |
| 62 | $(ALLSPHINXOPTS) \ |
| 63 | $(abspath $(srctree)/$(src)/$5) \ |
| 64 | $(abspath $(BUILDDIR)/$3/$4); |
Jani Nikula | 22cba31 | 2016-05-19 15:14:05 +0300 | [diff] [blame] | 65 | |
| 66 | htmldocs: |
Markus Heiser | 606b9ac | 2016-08-13 16:12:42 +0200 | [diff] [blame] | 67 | @$(foreach var,$(SPHINXDIRS),$(call loop_cmd,sphinx,html,$(var),,$(var))) |
Jani Nikula | 22cba31 | 2016-05-19 15:14:05 +0300 | [diff] [blame] | 68 | |
Mauro Carvalho Chehab | d565127 | 2016-08-18 11:53:39 -0300 | [diff] [blame] | 69 | latexdocs: |
Jani Nikula | f907ba9 | 2016-08-10 18:54:08 +0300 | [diff] [blame] | 70 | ifeq ($(HAVE_PDFLATEX),0) |
Mauro Carvalho Chehab | a682ec4 | 2016-08-16 13:25:39 -0300 | [diff] [blame] | 71 | $(warning The 'xelatex' 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] | 72 | @echo " SKIP Sphinx $@ target." |
Jani Nikula | f907ba9 | 2016-08-10 18:54:08 +0300 | [diff] [blame] | 73 | else # HAVE_PDFLATEX |
Markus Heiser | cd21379 | 2016-08-24 17:36:14 +0200 | [diff] [blame] | 74 | @$(foreach var,$(SPHINXDIRS),$(call loop_cmd,sphinx,latex,$(var),latex,$(var))) |
Mauro Carvalho Chehab | d565127 | 2016-08-18 11:53:39 -0300 | [diff] [blame] | 75 | endif # HAVE_PDFLATEX |
| 76 | |
| 77 | pdfdocs: latexdocs |
| 78 | ifneq ($(HAVE_PDFLATEX),0) |
Markus Heiser | cd21379 | 2016-08-24 17:36:14 +0200 | [diff] [blame] | 79 | $(foreach var,$(SPHINXDIRS), $(MAKE) PDFLATEX=xelatex LATEXOPTS="-interaction=nonstopmode" -C $(BUILDDIR)/$(var)/latex) |
Jani Nikula | f907ba9 | 2016-08-10 18:54:08 +0300 | [diff] [blame] | 80 | endif # HAVE_PDFLATEX |
Jani Nikula | 22cba31 | 2016-05-19 15:14:05 +0300 | [diff] [blame] | 81 | |
| 82 | epubdocs: |
Markus Heiser | 606b9ac | 2016-08-13 16:12:42 +0200 | [diff] [blame] | 83 | @$(foreach var,$(SPHINXDIRS),$(call loop_cmd,sphinx,epub,$(var),epub,$(var))) |
Jani Nikula | 22cba31 | 2016-05-19 15:14:05 +0300 | [diff] [blame] | 84 | |
| 85 | xmldocs: |
Markus Heiser | 606b9ac | 2016-08-13 16:12:42 +0200 | [diff] [blame] | 86 | @$(foreach var,$(SPHINXDIRS),$(call loop_cmd,sphinx,xml,$(var),xml,$(var))) |
Jani Nikula | 22cba31 | 2016-05-19 15:14:05 +0300 | [diff] [blame] | 87 | |
| 88 | # no-ops for the Sphinx toolchain |
| 89 | sgmldocs: |
| 90 | psdocs: |
| 91 | mandocs: |
| 92 | installmandocs: |
| 93 | |
| 94 | cleandocs: |
| 95 | $(Q)rm -rf $(BUILDDIR) |
| 96 | |
Jani Nikula | d9a77fe | 2016-08-01 12:37:05 +0300 | [diff] [blame] | 97 | endif # HAVE_SPHINX |
| 98 | |
Jani Nikula | ebc88ef | 2016-06-22 15:41:48 +0300 | [diff] [blame] | 99 | dochelp: |
| 100 | @echo ' Linux kernel internal documentation in different formats (Sphinx):' |
| 101 | @echo ' htmldocs - HTML' |
Mauro Carvalho Chehab | d565127 | 2016-08-18 11:53:39 -0300 | [diff] [blame] | 102 | @echo ' latexdocs - LaTeX' |
Jani Nikula | ebc88ef | 2016-06-22 15:41:48 +0300 | [diff] [blame] | 103 | @echo ' pdfdocs - PDF' |
| 104 | @echo ' epubdocs - EPUB' |
| 105 | @echo ' xmldocs - XML' |
| 106 | @echo ' cleandocs - clean all generated files' |
Markus Heiser | 606b9ac | 2016-08-13 16:12:42 +0200 | [diff] [blame] | 107 | @echo |
| 108 | @echo ' make SPHINXDIRS="s1 s2" [target] Generate only docs of folder s1, s2' |
| 109 | @echo ' valid values for SPHINXDIRS are: $(_SPHINXDIRS)' |
| 110 | @echo |
| 111 | @echo ' make SPHINX_CONF={conf-file} [target] use *additional* sphinx-build' |
| 112 | @echo ' configuration. This is e.g. useful to build with nit-picking config.' |