-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
284 lines (204 loc) · 8.51 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
######## Configuration
#
#
# This makefile supports multiple targets. Currently we have only one.
#
# SOURCES must end ".xml" and must be DocBook files.
#
SOURCES = Book.xml
# The extension for all HTML output (e.g. html or shtml). Must NOT
# start with a dot.
HTML_EXT = html
# All stylesheets used by various outputs
#
STYLESHEETS_TITLEPAGE := xsl/fo-titlepage.xsl
STYLESHEETS_CHUNK := xsl/html-chunk.xsl xsl/html-common.xsl xsl/common.xsl
STYLESHEETS_HTML := xsl/html-single.xsl xsl/html-common.xsl xsl/common.xsl
STYLESHEETS_FO := xsl/fo.xsl $(STYLESHEETS_TITLEPAGE) xsl/common.xsl
STYLESHEETS_MAN := xsl/man.xsl xsl/common.xsl
STYLESHEETS_EPUB := xsl/epub.xsl xsl/common.xsl
######### Some derived locations: output files
#
FO_FILES = $(SOURCES:%.xml=%-a4.fo) $(SOURCES:%.xml=%-letter.fo)
PDF_FILES = $(FO_FILES:%.fo=%.pdf)
HTML_SINGLE_FILES = $(SOURCES:%.xml=%.$(HTML_EXT))
HTML_CHUNK_FILES = $(SOURCES:%.xml=%/index.$(HTML_EXT))
HTML_COMMENTS_FILES = $(SOURCES:%.xml=%-comments/index.$(HTML_EXT))
HTML_ALL_CHUNK_FILES = $(SOURCES:%.xml=%)
HTML_ALL_COMMENTS_FILES = $(SOURCES:%.xml=%-comments)
TXT_FILES = $(SOURCES:%.xml=%.txt)
FO_DEPS = $(FO_FILES:%=.%.d)
HTML_SINGLE_DEPS = $(HTML_SINGLE_FILES:%=.%.d)
HTML_CHUNK_DEPS = $(SOURCES:%.xml=.%-chunk.d)
HTML_COMMENTS_DEPS = $(SOURCES:%.xml=.%-comments.d)
EPUB_FILES = $(SOURCES:%.xml=%.epub)
GFX_FILES = images/important.png images/warning.png images/caution.png images/note.png images/tip.png
# Used by deploy target
ALL = $(HTML_SINGLE_FILES) $(PDF_FILES) $(HTML_ALL_CHUNK_FILES) $(EPUB_FILES) book.css $(GFX_FILES)
ALL_COMMENTS = $(HTML_ALL_COMMENTS_FILES) book.css $(GFX_FILES)
ALL_INSTALLED = $(ALL:%=%__INSTALL__)
ALL_TEST_INSTALLED = $(ALL:%=%__TEST_INSTALL__)
COMMENTS_INSTALLED = $(ALL_COMMENTS:%=%__COMMENTS_INSTALL__)
WWW_SERVER = www.hepix.org
WWW_SERVER_BASE_DIR = /data/www/dcache.org
WWW_LOCATION = /manuals/Book-1.9.14/
WWW_TEST_LOCATION = /manuals/Book-1.9.14-test/
WWW_COMMENTS_LOCATION = /manuals/Book-1.9.14-comments/
# NB we don't do deps on txt as it depends on html-single output. This
# is cheating, but hey, it works.
DEP_FILES = $(FO_DEPS) $(HTML_SINGLE_DEPS) $(HTML_CHUNK_DEPS) $(HTML_COMMENTS_DEPS)
######### Common options
#
XSLT_FLAGS = --nonet --xinclude
######### Software Configs
#
# Default value for binaries
#
SVN ?= svn
FOP ?= fop
XSLTPROC ?= xsltproc
###### Docbook targets. Pure DocBook is generated from the sources first
#
.PHONY: info
info:
@echo
@echo " The HEPIX VWG Book"
@echo " ---------------"
@echo
@echo "Available main build targets:"
@echo
@echo " all -- build PDF, HTML, text, man and epub"
@echo " pdf -- build PDF versions"
@echo " html -- build HTML pages"
@echo " comments -- build HTML pages with comments"
@echo " txt -- build text version"
@echo " man -- build man pages"
@echo " epub -- build EPUB version"
@echo " deploy -- deploy files to http://${WWW_SERVER}${WWW_LOCATION}"
@echo " test-deploy -- deploy files to http://${WWW_SERVER}${WWW_TEST_LOCATION}"
@echo " comments-deploy -- deploy files to http://${WWW_SERVER}${WWW_COMMENTS_LOCATION}"
@echo
@echo "More specific build targets:"
@echo
@echo " html-single -- Build single-page HTML pages"
@echo " html-chunk -- Build multi-page HTML pages"
@echo
@echo "Cleaning targets:"
@echo " clean -- remove backup files"
@echo " distclean -- remove all generated files"
@echo
all: pdf html txt man epub
###### HTML targets
#
# Plain chunked HTML
#
html: html-single html-chunk
html-single: $(HTML_SINGLE_FILES)
html-chunk: $(HTML_CHUNK_FILES)
%.$(HTML_EXT): %.xml $(STYLESHEETS_HTML) shared-entities.xml
$(XSLTPROC) $(XSLT_FLAGS) --stringparam html.ext ".$(HTML_EXT)" -o $@ xsl/html-single.xsl $<
%/index.$(HTML_EXT): %.xml $(STYLESHEETS_CHUNK) shared-entities.xml
# $(XSLTPROC) $(XSLT_FLAGS) -o $(@:%/index.$(HTML_EXT)=%)/ xsl/html-chunk.xsl $<
$(XSLTPROC) $(XSLT_FLAGS) --stringparam html.ext ".$(HTML_EXT)" --stringparam base.dir $(@:%/index.$(HTML_EXT)=%)/ --stringparam comments.enabled false xsl/html-chunk.xsl $<
# Commented chunked HTML
#
comments: $(HTML_COMMENTS_FILES)
%-comments/index.$(HTML_EXT): %.xml $(STYLESHEETS_CHUNK) shared-entities.xml
$(XSLTPROC) $(XSLT_FLAGS) --stringparam html.ext ".$(HTML_EXT)" --stringparam base.dir $(@:%/index.$(HTML_EXT)=%)/ --stringparam comments.enabled true xsl/html-chunk.xsl $<
# TODO: review whether to use the same rule for comments and uncommented chunked output.
###### Text only
HTML_TO_TXT := /usr/bin/w3m -T text/html -dump
#HTML_TO_TXT := /usr/bin/lynx -force_html -dump -nolist -width=72
#HTML_TO_TXT : = /usr/bin/links -dump
txt: $(TXT_FILES)
%.txt: %.$(HTML_EXT)
$(HTML_TO_TXT) $< > $@
# (should we also produce install instructions as separate txt file?)
###### man page targets
#
## TODO: we should autogenerate dependencies, like with other targets
man: Book.xml $(STYLESHEETS_MAN) shared-entities.xml
@[ ! -d man ] && mkdir man || :
$(XSLTPROC) $(XSLT_FLAGS) --output man/ xsl/man.xsl $<
###### EPUB targets
#
## TODO: we should autogenerate dependencies, like with other targets
epub: $(EPUB_FILES)
%.epub: %.xml $(STYLESHEETS_EPUB) shared-entities.xml
$(XSLTPROC) $(XSLT_FLAGS) xsl/epub.xsl $<
echo application/epub+zip > mimetype
zip -rn mimetype $@ mimetype META-INF OEBPS
rm -rf mimetype META-INF OEBPS
###### FO-based targets
#
# PDF from XSL-FO
#
pdf: $(PDF_FILES)
%-a4.fo: %.xml $(STYLESHEETS_FO) shared-entities.xml
$(XSLTPROC) $(XSLT_FLAGS) --output $@ --stringparam paper.type A4 xsl/fo.xsl $<
%-letter.fo: %.xml $(STYLESHEETS_FO) shared-entities.xml
$(XSLTPROC) $(XSLT_FLAGS) --output $@ --stringparam paper.type letter xsl/fo.xsl $<
%.pdf: %.fo
$(FOP) -fo $< -pdf $@
# The title page is FO-specific; the format is derived from an XML file.
%.xsl: %.xml
$(XSLTPROC) $(XSLT_FLAGS) --output $@ http://docbook.sourceforge.net/release/xsl/current/template/titlepage.xsl $<
###### Deployment targets
#
deploy: $(ALL_INSTALLED)
@echo
@echo "Book now updated at http://${WWW_SERVER}${WWW_LOCATION}"
@echo
test-deploy: $(ALL_TEST_INSTALLED)
@echo
@echo "Book now updated at http://${WWW_SERVER}${WWW_TEST_LOCATION}"
@echo
comments-deploy: $(COMMENTS_INSTALLED)
@echo
@echo "Book with comments now updated at http://${WWW_SERVER}${WWW_COMMENTS_LOCATION}"
@echo
%__INSTALL__: %
chmod a+r,g+w $<
scp -p $< $(WWW_SERVER):$(WWW_SERVER_BASE_DIR)$(WWW_LOCATION)
%__TEST_INSTALL__: %
chmod a+r,g+w $<
scp -p $< $(WWW_SERVER):$(WWW_SERVER_BASE_DIR)$(WWW_TEST_LOCATION)
%__COMMENTS_INSTALL__: %
chmod a+r,g+w $<
scp -p $< $(WWW_SERVER):$(WWW_SERVER_BASE_DIR)$(WWW_COMMENTS_LOCATION)
# Unfortunately, we need a special case here.
Book__INSTALL__: Book/index.$(HTML_EXT)
chmod -R a+Xr,g+w Book/*
chmod g+s Book
find Book -type d -exec chmod g+s \{\} \;
scp -pr Book/* $(WWW_SERVER):$(WWW_SERVER_BASE_DIR)$(WWW_LOCATION)
Book__TEST_INSTALL__: Book/index.$(HTML_EXT)
chmod -R a+Xr,g+w Book/*
chmod g+s Book
find Book -type d -exec chmod g+s \{\} \;
scp -pr Book/* $(WWW_SERVER):$(WWW_SERVER_BASE_DIR)$(WWW_TEST_LOCATION)
Book-comments__COMMENTS_INSTALL__: Book-comments/index.$(HTML_EXT)
chmod -R a+Xr,g+w Book-comments/*
chmod g+s Book-comments
find Book-comments -type d -exec chmod g+s \{\} \;
scp -pr Book-comments/* $(WWW_SERVER):$(WWW_SERVER_BASE_DIR)$(WWW_COMMENTS_LOCATION)
###### Cleaning targets
#
clean:
rm -rf *~ *.bak
distclean: clean
rm -rf $(WEB_LOCATION) $(TXT_FILES) $(PDF_FILES) $(FO_FILES) $(DEP_FILES) $(HTML_SINGLE_FILES) $(HTML_ALL_CHUNK_FILES) $(HTML_ALL_COMMENTS_FILES) $(STYLESHEETS_TITLEPAGE) $(EPUB_FILES)
###### Create (dynamic) Makefile dependencies
#
.%-letter.fo.d .%-a4.fo.d: %.xml
$(XSLTPROC) --nonet -stringparam output-file $(@:.%.d=%) --stringparam initial-file $< --stringparam graphics SVG --stringparam dep-file $@ dependency.xsl $< > $@
.%.$(HTML_EXT).d: %.xml
$(XSLTPROC) --nonet -stringparam output-file $(@:.%.d=%) --stringparam initial-file $< --stringparam graphics none --stringparam dep-file $@ dependency.xsl $< > $@
.%-chunk.d: %.xml
$(XSLTPROC) --nonet -stringparam output-file $(@:.%-chunk.d=%/index.$(HTML_EXT)) --stringparam initial-file $< --stringparam graphics none --stringparam dep-file $@ dependency.xsl $< > $@
.%-comments.d: %.xml
$(XSLTPROC) --nonet -stringparam output-file $(@:.%-comments.d=%-comments/index.$(HTML_EXT)) --stringparam initial-file $< --stringparam graphics none --stringparam dep-file $@ dependency.xsl $< > $@
.PHONY: all pdf html html-single html-chunked
.PHONY: clean distclean
.PRECIOUS: $(FO_FILES)
-include $(DEP_FILES)