]> git.lizzy.rs Git - rust.git/blob - mk/docs.mk
manual -> reference & formatting
[rust.git] / mk / docs.mk
1 # Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
2 # file at the top-level directory of this distribution and at
3 # http://rust-lang.org/COPYRIGHT.
4 #
5 # Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 # http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 # <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 # option. This file may not be copied, modified, or distributed
9 # except according to those terms.
10
11 ######################################################################
12 # The various pieces of standalone documentation: guides, manual, etc
13 #
14 # The DOCS variable is their names (with no file extension).
15 #
16 # PDF_DOCS lists the targets for which PDF documentation should be
17 # build.
18 #
19 # RUSTDOC_FLAGS_xyz variables are extra arguments to pass to the
20 # rustdoc invocation for xyz.
21 #
22 # RUSTDOC_DEPS_xyz are extra dependencies for the rustdoc invocation
23 # on xyz.
24 #
25 # L10N_LANGS are the languages for which the docs have been
26 # translated.
27 ######################################################################
28 DOCS := index intro tutorial guide guide-ffi guide-macros guide-lifetimes \
29         guide-tasks guide-container guide-pointers guide-testing \
30         guide-runtime complement-bugreport \
31         complement-lang-faq complement-design-faq complement-project-faq rust \
32     rustdoc guide-unsafe guide-strings reference
33
34 PDF_DOCS := guide reference
35
36 RUSTDOC_DEPS_rust := doc/full-toc.inc
37 RUSTDOC_FLAGS_rust := --html-in-header=doc/full-toc.inc
38
39 L10N_LANGS := ja
40
41 # Generally no need to edit below here.
42
43 # The options are passed to the documentation generators.
44 RUSTDOC_HTML_OPTS_NO_CSS = --html-before-content=doc/version_info.html \
45         --html-in-header=doc/favicon.inc \
46         --html-after-content=doc/footer.inc \
47         --markdown-playground-url='http://play.rust-lang.org/'
48
49 RUSTDOC_HTML_OPTS = $(RUSTDOC_HTML_OPTS_NO_CSS) --markdown-css rust.css
50
51 PANDOC_BASE_OPTS := --standalone --toc --number-sections
52 PANDOC_TEX_OPTS = $(PANDOC_BASE_OPTS) --include-before-body=doc/version.tex \
53         --from=markdown --include-before-body=doc/footer.tex --to=latex
54 PANDOC_EPUB_OPTS = $(PANDOC_BASE_OPTS) --to=epub
55
56 # The rustdoc executable...
57 RUSTDOC_EXE = $(HBIN2_H_$(CFG_BUILD))/rustdoc$(X_$(CFG_BUILD))
58 # ...with rpath included in case --disable-rpath was provided to
59 # ./configure
60 RUSTDOC = $(RPATH_VAR2_T_$(CFG_BUILD)_H_$(CFG_BUILD)) $(RUSTDOC_EXE)
61
62 D := $(S)src/doc
63
64 DOC_TARGETS :=
65 COMPILER_DOC_TARGETS :=
66 DOC_L10N_TARGETS :=
67
68 # If NO_REBUILD is set then break the dependencies on rustdoc so we
69 # build the documentation without having to rebuild rustdoc.
70 ifeq ($(NO_REBUILD),)
71 HTML_DEPS := $(RUSTDOC_EXE)
72 else
73 HTML_DEPS :=
74 endif
75
76 # Check for the various external utilities for the EPUB/PDF docs:
77
78 ifeq ($(CFG_LUALATEX),)
79   $(info cfg: no lualatex found, deferring to xelatex)
80   ifeq ($(CFG_XELATEX),)
81     $(info cfg: no xelatex found, deferring to pdflatex)
82     ifeq ($(CFG_PDFLATEX),)
83       $(info cfg: no pdflatex found, disabling LaTeX docs)
84       NO_PDF_DOCS = 1
85         else
86       CFG_LATEX := $(CFG_PDFLATEX)
87     endif
88   else
89     CFG_LATEX := $(CFG_XELATEX)
90     XELATEX = 1
91   endif
92 else
93   CFG_LATEX := $(CFG_LUALATEX)
94 endif
95
96
97 ifeq ($(CFG_PANDOC),)
98 $(info cfg: no pandoc found, omitting PDF and EPUB docs)
99 ONLY_HTML_DOCS = 1
100 endif
101
102
103 ######################################################################
104 # Rust version
105 ######################################################################
106
107 doc/version.tex: $(MKFILE_DEPS) $(wildcard $(D)/*.*) | doc/
108         @$(call E, version-stamp: $@)
109         $(Q)echo "$(CFG_VERSION)" >$@
110
111 HTML_DEPS += doc/version_info.html
112 doc/version_info.html: $(D)/version_info.html.template $(MKFILE_DEPS) \
113                        $(wildcard $(D)/*.*) | doc/
114         @$(call E, version-info: $@)
115         $(Q)sed -e "s/VERSION/$(CFG_RELEASE)/; s/SHORT_HASH/$( \
116                     CFG_SHORT_VER_HASH)/; \
117                 s/STAMP/$(CFG_VER_HASH)/;" $< >$@
118
119 GENERATED += doc/version.tex doc/version_info.html
120
121 ######################################################################
122 # Docs, from rustdoc and sometimes pandoc
123 ######################################################################
124
125 doc/:
126         @mkdir -p $@
127
128 HTML_DEPS += doc/rust.css
129 doc/rust.css: $(D)/rust.css | doc/
130         @$(call E, cp: $@)
131         $(Q)cp -a $< $@ 2> /dev/null
132
133 HTML_DEPS += doc/favicon.inc
134 doc/favicon.inc: $(D)/favicon.inc | doc/
135         @$(call E, cp: $@)
136         $(Q)cp -a $< $@ 2> /dev/null
137
138 doc/full-toc.inc: $(D)/full-toc.inc | doc/
139         @$(call E, cp: $@)
140         $(Q)cp -a $< $@ 2> /dev/null
141
142 HTML_DEPS += doc/footer.inc
143 doc/footer.inc: $(D)/footer.inc | doc/
144         @$(call E, cp: $@)
145         $(Q)cp -a $< $@ 2> /dev/null
146
147 # The (english) documentation for each doc item.
148
149 define DEF_SHOULD_BUILD_PDF_DOC
150 SHOULD_BUILD_PDF_DOC_$(1) = 1
151 endef
152 $(foreach docname,$(PDF_DOCS),$(eval $(call DEF_SHOULD_BUILD_PDF_DOC,$(docname))))
153
154 doc/footer.tex: $(D)/footer.inc | doc/
155         @$(call E, pandoc: $@)
156         $(CFG_PANDOC) --from=html --to=latex $< --output=$@
157
158 # HTML (rustdoc)
159 DOC_TARGETS += doc/not_found.html
160 doc/not_found.html: $(D)/not_found.md $(HTML_DEPS) | doc/
161         @$(call E, rustdoc: $@)
162         $(Q)$(RUSTDOC) $(RUSTDOC_HTML_OPTS_NO_CSS) \
163                 --markdown-css http://doc.rust-lang.org/rust.css $<
164
165 define DEF_DOC
166
167 # HTML (rustdoc)
168 DOC_TARGETS += doc/$(1).html
169 doc/$(1).html: $$(D)/$(1).md $$(HTML_DEPS) $$(RUSTDOC_DEPS_$(1)) | doc/
170         @$$(call E, rustdoc: $$@)
171         $$(Q)$$(RUSTDOC) $$(RUSTDOC_HTML_OPTS) $$(RUSTDOC_FLAGS_$(1)) $$<
172
173 ifneq ($(ONLY_HTML_DOCS),1)
174
175 # EPUB (pandoc directly)
176 DOC_TARGETS += doc/$(1).epub
177 doc/$(1).epub: $$(D)/$(1).md | doc/
178         @$$(call E, pandoc: $$@)
179         $$(CFG_PANDOC) $$(PANDOC_EPUB_OPTS) $$< --output=$$@
180
181 # PDF (md =(pandoc)=> tex =(pdflatex)=> pdf)
182 DOC_TARGETS += doc/$(1).tex
183 doc/$(1).tex: $$(D)/$(1).md doc/footer.tex doc/version.tex | doc/
184         @$$(call E, pandoc: $$@)
185         $$(CFG_PANDOC) $$(PANDOC_TEX_OPTS) $$< --output=$$@
186
187 ifneq ($(NO_PDF_DOCS),1)
188 ifeq ($$(SHOULD_BUILD_PDF_DOC_$(1)),1)
189 DOC_TARGETS += doc/$(1).pdf
190 ifneq ($(XELATEX),1)
191 doc/$(1).pdf: doc/$(1).tex
192         @$$(call E, latex compiler: $$@)
193         $$(Q)$$(CFG_LATEX) \
194         -interaction=batchmode \
195         -output-directory=doc \
196         $$<
197 else
198 # The version of xelatex on the snap bots seemingly ingores -output-directory
199 # So we'll output to . and move to the doc directory manually.
200 # This will leave some intermediate files in the build directory.
201 doc/$(1).pdf: doc/$(1).tex
202         @$$(call E, latex compiler: $$@)
203         $$(Q)$$(CFG_LATEX) \
204         -interaction=batchmode \
205         -output-directory=. \
206         $$<
207         $$(Q)mv ./$(1).pdf $$@
208 endif # XELATEX
209 endif # SHOULD_BUILD_PDF_DOCS_$(1)
210 endif # NO_PDF_DOCS
211
212 endif # ONLY_HTML_DOCS
213
214 endef
215
216 $(foreach docname,$(DOCS),$(eval $(call DEF_DOC,$(docname))))
217
218
219 # Localized documentation
220
221 # FIXME: I (huonw) haven't actually been able to test properly, since
222 # e.g. (by default) I'm doing an out-of-tree build (#12763), but even
223 # adjusting for that, the files are too old(?) and are rejected by
224 # po4a.
225 #
226 # As such, I've attempted to get it working as much as possible (and
227 # switching from pandoc to rustdoc), but preserving the old behaviour
228 # (e.g. only running on the guide)
229 .PHONY: l10n-mds
230 l10n-mds: $(D)/po4a.conf \
231                 $(foreach lang,$(L10N_LANG),$(D)/po/$(lang)/*.md.po)
232         $(warning WARNING: localized documentation is experimental)
233         po4a --copyright-holder="The Rust Project Developers" \
234                 --package-name="Rust" \
235                 --package-version="$(CFG_RELEASE)" \
236                 -M UTF-8 -L UTF-8 \
237                 $(D)/po4a.conf
238
239 define DEF_L10N_DOC
240 DOC_L10N_TARGETS += doc/l10n/$(1)/$(2).html
241 doc/l10n/$(1)/$(2).html: l10n-mds $$(HTML_DEPS) $$(RUSTDOC_DEPS_$(2))
242         @$$(call E, rustdoc: $$@)
243         $$(RUSTDOC) $$(RUSTDOC_HTML_OPTS) $$(RUSTDOC_FLAGS_$(1)) doc/l10n/$(1)/$(2).md
244 endef
245
246 $(foreach lang,$(L10N_LANGS),$(eval $(call DEF_L10N_DOC,$(lang),guide)))
247
248
249 ######################################################################
250 # LLnextgen (grammar analysis from refman)
251 ######################################################################
252
253 ifeq ($(CFG_LLNEXTGEN),)
254   $(info cfg: no llnextgen found, omitting grammar-verification)
255 else
256 .PHONY: verify-grammar
257
258 doc/rust.g: $(D)/rust.md $(S)src/etc/extract_grammar.py
259         @$(call E, extract_grammar: $@)
260         $(Q)$(CFG_PYTHON) $(S)src/etc/extract_grammar.py $< >$@
261
262 verify-grammar: doc/rust.g
263         @$(call E, LLnextgen: $<)
264         $(Q)$(CFG_LLNEXTGEN) --generate-lexer-wrapper=no $< >$@
265         $(Q)rm -f doc/rust.c doc/rust.h
266 endif
267
268
269 ######################################################################
270 # Rustdoc (libstd/extra)
271 ######################################################################
272
273
274 # The library documenting macro
275 #
276 # $(1) - The crate name (std/extra)
277 #
278 # Passes --cfg stage2 to rustdoc because it uses the stage2 librustc.
279 define DEF_LIB_DOC
280
281 # If NO_REBUILD is set then break the dependencies on rustdoc so we
282 # build crate documentation without having to rebuild rustdoc.
283 ifeq ($(NO_REBUILD),)
284 LIB_DOC_DEP_$(1) = \
285         $$(CRATEFILE_$(1)) \
286         $$(RSINPUTS_$(1)) \
287         $$(RUSTDOC_EXE) \
288         $$(foreach dep,$$(RUST_DEPS_$(1)), \
289                 $$(TLIB2_T_$(CFG_BUILD)_H_$(CFG_BUILD))/stamp.$$(dep) \
290                 doc/$$(dep)/)
291 else
292 LIB_DOC_DEP_$(1) = $$(CRATEFILE_$(1)) $$(RSINPUTS_$(1))
293 endif
294
295 doc/$(1)/:
296         $$(Q)mkdir -p $$@
297
298 $(2) += doc/$(1)/index.html
299 doc/$(1)/index.html: CFG_COMPILER_HOST_TRIPLE = $(CFG_TARGET)
300 doc/$(1)/index.html: $$(LIB_DOC_DEP_$(1)) doc/$(1)/
301         @$$(call E, rustdoc: $$@)
302         $$(Q)$$(RUSTDOC) --cfg dox --cfg stage2 $$<
303 endef
304
305 $(foreach crate,$(DOC_CRATES),$(eval $(call DEF_LIB_DOC,$(crate),DOC_TARGETS)))
306 $(foreach crate,$(COMPILER_DOC_CRATES),$(eval $(call DEF_LIB_DOC,$(crate),COMPILER_DOC_TARGETS)))
307
308 ifdef CFG_DISABLE_DOCS
309   $(info cfg: disabling doc build (CFG_DISABLE_DOCS))
310   DOC_TARGETS :=
311   COMPILER_DOC_TARGETS :=
312 endif
313
314 docs: $(DOC_TARGETS)
315 compiler-docs: $(COMPILER_DOC_TARGETS)
316
317 docs-l10n: $(DOC_L10N_TARGETS)
318
319 .PHONY: docs-l10n