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