-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.dbk
314 lines (276 loc) · 11.6 KB
/
Makefile.dbk
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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
# Produce documentation
# Copyright (C) 2015 Osamu Aoki
include Makefile.common
#######################################################################
# Update release names below for every Debian stable release
#######################################################################
# Document translation strategy: use itstool instead of po4a
# 1. Generate $(BASEXML) using AsciiDoc with docbook4 backend
# (Ease of writing main cantents)
# 2. Make docbook 5 source $(MANUAL).en.x01 with db4-upgrade.xsl
# 3. Write the info header section as $(HEADXML)
# 4. Merge $(HEADXML) and $(MANUAL).en.x01 as $(MANUAL).en.x02
# 5. Generate po/$(MANUAL).pot from $(MANUAL).en.x02 with itstool
# 6. Translate po/$(MANUAL).pot and create po/<lang>.po
# 7. Generate $(MANUAL).<lang>.x02 from $(MANUAL).en.x02 and po/<lang>.po
# using itstool
# 8. Make $(MANUAL).<lang>.xml from $(MANUAL).<lang>.x02
# 9. Build html, ... from $(MANUAL).<lang>.xml
#######################################################################
# Build documentation
MANUAL := debmake-doc
BASEXML := $(ASCIIDOC_DIR)/$(MANUAL).xml
HEADXML := $(ASCIIDOC_DIR)/head.txt
# languages translated with PO files (not used now)
LANGPO ?= ja zh-cn de ru
# languages to skip generation of PDF files (not used now)
NOPDF ?=
# languages to build document
LANGALL := en $(LANGPO)
SRC_PO := $(addsuffix .po, $(addprefix $(PO_DIR)/, $(LANGPO)))
SRC_XML := $(addsuffix .xml, $(addprefix $(MANUAL)., $(LANGALL)))
ENT_ALL := url.ent
#######################################################################
# Build time determined text
# version of the debmake command used
DEBMAKEVERSION ?= $(shell { debmake -v 2>&1 | sed -ne '/^debmake/s/^.*(version: \([0-9.]*\)).*$$/\1/p' ; })
# version of this Debian package (debian/changelog)
DEBVERSION ?= $(shell { dpkg-parsechangelog -SVersion || echo "vcs-0.0" ; })
# short date of this Debian package (debian/changelog)
DEBDATE ?= $(shell { date +'%Y-%m-%d' -d"`dpkg-parsechangelog -SDate`" || date +'(No changelog) %Y-%m-%d' ; })
#######################################################################
dbk:
-mkdir -p $(TMPDIR)
-mkdir -p $(BASEDIR)/html
$(MAKE) -C $(ASCIIDOC_DIR) xml
$(MAKE) css html
.PHONY: dbk
#######################################################################
# Constants for asciidoc -> xml -> any conversion
# Program name and option
XSLT := xsltproc --novalid --nonet --xinclude
ITSTOOL := itstool -i $(XSLT_DIR)/docbook.its
MKDIRP := mkdir -p
MSGCAT := msgcat
MSGFMT := msgfmt
MSGMERGE := msgmerge --update --previous
MSGATTRIB := msgattrib
DBLATEX := dblatex
# Change $(DRAFTMODE) from "yes" to "maybe" when this document
# should go into production mode
#export DRAFTMODE := yes
export DRAFTMODE := maybe
#######################################################################
# Normal doc content as English base xml
$(BASEXML): $(wildcard $(ASCIIDOC_DIR)/*.txt)
$(MAKE) -C $(ASCIIDOC_DIR) xml # base XML doc
# set last chapter as appendix.
$(MANUAL).en.x01: $(BASEXML)
@$(call check-command, xsltproc, xsltproc)
$(XSLT) $(XSLT_DIR)/modappendix.xsl $< > $@
# header is manually written and main content is generated from asciidoc
$(MANUAL).en.x02: $(MANUAL).en.x01 $(HEADXML) $(ENT_ALL)
cat $(HEADXML) > $@
sed -e '1,/<\/bookinfo>/d' $(MANUAL).en.x01 >> $@
url.ent: $(BASEXML)
@$(call check-command, xsltproc, xsltproc)
$(XSLT) $(XSLT_DIR)/urls.xsl $^ | sort | uniq | sed -e "s/&/\&/g"> $@
# Check duplicates
#ifndef DEBUG
@DUPLICATE="$$(sed -ne 's/<[^ ]* \([^ ]*\) .*$$/\1/p' $@ | uniq -d)" ; \
if [ "$${DUPLICATE}" != "" ]; then \
echo "E: duplicate entity = $${DUPLICATE}"; false; \
fi
#else
@DUPLICATE="$$(sed -ne 's/<[^ ]* \([^ ]*\) .*$$/\1/p' $@ | uniq -d)" ; \
if [ "$${DUPLICATE}" != "" ]; then \
echo "W: #######################################################################"; \
echo "W: duplicate entity = $${DUPLICATE}"; \
echo "W: #######################################################################"; \
fi
#endif
pot: $(PO_DIR)/templates.pot
$(PO_DIR)/templates.pot: $(MANUAL).en.x02 .FORCE
$(ITSTOOL) $< -o - | $(MSGCAT) - -o $@
$(MANUAL).%.x02: $(PO_DIR)/%.po $(MANUAL).en.x02
$(MKDIRP) po/
$(MSGFMT) -D $(PO_DIR) $*.po -o $(PO_DIR)/$*.mo
-$(MKDIRP) po/$*/
$(ITSTOOL) -m $(PO_DIR)/$*.mo -o po/$*/ $(MANUAL).en.x02
cp po/$*/$(MANUAL).en.x02 $(MANUAL).$*.x02
rm po/$*/$(MANUAL).en.x02
rmdir po/$*
$(MANUAL).%.xml: $(MANUAL).%.x02
sed \
-e "s/@@@debmakeversion@@@/$(DEBMAKEVERSION)/g" \
-e "s/@@@debversion@@@/$(DEBVERSION)/g" \
-e "s/@@@debdate@@@/$(DEBDATE)/g" \
< $^ > $@
po: $(SRC_PO)
.PHONY: po pot
# Always update
$(PO_DIR)/%.po: $(PO_DIR)/templates.pot
@$(call check-command, msgmerge, gettext)
$(MSGMERGE) $(PO_DIR)/$*.po $(PO_DIR)/templates.pot
MESS1="no-obsolete $* `$(MSGATTRIB) --no-obsolete $(PO_DIR)/$*.po |grep ^msgid |sed 1d|wc -l`";\
MESS2="untranslated $* `$(MSGATTRIB) --untranslated $(PO_DIR)/$*.po |grep ^msgid |sed 1d|wc -l`";\
MESS3="fuzzy $* `$(MSGATTRIB) --fuzzy $(PO_DIR)/$*.po |grep ^msgid |sed 1d|wc -l`";\
echo "$$MESS1" >>fuzzy.log ; \
echo "$$MESS2" >>fuzzy.log ; \
echo "$$MESS3" >>fuzzy.log ; \
echo "" >>fuzzy.log
.FORCE:
echo "FORCE"
doc-clean:
-rm -f *.swp *~ *.tmp
-rm -f $(ENT_ALL)
-rm -f $(PO_DIR)/*~ $(PO_DIR)/*.mo $(PO_DIR)/*.pot
-rm -rf $(TMPDIR)
-rm -rf $(BASEDIR)
-rm -rf $(LANGALL) en
-rm -f $(addsuffix .x00, $(addprefix $(MANUAL)., $(LANGALL)))
-rm -f $(addsuffix .x01, $(addprefix $(MANUAL)., $(LANGALL)))
-rm -f $(addsuffix .x02, $(addprefix $(MANUAL)., $(LANGALL)))
-rm -f $(addsuffix .xml, $(addprefix $(MANUAL)., $(LANGALL)))
-rm -f fuzzy.log
clean:: doc-clean
#######################################################################
.PHONY: base-xml
base-xml: $(BASEXML)
#######################################################################
.PHONY: all-xml
all-xml: $(SRC_XML) $(ENT_ALL)
#######################################################################
.PHONY: doc-all
doc-all: css html txt epub
#######################################################################
# $ make test # build html for testing (for Translator)
#######################################################################
.PHONY: doc-test
doc-test: html css
#######################################################################
# $ make wrap # wrap all PO
#######################################################################
.PHONY: wrap nowrap wip
wrap:
@$(call check-command, msgcat, gettext)
for XX in $(foreach LX, $(LANGPO), $(DPO)/$(LX).po); do \
$(MSGCAT) -o $$XX $$XX ;\
done
nowrap:
@$(call check-command, msgcat, gettext)
for XX in $(foreach LX, $(LANGPO), $(DPO)/$(LX).po); do \
$(MSGCAT) -o $$XX --no-wrap $$XX ;\
done
wip:
@$(call check-command, msgattrib, gettext)
for XX in $(foreach LX, $(LANGPO), $(DPO)/$(LX).po); do \
$(MSGATTR) -o $$XX.fuzz --fuzzy $$XX ;\
$(MSGATTR) -o $$XX.untr --untranslated $$XX ;\
done
#######################################################################
# $ make css # update CSS and DIMG in $(BASEDIR)
#######################################################################
.PHONY: css
css:
-rm -rf $(BASEDIR)/html/images
mkdir -p $(BASEDIR)/html/images
cp -f $(XSLT_DIR)/debian.css $(BASEDIR)/html/debian.css
echo "AddCharset UTF-8 .txt" > $(BASEDIR)/html/.htaccess
cd png ; \
cp caution.png home.png important.png next.png note.png \
prev.png tip.png warning.png $(BASEDIR)/html/images
#######################################################################
# $ make html # update all HTML in $(BASEDIR)
#######################################################################
.PHONY: html
html: $(foreach LX, $(LANGALL), $(BASEDIR)/html/index.$(LX).html)
$(BASEDIR)/html/index.%.html: $(MANUAL).%.xml $(ENT_ALL)
@$(call check-command, xsltproc, xsltproc)
-mkdir -p $(BASEDIR)/html
$(XSLT) --stringparam base.dir $(BASEDIR)/html \
--stringparam html.ext .$*.html \
$(XSLT_DIR)/style-html.xsl $<
#######################################################################
# $ make txt # update all Plain TEXT in $(BASEDIR)
#######################################################################
.PHONY: txt
txt: $(foreach LX, $(LANGALL), $(BASEDIR)/$(MANUAL).$(LX).txt.gz)
# style-txt.xsl provides work around for hidden URL links by appending them explicitly.
$(BASEDIR)/$(MANUAL).%.txt.gz: $(MANUAL).%.xml $(ENT_ALL)
@$(call check-command, w3m, w3m)
@$(call check-command, xsltproc, xsltproc)
-mkdir -p $(BASEDIR)
@test -n "`which w3m`" || { echo "ERROR: w3m not found. Please install the w3m package." ; false ; }
$(XSLT) $(XSLT_DIR)/style-txt.xsl $< | LC_ALL=C.UTF-8 \
w3m -o display_charset=UTF-8 -cols 70 -dump -no-graph -T text/html | \
gzip -n -9 - > $@
#######################################################################
# $ make pdf # update all PDF in $(BASEDIR)
#######################################################################
.PHONY: pdf nopdf
pdf: $(foreach LX, $(LANGALL), $(BASEDIR)/$(MANUAL).$(LX).pdf)
nopdf: $(TMPDIR)/nopdf.pdf
$(TMPDIR)/nopdf.pdf: nopdf.tex
cp -f nopdf.tex $(TMPDIR)/nopdf.tex
cd "$(TMPDIR)"; \
xelatex nopdf.tex
$(foreach LX, $(NOPDF), $(BASEDIR)/$(MANUAL).$(LX).pdf): $(TMPDIR)/nopdf.pdf
cp $(TMPDIR)/nopdf.pdf $@
# dblatex.xsl provide work around for hidden URL links by appending them explicitly.
$(BASEDIR)/$(MANUAL).%.pdf: $(MANUAL).%.xml $(ENT_ALL)
@$(call check-command, dblatex, dblatex)
@$(call check-command, xsltproc, xsltproc)
-mkdir -p $(BASEDIR)
@test -n "`which $(DBLATEX)`" || { echo "ERROR: dblatex not found. Please install the dblatex package." ; false ; }
export TEXINPUTS=".:"; \
export TMPDIR="$(TMPDIR)"; \
$(XSLT) $(XSLT_DIR)/dblatex.xsl $< | \
$(DBLATEX) --style=db2latex \
--debug \
--backend=xetex \
--xsl-user=$(XSLT_DIR)/user_param.xsl \
--xsl-user=$(XSLT_DIR)/xetex_param.xsl \
--param=draft.mode=$(DRAFTMODE) \
--param=doc.collab.show=0 \
--param=latex.output.revhistory=0 \
--param=doc.lot.show="" \
--param=lingua=$* \
--output=$@ - || { echo "OMG!!!!!! XXX_CHECK_XXX ... Do not worry ..."; true ; }
#######################################################################
# $ make tex # update all TeX source in $(BASEDIR)
#######################################################################
.PHONY: tex
tex: $(foreach LX, $(LANGALL), $(BASEDIR)/$(MANUAL).$(LX).tex)
# dblatex.xsl provide work around for hidden URL links by appending them explicitly.
$(BASEDIR)/$(MANUAL).%.tex: $(MANUAL).%.xml $(ENT_ALL)
-mkdir -p $(BASEDIR)
@test -n "`which $(DBLATEX)`" || { echo "ERROR: dblatex not found. Please install the dblatex package." ; false ; }
export TEXINPUTS=".:"; \
export TMPDIR="$(TMPDIR)"; \
$(XSLT) $(XSLT_DIR)/dblatex.xsl $< | \
$(DBLATEX) --style=native \
--debug \
--type=tex \
--backend=xetex \
--xsl-user=$(XSLT_DIR)/user_param.xsl \
--xsl-user=$(XSLT_DIR)/xetex_param.xsl \
--param=draft.mode=$(DRAFTMODE) \
--param=doc.collab.show=0 \
--param=latex.output.revhistory=0 \
--param=doc.lot.show="" \
--param=lingua=$* \
--output=$@ - || { echo "OMG!!!!!! XXX_CHECK_XXX ... Do not worry ..."; true ; }
#######################################################################
# $ make epub # update all epub in $(BASEDIR)
#######################################################################
.PHONY: epub
epub: $(foreach LX, $(LANGALL), $(BASEDIR)/$(MANUAL).$(LX).epub)
$(BASEDIR)/$(MANUAL).%.epub: $(MANUAL).%.xml $(ENT_ALL)
@$(call check-command, xsltproc, xsltproc)
-mkdir -p $(TMPDIR)/$*/
cd $(TMPDIR)/$*/ ; $(XSLT) $(CURDIR)/$(XSLT_DIR)/style-epub.xsl $(CURDIR)/$<
cp -f $(XSLT_DIR)/mimetype $(TMPDIR)/$*/mimetype
cp -f $(XSLT_DIR)/debian.css $(TMPDIR)/$*/OEBPS/debian.css
cp -f $(XSLT_DIR)/debian-openlogo.png $(TMPDIR)/$*/OEBPS/debian-openlogo.png
cd $(TMPDIR)/$*/ ; zip -r $@ ./