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.
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.
11 ######################################################################
12 # The various pieces of standalone documentation: guides, tutorial,
15 # The DOCS variable is their names (with no file extension).
17 # PDF_DOCS lists the targets for which PDF documentation should be
20 # RUSTDOC_FLAGS_xyz variables are extra arguments to pass to the
21 # rustdoc invocation for xyz.
23 # RUSTDOC_DEPS_xyz are extra dependencies for the rustdoc invocation
26 # L10N_LANGS are the languages for which the docs have been
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 \
35 PDF_DOCS := tutorial rust
37 RUSTDOC_DEPS_rust := doc/full-toc.inc
38 RUSTDOC_FLAGS_rust := --markdown-in-header=doc/full-toc.inc
42 # Generally no need to edit below here.
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
48 RUSTDOC_HTML_OPTS = $(RUSTDOC_HTML_OPTS_NO_CSS) --markdown-css rust.css
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
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
59 RUSTDOC = $(RPATH_VAR2_T_$(CFG_BUILD)_H_$(CFG_BUILD)) $(RUSTDOC_EXE)
64 COMPILER_DOC_TARGETS :=
67 # If NO_REBUILD is set then break the dependencies on rustdoc so we
68 # build the documentation without having to rebuild rustdoc.
70 HTML_DEPS := $(RUSTDOC_EXE)
75 # Check for the various external utilities for the EPUB/PDF docs:
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)
85 CFG_LATEX := $(CFG_LUALATEX)
88 CFG_LATEX := $(CFG_XELATEX)
91 CFG_LATEX := $(CFG_PDFLATEX)
96 $(info cfg: no pandoc found, omitting PDF and EPUB docs)
101 ######################################################################
103 ######################################################################
105 doc/version.tex: $(MKFILE_DEPS) $(wildcard $(D)/*.*) | doc/
106 @$(call E, version-stamp: $@)
107 $(Q)echo "$(CFG_VERSION)" >$@
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)/;" $< >$@
117 GENERATED += doc/version.tex doc/version_info.html
119 ######################################################################
120 # Docs, from rustdoc and sometimes pandoc
121 ######################################################################
126 HTML_DEPS += doc/rust.css
127 doc/rust.css: $(D)/rust.css | doc/
129 $(Q)cp -a $< $@ 2> /dev/null
131 HTML_DEPS += doc/favicon.inc
132 doc/favicon.inc: $(D)/favicon.inc | doc/
134 $(Q)cp -a $< $@ 2> /dev/null
136 doc/full-toc.inc: $(D)/full-toc.inc | doc/
138 $(Q)cp -a $< $@ 2> /dev/null
140 HTML_DEPS += doc/footer.inc
141 doc/footer.inc: $(D)/footer.inc | doc/
143 $(Q)cp -a $< $@ 2> /dev/null
145 # The (english) documentation for each doc item.
147 define DEF_SHOULD_BUILD_PDF_DOC
148 SHOULD_BUILD_PDF_DOC_$(1) = 1
150 $(foreach docname,$(PDF_DOCS),$(eval $(call DEF_SHOULD_BUILD_PDF_DOC,$(docname))))
152 doc/footer.tex: $(D)/footer.inc | doc/
153 @$(call E, pandoc: $@)
154 $(CFG_PANDOC) --from=html --to=latex $< --output=$@
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://doc.rust-lang.org/rust.css $<
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)) $$<
169 ifneq ($(ONLY_HTML_DOCS),1)
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=$$@
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=$$@
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: $$@)
189 -interaction=batchmode \
190 -output-directory=doc \
192 endif # SHOULD_BUILD_PDF_DOCS_$(1)
195 endif # ONLY_HTML_DOCS
199 $(foreach docname,$(DOCS),$(eval $(call DEF_DOC,$(docname))))
202 # Localized documentation
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
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)
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)" \
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
229 $(foreach lang,$(L10N_LANGS),$(eval $(call DEF_L10N_DOC,$(lang),tutorial)))
232 ######################################################################
233 # LLnextgen (grammar analysis from refman)
234 ######################################################################
236 ifeq ($(CFG_LLNEXTGEN),)
237 $(info cfg: no llnextgen found, omitting grammar-verification)
239 .PHONY: verify-grammar
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 $< >$@
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
252 ######################################################################
253 # Rustdoc (libstd/extra)
254 ######################################################################
257 # The library documenting macro
259 # $(1) - The crate name (std/extra)
261 # Passes --cfg stage2 to rustdoc because it uses the stage2 librustc.
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),)
271 $$(foreach dep,$$(RUST_DEPS_$(1)), \
272 $$(TLIB2_T_$(CFG_BUILD)_H_$(CFG_BUILD))/stamp.$$(dep))
274 LIB_DOC_DEP_$(1) = $$(CRATEFILE_$(1)) $$(RSINPUTS_$(1))
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 $$<
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)))
287 ifdef CFG_DISABLE_DOCS
288 $(info cfg: disabling doc build (CFG_DISABLE_DOCS))
293 compiler-docs: $(COMPILER_DOC_TARGETS)
295 docs-l10n: $(DOC_L10N_TARGETS)