-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
338 lines (276 loc) · 9.49 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
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
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
# Makefile of _Disionario de elefen_
# This file is part of the project
# "Disionario de elefen"
# (http://ne.alinome.net)
#
# By Marcos Cruz (programandala.net)
# Last modified 201902241534
# See change log at the end of the file
# ==============================================================
# Requirements
# - asciidoctor
# - asciidoctor-epub3
# - dbtoepub
# - dictfmt
# - gforth
# - make
# - pandoc
# - vim
# - wget
# - xsltproc
# ==============================================================
# Config
VPATH=./src:./target
# ==============================================================
# Interface
.PHONY: all
all: epub dict
# EPUB in 1 and 4 tomes:
.PHONY: epub
epub: epub1 epub4
# EPUB in 1 tome:
.PHONY: epub1
epub1: epub1d epub1p
# EPUB in 1 tome, with asciidoctor-epub3:
.PHONY: epub1a
epub1a: target/disionario_de_elefen.adoc.epub
# EPUB in 1 tome, with dbtoepub:
.PHONY: epub1d
epub1d: target/disionario_de_elefen.adoc.xml.dbtoepub.epub
# EPUB in 1 tome, with pandoc:
.PHONY: epub1p
epub1p: target/disionario_de_elefen.adoc.xml.pandoc.epub
# EPUB in 1 tome, with xsltproc:
.PHONY: epub1x
epub1x: target/disionario_de_elefen.adoc.xml.xsltproc.epub
# EPUB in 4 tomes:
.PHONY: epub4
epub4: epub4d epub4p
# EPUB in 4 tomes, with asciidoctor-epub3:
.PHONY: epub4a
epub4a: \
target/disionario_de_elefen_en_4_librones_a-c.adoc.epub \
target/disionario_de_elefen_en_4_librones_d-l.adoc.epub \
target/disionario_de_elefen_en_4_librones_m-r.adoc.epub \
target/disionario_de_elefen_en_4_librones_s-z.adoc.epub
# EPUB in 4 tomes, with dbtoepub:
.PHONY: epub4d
epub4d: \
target/disionario_de_elefen_en_4_librones_a-c.adoc.xml.dbtoepub.epub \
target/disionario_de_elefen_en_4_librones_d-l.adoc.xml.dbtoepub.epub \
target/disionario_de_elefen_en_4_librones_m-r.adoc.xml.dbtoepub.epub \
target/disionario_de_elefen_en_4_librones_s-z.adoc.xml.dbtoepub.epub
# EPUB in 4 tomes, with pandoc:
.PHONY: epub4p
epub4p: \
target/disionario_de_elefen_en_4_librones_a-c.adoc.xml.pandoc.epub \
target/disionario_de_elefen_en_4_librones_d-l.adoc.xml.pandoc.epub \
target/disionario_de_elefen_en_4_librones_m-r.adoc.xml.pandoc.epub \
target/disionario_de_elefen_en_4_librones_s-z.adoc.xml.pandoc.epub
# EPUB in 4 tomes, with xsltproc:
.PHONY: epub4x
epub4x: \
target/disionario_de_elefen_en_4_librones_a-c.adoc.xml.xsltproc.epub \
target/disionario_de_elefen_en_4_librones_d-l.adoc.xml.xsltproc.epub \
target/disionario_de_elefen_en_4_librones_m-r.adoc.xml.xsltproc.epub \
target/disionario_de_elefen_en_4_librones_s-z.adoc.xml.xsltproc.epub
# XXX TMP -- for debugging
.PHONY: test
test: \
target/disionario_de_elefen_en_4_librones_a-c.adoc.xml.pandoc.epub
.PHONY: adoc
adoc: tmp/disionario_completa.adoc
.PHONY: c5
c5: tmp/disionario_completa.c5
.PHONY: dict
dict: target/elefen.dict.dz
# XXX TMP -- for debugging
.PHONY: xml
xml: tmp/disionario_completa.adoc.xml
.PHONY: clean
clean:
rm -fr target/* tmp/*
# ==============================================================
# Update the original data
.PHONY: update
update:
wget \
-O src/disionario_completa.txt \
http://elefen.org/disionario/disionario_completa.txt
# ==============================================================
# Convert the original data file to Asciidoctor
.SECONDARY: tmp/disionario_completa.adoc
tmp/%.adoc: src/%.txt
gforth make/convert_data.fs -e "to-asciidoctor $< bye" > $@
vim -e -S make/tidy_data.vim $@
# ==============================================================
# Create one Asciidoctor file per letter
letter_files=\
tmp/disionario_de_elefen_a.adoc \
tmp/disionario_de_elefen_b.adoc \
tmp/disionario_de_elefen_c.adoc \
tmp/disionario_de_elefen_d.adoc \
tmp/disionario_de_elefen_e.adoc \
tmp/disionario_de_elefen_f.adoc \
tmp/disionario_de_elefen_g.adoc \
tmp/disionario_de_elefen_h.adoc \
tmp/disionario_de_elefen_i.adoc \
tmp/disionario_de_elefen_j.adoc \
tmp/disionario_de_elefen_k.adoc \
tmp/disionario_de_elefen_l.adoc \
tmp/disionario_de_elefen_m.adoc \
tmp/disionario_de_elefen_n.adoc \
tmp/disionario_de_elefen_o.adoc \
tmp/disionario_de_elefen_p.adoc \
tmp/disionario_de_elefen_q.adoc \
tmp/disionario_de_elefen_r.adoc \
tmp/disionario_de_elefen_s.adoc \
tmp/disionario_de_elefen_t.adoc \
tmp/disionario_de_elefen_u.adoc \
tmp/disionario_de_elefen_v.adoc \
tmp/disionario_de_elefen_w.adoc \
tmp/disionario_de_elefen_x.adoc \
tmp/disionario_de_elefen_y.adoc \
tmp/disionario_de_elefen_z.adoc
$(letter_files): tmp/disionario_completa.adoc
vim -e -R \
-S make/split_dictionary_into_letters.vim \
-c 'quit!' \
$<
# ==============================================================
# Convert the original data file to c5
.SECONDARY: tmp/disionario_completa.c5
tmp/%.c5: src/%.txt
gforth make/convert_data.fs -e "to-c5 $< bye" > $@
vim -e -S make/tidy_data.vim $@
# ==============================================================
# Convert c5 to dict
target/elefen.dict: tmp/disionario_completa.c5
dictfmt \
--utf8 \
-u "http://elefen.org" \
-s "Disionario de elefen" \
-c5 $(basename $@) \
< $<
# ==============================================================
# Install and uninstall dict
%.dict.dz: %.dict
dictzip --force $<
.PHONY: install
install: target/elefen.dict.dz
cp --force \
$< \
$(addsuffix .index, $(basename $(basename $^))) \
/usr/share/dictd/
/usr/sbin/dictdconfig --write
/etc/init.d/dictd restart
.PHONY: uninstall
uninstall:
rm --force /usr/share/dictd/elefen.*
/usr/sbin/dictdconfig --write
/etc/init.d/dictd restart
# ==============================================================
# Convert Asciidoctor to DocBook
.SECONDARY: \
tmp/disionario_completa.adoc.xml \
tmp/disionario_de_elefen_en_4_librones_a-c.adoc.xml \
tmp/disionario_de_elefen_en_4_librones_d-l.adoc.xml \
tmp/disionario_de_elefen_en_4_librones_m-r.adoc.xml \
tmp/disionario_de_elefen_en_4_librones_s-z.adoc.xml
tmp/%.adoc.xml: src/%.adoc
asciidoctor --backend=docbook5 --out-file=$@ $<
# XXX TMP -- for debugging
tmp/%.adoc.xml: tmp/%.adoc
asciidoctor --backend=docbook5 --out-file=$@ $<
# ==============================================================
# Make the EPUB
# ----------------------------------------------
# By asciidoctor-epub3, from Asciidoctor
# This is not used by default, because the result is bigger, slower to use,
# less versatile and less configurable by the viewer, though the text is better
# looking.
target/%.adoc.epub: src/%.adoc $(letter_files)
asciidoctor-epub3 --out-file=$@ $<
# ----------------------------------------------
# By dbtoepub, from DocBook
target/%.adoc.xml.dbtoepub.epub: \
tmp/%.adoc.xml \
$(letter_files)
dbtoepub --output $@ $<
# ----------------------------------------------
# By pandoc, from DocBook
tmp/%.adoc.xml.pandoc.raw.epub: tmp/%.adoc.xml $(letter_files)
pandoc \
--from=docbook \
--to=epub3 \
--template=src/pandoc_epub_template.txt \
--variable=lang:lfn \
--output=$@ $<
target/%.adoc.xml.pandoc.epub: tmp/%.adoc.xml.pandoc.raw.epub
make/epubunzip $< && \
vim -e \
-S make/convert_note_captions.vim \
$$(ls tmp/$$(basename $< .epub)/EPUB/text/*.xhtml) && \
mv tmp/$$(basename $< .epub) tmp/$$(basename $< .raw.epub) && \
make/epubzip tmp/$$(basename $< .raw.epub) && \
mv tmp/$$(basename $< .raw.epub).epub $@
# ----------------------------------------------
# By xsltproc, from DocBook
# This is not used by default, because the result is identical to that of
# dbtoepub, which is a wrapper on xsltproc.
target/%.adoc.xml.xsltproc.epub: tmp/%.adoc.xml $(letter_files)
rm -fr tmp/xsltproc/* && \
xsltproc \
--output tmp/xsltproc/ \
/usr/share/xml/docbook/stylesheet/docbook-xsl/epub/docbook.xsl \
$< && \
echo -n "application/epub+zip" > tmp/xsltproc/mimetype && \
cd tmp/xsltproc/ && \
zip -0 -X ../../[email protected] mimetype && \
zip -rg9 ../../[email protected] META-INF && \
zip -rg9 ../../[email protected] OEBPS && \
cd - && \
mv [email protected] $@
# XXX TODO -- Find out how to pass parameters and their names, from the XLS:
# --param epub.ncx.filename testing.ncx \
# XXX TODO -- Add the stylesheet. The XLS must be modified first,
# or the resulting XHTML must be modified at the end.
# cp -f src/xsltproc/stylesheet.css tmp/xsltproc/OEBPS/ && \
# ==============================================================
# Change log
# 2018-12-28: Start.
#
# 2018-12-29: Fix and finish the preprocessing expressions.
#
# 2018-12-30: Markup the species names. Fix the "nb" notes, which were
# interpreted as a translation into language code "nb". Separate references
# from the previous paragraph. Markup examples as example blocks.
#
# 2019-01-04: Rewrite: Use the original data file.
#
# 2019-01-05: Write a new converter in Forth to replace the Vim code.
#
# 2019-01-09: Remove the old Vim converter. Use Vim to split the converted file
# into letters. Add an EPUB version build by pandoc. Convert original internal
# notes and curly brackets markup. Build the dictionary also in four tomes.
#
# 2019-01-11: Improve: Add the letter files to the prerequisites of pandoc
# EPUB, and use `.SECONDARY` to keep the temporary DocBook files.
#
# 2019-01-12: Make an EPUB also with xsltproc.
#
# 2019-01-13: Make also a dict file.
#
# 2019-01-24: Deactivate asciidoctor-epub3. Use a pandoc template. Create EPUB3
# with pandoc.
#
# 2019-01-29: Create a file from the Vim commands that tidy the Asciidoctor
# document, in order to reuse it to tidy also the c5 file.
#
# 2019-02-03: Make an EPUB also with dbtoepub. Modify the EPUB created by
# pandoc, in order to convert the note captions.
#
# 2019-02-15: Make rule to update the original data (formerly this was done
# with an internal shell script).
#
# 2019-02-24: Don't use xsltproc by default.