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