-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
577 lines (484 loc) · 15.8 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
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
# Makefile of _Glosa Internet Directory_
# By Marcos Cruz (programandala.net)
# Last modified 201901101545
# See change log at the end of the file
# ==============================================================
# Requirements
# - asciidoctor
# - dictfmt
# - grep
# - make
# - pandoc
# - tr
# - sed
# - zcat
# ==============================================================
# Config
VPATH=./src:./target:./original
# ----------------------------------------------
# Base filenames
complete_name=glosa_dictionary
english_glosa_name=english-glosa_dictionary
glosa_english_name=glosa-english_dictionary
english_glosa_dict_name=eng-glosa
glosa_english_dict_name=glosa-eng
# ----------------------------------------------
# A temporary field separator. Any character not used in the original data
# file is valid.
#
# Note: This character must be different from the `bullet` variable.
separator=|
# ----------------------------------------------
# A mark that will be added at the start of every entry, in order to facilitate
# searches in e-books, where regular expressions are not available. I.e.
# searching the book for "word" will find the string "word" in any position of
# the text, including as part of longer words, but searching for ".word" will
# find only the dictionary entry.
#
# Note: This character must be different from the `separator` variable.
bullet={dot}
# ==============================================================
# Interface
.PHONY: all
all: epub
.PHONY: clean
clean:
rm -f target/* tmp/*
.PHONY: data
data: csv list paragraph linebreak
.PHONY: csv
csv: tmp/engl.csv tmp/glen.csv
.PHONY: jargon
jargon: tmp/engl.jargon.txt tmp/glen.jargon.txt
.PHONY: dict
dict: \
target/$(english_glosa_dict_name).dict.dz \
target/$(glosa_english_dict_name).dict.dz
.PHONY: list
list: tmp/engl.list.adoc tmp/glen.list.adoc
.PHONY: paragraph
paragraph: tmp/engl.paragraph.adoc tmp/glen.paragraph.adoc
.PHONY: linebreak
linebreak: tmp/engl.linebreak.adoc tmp/glen.linebreak.adoc
.PHONY: epub
epub: epub_with_paragraphs
.PHONY: epub_with_paragraphs
epub_with_paragraphs: \
target/$(complete_name).paragraph.adoc.xml.pandoc.epub \
target/$(english_glosa_name).paragraph.adoc.xml.pandoc.epub \
target/$(glosa_english_name).paragraph.adoc.xml.pandoc.epub
.PHONY: epub_with_lists
epub_with_lists: \
target/$(complete_name).list.adoc.xml.pandoc.epub \
target/$(english_glosa_name).list.adoc.xml.pandoc.epub \
target/$(glosa_english_name).list.adoc.xml.pandoc.epub
.PHONY: epub_with_tables
epub_with_tables: \
target/$(complete_name).table.adoc.xml.pandoc.epub \
target/$(english_glosa_name).table.adoc.xml.pandoc.epub \
target/$(glosa_english_name).table.adoc.xml.pandoc.epub
# XXX TODO --
# target/$(complete_name).linebreak.adoc.xml.pandoc.epub
.PHONY: html
html: html_with_lists
.PHONY: html_with_paragraphs
html_with_paragraphs: \
target/$(complete_name).paragraph.adoc.html \
target/$(complete_name).paragraph.adoc.plain.html \
target/$(complete_name).paragraph.adoc.xml.pandoc.html \
target/$(english_glosa_name).paragraph.adoc.html \
target/$(english_glosa_name).paragraph.adoc.plain.html \
target/$(english_glosa_name).paragraph.adoc.xml.pandoc.html \
target/$(glosa_english_name).paragraph.adoc.html \
target/$(glosa_english_name).paragraph.adoc.plain.html \
target/$(glosa_english_name).paragraph.adoc.xml.pandoc.html
.PHONY: html_with_lists
html_with_lists: \
target/$(complete_name).list.adoc.html \
target/$(complete_name).list.adoc.plain.html \
target/$(complete_name).list.adoc.xml.pandoc.html \
target/$(english_glosa_name).list.adoc.html \
target/$(english_glosa_name).list.adoc.plain.html \
target/$(english_glosa_name).list.adoc.xml.pandoc.html \
target/$(glosa_english_name).list.adoc.html \
target/$(glosa_english_name).list.adoc.plain.html \
target/$(glosa_english_name).list.adoc.xml.pandoc.html
.PHONY: html_with_tables
html_with_tables: \
target/$(complete_name).table.adoc.html \
target/$(complete_name).table.adoc.plain.html \
target/$(complete_name).table.adoc.xml.pandoc.html \
target/$(english_glosa_name).table.adoc.html \
target/$(english_glosa_name).table.adoc.plain.html \
target/$(english_glosa_name).table.adoc.xml.pandoc.html \
target/$(glosa_english_name).table.adoc.html \
target/$(glosa_english_name).table.adoc.plain.html \
target/$(glosa_english_name).table.adoc.xml.pandoc.html
# XXX TODO --
#.PHONY: html_with_linebreaks
#html_with_linebreaks: \
# target/$(complete_name).linebreak.adoc.html \
# target/$(complete_name).linebreak.adoc.plain.html \
# target/$(complete_name).linebreak.adoc.xml.pandoc.html \
# target/$(english_glosa_name).linebreak.adoc.html \
# target/$(english_glosa_name).linebreak.adoc.plain.html \
# target/$(english_glosa_name).linebreak.adoc.xml.pandoc.html \
# target/$(glosa_english_name).linebreak.adoc.html \
# target/$(glosa_english_name).linebreak.adoc.plain.html \
# target/$(glosa_english_name).linebreak.adoc.xml.pandoc.html
# ==============================================================
# Convert the original data files
# NOTE: The `.SECONDARY` special target prevents intermediate files from being
# removed at the end. See section "10.4 Chains of Implicit Rules" of the GNU
# make manual.
# ----------------------------------------------
# Basic tidy
# - Change the encoding of the original data files to UTF-8 (as required by all
# target formats).
# - Remove comment lines.
# - Remove empty lines, just in case.
# - Fix typo in the description notation of 'akademi': "*1" -> "1*".
# - Add a field separator at the start of the lines.
# - Add a field separator between the fields, preceding a semicolon and a space,
# in order to mark the start of a definition and make later expressions simpler.
# - Replace curly brackets with parens.
.SECONDARY: tmp/engl.tidy_0_basic.txt tmp/glen.tidy_0_basic.txt
tmp/%.tidy_0_basic.txt: original/%.txt.gz Makefile
zcat $< \
| iconv --from-code latin1 --to-code utf-8 \
| grep --invert-match "^%" \
| grep --invert-match "^$$" \
| sed \
-e '/akademi/s/\*1+/1+\*/' \
-e 's/ \+$$//' \
-e 's/^/$(separator)/' \
-e 's/ \+/$(separator)/' \
-e 's/\($(separator)\|; \)\([^$(separator);]\+\)\[\([^$(separator);]\+\)]/\1\3\2/g' \
-e 's/ $(separator)/$(separator)/g' \
-e 's/ \(1+\{0,2\}\*\?X\?G\?\)/ [\1]/g' \
-e 's/\<\(X\)\($$\|;\)/[\1]\2/g' \
-e 's/\<\(G\)\($$\|;\)/[\1]\2/g' \
-e 's/\(+\{1,2\}\)$$/[\1]/g' \
-e 's/\([$(separator);]\)\([^$(separator);]\+\); \2\([$(separator);]\)/\1\2\3/' \
| tr '[{}]' '[()]' > $@
# Description of the `sed` commands:
#
# 1: Fix typo in the description of entry 'akademy'.
#
# 2: Remove trailing spaces.
#
# 3: Add the separator at the start of the lines.
#
# 4: Use the separator to separate the fields, instead two or more spaces.
#
# 5: Move the second part of the compound expressions, which are in brackets,
# before their main entry, and remove the brackets.
#
# 6: Remove spaces caused by command #5 in some cases.
#
# 7: Put the notes about the entry into brackets.
#
# 8: Put the notes 'X' alone into brackets (not catched by the command #7).
#
# 9: Put the notes 'G' alone into brackets (not catched by the command #7).
#
# 10: Put the notes '+/++' alone into brackets (not catched by the command #7).
#
# 11: Remove duplicated expressions caused by command #5.
# ----------------------------------------------
# Additional tidy for dict
# Move the notes about the word, if any, to the description field.
.SECONDARY: tmp/engl.tidy_1_dict.txt tmp/glen.tidy_1_dict.txt
%.tidy_1_dict.txt: %.tidy_0_basic.txt Makefile
cat $< \
| sed \
-e 's/ \(\[.\+\]\)$(separator)/$(separator)\1 /' \
> $@
# ----------------------------------------------
# Convert into CSV (Comma Separated Values)
# CSV format (with bullet '>' prefix added):
#
# -------------------
# ">word1","definition 1"
# ">word2","definition 2"
# -------------------
%.csv: %.tidy_0_basic.txt
cat $< \
| sed \
-e 's/^|\([^|]\+\)|\(.\)$$/"\1","\2"/' \
-e 's/"/"$(bullet)/' \
> $@
# Description of the `sed` commands:
#
# 1: Convert the lines to CSV.
#
# 2: Add the bullet before the term.
# ----------------------------------------------
# Convert into Jargon format
# Jargon format:
#
# -------------------
# :word1:definition 1
# :word2:definition 2
# -------------------
%.jargon.txt: %.tidy_1_dict.txt
cat $< \
| sed \
-e 's/|/:/g' \
> $@
# ----------------------------------------------
# Convert into Asciidoctor unordered lists
%.list.adoc: %.tidy_0_basic.txt
cat $< \
| sed \
-e 's/^|/- $(bullet)/' \
-e 's/|/: /' \
> $@
# ----------------------------------------------
# Convert into Asciidoctor paragraph with line breaks
# XXX FIXME -- This does not work. See details in the TO-DO file.
%.linebreak.adoc: %.tidy_0_basic.txt
cat $< \
| sed \
-e 's/^|/$(bullet)/' \
-e 's/|/: /' \
-e 's/$$/ +/' \
> $@
# ----------------------------------------------
# Convert into Asciidoctor paragraph
%.paragraph.adoc: %.tidy_0_basic.txt
cat $< \
| sed \
-e 's/^|/$(bullet)/' \
-e 's/|/: /' \
-e 's/$$/\n/' \
> $@
# ==============================================================
# Convert to dict and install it
target/$(english_glosa_dict_name).dict: tmp/engl.jargon.txt
dictfmt \
--utf8 \
--allchars \
-u "http://glosa.org" \
-s "English-Glosa Dictionary" \
-j $(basename $@) \
< $<
target/$(glosa_english_dict_name).dict: tmp/glen.jargon.txt
dictfmt \
--utf8 \
--allchars \
-u "http://glosa.org" \
-s "Glosa-English Dictionary" \
-j $(basename $@) \
< $<
%.dict.dz: %.dict
dictzip --force $<
.PHONY: install
install: \
target/$(english_glosa_dict_name).dict.dz \
target/$(glosa_english_dict_name).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/$(english_glosa_dict_name).* \
/usr/share/dictd/$(glosa_english_dict_name).*
/usr/sbin/dictdconfig --write
/etc/init.d/dictd restart
# ==============================================================
# Convert to Asciidoctor
# ---------------------------------------------
# Complete versions
target/$(complete_name).table.adoc: \
tmp/engl.csv \
tmp/glen.csv \
src/$(complete_name).title.adoc \
src/common.adoc
cat \
src/$(complete_name).title.adoc \
src/common.adoc \
src/$(english_glosa_name).table.adoc \
src/$(glosa_english_name).table.adoc > $@
target/$(complete_name).list.adoc: \
tmp/engl.list.adoc \
tmp/glen.list.adoc \
src/$(complete_name).title.adoc \
src/common.adoc
cat \
src/$(complete_name).title.adoc \
src/common.adoc \
src/$(english_glosa_name).list.adoc \
src/$(glosa_english_name).list.adoc > $@
target/$(complete_name).paragraph.adoc: \
tmp/engl.paragraph.adoc \
tmp/glen.paragraph.adoc \
src/$(complete_name).title.adoc \
src/common.adoc
cat \
src/$(complete_name).title.adoc \
src/common.adoc \
src/$(english_glosa_name).paragraph.adoc \
src/$(glosa_english_name).paragraph.adoc > $@
target/$(complete_name).linebreak.adoc: \
tmp/engl.linebreak.adoc \
tmp/glen.linebreak.adoc \
src/$(complete_name).title.adoc \
src/common.adoc
cat \
src/$(complete_name).title.adoc \
src/common.adoc \
src/$(english_glosa_name).linebreak.adoc \
src/$(glosa_english_name).linebreak.adoc > $@
# ---------------------------------------------
# English-Glosa versions
target/$(english_glosa_name).table.adoc: \
tmp/engl.csv \
src/$(english_glosa_name).title.adoc \
src/common.adoc
cat \
src/$(english_glosa_name).title.adoc \
src/common.adoc \
src/$(english_glosa_name).table.adoc > $@
target/$(english_glosa_name).list.adoc: \
tmp/engl.list.adoc \
src/$(english_glosa_name).title.adoc \
src/common.adoc
cat \
src/$(english_glosa_name).title.adoc \
src/common.adoc \
src/$(english_glosa_name).list.adoc > $@
target/$(english_glosa_name).paragraph.adoc: \
tmp/engl.paragraph.adoc \
src/$(english_glosa_name).title.adoc \
src/common.adoc
cat \
src/$(english_glosa_name).title.adoc \
src/common.adoc \
src/$(english_glosa_name).paragraph.adoc > $@
target/$(english_glosa_name).linebreak.adoc: \
tmp/engl.linebreak.adoc \
src/$(english_glosa_name).title.adoc \
src/common.adoc
cat \
src/$(english_glosa_name).title.adoc
src/common.adoc \
src/$(english_glosa_name).linebreak.adoc > $@
# ---------------------------------------------
# Glosa-English versions
target/$(glosa_english_name).table.adoc: \
tmp/glen.csv \
src/$(glosa_english_name).title.adoc \
src/common.adoc
cat \
src/$(glosa_english_name).title.adoc \
src/common.adoc \
src/$(glosa_english_name).table.adoc > $@
target/$(glosa_english_name).list.adoc: \
tmp/glen.list.adoc \
src/$(glosa_english_name).title.adoc \
src/common.adoc
cat \
src/$(glosa_english_name).title.adoc \
src/common.adoc \
src/$(glosa_english_name).list.adoc > $@
target/$(glosa_english_name).paragraph.adoc: \
tmp/glen.paragraph.adoc \
src/$(glosa_english_name).title.adoc \
src/common.adoc
cat \
src/$(glosa_english_name).title.adoc \
src/common.adoc \
src/$(glosa_english_name).paragraph.adoc > $@
target/$(glosa_english_name).linebreak.adoc: \
tmp/glen.linebreak.adoc \
src/$(glosa_english_name).title.adoc \
src/common.adoc
cat \
src/$(glosa_english_name).title.adoc \
src/common.adoc \
src/$(glosa_english_name).linebreak.adoc > $@
# ==============================================================
# Convert to DocBook
%.adoc.xml: %.adoc
adoc --backend=docbook5 --out-file=$@ $<
# ==============================================================
# Convert to EPUB
# NB: Pandoc does not allow alternative templates. The default templates must
# be modified or redirected instead. They are the following:
#
# /usr/share/pandoc-1.9.4.2/templates/epub-coverimage.html
# /usr/share/pandoc-1.9.4.2/templates/epub-page.html
# /usr/share/pandoc-1.9.4.2/templates/epub-titlepage.html
%.adoc.xml.pandoc.epub: %.adoc.xml
pandoc \
--from=docbook \
--to=epub \
--output=$@ \
$<
# ==============================================================
# Convert to HTML
%.adoc.plain.html: %.adoc
adoc \
--attribute="stylesheet=none" \
--quiet \
--out-file=$@ \
$<
%.adoc.html: %.adoc
adoc --out-file=$@ $<
%.adoc.xml.pandoc.html: %.adoc.xml
pandoc \
--from=docbook \
--to=html \
--standalone \
--output=$@ \
$<
# ==============================================================
# Change log
# 2018-12-06: Start. Create an Asciidoctor document from the original data
# files.
#
# 2018-12-08: Rewrite. Use the original data files to build the tables of the
# Asciidoctor source. This makes it possible to update the e-book whenever the
# original data is updated in glosa.org.
#
# 2018-12-09:
#
# Finish the regular expressions that rearrange the parts in brackets.
#
# Put the notes of word origins into brackets.
#
# Make a rule to build both CSV files, using Makefile as prerrequisite; this
# makes testing easier.
#
# Remove duplicated meanings caused by variants in brackets.
#
# Mark entries with a hardcoded bullet, in order to make searches easier.
#
# Build a variant target, using lists, which the e-reader renders much faster
# than tables. Build also a target using paragraphs, which is even a bit
# faster.
#
# 2018-12-11:
#
# Convert to dict format. The process is not fully working yet. The notes
# about the Glosa words must be moved to the description field, otherwise it's
# considered part of the word.
#
# 2018-12-12: Move the notes about the Glosa words to the description field.
#
# 2018-12-15: Fix the typo of the description notation of 'akademi' in the
# first tidy. This way later regexp don't need to be modified.
#
# 2018-12-22: Finish the rewritting of most rules. Now most operations are done
# during the first processing of the original data. This makes all later
# recipes easier.
#
# 2018-12-24: Fix minor regexp. Build only EPUB with paragraphs by default.
#
# 2019-01-10: Shorten the filenames and descriptions of the dict files. Add
# rule to uninstall the dict dictionaries.