]> git.lizzy.rs Git - rust.git/blob - mk/docs.mk
auto merge of #14644 : alexcrichton/rust/more-no-runtime-use-cases, r=brson
[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-design-faq complement-project-faq rust \
33     rustdoc 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         $(Q)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         @$(call E, rustdoc: $@)
160         $(Q)$(RUSTDOC) $(RUSTDOC_HTML_OPTS_NO_CSS) \
161                 --markdown-css http://doc.rust-lang.org/rust.css $<
162
163 define DEF_DOC
164
165 # HTML (rustdoc)
166 DOC_TARGETS += doc/$(1).html
167 doc/$(1).html: $$(D)/$(1).md $$(HTML_DEPS) $$(RUSTDOC_DEPS_$(1)) | doc/
168         @$$(call E, rustdoc: $$@)
169         $$(Q)$$(RUSTDOC) $$(RUSTDOC_HTML_OPTS) $$(RUSTDOC_FLAGS_$(1)) $$<
170
171 ifneq ($(ONLY_HTML_DOCS),1)
172
173 # EPUB (pandoc directly)
174 DOC_TARGETS += doc/$(1).epub
175 doc/$(1).epub: $$(D)/$(1).md | doc/
176         @$$(call E, pandoc: $$@)
177         $$(CFG_PANDOC) $$(PANDOC_EPUB_OPTS) $$< --output=$$@
178
179 # PDF (md =(pandoc)=> tex =(pdflatex)=> pdf)
180 DOC_TARGETS += doc/$(1).tex
181 doc/$(1).tex: $$(D)/$(1).md doc/footer.tex doc/version.tex | doc/
182         @$$(call E, pandoc: $$@)
183         $$(CFG_PANDOC) $$(PANDOC_TEX_OPTS) $$< --output=$$@
184
185 ifneq ($(NO_PDF_DOCS),1)
186 ifeq ($$(SHOULD_BUILD_PDF_DOC_$(1)),1)
187 DOC_TARGETS += doc/$(1).pdf
188 doc/$(1).pdf: doc/$(1).tex
189         @$$(call E, latex compiler: $$@)
190         $$(Q)$$(CFG_LATEX) \
191         -interaction=batchmode \
192         -output-directory=doc \
193         $$<
194 endif # SHOULD_BUILD_PDF_DOCS_$(1)
195 endif # NO_PDF_DOCS
196
197 endif # ONLY_HTML_DOCS
198
199 endef
200
201 $(foreach docname,$(DOCS),$(eval $(call DEF_DOC,$(docname))))
202
203
204 # Localized documentation
205
206 # FIXME: I (huonw) haven't actually been able to test properly, since
207 # e.g. (by default) I'm doing an out-of-tree build (#12763), but even
208 # adjusting for that, the files are too old(?) and are rejected by
209 # po4a.
210 #
211 # As such, I've attempted to get it working as much as possible (and
212 # switching from pandoc to rustdoc), but preserving the old behaviour
213 # (e.g. only running on the tutorial)
214 .PHONY: l10n-mds
215 l10n-mds: $(D)/po4a.conf \
216                 $(foreach lang,$(L10N_LANG),$(D)/po/$(lang)/*.md.po)
217         $(warning WARNING: localized documentation is experimental)
218         po4a --copyright-holder="The Rust Project Developers" \
219                 --package-name="Rust" \
220                 --package-version="$(CFG_RELEASE)" \
221                 -M UTF-8 -L UTF-8 \
222                 $(D)/po4a.conf
223
224 define DEF_L10N_DOC
225 DOC_L10N_TARGETS += doc/l10n/$(1)/$(2).html
226 doc/l10n/$(1)/$(2).html: l10n-mds $$(HTML_DEPS) $$(RUSTDOC_DEPS_$(2))
227         @$$(call E, rustdoc: $$@)
228         $$(RUSTDOC) $$(RUSTDOC_HTML_OPTS) $$(RUSTDOC_FLAGS_$(1)) doc/l10n/$(1)/$(2).md
229 endef
230
231 $(foreach lang,$(L10N_LANGS),$(eval $(call DEF_L10N_DOC,$(lang),tutorial)))
232
233
234 ######################################################################
235 # LLnextgen (grammar analysis from refman)
236 ######################################################################
237
238 ifeq ($(CFG_LLNEXTGEN),)
239   $(info cfg: no llnextgen found, omitting grammar-verification)
240 else
241 .PHONY: verify-grammar
242
243 doc/rust.g: $(D)/rust.md $(S)src/etc/extract_grammar.py
244         @$(call E, extract_grammar: $@)
245         $(Q)$(CFG_PYTHON) $(S)src/etc/extract_grammar.py $< >$@
246
247 verify-grammar: doc/rust.g
248         @$(call E, LLnextgen: $<)
249         $(Q)$(CFG_LLNEXTGEN) --generate-lexer-wrapper=no $< >$@
250         $(Q)rm -f doc/rust.c doc/rust.h
251 endif
252
253
254 ######################################################################
255 # Rustdoc (libstd/extra)
256 ######################################################################
257
258
259 # The library documenting macro
260 #
261 # $(1) - The crate name (std/extra)
262 #
263 # Passes --cfg stage2 to rustdoc because it uses the stage2 librustc.
264 define DEF_LIB_DOC
265
266 # If NO_REBUILD is set then break the dependencies on rustdoc so we
267 # build crate documentation without having to rebuild rustdoc.
268 ifeq ($(NO_REBUILD),)
269 LIB_DOC_DEP_$(1) = \
270         $$(CRATEFILE_$(1)) \
271         $$(RSINPUTS_$(1)) \
272         $$(RUSTDOC_EXE) \
273         $$(foreach dep,$$(RUST_DEPS_$(1)), \
274                 $$(TLIB2_T_$(CFG_BUILD)_H_$(CFG_BUILD))/stamp.$$(dep))
275 else
276 LIB_DOC_DEP_$(1) = $$(CRATEFILE_$(1)) $$(RSINPUTS_$(1))
277 endif
278
279 $(2) += doc/$(1)/index.html
280 doc/$(1)/index.html: CFG_COMPILER_HOST_TRIPLE = $(CFG_TARGET)
281 doc/$(1)/index.html: $$(LIB_DOC_DEP_$(1))
282         @$$(call E, rustdoc $$@)
283         $$(Q)$$(RUSTDOC) --cfg dox --cfg stage2 $$<
284 endef
285
286 $(foreach crate,$(DOC_CRATES),$(eval $(call DEF_LIB_DOC,$(crate),DOC_TARGETS)))
287 $(foreach crate,$(COMPILER_DOC_CRATES),$(eval $(call DEF_LIB_DOC,$(crate),COMPILER_DOC_TARGETS)))
288
289 ifdef CFG_DISABLE_DOCS
290   $(info cfg: disabling doc build (CFG_DISABLE_DOCS))
291   DOC_TARGETS :=
292   COMPILER_DOC_TARGETS :=
293 endif
294
295 docs: $(DOC_TARGETS)
296 compiler-docs: $(COMPILER_DOC_TARGETS)
297
298 docs-l10n: $(DOC_L10N_TARGETS)
299
300 .PHONY: docs-l10n