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