← Documents Documentation/Makefile GitHub 원문 ↗

Linux 6.18.37 · Documentation Build

Documentation Makefile

Kernel Documentation의 Sphinx dependency 검사, builder command, HTML·PDF·EPUB·XML target과 help option을 정의하는 Makefile입니다.

Source pathDocumentation/Makefile
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.

1. 요약·해설

원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.

요약·해설

Makefile:1-204

이 Makefile은 Sphinx 설치와 config를 검사하고 여러 documentation book을 Kbuild jobserver 아래에서 format별로 생성합니다.

HTML·Texinfo·Info·LaTeX·PDF·EPUB·XML, link·file reference 검사와 clean target을 제공하며 command-line 변수로 source 범위, theme, CSS, config를 조정합니다.

원문 code와 target 이름은 그대로 보존하고 각 conditional·variable·command·help line의 역할을 한국어로 설명했습니다.

2. 영어 원문 전체

번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.

원문 전체 펼치기
1 # -*- makefile -*-
2 # Makefile for Sphinx documentation
3 #
4
5 # for cleaning
6 subdir- := devicetree/bindings
7
8 ifneq ($(MAKECMDGOALS),cleandocs)
9 # Check for broken documentation file references
10 ifeq ($(CONFIG_WARN_MISSING_DOCUMENTS),y)
11 $(shell $(srctree)/scripts/documentation-file-ref-check --warn)
12 endif
13
14 # Check for broken ABI files
15 ifeq ($(CONFIG_WARN_ABI_ERRORS),y)
16 $(shell $(srctree)/scripts/get_abi.py --dir $(srctree)/Documentation/ABI validate)
17 endif
18 endif
19
20 # You can set these variables from the command line.
21 SPHINXBUILD = sphinx-build
22 SPHINXOPTS =
23 SPHINXDIRS = .
24 DOCS_THEME =
25 DOCS_CSS =
26 _SPHINXDIRS = $(sort $(patsubst $(srctree)/Documentation/%/index.rst,%,$(wildcard $(srctree)/Documentation/*/index.rst)))
27 SPHINX_CONF = conf.py
28 PAPER =
29 BUILDDIR = $(obj)/output
30 PDFLATEX = xelatex
31 LATEXOPTS = -interaction=batchmode -no-shell-escape
32
33 # For denylisting "variable font" files
34 # Can be overridden by setting as an env variable
35 FONTS_CONF_DENY_VF ?= $(HOME)/deny-vf
36
37 ifeq ($(findstring 1, $(KBUILD_VERBOSE)),)
38 SPHINXOPTS += "-q"
39 endif
40
41 # User-friendly check for sphinx-build
42 HAVE_SPHINX := $(shell if which $(SPHINXBUILD) >/dev/null 2>&1; then echo 1; else echo 0; fi)
43
44 ifeq ($(HAVE_SPHINX),0)
45
46 .DEFAULT:
47 $(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.)
48 @echo
49 @$(srctree)/scripts/sphinx-pre-install
50 @echo " SKIP Sphinx $@ target."
51
52 else # HAVE_SPHINX
53
54 # User-friendly check for pdflatex and latexmk
55 HAVE_PDFLATEX := $(shell if which $(PDFLATEX) >/dev/null 2>&1; then echo 1; else echo 0; fi)
56 HAVE_LATEXMK := $(shell if which latexmk >/dev/null 2>&1; then echo 1; else echo 0; fi)
57
58 ifeq ($(HAVE_LATEXMK),1)
59 PDFLATEX := latexmk -$(PDFLATEX)
60 endif #HAVE_LATEXMK
61
62 # Internal variables.
63 PAPEROPT_a4 = -D latex_elements.papersize=a4paper
64 PAPEROPT_letter = -D latex_elements.papersize=letterpaper
65 ALLSPHINXOPTS = -D kerneldoc_srctree=$(srctree) -D kerneldoc_bin=$(KERNELDOC)
66 ALLSPHINXOPTS += $(PAPEROPT_$(PAPER)) $(SPHINXOPTS)
67 ifneq ($(wildcard $(srctree)/.config),)
68 ifeq ($(CONFIG_RUST),y)
69 # Let Sphinx know we will include rustdoc
70 ALLSPHINXOPTS += -t rustdoc
71 endif
72 endif
73 # the i18n builder cannot share the environment and doctrees with the others
74 I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
75
76 # commands; the 'cmd' from scripts/Kbuild.include is not *loopable*
77 loop_cmd = $(echo-cmd) $(cmd_$(1)) || exit;
78
79 # $2 sphinx builder e.g. "html"
80 # $3 name of the build subfolder / e.g. "userspace-api/media", used as:
81 # * dest folder relative to $(BUILDDIR) and
82 # * cache folder relative to $(BUILDDIR)/.doctrees
83 # $4 dest subfolder e.g. "man" for man pages at userspace-api/media/man
84 # $5 reST source folder relative to $(src),
85 # e.g. "userspace-api/media" for the linux-tv book-set at ./Documentation/userspace-api/media
86
87 PYTHONPYCACHEPREFIX ?= $(abspath $(BUILDDIR)/__pycache__)
88
89 quiet_cmd_sphinx = SPHINX $@ --> file://$(abspath $(BUILDDIR)/$3/$4)
90 cmd_sphinx = \
91 PYTHONPYCACHEPREFIX="$(PYTHONPYCACHEPREFIX)" \
92 BUILDDIR=$(abspath $(BUILDDIR)) SPHINX_CONF=$(abspath $(src)/$5/$(SPHINX_CONF)) \
93 $(PYTHON3) $(srctree)/scripts/jobserver-exec \
94 $(CONFIG_SHELL) $(srctree)/Documentation/sphinx/parallel-wrapper.sh \
95 $(SPHINXBUILD) \
96 -b $2 \
97 -c $(abspath $(src)) \
98 -d $(abspath $(BUILDDIR)/.doctrees/$3) \
99 -D version=$(KERNELVERSION) -D release=$(KERNELRELEASE) \
100 $(ALLSPHINXOPTS) \
101 $(abspath $(src)/$5) \
102 $(abspath $(BUILDDIR)/$3/$4) && \
103 if [ "x$(DOCS_CSS)" != "x" ]; then \
104 cp $(if $(patsubst /%,,$(DOCS_CSS)),$(abspath $(srctree)/$(DOCS_CSS)),$(DOCS_CSS)) $(BUILDDIR)/$3/_static/; \
105 fi
106
107 htmldocs:
108 @$(srctree)/scripts/sphinx-pre-install --version-check
109 @+$(foreach var,$(SPHINXDIRS),$(call loop_cmd,sphinx,html,$(var),,$(var)))
110
111 htmldocs-redirects: $(srctree)/Documentation/.renames.txt
112 @tools/docs/gen-redirects.py --output $(BUILDDIR) < $<
113
114 # If Rust support is available and .config exists, add rustdoc generated contents.
115 # If there are any, the errors from this make rustdoc will be displayed but
116 # won't stop the execution of htmldocs
117
118 ifneq ($(wildcard $(srctree)/.config),)
119 ifeq ($(CONFIG_RUST),y)
120 $(Q)$(MAKE) rustdoc || true
121 endif
122 endif
123
124 texinfodocs:
125 @$(srctree)/scripts/sphinx-pre-install --version-check
126 @+$(foreach var,$(SPHINXDIRS),$(call loop_cmd,sphinx,texinfo,$(var),texinfo,$(var)))
127
128 # Note: the 'info' Make target is generated by sphinx itself when
129 # running the texinfodocs target define above.
130 infodocs: texinfodocs
131 $(MAKE) -C $(BUILDDIR)/texinfo info
132
133 linkcheckdocs:
134 @$(foreach var,$(SPHINXDIRS),$(call loop_cmd,sphinx,linkcheck,$(var),,$(var)))
135
136 latexdocs:
137 @$(srctree)/scripts/sphinx-pre-install --version-check
138 @+$(foreach var,$(SPHINXDIRS),$(call loop_cmd,sphinx,latex,$(var),latex,$(var)))
139
140 ifeq ($(HAVE_PDFLATEX),0)
141
142 pdfdocs:
143 $(warning The '$(PDFLATEX)' command was not found. Make sure you have it installed and in PATH to produce PDF output.)
144 @echo " SKIP Sphinx $@ target."
145
146 else # HAVE_PDFLATEX
147
148 pdfdocs: DENY_VF = XDG_CONFIG_HOME=$(FONTS_CONF_DENY_VF)
149 pdfdocs: latexdocs
150 @$(srctree)/scripts/sphinx-pre-install --version-check
151 $(foreach var,$(SPHINXDIRS), \
152 $(MAKE) PDFLATEX="$(PDFLATEX)" LATEXOPTS="$(LATEXOPTS)" $(DENY_VF) -C $(BUILDDIR)/$(var)/latex || sh $(srctree)/scripts/check-variable-fonts.sh || exit; \
153 mkdir -p $(BUILDDIR)/$(var)/pdf; \
154 mv $(subst .tex,.pdf,$(wildcard $(BUILDDIR)/$(var)/latex/*.tex)) $(BUILDDIR)/$(var)/pdf/; \
155 )
156
157 endif # HAVE_PDFLATEX
158
159 epubdocs:
160 @$(srctree)/scripts/sphinx-pre-install --version-check
161 @+$(foreach var,$(SPHINXDIRS),$(call loop_cmd,sphinx,epub,$(var),epub,$(var)))
162
163 xmldocs:
164 @$(srctree)/scripts/sphinx-pre-install --version-check
165 @+$(foreach var,$(SPHINXDIRS),$(call loop_cmd,sphinx,xml,$(var),xml,$(var)))
166
167 endif # HAVE_SPHINX
168
169 # The following targets are independent of HAVE_SPHINX, and the rules should
170 # work or silently pass without Sphinx.
171
172 refcheckdocs:
173 $(Q)cd $(srctree);scripts/documentation-file-ref-check
174
175 cleandocs:
176 $(Q)rm -rf $(BUILDDIR)
177
178 dochelp:
179 @echo ' Linux kernel internal documentation in different formats from ReST:'
180 @echo ' htmldocs - HTML'
181 @echo ' htmldocs-redirects - generate HTML redirects for moved pages'
182 @echo ' texinfodocs - Texinfo'
183 @echo ' infodocs - Info'
184 @echo ' latexdocs - LaTeX'
185 @echo ' pdfdocs - PDF'
186 @echo ' epubdocs - EPUB'
187 @echo ' xmldocs - XML'
188 @echo ' linkcheckdocs - check for broken external links'
189 @echo ' (will connect to external hosts)'
190 @echo ' refcheckdocs - check for references to non-existing files under'
191 @echo ' Documentation'
192 @echo ' cleandocs - clean all generated files'
193 @echo
194 @echo ' make SPHINXDIRS="s1 s2" [target] Generate only docs of folder s1, s2'
195 @echo ' valid values for SPHINXDIRS are: $(_SPHINXDIRS)'
196 @echo
197 @echo ' make SPHINX_CONF={conf-file} [target] use *additional* sphinx-build'
198 @echo ' configuration. This is e.g. useful to build with nit-picking config.'
199 @echo
200 @echo ' make DOCS_THEME={sphinx-theme} selects a different Sphinx theme.'
201 @echo
202 @echo ' make DOCS_CSS={a .css file} adds a DOCS_CSS override file for html/epub output.'
203 @echo
204 @echo ' Default location for the generated documents is Documentation/output'
205

3. 한국어 전문 번역

영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.

정리 대상과 사전 문서 검사

1-18

이 file은 Sphinx documentation을 build하는 Makefile입니다. `subdir- := devicetree/bindings`는 정리 대상 하위 directory를 등록합니다.

`cleandocs`가 아닌 target을 실행할 때만 broken documentation file reference와 ABI file을 검사합니다. `CONFIG_WARN_MISSING_DOCUMENTS=y`이면 `scripts/documentation-file-ref-check --warn`을 실행합니다.

`CONFIG_WARN_ABI_ERRORS=y`이면 `scripts/get_abi.py --dir Documentation/ABI validate`를 실행해 ABI file을 검증합니다. 정리 작업에서는 이런 사전 검사를 건너뜁니다.

Build 전 조건부 검사
조건실행 도구목적
Target이 `cleandocs` 아님 + `CONFIG_WARN_MISSING_DOCUMENTS=y``documentation-file-ref-check --warn`깨진 문서 file reference 경고
Target이 `cleandocs` 아님 + `CONFIG_WARN_ABI_ERRORS=y``get_abi.py ... validate`ABI 문서 형식·내용 검증
`cleandocs`사전 검사 생략생성물 정리에 집중

Config와 target에 따라 reference·ABI 검사를 선택합니다.

# -*- makefile -*-
# Makefile for Sphinx documentation
#

# for cleaning
subdir- := devicetree/bindings

ifneq ($(MAKECMDGOALS),cleandocs)
# Check for broken documentation file references
ifeq ($(CONFIG_WARN_MISSING_DOCUMENTS),y)
$(shell $(srctree)/scripts/documentation-file-ref-check --warn)
endif

# Check for broken ABI files
ifeq ($(CONFIG_WARN_ABI_ERRORS),y)
$(shell $(srctree)/scripts/get_abi.py --dir $(srctree)/Documentation/ABI validate)
endif
endif

Command-line 변수와 기본값

19-43

사용자는 command line에서 Sphinx build 관련 변수를 덮어쓸 수 있습니다. `SPHINXBUILD`는 executable, `SPHINXOPTS`는 추가 option, `SPHINXDIRS`는 build할 문서 집합, `DOCS_THEME`와 `DOCS_CSS`는 theme와 CSS override입니다.

`_SPHINXDIRS`는 `Documentation/*/index.rst`를 찾아 유효한 최상위 Sphinx directory 목록을 계산합니다. `SPHINX_CONF=conf.py`, `PAPER`, `BUILDDIR=$(obj)/output`, `PDFLATEX=xelatex`, `LATEXOPTS=-interaction=batchmode -no-shell-escape`도 기본값으로 둡니다.

Variable font file을 denylist하기 위한 fontconfig 위치는 `FONTS_CONF_DENY_VF ?= $(HOME)/deny-vf`이며 environment variable로 덮어쓸 수 있습니다.

`KBUILD_VERBOSE`에 1이 없으면 `SPHINXOPTS`에 `-q`를 추가해 조용한 output을 사용합니다. 마지막으로 `which sphinx-build` 결과를 `HAVE_SPHINX`에 저장합니다.

주요 Documentation build 변수
변수기본값·의미
`SPHINXBUILD``sphinx-build` executable
`SPHINXDIRS``.` 또는 선택한 book directory
`SPHINX_CONF``conf.py`
`BUILDDIR``$(obj)/output`
`PDFLATEX``xelatex`, 가능하면 `latexmk -xelatex`
`DOCS_THEME`·`DOCS_CSS`Theme와 html·epub CSS override
`FONTS_CONF_DENY_VF`Variable font denylist용 config directory

입력 source, 출력 위치, renderer, 스타일을 command line에서 제어합니다.


# You can set these variables from the command line.
SPHINXBUILD   = sphinx-build
SPHINXOPTS    =
SPHINXDIRS    = .
DOCS_THEME    =
DOCS_CSS      =
_SPHINXDIRS   = $(sort $(patsubst $(srctree)/Documentation/%/index.rst,%,$(wildcard $(srctree)/Documentation/*/index.rst)))
SPHINX_CONF   = conf.py
PAPER         =
BUILDDIR      = $(obj)/output
PDFLATEX      = xelatex
LATEXOPTS     = -interaction=batchmode -no-shell-escape

# For denylisting "variable font" files
# Can be overridden by setting as an env variable
FONTS_CONF_DENY_VF ?= $(HOME)/deny-vf

ifeq ($(findstring 1, $(KBUILD_VERBOSE)),)
SPHINXOPTS    += "-q"
endif

# User-friendly check for sphinx-build
HAVE_SPHINX := $(shell if which $(SPHINXBUILD) >/dev/null 2>&1; then echo 1; else echo 0; fi)

Sphinx가 없을 때의 동작

44-57

`HAVE_SPHINX=0`이면 `.DEFAULT` rule이 모든 Sphinx target을 대신 처리합니다.

먼저 `sphinx-build` command를 찾지 못했다는 warning과 함께 Sphinx를 설치해 `PATH`에 넣거나 `SPHINXBUILD` make variable로 전체 경로를 지정하라고 안내합니다.

그 다음 `scripts/sphinx-pre-install`을 실행해 설치 정보를 보여 주고, 요청한 Sphinx target을 `SKIP`했다고 출력합니다. Build를 이해하기 어려운 command-not-found 오류로 끝내지 않고 사용 가능한 안내를 제공합니다.

Sphinx 부재 처리
`which $(SPHINXBUILD)` 실패`HAVE_SPHINX=0`설치 또는 `SPHINXBUILD` 경로 설정 warning`scripts/sphinx-pre-install` 실행현재 Sphinx target을 `SKIP` 표시

Dependency 확인 실패를 설치 안내와 명시적 skip으로 바꿉니다.

ifeq ($(HAVE_SPHINX),0)

.DEFAULT:
        $(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.)
        @echo
        @$(srctree)/scripts/sphinx-pre-install
        @echo "  SKIP    Sphinx $@ target."

else # HAVE_SPHINX

# User-friendly check for pdflatex and latexmk
HAVE_PDFLATEX := $(shell if which $(PDFLATEX) >/dev/null 2>&1; then echo 1; else echo 0; fi)
HAVE_LATEXMK := $(shell if which latexmk >/dev/null 2>&1; then echo 1; else echo 0; fi)

PDF tool과 내부 Sphinx option

58-82

Sphinx가 있으면 `pdflatex` 역할의 `PDFLATEX` command와 `latexmk` 존재 여부를 검사합니다. `latexmk`가 있으면 `PDFLATEX`를 `latexmk -$(PDFLATEX)` 형태로 바꿔 PDF build를 관리합니다.

Paper size option은 A4와 letter용 `PAPEROPT_a4`, `PAPEROPT_letter`로 나뉩니다. `ALLSPHINXOPTS`에는 kernel source tree와 `kernel-doc` binary 위치를 정의하고 선택한 paper option과 사용자 `SPHINXOPTS`를 더합니다.

Kernel `.config`가 있고 `CONFIG_RUST=y`이면 Sphinx에 `-t rustdoc` tag를 넘겨 rustdoc 생성 내용을 포함한다고 알립니다.

i18n builder는 다른 builder와 environment·doctree를 공유할 수 없어 별도 `I18NSPHINXOPTS`를 사용합니다. `loop_cmd`는 Kbuild의 loop 불가능한 `cmd`를 여러 `SPHINXDIRS`에 적용하도록 감싼 command입니다.

내부 option 구성
항목역할
`PAPEROPT_*`LaTeX paper size 정의
`ALLSPHINXOPTS`Source tree·kernel-doc·paper·사용자 option 결합
`-t rustdoc`Rust 지원 시 rustdoc content 포함
`I18NSPHINXOPTS`공유할 수 없는 i18n 환경 분리
`loop_cmd`여러 documentation directory 순회

Builder와 kernel config에 따라 Sphinx 실행 인자를 조립합니다.

ifeq ($(HAVE_LATEXMK),1)
        PDFLATEX := latexmk -$(PDFLATEX)
endif #HAVE_LATEXMK

# Internal variables.
PAPEROPT_a4     = -D latex_elements.papersize=a4paper
PAPEROPT_letter = -D latex_elements.papersize=letterpaper
ALLSPHINXOPTS   = -D kerneldoc_srctree=$(srctree) -D kerneldoc_bin=$(KERNELDOC)
ALLSPHINXOPTS   += $(PAPEROPT_$(PAPER)) $(SPHINXOPTS)
ifneq ($(wildcard $(srctree)/.config),)
ifeq ($(CONFIG_RUST),y)
        # Let Sphinx know we will include rustdoc
        ALLSPHINXOPTS   +=  -t rustdoc
endif
endif
# the i18n builder cannot share the environment and doctrees with the others
I18NSPHINXOPTS  = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .

# commands; the 'cmd' from scripts/Kbuild.include is not *loopable*
loop_cmd = $(echo-cmd) $(cmd_$(1)) || exit;

# $2 sphinx builder e.g. "html"
# $3 name of the build subfolder / e.g. "userspace-api/media", used as:
#    * dest folder relative to $(BUILDDIR) and
#    * cache folder relative to $(BUILDDIR)/.doctrees

Sphinx command와 HTML target

83-114

주석의 `$2`는 `html` 같은 Sphinx builder, `$3`는 build·doctree cache 하위 directory, `$4`는 man page 같은 destination subfolder, `$5`는 `Documentation` 기준 reST source folder입니다.

`PYTHONPYCACHEPREFIX`는 build output 아래 `__pycache__`를 사용합니다. `quiet_cmd_sphinx`는 target과 file URL을 표시하고, `cmd_sphinx`는 environment와 모든 Sphinx option을 조합해 실제 build를 실행합니다.

실행 chain은 `jobserver-exec`, `parallel-wrapper.sh`, `sphinx-build`를 거치며 builder, config, doctree cache, kernel version·release, source, destination을 전달합니다.

`DOCS_CSS`가 지정되면 상대 경로는 source tree 기준 absolute path로 바꿔 build 결과의 `_static`에 복사합니다.

`htmldocs`는 dependency version check 뒤 모든 `SPHINXDIRS`를 html builder로 build합니다. `htmldocs-redirects`는 `.renames.txt`를 입력으로 moved page redirect를 생성합니다.

Rust support와 `.config`가 있으면 `make rustdoc`을 실행하지만 오류가 html documentation build 전체를 중단하지 않도록 `|| true`를 사용합니다.

Sphinx build command
Builder·source·destination parameter 결정Kernel version·release와 doctree cache option 구성`scripts/jobserver-exec` 실행`Documentation/sphinx/parallel-wrapper.sh` 실행`sphinx-build`로 target format 생성선택한 `DOCS_CSS`를 `_static`에 복사

Kbuild jobserver와 wrapper를 통해 builder별 source를 output으로 변환합니다.

# $4 dest subfolder e.g. "man" for man pages at userspace-api/media/man
# $5 reST source folder relative to $(src),
#    e.g. "userspace-api/media" for the linux-tv book-set at ./Documentation/userspace-api/media

PYTHONPYCACHEPREFIX ?= $(abspath $(BUILDDIR)/__pycache__)

quiet_cmd_sphinx = SPHINX  $@ --> file://$(abspath $(BUILDDIR)/$3/$4)
      cmd_sphinx = \
        PYTHONPYCACHEPREFIX="$(PYTHONPYCACHEPREFIX)" \
        BUILDDIR=$(abspath $(BUILDDIR)) SPHINX_CONF=$(abspath $(src)/$5/$(SPHINX_CONF)) \
        $(PYTHON3) $(srctree)/scripts/jobserver-exec \
        $(CONFIG_SHELL) $(srctree)/Documentation/sphinx/parallel-wrapper.sh \
        $(SPHINXBUILD) \
        -b $2 \
        -c $(abspath $(src)) \
        -d $(abspath $(BUILDDIR)/.doctrees/$3) \
        -D version=$(KERNELVERSION) -D release=$(KERNELRELEASE) \
        $(ALLSPHINXOPTS) \
        $(abspath $(src)/$5) \
        $(abspath $(BUILDDIR)/$3/$4) && \
        if [ "x$(DOCS_CSS)" != "x" ]; then \
                cp $(if $(patsubst /%,,$(DOCS_CSS)),$(abspath $(srctree)/$(DOCS_CSS)),$(DOCS_CSS)) $(BUILDDIR)/$3/_static/; \
        fi

htmldocs:
        @$(srctree)/scripts/sphinx-pre-install --version-check
        @+$(foreach var,$(SPHINXDIRS),$(call loop_cmd,sphinx,html,$(var),,$(var)))

htmldocs-redirects: $(srctree)/Documentation/.renames.txt
        @tools/docs/gen-redirects.py --output $(BUILDDIR) < $<

# If Rust support is available and .config exists, add rustdoc generated contents.

Texinfo·linkcheck·LaTeX·PDF target

115-151

`texinfodocs`는 version check 뒤 texinfo builder를 실행합니다. Sphinx가 생성한 `info` Make target은 `infodocs`가 `$(BUILDDIR)/texinfo`에서 실행합니다.

`linkcheckdocs`는 외부 link를 검사하는 builder를 각 directory에 적용합니다. `latexdocs`는 LaTeX source를 만듭니다.

PDF tool이 없으면 `pdfdocs`는 설치 warning을 내고 target을 skip합니다. Tool이 있으면 `pdfdocs`가 `latexdocs`에 의존하고, variable font를 차단하는 `XDG_CONFIG_HOME`을 설정합니다.

각 Sphinx directory의 LaTeX output에서 PDF build를 실행합니다. 실패하면 `check-variable-fonts.sh`로 variable font 문제를 확인하고, `pdf` directory를 만든 뒤 생성된 `.pdf`를 옮깁니다.

문서 출력 target
Target결과·검사
`texinfodocs`Sphinx Texinfo source
`infodocs`Texinfo output에서 Info 생성
`linkcheckdocs`외부 link 유효성 검사
`latexdocs`LaTeX source 생성
`pdfdocs`LaTeX build, variable font 검사, PDF 정리

중간 format 생성과 최종 변환 단계를 구분합니다.

# If there are any, the errors from this make rustdoc will be displayed but
# won't stop the execution of htmldocs

ifneq ($(wildcard $(srctree)/.config),)
ifeq ($(CONFIG_RUST),y)
        $(Q)$(MAKE) rustdoc || true
endif
endif

texinfodocs:
        @$(srctree)/scripts/sphinx-pre-install --version-check
        @+$(foreach var,$(SPHINXDIRS),$(call loop_cmd,sphinx,texinfo,$(var),texinfo,$(var)))

# Note: the 'info' Make target is generated by sphinx itself when
# running the texinfodocs target define above.
infodocs: texinfodocs
        $(MAKE) -C $(BUILDDIR)/texinfo info

linkcheckdocs:
        @$(foreach var,$(SPHINXDIRS),$(call loop_cmd,sphinx,linkcheck,$(var),,$(var)))

latexdocs:
        @$(srctree)/scripts/sphinx-pre-install --version-check
        @+$(foreach var,$(SPHINXDIRS),$(call loop_cmd,sphinx,latex,$(var),latex,$(var)))

ifeq ($(HAVE_PDFLATEX),0)

pdfdocs:
        $(warning The '$(PDFLATEX)' command was not found. Make sure you have it installed and in PATH to produce PDF output.)
        @echo "  SKIP    Sphinx $@ target."

else # HAVE_PDFLATEX

pdfdocs: DENY_VF = XDG_CONFIG_HOME=$(FONTS_CONF_DENY_VF)
pdfdocs: latexdocs
        @$(srctree)/scripts/sphinx-pre-install --version-check
        $(foreach var,$(SPHINXDIRS), \

EPUB·XML과 Sphinx 조건 종료

152-171

`epubdocs`는 version check 후 각 `SPHINXDIRS`를 `epub` builder로 처리하고 destination도 `epub` subfolder로 지정합니다.

`xmldocs`는 같은 방식으로 `xml` builder를 실행해 XML output을 만듭니다.

여기서 `HAVE_SPHINX` 조건부 block이 끝납니다. 이후 target은 Sphinx 존재와 무관하게 동작하거나 Sphinx 없이 조용히 통과하도록 작성됩니다.

추가 builder
TargetBuilderDestination
`epubdocs``epub``epub`
`xmldocs``xml``xml`

같은 loop command에 builder와 destination만 바꿔 format을 추가합니다.

           $(MAKE) PDFLATEX="$(PDFLATEX)" LATEXOPTS="$(LATEXOPTS)" $(DENY_VF) -C $(BUILDDIR)/$(var)/latex || sh $(srctree)/scripts/check-variable-fonts.sh || exit; \
           mkdir -p $(BUILDDIR)/$(var)/pdf; \
           mv $(subst .tex,.pdf,$(wildcard $(BUILDDIR)/$(var)/latex/*.tex)) $(BUILDDIR)/$(var)/pdf/; \
        )

endif # HAVE_PDFLATEX

epubdocs:
        @$(srctree)/scripts/sphinx-pre-install --version-check
        @+$(foreach var,$(SPHINXDIRS),$(call loop_cmd,sphinx,epub,$(var),epub,$(var)))

xmldocs:
        @$(srctree)/scripts/sphinx-pre-install --version-check
        @+$(foreach var,$(SPHINXDIRS),$(call loop_cmd,sphinx,xml,$(var),xml,$(var)))

endif # HAVE_SPHINX

# The following targets are independent of HAVE_SPHINX, and the rules should
# work or silently pass without Sphinx.

독립 target과 dochelp

172-204

`refcheckdocs`는 source tree root에서 `scripts/documentation-file-ref-check`를 실행해 존재하지 않는 file reference를 검사합니다. `cleandocs`는 `$(BUILDDIR)`을 제거합니다.

`dochelp`는 사용 가능한 documentation target과 의미를 출력합니다. HTML, redirect, Texinfo, Info, LaTeX, PDF, EPUB, XML, external link check, internal file reference check, clean target을 안내합니다.

또한 `make SPHINXDIRS="s1 s2" [target]`으로 특정 folder만 생성하는 방법과 유효한 directory 목록을 보여 줍니다.

`SPHINX_CONF={conf-file}`로 추가 Sphinx config를 사용하고, `DOCS_THEME={sphinx-theme}`로 theme를 고르며, `DOCS_CSS={a .css file}`로 html·epub CSS override를 추가할 수 있습니다.

생성 문서의 기본 위치는 `Documentation/output`입니다.

Sphinx와 무관한 target·help option
항목의미
`refcheckdocs`존재하지 않는 Documentation file reference 검사
`cleandocs`생성 output 제거
`SPHINXDIRS`선택한 book directory만 build
`SPHINX_CONF`추가 Sphinx configuration
`DOCS_THEME`다른 Sphinx theme 선택
`DOCS_CSS`HTML·EPUB용 CSS override
기본 output`Documentation/output`

정리·reference 검사와 사용자 지정 build 방법을 제공합니다.

refcheckdocs:
        $(Q)cd $(srctree);scripts/documentation-file-ref-check

cleandocs:
        $(Q)rm -rf $(BUILDDIR)

dochelp:
        @echo  ' Linux kernel internal documentation in different formats from ReST:'
        @echo  '  htmldocs        - HTML'
        @echo  '  htmldocs-redirects - generate HTML redirects for moved pages'
        @echo  '  texinfodocs     - Texinfo'
        @echo  '  infodocs        - Info'
        @echo  '  latexdocs       - LaTeX'
        @echo  '  pdfdocs         - PDF'
        @echo  '  epubdocs        - EPUB'
        @echo  '  xmldocs         - XML'
        @echo  '  linkcheckdocs   - check for broken external links'
        @echo  '                    (will connect to external hosts)'
        @echo  '  refcheckdocs    - check for references to non-existing files under'
        @echo  '                    Documentation'
        @echo  '  cleandocs       - clean all generated files'
        @echo
        @echo  '  make SPHINXDIRS="s1 s2" [target] Generate only docs of folder s1, s2'
        @echo  '  valid values for SPHINXDIRS are: $(_SPHINXDIRS)'
        @echo
        @echo  '  make SPHINX_CONF={conf-file} [target] use *additional* sphinx-build'
        @echo  '  configuration. This is e.g. useful to build with nit-picking config.'
        @echo
        @echo  '  make DOCS_THEME={sphinx-theme} selects a different Sphinx theme.'
        @echo
        @echo  '  make DOCS_CSS={a .css file} adds a DOCS_CSS override file for html/epub output.'
        @echo
        @echo  '  Default location for the generated documents is Documentation/output'