]> git.lizzy.rs Git - rust.git/blob - mk/docs.mk
084f027b4340b94a4c31f21244127e3ec9df7361
[rust.git] / mk / docs.mk
1 ######################################################################
2 # Doc variables and rules
3 ######################################################################
4
5 DOCS :=
6
7
8 ######################################################################
9 # Pandoc (reference-manual related)
10 ######################################################################
11 ifeq ($(CFG_PANDOC),)
12   $(info cfg: no pandoc found, omitting doc/rust.pdf)
13 else
14
15   ifeq ($(CFG_NODE),)
16     $(info cfg: no node found, omitting doc/tutorial.html)
17   else
18
19 doc/rust.css: rust.css
20         @$(call E, cp: $@)
21         $(Q)cp -a $< $@ 2> /dev/null
22
23 DOCS += doc/rust.html
24 doc/rust.html: rust.md doc/version_info.html doc/rust.css
25         @$(call E, pandoc: $@)
26         $(Q)$(CFG_NODE) $(S)doc/prep.js --highlight $< | \
27         "$(CFG_PANDOC)" \
28          --standalone --toc \
29          --section-divs \
30          --number-sections \
31          --from=markdown --to=html \
32          --css=rust.css \
33          --include-before-body=doc/version_info.html \
34          --output=$@
35   endif
36
37   ifeq ($(CFG_PDFLATEX),)
38     $(info cfg: no pdflatex found, omitting doc/rust.pdf)
39   else
40     ifeq ($(CFG_XETEX),)
41       $(info cfg: no xetex found, disabling doc/rust.pdf)
42     else
43       ifeq ($(CFG_LUATEX),)
44         $(info cfg: lacking luatex, disabling pdflatex)
45       else
46
47 DOCS += doc/rust.pdf
48 doc/rust.tex: rust.md doc/version.md
49         @$(call E, pandoc: $@)
50         $(Q)$(CFG_NODE) $(S)doc/prep.js $< | \
51         "$(CFG_PANDOC)" \
52          --standalone --toc \
53          --number-sections \
54          --from=markdown --to=latex \
55          --output=$@
56
57 doc/rust.pdf: doc/rust.tex
58         @$(call E, pdflatex: $@)
59         $(Q)$(CFG_PDFLATEX) \
60         -interaction=batchmode \
61         -output-directory=doc \
62         $<
63
64       endif
65     endif
66   endif
67
68 ######################################################################
69 # Node (tutorial related)
70 ######################################################################
71   ifeq ($(CFG_NODE),)
72     $(info cfg: no node found, omitting doc/tutorial.html)
73   else
74
75 DOCS += doc/tutorial.html
76 doc/tutorial.html: tutorial.md doc/version_info.html doc/rust.css
77         @$(call E, pandoc: $@)
78         $(Q)$(CFG_NODE) $(S)doc/prep.js --highlight $< | \
79           $(CFG_PANDOC) --standalone --toc \
80            --section-divs --number-sections \
81            --from=markdown --to=html --css=rust.css \
82            --include-before-body=doc/version_info.html \
83            --output=$@
84
85 DOCS += doc/tutorial-macros.html
86 doc/tutorial-macros.html: tutorial-macros.md doc/version_info.html \
87                                                   doc/rust.css
88         @$(call E, pandoc: $@)
89         $(Q)$(CFG_NODE) $(S)doc/prep.js --highlight $< | \
90           $(CFG_PANDOC) --standalone --toc \
91            --section-divs --number-sections \
92            --from=markdown --to=html --css=rust.css \
93            --include-before-body=doc/version_info.html \
94            --output=$@
95
96 DOCS += doc/tutorial-ffi.html
97 doc/tutorial-ffi.html: tutorial-ffi.md doc/version_info.html doc/rust.css
98         @$(call E, pandoc: $@)
99         $(Q)$(CFG_NODE) $(S)doc/prep.js --highlight $< | \
100           $(CFG_PANDOC) --standalone --toc \
101            --section-divs --number-sections \
102            --from=markdown --to=html --css=rust.css \
103            --include-before-body=doc/version_info.html \
104            --output=$@
105
106 DOCS += doc/tutorial-borrowed-ptr.html
107 doc/tutorial-borrowed-ptr.html: tutorial-borrowed-ptr.md doc/version_info.html doc/rust.css
108         @$(call E, pandoc: $@)
109         $(Q)$(CFG_NODE) $(S)doc/prep.js --highlight $< | \
110           $(CFG_PANDOC) --standalone --toc \
111            --section-divs --number-sections \
112            --from=markdown --to=html --css=rust.css \
113            --include-before-body=doc/version_info.html \
114            --output=$@
115
116   endif
117 endif
118
119
120 ######################################################################
121 # LLnextgen (grammar analysis from refman)
122 ######################################################################
123 ifeq ($(CFG_LLNEXTGEN),)
124   $(info cfg: no llnextgen found, omitting grammar-verification)
125 else
126 .PHONY: verify-grammar
127
128 doc/rust.g: rust.md $(S)src/etc/extract_grammar.py
129         @$(call E, extract_grammar: $@)
130         $(Q)$(S)src/etc/extract_grammar.py $< >$@
131
132 verify-grammar: doc/rust.g
133         @$(call E, LLnextgen: $<)
134         $(Q)$(CFG_LLNEXTGEN) --generate-lexer-wrapper=no $< >$@
135         $(Q)rm -f doc/rust.c doc/rust.h
136 endif
137
138
139 ######################################################################
140 # Rustdoc (libcore/std)
141 ######################################################################
142
143 ifeq ($(CFG_PANDOC),)
144   $(info cfg: no pandoc found, omitting library doc build)
145 else
146
147 # The rustdoc executable
148 RUSTDOC = $(HBIN2_H_$(CFG_HOST_TRIPLE))/rustdoc$(X)
149
150 # The library documenting macro
151 # $(1) - The output directory
152 # $(2) - The crate file
153 # $(3) - The crate soruce files
154 define libdoc
155 doc/$(1)/index.html: $(2) $(3) $$(RUSTDOC) doc/$(1)/rust.css
156         @$$(call E, rustdoc: $$@)
157         $(Q)$(RUSTDOC) $(2) --output-dir=doc/$(1)
158
159 doc/$(1)/rust.css: rust.css
160         @$$(call E, cp: $$@)
161         $(Q)cp $$< $$@
162
163 DOCS += doc/$(1)/index.html
164 endef
165
166 $(eval $(call libdoc,core,$(CORELIB_CRATE),$(CORELIB_INPUTS)))
167 $(eval $(call libdoc,std,$(STDLIB_CRATE),$(STDLIB_INPUTS)))
168 endif
169
170
171 ifdef CFG_DISABLE_DOCS
172   $(info cfg: disabling doc build (CFG_DISABLE_DOCS))
173   DOCS :=
174 endif
175
176
177 doc/version.md: $(MKFILE_DEPS) rust.md
178         @$(call E, version-stamp: $@)
179         $(Q)echo "$(CFG_VERSION)" >$@
180
181 doc/version_info.html: version_info.html.template
182         @$(call E, version-info: $@)
183         sed -e "s/VERSION/$(CFG_RELEASE)/; s/SHORT_HASH/$(shell echo \
184                     $(CFG_VER_HASH) | head -c 8)/;\
185                     s/STAMP/$(CFG_VER_HASH)/;" $< >$@
186
187 GENERATED += doc/version.md
188
189 docs: $(DOCS)