xref: /OK3568_Linux_fs/kernel/Documentation/Makefile (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun# -*- makefile -*-
2*4882a593Smuzhiyun# Makefile for Sphinx documentation
3*4882a593Smuzhiyun#
4*4882a593Smuzhiyun
5*4882a593Smuzhiyun# for cleaning
6*4882a593Smuzhiyunsubdir- := devicetree/bindings
7*4882a593Smuzhiyun
8*4882a593Smuzhiyun# Check for broken documentation file references
9*4882a593Smuzhiyunifeq ($(CONFIG_WARN_MISSING_DOCUMENTS),y)
10*4882a593Smuzhiyun$(shell $(srctree)/scripts/documentation-file-ref-check --warn)
11*4882a593Smuzhiyunendif
12*4882a593Smuzhiyun
13*4882a593Smuzhiyun# Check for broken ABI files
14*4882a593Smuzhiyunifeq ($(CONFIG_WARN_ABI_ERRORS),y)
15*4882a593Smuzhiyun$(shell $(srctree)/scripts/get_abi.pl validate --dir $(srctree)/Documentation/ABI)
16*4882a593Smuzhiyunendif
17*4882a593Smuzhiyun
18*4882a593Smuzhiyun# You can set these variables from the command line.
19*4882a593SmuzhiyunSPHINXBUILD   = sphinx-build
20*4882a593SmuzhiyunSPHINXOPTS    =
21*4882a593SmuzhiyunSPHINXDIRS    = .
22*4882a593Smuzhiyun_SPHINXDIRS   = $(sort $(patsubst $(srctree)/Documentation/%/index.rst,%,$(wildcard $(srctree)/Documentation/*/index.rst)))
23*4882a593SmuzhiyunSPHINX_CONF   = conf.py
24*4882a593SmuzhiyunPAPER         =
25*4882a593SmuzhiyunBUILDDIR      = $(obj)/output
26*4882a593SmuzhiyunPDFLATEX      = xelatex
27*4882a593SmuzhiyunLATEXOPTS     = -interaction=batchmode
28*4882a593Smuzhiyun
29*4882a593Smuzhiyunifeq ($(KBUILD_VERBOSE),0)
30*4882a593SmuzhiyunSPHINXOPTS    += "-q"
31*4882a593Smuzhiyunendif
32*4882a593Smuzhiyun
33*4882a593Smuzhiyun# User-friendly check for sphinx-build
34*4882a593SmuzhiyunHAVE_SPHINX := $(shell if which $(SPHINXBUILD) >/dev/null 2>&1; then echo 1; else echo 0; fi)
35*4882a593Smuzhiyun
36*4882a593Smuzhiyunifeq ($(HAVE_SPHINX),0)
37*4882a593Smuzhiyun
38*4882a593Smuzhiyun.DEFAULT:
39*4882a593Smuzhiyun	$(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.)
40*4882a593Smuzhiyun	@echo
41*4882a593Smuzhiyun	@$(srctree)/scripts/sphinx-pre-install
42*4882a593Smuzhiyun	@echo "  SKIP    Sphinx $@ target."
43*4882a593Smuzhiyun
44*4882a593Smuzhiyunelse # HAVE_SPHINX
45*4882a593Smuzhiyun
46*4882a593Smuzhiyun# User-friendly check for pdflatex and latexmk
47*4882a593SmuzhiyunHAVE_PDFLATEX := $(shell if which $(PDFLATEX) >/dev/null 2>&1; then echo 1; else echo 0; fi)
48*4882a593SmuzhiyunHAVE_LATEXMK := $(shell if which latexmk >/dev/null 2>&1; then echo 1; else echo 0; fi)
49*4882a593Smuzhiyun
50*4882a593Smuzhiyunifeq ($(HAVE_LATEXMK),1)
51*4882a593Smuzhiyun	PDFLATEX := latexmk -$(PDFLATEX)
52*4882a593Smuzhiyunendif #HAVE_LATEXMK
53*4882a593Smuzhiyun
54*4882a593Smuzhiyun# Internal variables.
55*4882a593SmuzhiyunPAPEROPT_a4     = -D latex_paper_size=a4
56*4882a593SmuzhiyunPAPEROPT_letter = -D latex_paper_size=letter
57*4882a593SmuzhiyunKERNELDOC       = $(srctree)/scripts/kernel-doc
58*4882a593SmuzhiyunKERNELDOC_CONF  = -D kerneldoc_srctree=$(srctree) -D kerneldoc_bin=$(KERNELDOC)
59*4882a593SmuzhiyunALLSPHINXOPTS   =  $(KERNELDOC_CONF) $(PAPEROPT_$(PAPER)) $(SPHINXOPTS)
60*4882a593Smuzhiyun# the i18n builder cannot share the environment and doctrees with the others
61*4882a593SmuzhiyunI18NSPHINXOPTS  = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
62*4882a593Smuzhiyun
63*4882a593Smuzhiyun# commands; the 'cmd' from scripts/Kbuild.include is not *loopable*
64*4882a593Smuzhiyunloop_cmd = $(echo-cmd) $(cmd_$(1)) || exit;
65*4882a593Smuzhiyun
66*4882a593Smuzhiyun# $2 sphinx builder e.g. "html"
67*4882a593Smuzhiyun# $3 name of the build subfolder / e.g. "userspace-api/media", used as:
68*4882a593Smuzhiyun#    * dest folder relative to $(BUILDDIR) and
69*4882a593Smuzhiyun#    * cache folder relative to $(BUILDDIR)/.doctrees
70*4882a593Smuzhiyun# $4 dest subfolder e.g. "man" for man pages at userspace-api/media/man
71*4882a593Smuzhiyun# $5 reST source folder relative to $(srctree)/$(src),
72*4882a593Smuzhiyun#    e.g. "userspace-api/media" for the linux-tv book-set at ./Documentation/userspace-api/media
73*4882a593Smuzhiyun
74*4882a593Smuzhiyunquiet_cmd_sphinx = SPHINX  $@ --> file://$(abspath $(BUILDDIR)/$3/$4)
75*4882a593Smuzhiyun      cmd_sphinx = $(MAKE) BUILDDIR=$(abspath $(BUILDDIR)) $(build)=Documentation/userspace-api/media $2 && \
76*4882a593Smuzhiyun	PYTHONDONTWRITEBYTECODE=1 \
77*4882a593Smuzhiyun	BUILDDIR=$(abspath $(BUILDDIR)) SPHINX_CONF=$(abspath $(srctree)/$(src)/$5/$(SPHINX_CONF)) \
78*4882a593Smuzhiyun	$(PYTHON) $(srctree)/scripts/jobserver-exec \
79*4882a593Smuzhiyun	$(SHELL) $(srctree)/Documentation/sphinx/parallel-wrapper.sh \
80*4882a593Smuzhiyun	$(SPHINXBUILD) \
81*4882a593Smuzhiyun	-b $2 \
82*4882a593Smuzhiyun	-c $(abspath $(srctree)/$(src)) \
83*4882a593Smuzhiyun	-d $(abspath $(BUILDDIR)/.doctrees/$3) \
84*4882a593Smuzhiyun	-D version=$(KERNELVERSION) -D release=$(KERNELRELEASE) \
85*4882a593Smuzhiyun	$(ALLSPHINXOPTS) \
86*4882a593Smuzhiyun	$(abspath $(srctree)/$(src)/$5) \
87*4882a593Smuzhiyun	$(abspath $(BUILDDIR)/$3/$4)
88*4882a593Smuzhiyun
89*4882a593Smuzhiyunhtmldocs:
90*4882a593Smuzhiyun	@$(srctree)/scripts/sphinx-pre-install --version-check
91*4882a593Smuzhiyun	@+$(foreach var,$(SPHINXDIRS),$(call loop_cmd,sphinx,html,$(var),,$(var)))
92*4882a593Smuzhiyun
93*4882a593Smuzhiyunlinkcheckdocs:
94*4882a593Smuzhiyun	@$(foreach var,$(SPHINXDIRS),$(call loop_cmd,sphinx,linkcheck,$(var),,$(var)))
95*4882a593Smuzhiyun
96*4882a593Smuzhiyunlatexdocs:
97*4882a593Smuzhiyun	@$(srctree)/scripts/sphinx-pre-install --version-check
98*4882a593Smuzhiyun	@+$(foreach var,$(SPHINXDIRS),$(call loop_cmd,sphinx,latex,$(var),latex,$(var)))
99*4882a593Smuzhiyun
100*4882a593Smuzhiyunifeq ($(HAVE_PDFLATEX),0)
101*4882a593Smuzhiyun
102*4882a593Smuzhiyunpdfdocs:
103*4882a593Smuzhiyun	$(warning The '$(PDFLATEX)' command was not found. Make sure you have it installed and in PATH to produce PDF output.)
104*4882a593Smuzhiyun	@echo "  SKIP    Sphinx $@ target."
105*4882a593Smuzhiyun
106*4882a593Smuzhiyunelse # HAVE_PDFLATEX
107*4882a593Smuzhiyun
108*4882a593Smuzhiyunpdfdocs: latexdocs
109*4882a593Smuzhiyun	@$(srctree)/scripts/sphinx-pre-install --version-check
110*4882a593Smuzhiyun	$(foreach var,$(SPHINXDIRS), \
111*4882a593Smuzhiyun	   $(MAKE) PDFLATEX="$(PDFLATEX)" LATEXOPTS="$(LATEXOPTS)" -C $(BUILDDIR)/$(var)/latex || exit; \
112*4882a593Smuzhiyun	   mkdir -p $(BUILDDIR)/$(var)/pdf; \
113*4882a593Smuzhiyun	   mv $(subst .tex,.pdf,$(wildcard $(BUILDDIR)/$(var)/latex/*.tex)) $(BUILDDIR)/$(var)/pdf/; \
114*4882a593Smuzhiyun	)
115*4882a593Smuzhiyun
116*4882a593Smuzhiyunendif # HAVE_PDFLATEX
117*4882a593Smuzhiyun
118*4882a593Smuzhiyunepubdocs:
119*4882a593Smuzhiyun	@$(srctree)/scripts/sphinx-pre-install --version-check
120*4882a593Smuzhiyun	@+$(foreach var,$(SPHINXDIRS),$(call loop_cmd,sphinx,epub,$(var),epub,$(var)))
121*4882a593Smuzhiyun
122*4882a593Smuzhiyunxmldocs:
123*4882a593Smuzhiyun	@$(srctree)/scripts/sphinx-pre-install --version-check
124*4882a593Smuzhiyun	@+$(foreach var,$(SPHINXDIRS),$(call loop_cmd,sphinx,xml,$(var),xml,$(var)))
125*4882a593Smuzhiyun
126*4882a593Smuzhiyunendif # HAVE_SPHINX
127*4882a593Smuzhiyun
128*4882a593Smuzhiyun# The following targets are independent of HAVE_SPHINX, and the rules should
129*4882a593Smuzhiyun# work or silently pass without Sphinx.
130*4882a593Smuzhiyun
131*4882a593Smuzhiyunrefcheckdocs:
132*4882a593Smuzhiyun	$(Q)cd $(srctree);scripts/documentation-file-ref-check
133*4882a593Smuzhiyun
134*4882a593Smuzhiyuncleandocs:
135*4882a593Smuzhiyun	$(Q)rm -rf $(BUILDDIR)
136*4882a593Smuzhiyun	$(Q)$(MAKE) BUILDDIR=$(abspath $(BUILDDIR)) $(build)=Documentation/userspace-api/media clean
137*4882a593Smuzhiyun
138*4882a593Smuzhiyundochelp:
139*4882a593Smuzhiyun	@echo  ' Linux kernel internal documentation in different formats from ReST:'
140*4882a593Smuzhiyun	@echo  '  htmldocs        - HTML'
141*4882a593Smuzhiyun	@echo  '  latexdocs       - LaTeX'
142*4882a593Smuzhiyun	@echo  '  pdfdocs         - PDF'
143*4882a593Smuzhiyun	@echo  '  epubdocs        - EPUB'
144*4882a593Smuzhiyun	@echo  '  xmldocs         - XML'
145*4882a593Smuzhiyun	@echo  '  linkcheckdocs   - check for broken external links'
146*4882a593Smuzhiyun	@echo  '                    (will connect to external hosts)'
147*4882a593Smuzhiyun	@echo  '  refcheckdocs    - check for references to non-existing files under'
148*4882a593Smuzhiyun	@echo  '                    Documentation'
149*4882a593Smuzhiyun	@echo  '  cleandocs       - clean all generated files'
150*4882a593Smuzhiyun	@echo
151*4882a593Smuzhiyun	@echo  '  make SPHINXDIRS="s1 s2" [target] Generate only docs of folder s1, s2'
152*4882a593Smuzhiyun	@echo  '  valid values for SPHINXDIRS are: $(_SPHINXDIRS)'
153*4882a593Smuzhiyun	@echo
154*4882a593Smuzhiyun	@echo  '  make SPHINX_CONF={conf-file} [target] use *additional* sphinx-build'
155*4882a593Smuzhiyun	@echo  '  configuration. This is e.g. useful to build with nit-picking config.'
156*4882a593Smuzhiyun	@echo
157*4882a593Smuzhiyun	@echo  '  Default location for the generated documents is Documentation/output'
158