hgbook

view en/Makefile @ 566:27043f385f3f

Get autogeneration of examples more or less working.
author Bryan O'Sullivan <bos@serpentine.com>
date Mon Mar 09 22:55:38 2009 -0700 (2009-03-09)
parents b90b024729f1
children 3bcc001ce34f
line source
1 # This makefile requires GNU make.
3 image-sources := \
4 feature-branches.dot \
5 filelog.svg \
6 kdiff3.png \
7 metadata.svg \
8 mq-stack.svg \
9 note.png \
10 revlog.svg \
11 snapshot.svg \
12 tour-history.svg \
13 tour-merge-conflict.svg \
14 tour-merge-merge.svg \
15 tour-merge-pull.svg \
16 tour-merge-sep-repos.svg \
17 undo-manual.dot \
18 undo-manual-merge.dot \
19 undo-non-tip.dot \
20 undo-simple.dot \
21 wdir.svg \
22 wdir-after-commit.svg \
23 wdir-branch.svg \
24 wdir-merge.svg \
25 wdir-pre-branch.svg
27 xml-src-files := \
28 00book.xml \
29 app*.xml \
30 ch*.xml
32 image-dot := $(filter %.dot,$(image-sources))
33 image-svg := $(filter %.svg,$(image-sources))
34 image-png := $(filter %.png,$(image-sources))
36 image-pdf := $(image-dot:%.dot=%.pdf) $(image-svg:%.svg=%.pdf) $(image-png)
37 image-html := $(image-dot:%.dot=%.png) $(image-svg:%.svg=%.png) $(image-png)
39 example-sources := \
40 backout \
41 bisect \
42 branching \
43 branch-named \
44 branch-repo \
45 cmdref \
46 daily.copy \
47 daily.files \
48 daily.rename \
49 daily.revert \
50 extdiff \
51 filenames \
52 hook.msglen \
53 hook.simple \
54 hook.ws \
55 issue29 \
56 mq.guards \
57 mq.qinit-help \
58 mq.dodiff \
59 mq.id \
60 mq.tarball \
61 mq.tools \
62 mq.tutorial \
63 rename.divergent \
64 rollback \
65 tag \
66 template.simple \
67 template.svnstyle \
68 tour \
69 tour-merge-conflict
71 xsltproc := xsltproc
72 xsltproc-opts := --nonet --xinclude --path '$(xml-path)'
74 xmllint := xmllint
75 xmllint-opts := --noout --nonet --valid
77 system-xsl-dir := $(firstword $(wildcard \
78 /usr/share/sgml/docbook/xsl-stylesheets \
79 /usr/share/xml/docbook/stylesheet/nwalsh \
80 ))
82 # Bletcherousness.
84 ifneq ($(wildcard /usr/share/sgml/docbook/xml-dtd-4.4-*),)
85 dtd-dir := $(wildcard /usr/share/sgml/docbook/xml-dtd-4.4-*)
86 else
87 ifneq ($(wildcard /usr/share/xml/docbook/schema/dtd/4.4),)
88 dtd-dir := $(wildcard /usr/share/xml/docbook/schema/dtd/4.4)
89 else
90 $(error Do not know where to look for DocBook XML 4.4 DTD)
91 endif
92 endif
94 ifeq ($(system-xsl-dir),)
95 $(error add a suitable directory to system-xsl-dir)
96 endif
98 example-prereqs := \
99 /usr/bin/merge
101 dist-sources := \
102 ../html/hgicon.png \
103 ../html/index.html.var \
104 ../html/index.en.html
106 latex-options = \
107 -interaction batchmode \
108 -output-directory $(dir $(1)) \
109 -jobname $(basename $(notdir $(1)))
111 hg = $(shell which hg)
113 hg-id = $(shell hg parents --template '{node|short}, dated {date|isodate},\n')
115 hg-version = $(shell hg version -q | \
116 sed 's,.*(version \(unknown\|[a-f0-9+]*\)),\1,')
118 all: pdf html
120 pdf: pdf/hgbook.pdf
122 define pdf
123 mkdir -p $(dir $@)
124 TEXINPUTS=$(dir $<): pdflatex $(call latex-options,$@) $< || (rm -f $@; exit 1)
125 cp 99book.bib $(dir $@)
126 cd $(dir $@) && bibtex $(basename $(notdir $@))
127 cd $(dir $@) && makeindex $(basename $(notdir $@))
128 TEXINPUTS=$(dir $<): pdflatex $(call latex-options,$@) $< || (rm -f $@; exit 1)
129 TEXINPUTS=$(dir $<): pdflatex $(call latex-options,$@) $< || (rm -f $@; exit 1)
130 if grep 'Reference.*undefined' $(@:.pdf=.log); then exit 1; fi
131 endef
133 pdf/hgbook.pdf: $(sources) examples $(image-pdf)
134 $(call pdf)
136 html: onepage split
138 ../xsl/system-xsl: $(system-xsl-dir)
139 ln -s $< $@
141 dbhtml: ../xsl/system-xsl $(xml-src-files) valid
142 xsltproc $(xsltproc-opts) ../xsl/chunk-stylesheet.xsl 00book.xml
144 valid: .validated-00book.xml
146 .validated-00book.xml: $(xml-src-files)
147 $(xmllint) --path '$(dtd-dir):$(xml-path)' $(xmllint-opts) $<
148 touch $@
150 onepage: $(htlatex) html/onepage/hgbook.html html/onepage/hgbook.css $(image-html:%=html/onepage/%)
152 html/onepage/%: %
153 cp $< $@
155 split: $(htlatex) html/split/hgbook.html html/split/hgbook.css $(image-html:%=html/split/%)
157 html/split/%: %
158 cp $< $@
160 # This is a horrible hack to work around the fact that the htlatex
161 # command in tex4ht is itself a horrible hack. I really don't want to
162 # include verbatim the big wad of TeX that is repeated in that script,
163 # but I've given up and run a hacked copy as htlatex.book here.
165 define htlatex
166 mkdir -p $(dir $(1))
167 cp 99book.bib $(dir $(1))
168 TEXINPUTS=$(dir $(2)): ./htlatex.book $(2) "bookhtml,html4-uni,$(3)" " -cunihtf -utf8" "$(dir $(1))" "$(call latex-options,$(1))" || (rm -f $(1); exit 1)
169 cd $(dir $(1)) && tex4ht -f/$(basename $(notdir $(1))) -cvalidate -cunihtf
170 cd $(dir $(1)) && t4ht -f/$(basename $(notdir $(1)))
171 ./fixhtml.py $(dir $(1))/*.html
172 rm $(dir $(1))/hgbook.css
173 endef
175 html/onepage/hgbook.html: $(sources) examples $(image-html) bookhtml.cfg
176 $(call htlatex,$@,$<)
178 html/split/hgbook.html: $(sources) examples bookhtml.cfg
179 $(call htlatex,$@,$<,2)
181 # Produce 90dpi PNGs for the web.
183 %.png: %.svg fixsvg
184 ./fixsvg $<
185 inkscape -D -e $@ $<-tmp.svg
186 rm $<-tmp.svg
188 %.svg: %.dot
189 dot -Tsvg -o $@ $<
191 # Produce eps & pdf for the pdf
193 %.pdf: %.eps
194 epstopdf $<
196 %.eps: %.svg
197 ./fixsvg $<
198 inkscape -E $@ $<-tmp.svg
199 rm $<-tmp.svg
201 %.eps: %.dot
202 dot -Tps -o $@ $<
204 examples: $(example-prereqs) examples/.run
206 examples/.run: $(example-sources:%=examples/%.run)
207 touch examples/.run
209 examples/%.run: examples/% examples/run-example
210 cd examples && ./run-example $(notdir $<)
212 changelog := $(wildcard ../.hg/store/00changelog.[id])
213 ifeq ($(changelog),)
214 changelog := $(wildcard ../.hg/00changelog.[id])
215 endif
217 build_id.tex: $(changelog)
218 echo -n '$(hg-id)' > build_id.tex
220 hg_id.tex: $(hg)
221 echo -n '$(hg-version)' > hg_id.tex
223 clean:
224 rm -rf dist html pdf \
225 $(image-dot:%.dot=%.pdf) \
226 $(image-dot:%.dot=%.png) \
227 $(image-svg:%.svg=%.pdf) \
228 $(image-svg:%.svg=%.png) \
229 examples/*.{lxo,run} examples/.run build_id.tex hg_id.tex
231 install: pdf split $(dist-sources)
232 rm -rf dist
233 mkdir -p dist
234 cp pdf/hgbook.pdf dist
235 cp html/split/*.{css,html,png} dist
236 cp $(dist-sources) dist
238 rsync: install
239 rsync -avz --delete dist sp.red-bean.com:public_html/hgbook