162306a36Sopenharmony_ci# -*- makefile -*-
262306a36Sopenharmony_ci# Makefile for Sphinx documentation
362306a36Sopenharmony_ci#
462306a36Sopenharmony_ci
562306a36Sopenharmony_ci# for cleaning
662306a36Sopenharmony_cisubdir- := devicetree/bindings
762306a36Sopenharmony_ci
862306a36Sopenharmony_ci# Check for broken documentation file references
962306a36Sopenharmony_ciifeq ($(CONFIG_WARN_MISSING_DOCUMENTS),y)
1062306a36Sopenharmony_ci$(shell $(srctree)/scripts/documentation-file-ref-check --warn)
1162306a36Sopenharmony_ciendif
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_ci# Check for broken ABI files
1462306a36Sopenharmony_ciifeq ($(CONFIG_WARN_ABI_ERRORS),y)
1562306a36Sopenharmony_ci$(shell $(srctree)/scripts/get_abi.pl validate --dir $(srctree)/Documentation/ABI)
1662306a36Sopenharmony_ciendif
1762306a36Sopenharmony_ci
1862306a36Sopenharmony_ci# You can set these variables from the command line.
1962306a36Sopenharmony_ciSPHINXBUILD   = sphinx-build
2062306a36Sopenharmony_ciSPHINXOPTS    =
2162306a36Sopenharmony_ciSPHINXDIRS    = .
2262306a36Sopenharmony_ciDOCS_THEME    =
2362306a36Sopenharmony_ciDOCS_CSS      =
2462306a36Sopenharmony_ci_SPHINXDIRS   = $(sort $(patsubst $(srctree)/Documentation/%/index.rst,%,$(wildcard $(srctree)/Documentation/*/index.rst)))
2562306a36Sopenharmony_ciSPHINX_CONF   = conf.py
2662306a36Sopenharmony_ciPAPER         =
2762306a36Sopenharmony_ciBUILDDIR      = $(obj)/output
2862306a36Sopenharmony_ciPDFLATEX      = xelatex
2962306a36Sopenharmony_ciLATEXOPTS     = -interaction=batchmode -no-shell-escape
3062306a36Sopenharmony_ci
3162306a36Sopenharmony_ciifeq ($(findstring 1, $(KBUILD_VERBOSE)),)
3262306a36Sopenharmony_ciSPHINXOPTS    += "-q"
3362306a36Sopenharmony_ciendif
3462306a36Sopenharmony_ci
3562306a36Sopenharmony_ci# User-friendly check for sphinx-build
3662306a36Sopenharmony_ciHAVE_SPHINX := $(shell if which $(SPHINXBUILD) >/dev/null 2>&1; then echo 1; else echo 0; fi)
3762306a36Sopenharmony_ci
3862306a36Sopenharmony_ciifeq ($(HAVE_SPHINX),0)
3962306a36Sopenharmony_ci
4062306a36Sopenharmony_ci.DEFAULT:
4162306a36Sopenharmony_ci	$(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.)
4262306a36Sopenharmony_ci	@echo
4362306a36Sopenharmony_ci	@$(srctree)/scripts/sphinx-pre-install
4462306a36Sopenharmony_ci	@echo "  SKIP    Sphinx $@ target."
4562306a36Sopenharmony_ci
4662306a36Sopenharmony_cielse # HAVE_SPHINX
4762306a36Sopenharmony_ci
4862306a36Sopenharmony_ci# User-friendly check for pdflatex and latexmk
4962306a36Sopenharmony_ciHAVE_PDFLATEX := $(shell if which $(PDFLATEX) >/dev/null 2>&1; then echo 1; else echo 0; fi)
5062306a36Sopenharmony_ciHAVE_LATEXMK := $(shell if which latexmk >/dev/null 2>&1; then echo 1; else echo 0; fi)
5162306a36Sopenharmony_ci
5262306a36Sopenharmony_ciifeq ($(HAVE_LATEXMK),1)
5362306a36Sopenharmony_ci	PDFLATEX := latexmk -$(PDFLATEX)
5462306a36Sopenharmony_ciendif #HAVE_LATEXMK
5562306a36Sopenharmony_ci
5662306a36Sopenharmony_ci# Internal variables.
5762306a36Sopenharmony_ciPAPEROPT_a4     = -D latex_paper_size=a4
5862306a36Sopenharmony_ciPAPEROPT_letter = -D latex_paper_size=letter
5962306a36Sopenharmony_ciKERNELDOC       = $(srctree)/scripts/kernel-doc
6062306a36Sopenharmony_ciKERNELDOC_CONF  = -D kerneldoc_srctree=$(srctree) -D kerneldoc_bin=$(KERNELDOC)
6162306a36Sopenharmony_ciALLSPHINXOPTS   =  $(KERNELDOC_CONF) $(PAPEROPT_$(PAPER)) $(SPHINXOPTS)
6262306a36Sopenharmony_ciifneq ($(wildcard $(srctree)/.config),)
6362306a36Sopenharmony_ciifeq ($(CONFIG_RUST),y)
6462306a36Sopenharmony_ci	# Let Sphinx know we will include rustdoc
6562306a36Sopenharmony_ci	ALLSPHINXOPTS   +=  -t rustdoc
6662306a36Sopenharmony_ciendif
6762306a36Sopenharmony_ciendif
6862306a36Sopenharmony_ci# the i18n builder cannot share the environment and doctrees with the others
6962306a36Sopenharmony_ciI18NSPHINXOPTS  = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
7062306a36Sopenharmony_ci
7162306a36Sopenharmony_ci# commands; the 'cmd' from scripts/Kbuild.include is not *loopable*
7262306a36Sopenharmony_ciloop_cmd = $(echo-cmd) $(cmd_$(1)) || exit;
7362306a36Sopenharmony_ci
7462306a36Sopenharmony_ci# $2 sphinx builder e.g. "html"
7562306a36Sopenharmony_ci# $3 name of the build subfolder / e.g. "userspace-api/media", used as:
7662306a36Sopenharmony_ci#    * dest folder relative to $(BUILDDIR) and
7762306a36Sopenharmony_ci#    * cache folder relative to $(BUILDDIR)/.doctrees
7862306a36Sopenharmony_ci# $4 dest subfolder e.g. "man" for man pages at userspace-api/media/man
7962306a36Sopenharmony_ci# $5 reST source folder relative to $(srctree)/$(src),
8062306a36Sopenharmony_ci#    e.g. "userspace-api/media" for the linux-tv book-set at ./Documentation/userspace-api/media
8162306a36Sopenharmony_ci
8262306a36Sopenharmony_ciquiet_cmd_sphinx = SPHINX  $@ --> file://$(abspath $(BUILDDIR)/$3/$4)
8362306a36Sopenharmony_ci      cmd_sphinx = $(MAKE) BUILDDIR=$(abspath $(BUILDDIR)) $(build)=Documentation/userspace-api/media $2 && \
8462306a36Sopenharmony_ci	PYTHONDONTWRITEBYTECODE=1 \
8562306a36Sopenharmony_ci	BUILDDIR=$(abspath $(BUILDDIR)) SPHINX_CONF=$(abspath $(srctree)/$(src)/$5/$(SPHINX_CONF)) \
8662306a36Sopenharmony_ci	$(PYTHON3) $(srctree)/scripts/jobserver-exec \
8762306a36Sopenharmony_ci	$(CONFIG_SHELL) $(srctree)/Documentation/sphinx/parallel-wrapper.sh \
8862306a36Sopenharmony_ci	$(SPHINXBUILD) \
8962306a36Sopenharmony_ci	-b $2 \
9062306a36Sopenharmony_ci	-c $(abspath $(srctree)/$(src)) \
9162306a36Sopenharmony_ci	-d $(abspath $(BUILDDIR)/.doctrees/$3) \
9262306a36Sopenharmony_ci	-D version=$(KERNELVERSION) -D release=$(KERNELRELEASE) \
9362306a36Sopenharmony_ci	$(ALLSPHINXOPTS) \
9462306a36Sopenharmony_ci	$(abspath $(srctree)/$(src)/$5) \
9562306a36Sopenharmony_ci	$(abspath $(BUILDDIR)/$3/$4) && \
9662306a36Sopenharmony_ci	if [ "x$(DOCS_CSS)" != "x" ]; then \
9762306a36Sopenharmony_ci		cp $(if $(patsubst /%,,$(DOCS_CSS)),$(abspath $(srctree)/$(DOCS_CSS)),$(DOCS_CSS)) $(BUILDDIR)/$3/_static/; \
9862306a36Sopenharmony_ci	fi
9962306a36Sopenharmony_ci
10062306a36Sopenharmony_cihtmldocs:
10162306a36Sopenharmony_ci	@$(srctree)/scripts/sphinx-pre-install --version-check
10262306a36Sopenharmony_ci	@+$(foreach var,$(SPHINXDIRS),$(call loop_cmd,sphinx,html,$(var),,$(var)))
10362306a36Sopenharmony_ci
10462306a36Sopenharmony_ci# If Rust support is available and .config exists, add rustdoc generated contents.
10562306a36Sopenharmony_ci# If there are any, the errors from this make rustdoc will be displayed but
10662306a36Sopenharmony_ci# won't stop the execution of htmldocs
10762306a36Sopenharmony_ci
10862306a36Sopenharmony_ciifneq ($(wildcard $(srctree)/.config),)
10962306a36Sopenharmony_ciifeq ($(CONFIG_RUST),y)
11062306a36Sopenharmony_ci	$(Q)$(MAKE) rustdoc || true
11162306a36Sopenharmony_ciendif
11262306a36Sopenharmony_ciendif
11362306a36Sopenharmony_ci
11462306a36Sopenharmony_citexinfodocs:
11562306a36Sopenharmony_ci	@$(srctree)/scripts/sphinx-pre-install --version-check
11662306a36Sopenharmony_ci	@+$(foreach var,$(SPHINXDIRS),$(call loop_cmd,sphinx,texinfo,$(var),texinfo,$(var)))
11762306a36Sopenharmony_ci
11862306a36Sopenharmony_ci# Note: the 'info' Make target is generated by sphinx itself when
11962306a36Sopenharmony_ci# running the texinfodocs target define above.
12062306a36Sopenharmony_ciinfodocs: texinfodocs
12162306a36Sopenharmony_ci	$(MAKE) -C $(BUILDDIR)/texinfo info
12262306a36Sopenharmony_ci
12362306a36Sopenharmony_cilinkcheckdocs:
12462306a36Sopenharmony_ci	@$(foreach var,$(SPHINXDIRS),$(call loop_cmd,sphinx,linkcheck,$(var),,$(var)))
12562306a36Sopenharmony_ci
12662306a36Sopenharmony_cilatexdocs:
12762306a36Sopenharmony_ci	@$(srctree)/scripts/sphinx-pre-install --version-check
12862306a36Sopenharmony_ci	@+$(foreach var,$(SPHINXDIRS),$(call loop_cmd,sphinx,latex,$(var),latex,$(var)))
12962306a36Sopenharmony_ci
13062306a36Sopenharmony_ciifeq ($(HAVE_PDFLATEX),0)
13162306a36Sopenharmony_ci
13262306a36Sopenharmony_cipdfdocs:
13362306a36Sopenharmony_ci	$(warning The '$(PDFLATEX)' command was not found. Make sure you have it installed and in PATH to produce PDF output.)
13462306a36Sopenharmony_ci	@echo "  SKIP    Sphinx $@ target."
13562306a36Sopenharmony_ci
13662306a36Sopenharmony_cielse # HAVE_PDFLATEX
13762306a36Sopenharmony_ci
13862306a36Sopenharmony_cipdfdocs: latexdocs
13962306a36Sopenharmony_ci	@$(srctree)/scripts/sphinx-pre-install --version-check
14062306a36Sopenharmony_ci	$(foreach var,$(SPHINXDIRS), \
14162306a36Sopenharmony_ci	   $(MAKE) PDFLATEX="$(PDFLATEX)" LATEXOPTS="$(LATEXOPTS)" -C $(BUILDDIR)/$(var)/latex || exit; \
14262306a36Sopenharmony_ci	   mkdir -p $(BUILDDIR)/$(var)/pdf; \
14362306a36Sopenharmony_ci	   mv $(subst .tex,.pdf,$(wildcard $(BUILDDIR)/$(var)/latex/*.tex)) $(BUILDDIR)/$(var)/pdf/; \
14462306a36Sopenharmony_ci	)
14562306a36Sopenharmony_ci
14662306a36Sopenharmony_ciendif # HAVE_PDFLATEX
14762306a36Sopenharmony_ci
14862306a36Sopenharmony_ciepubdocs:
14962306a36Sopenharmony_ci	@$(srctree)/scripts/sphinx-pre-install --version-check
15062306a36Sopenharmony_ci	@+$(foreach var,$(SPHINXDIRS),$(call loop_cmd,sphinx,epub,$(var),epub,$(var)))
15162306a36Sopenharmony_ci
15262306a36Sopenharmony_cixmldocs:
15362306a36Sopenharmony_ci	@$(srctree)/scripts/sphinx-pre-install --version-check
15462306a36Sopenharmony_ci	@+$(foreach var,$(SPHINXDIRS),$(call loop_cmd,sphinx,xml,$(var),xml,$(var)))
15562306a36Sopenharmony_ci
15662306a36Sopenharmony_ciendif # HAVE_SPHINX
15762306a36Sopenharmony_ci
15862306a36Sopenharmony_ci# The following targets are independent of HAVE_SPHINX, and the rules should
15962306a36Sopenharmony_ci# work or silently pass without Sphinx.
16062306a36Sopenharmony_ci
16162306a36Sopenharmony_cirefcheckdocs:
16262306a36Sopenharmony_ci	$(Q)cd $(srctree);scripts/documentation-file-ref-check
16362306a36Sopenharmony_ci
16462306a36Sopenharmony_cicleandocs:
16562306a36Sopenharmony_ci	$(Q)rm -rf $(BUILDDIR)
16662306a36Sopenharmony_ci	$(Q)$(MAKE) BUILDDIR=$(abspath $(BUILDDIR)) $(build)=Documentation/userspace-api/media clean
16762306a36Sopenharmony_ci
16862306a36Sopenharmony_cidochelp:
16962306a36Sopenharmony_ci	@echo  ' Linux kernel internal documentation in different formats from ReST:'
17062306a36Sopenharmony_ci	@echo  '  htmldocs        - HTML'
17162306a36Sopenharmony_ci	@echo  '  texinfodocs     - Texinfo'
17262306a36Sopenharmony_ci	@echo  '  infodocs        - Info'
17362306a36Sopenharmony_ci	@echo  '  latexdocs       - LaTeX'
17462306a36Sopenharmony_ci	@echo  '  pdfdocs         - PDF'
17562306a36Sopenharmony_ci	@echo  '  epubdocs        - EPUB'
17662306a36Sopenharmony_ci	@echo  '  xmldocs         - XML'
17762306a36Sopenharmony_ci	@echo  '  linkcheckdocs   - check for broken external links'
17862306a36Sopenharmony_ci	@echo  '                    (will connect to external hosts)'
17962306a36Sopenharmony_ci	@echo  '  refcheckdocs    - check for references to non-existing files under'
18062306a36Sopenharmony_ci	@echo  '                    Documentation'
18162306a36Sopenharmony_ci	@echo  '  cleandocs       - clean all generated files'
18262306a36Sopenharmony_ci	@echo
18362306a36Sopenharmony_ci	@echo  '  make SPHINXDIRS="s1 s2" [target] Generate only docs of folder s1, s2'
18462306a36Sopenharmony_ci	@echo  '  valid values for SPHINXDIRS are: $(_SPHINXDIRS)'
18562306a36Sopenharmony_ci	@echo
18662306a36Sopenharmony_ci	@echo  '  make SPHINX_CONF={conf-file} [target] use *additional* sphinx-build'
18762306a36Sopenharmony_ci	@echo  '  configuration. This is e.g. useful to build with nit-picking config.'
18862306a36Sopenharmony_ci	@echo
18962306a36Sopenharmony_ci	@echo  '  make DOCS_THEME={sphinx-theme} selects a different Sphinx theme.'
19062306a36Sopenharmony_ci	@echo
19162306a36Sopenharmony_ci	@echo  '  make DOCS_CSS={a .css file} adds a DOCS_CSS override file for html/epub output.'
19262306a36Sopenharmony_ci	@echo
19362306a36Sopenharmony_ci	@echo  '  Default location for the generated documents is Documentation/output'
194