]> git.proxmox.com Git - rustc.git/blob - mk/docs.mk
Imported Upstream version 1.0.0~beta
[rustc.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.
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 \
29 complement-lang-faq complement-design-faq complement-project-faq \
30 rustdoc reference grammar
31
32 # Legacy guides, preserved for a while to reduce the number of 404s
33 DOCS += guide-crates guide-error-handling guide-ffi guide-macros guide \
34 guide-ownership guide-plugins guide-pointers guide-strings guide-tasks \
35 guide-testing
36
37
38 PDF_DOCS := reference
39
40 RUSTDOC_DEPS_reference := doc/full-toc.inc
41 RUSTDOC_FLAGS_reference := --html-in-header=doc/full-toc.inc
42
43 L10N_LANGS := ja
44
45 # Generally no need to edit below here.
46
47 # The options are passed to the documentation generators.
48 RUSTDOC_HTML_OPTS_NO_CSS = --html-before-content=doc/version_info.html \
49 --html-in-header=doc/favicon.inc \
50 --html-after-content=doc/footer.inc \
51 --markdown-playground-url='http://play.rust-lang.org/'
52
53 RUSTDOC_HTML_OPTS = $(RUSTDOC_HTML_OPTS_NO_CSS) --markdown-css rust.css
54
55 PANDOC_BASE_OPTS := --standalone --toc --number-sections
56 PANDOC_TEX_OPTS = $(PANDOC_BASE_OPTS) --from=markdown --to=latex \
57 --include-before-body=doc/version.tex \
58 --include-before-body=doc/footer.tex \
59 --include-in-header=doc/uptack.tex
60 PANDOC_EPUB_OPTS = $(PANDOC_BASE_OPTS) --to=epub
61
62 # The rustdoc executable...
63 RUSTDOC_EXE = $(HBIN2_H_$(CFG_BUILD))/rustdoc$(X_$(CFG_BUILD))
64 # ...with rpath included in case --disable-rpath was provided to
65 # ./configure
66 RUSTDOC = $(RPATH_VAR2_T_$(CFG_BUILD)_H_$(CFG_BUILD)) $(RUSTDOC_EXE)
67
68 # The rustbook executable...
69 RUSTBOOK_EXE = $(HBIN2_H_$(CFG_BUILD))/rustbook$(X_$(CFG_BUILD))
70 # ...with rpath included in case --disable-rpath was provided to
71 # ./configure
72 RUSTBOOK = $(RPATH_VAR2_T_$(CFG_BUILD)_H_$(CFG_BUILD)) $(RUSTBOOK_EXE)
73
74 D := $(S)src/doc
75
76 DOC_TARGETS := trpl style
77 COMPILER_DOC_TARGETS :=
78 DOC_L10N_TARGETS :=
79
80 # If NO_REBUILD is set then break the dependencies on rustdoc so we
81 # build the documentation without having to rebuild rustdoc.
82 ifeq ($(NO_REBUILD),)
83 HTML_DEPS := $(RUSTDOC_EXE)
84 else
85 HTML_DEPS :=
86 endif
87
88 # Check for xelatex
89
90 ifneq ($(CFG_XELATEX),)
91 CFG_LATEX := $(CFG_XELATEX)
92 XELATEX = 1
93 else
94 $(info cfg: no xelatex found, disabling LaTeX docs)
95 NO_PDF_DOCS = 1
96 endif
97
98 ifeq ($(CFG_PANDOC),)
99 $(info cfg: no pandoc found, omitting PDF and EPUB docs)
100 ONLY_HTML_DOCS = 1
101 endif
102
103
104 ######################################################################
105 # Rust version
106 ######################################################################
107
108 doc/version.tex: $(MKFILE_DEPS) $(wildcard $(D)/*.*) | doc/
109 @$(call E, version-stamp: $@)
110 $(Q)echo "$(CFG_VERSION)" >$@
111
112 HTML_DEPS += doc/version_info.html
113 doc/version_info.html: $(D)/version_info.html.template $(MKFILE_DEPS) \
114 $(wildcard $(D)/*.*) | doc/
115 @$(call E, version-info: $@)
116 $(Q)sed -e "s/VERSION/$(CFG_RELEASE)/; \
117 s/SHORT_HASH/$(CFG_SHORT_VER_HASH)/; \
118 s/STAMP/$(CFG_VER_HASH)/;" $< >$@
119
120 GENERATED += doc/version.tex doc/version_info.html
121
122 ######################################################################
123 # Docs, from rustdoc and sometimes pandoc
124 ######################################################################
125
126 doc/:
127 @mkdir -p $@
128
129 HTML_DEPS += doc/rust.css
130 doc/rust.css: $(D)/rust.css | doc/
131 @$(call E, cp: $@)
132 $(Q)cp -PRp $< $@ 2> /dev/null
133
134 HTML_DEPS += doc/favicon.inc
135 doc/favicon.inc: $(D)/favicon.inc | doc/
136 @$(call E, cp: $@)
137 $(Q)cp -PRp $< $@ 2> /dev/null
138
139 doc/full-toc.inc: $(D)/full-toc.inc | doc/
140 @$(call E, cp: $@)
141 $(Q)cp -PRp $< $@ 2> /dev/null
142
143 HTML_DEPS += doc/footer.inc
144 doc/footer.inc: $(D)/footer.inc | doc/
145 @$(call E, cp: $@)
146 $(Q)cp -PRp $< $@ 2> /dev/null
147
148 # The (english) documentation for each doc item.
149
150 define DEF_SHOULD_BUILD_PDF_DOC
151 SHOULD_BUILD_PDF_DOC_$(1) = 1
152 endef
153 $(foreach docname,$(PDF_DOCS),$(eval $(call DEF_SHOULD_BUILD_PDF_DOC,$(docname))))
154
155 doc/footer.tex: $(D)/footer.inc | doc/
156 @$(call E, pandoc: $@)
157 $(CFG_PANDOC) --from=html --to=latex $< --output=$@
158
159 doc/uptack.tex: $(D)/uptack.tex | doc/
160 $(Q)cp $< $@
161
162 # HTML (rustdoc)
163 DOC_TARGETS += doc/not_found.html
164 doc/not_found.html: $(D)/not_found.md $(HTML_DEPS) | doc/
165 @$(call E, rustdoc: $@)
166 $(Q)$(RUSTDOC) $(RUSTDOC_HTML_OPTS_NO_CSS) \
167 --markdown-css http://doc.rust-lang.org/rust.css $<
168
169 define DEF_DOC
170
171 # HTML (rustdoc)
172 DOC_TARGETS += doc/$(1).html
173 doc/$(1).html: $$(D)/$(1).md $$(HTML_DEPS) $$(RUSTDOC_DEPS_$(1)) | doc/
174 @$$(call E, rustdoc: $$@)
175 $$(Q)$$(RUSTDOC) $$(RUSTDOC_HTML_OPTS) $$(RUSTDOC_FLAGS_$(1)) $$<
176
177 ifneq ($(ONLY_HTML_DOCS),1)
178
179 # EPUB (pandoc directly)
180 DOC_TARGETS += doc/$(1).epub
181 doc/$(1).epub: $$(D)/$(1).md | doc/
182 @$$(call E, pandoc: $$@)
183 $$(CFG_PANDOC) $$(PANDOC_EPUB_OPTS) $$< --output=$$@
184
185 # PDF (md =(pandoc)=> tex =(pdflatex)=> pdf)
186 DOC_TARGETS += doc/$(1).tex
187 doc/$(1).tex: $$(D)/$(1).md doc/uptack.tex doc/footer.tex doc/version.tex | doc/
188 @$$(call E, pandoc: $$@)
189 $$(CFG_PANDOC) $$(PANDOC_TEX_OPTS) $$< --output=$$@
190
191 ifneq ($(NO_PDF_DOCS),1)
192 ifeq ($$(SHOULD_BUILD_PDF_DOC_$(1)),1)
193 DOC_TARGETS += doc/$(1).pdf
194 ifneq ($(XELATEX),1)
195 doc/$(1).pdf: doc/$(1).tex
196 @$$(call E, latex compiler: $$@)
197 $$(Q)$$(CFG_LATEX) \
198 -interaction=batchmode \
199 -output-directory=doc \
200 $$<
201 else
202 # The version of xelatex on the snap bots seemingly ingores -output-directory
203 # So we'll output to . and move to the doc directory manually.
204 # This will leave some intermediate files in the build directory.
205 doc/$(1).pdf: doc/$(1).tex
206 @$$(call E, latex compiler: $$@)
207 $$(Q)$$(CFG_LATEX) \
208 -interaction=batchmode \
209 -output-directory=. \
210 $$<
211 $$(Q)mv ./$(1).pdf $$@
212 endif # XELATEX
213 endif # SHOULD_BUILD_PDF_DOCS_$(1)
214 endif # NO_PDF_DOCS
215
216 endif # ONLY_HTML_DOCS
217
218 endef
219
220 $(foreach docname,$(DOCS),$(eval $(call DEF_DOC,$(docname))))
221
222
223 ######################################################################
224 # Rustdoc (libstd/extra)
225 ######################################################################
226
227
228 # The library documenting macro
229 #
230 # $(1) - The crate name (std/extra)
231 #
232 # Passes --cfg stage2 to rustdoc because it uses the stage2 librustc.
233 define DEF_LIB_DOC
234
235 # If NO_REBUILD is set then break the dependencies on rustdoc so we
236 # build crate documentation without having to rebuild rustdoc.
237 ifeq ($(NO_REBUILD),)
238 LIB_DOC_DEP_$(1) = \
239 $$(CRATEFILE_$(1)) \
240 $$(RSINPUTS_$(1)) \
241 $$(RUSTDOC_EXE) \
242 $$(foreach dep,$$(RUST_DEPS_$(1)), \
243 $$(TLIB2_T_$(CFG_BUILD)_H_$(CFG_BUILD))/stamp.$$(dep)) \
244 $$(foreach dep,$$(filter $$(DOC_CRATES), $$(RUST_DEPS_$(1))), \
245 doc/$$(dep)/)
246 else
247 LIB_DOC_DEP_$(1) = $$(CRATEFILE_$(1)) $$(RSINPUTS_$(1))
248 endif
249
250 doc/$(1)/:
251 $$(Q)mkdir -p $$@
252
253 $(2) += doc/$(1)/index.html
254 doc/$(1)/index.html: CFG_COMPILER_HOST_TRIPLE = $(CFG_TARGET)
255 doc/$(1)/index.html: $$(LIB_DOC_DEP_$(1)) doc/$(1)/
256 @$$(call E, rustdoc: $$@)
257 $$(Q)CFG_LLVM_LINKAGE_FILE=$$(LLVM_LINKAGE_PATH_$(CFG_BUILD)) \
258 $$(RUSTDOC) --cfg dox --cfg stage2 $$<
259 endef
260
261 $(foreach crate,$(DOC_CRATES),$(eval $(call DEF_LIB_DOC,$(crate),DOC_TARGETS)))
262
263 ifdef CFG_COMPILER_DOCS
264 $(foreach crate,$(COMPILER_DOC_CRATES),$(eval $(call DEF_LIB_DOC,$(crate),COMPILER_DOC_TARGETS)))
265 endif
266
267 ifdef CFG_DISABLE_DOCS
268 $(info cfg: disabling doc build (CFG_DISABLE_DOCS))
269 DOC_TARGETS :=
270 COMPILER_DOC_TARGETS :=
271 endif
272
273 docs: $(DOC_TARGETS)
274 compiler-docs: $(COMPILER_DOC_TARGETS)
275
276 trpl: doc/book/index.html
277
278 doc/book/index.html: $(RUSTBOOK_EXE) $(wildcard $(S)/src/doc/trpl/*.md) | doc/
279 @$(call E, rustbook: $@)
280 $(Q)rm -rf doc/book
281 $(Q)$(RUSTBOOK) build $(S)src/doc/trpl doc/book
282
283 style: doc/style/index.html
284
285 doc/style/index.html: $(RUSTBOOK_EXE) $(wildcard $(S)/src/doc/style/*.md) | doc/
286 @$(call E, rustbook: $@)
287 $(Q)rm -rf doc/style
288 $(Q)$(RUSTBOOK) build $(S)src/doc/style doc/style