File: Makefile

package info (click to toggle)
igerman98 20161207-9
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 4,252 kB
  • sloc: perl: 925; makefile: 475; sh: 471; sed: 46
file content (597 lines) | stat: -rw-r--r-- 22,007 bytes parent folder | download | duplicates (4)
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
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
# Makefile for the dictionary igerman98
#
# Author: Bjoern Jacke <bjoern@j3e.de>
#
# Copyright: GNU GPLv2 and GPLv3

# we need want out own executables first:
export PATH := .:bin:$(PATH)
LANGS=de_DE de_AT de_CH
LANGS2=$(LANGS) de_all
DATE=`date +%Y%m%d`
VERSION=`cat VERSION`
VERSION_EXTRA=$(shell find . -name "VERSION.*" -print | while read i ; do echo -n "+"; head -1 "$$i" | tr -d "\n" ; done)
# the build string makes the reproducible builds impossible. And builddate isn't really that much needed:
# VERSION_STRING=$(VERSION)$(VERSION_EXTRA) (build $(DATE))
VERSION_STRING=$(VERSION)$(VERSION_EXTRA)

all:
	@echo "A default make target doesn't exist. You might want to use one of those:"
	@echo "  make hunspell/de_DE.dic hunspell/de_DE.aff (or de_AT or de_CH)"
	@echo "  make myspell/de_DE.dic myspell/de_DE.aff (or de_AT or de_CH)"
	@echo "  make ispell/de_DE.aff ispell/de_DE.hash (or de_AT, de_CH ...)"
	@echo "  make aspell/de_DE.rws (or de_AT, de_CH ...)"
	@echo "  make ligature/rmligs"
	@echo "  make isowordlist-de_DE (or de_AT, de_CH ...)"
	@echo "Did I forget an important one ?-)"



#MYLANG = $(shell echo -n $@ | sed "s/^.*_\(de_.*$$\)/\1/")
MYLANG = $(shell echo $@ | sed "s/^.*[_/]\(de_[a-zA-Z]*\).*/\1/")

# FIND_OPTS can be used to exclude directories from being used, like:
# FIND_OPTS = ! -name "*-a-*"

define WORDS_define_template

WORDS_$(1) = $$(shell $$(FIND) ./dicts/ -name "*$(1)*.txt" ! -name "*compound*" $$(FIND_OPTS) -print)

WORDS_COMP_$(1) = $$(shell $$(FIND) ./dicts/ -name "compound*$(1)*.txt" $$(FIND_OPTS) -print)

## alle ohne "*-x*"
WORDS_CAPMAIN_SMALL_$(1)	= $$(shell $$(FIND) ./dicts/ -name "*$(1)*.txt" ! -name "*-x*" ! -name "*compound*" $$(FIND_OPTS) -print)

## alle "*-xx*"
WORDS_CAPMAIN_PLUS_$(1)	= $$(shell $$(FIND) ./dicts/ -name "*$(1)*.txt" -name "*-xx*" ! -name "*compound*" $$(FIND_OPTS) -print)

## alle "*-x*" ohne "*-xx*"
WORDS_NOCAPMAIN_$(1)	= $$(shell $$(FIND) ./dicts/ -name "*$(1)*.txt" -name "*-x*" ! -name "*-xx*" ! -name "*compound*" $(FIND_OPTS) -print)

WORDS_BLACKLISTS_$(1) = $$(shell $$(FIND) ./dicts/ -name "blacklist*$(1)*" $(FIND_OPTS) -print)

endef
$(foreach langcode,$(LANGS2),$(eval $(call WORDS_define_template,$(langcode))))

ISPELLIBDIR = $$($(ISPELL) -vv |grep "LIBDIR" |$(SED) "s/.*\=//" |tr -d \")
DESTDIR =
# make might have to be GNU make,
# please report problems with other make versions to me.
MAKE = make
FIND = find
SORT = sort
TAR = tar
SED = sed
NL = nl
CP = cp
# some incarnations of "wc -l" print out leading whitespace, let's use sed:
WCL = $(SED) -n '$$='

# the following is to remove temp files during build. Set it
# to rm if disk space is an issue during build time:
RM_OR_NOT = @\#
#RM_OR_NOT = rm

#ZIP = zip
#ZIP_OPTS = -j -r -9 -X
ZIP = 7z
ZIP_OPTS = a -tzip -mx=9
BUILDHASH = buildhash

ISPELL = ispell
HUNSPELL_BIN = hunspell
# Hunspell starting with 1.1.9 (?) uses automatic charset transcoding,
# we need to make sure we use latin1:
HUNSPELL = $(HUNSPELL_BIN) `$(HUNSPELL_BIN) -h 2>&1 | grep -q "hunspell \\-i" && echo "-i latin1"`


SQ = sq
UNSQ = unsq
#   if for some reason you don't have Ispell's unsq use my Perl sq/unsq
#  and put it into a directory known by your PATH variable!
#UNSQ = unsq.pl

ASPELL = aspell
PREZIP = prezip

# if you don't have ispell around, you may change this to aspell:
AFFIX_EXPANDER = ispell

ifeq ($(AFFIX_EXPANDER),ispell)
AFFIX_EXPAND_PREREQ = ispell/$(1)_null.hash ispell/$(1)_null.aff
AFFIX_EXPAND_COMMAND = $(ISPELL) -d./ispell/$(1)_null -e
MUNCH_PFX = munch.
else
AFFIX_EXPAND_PREREQ = aspell/$(1).dat aspell/$(1)_affix.dat
AFFIX_EXPAND_COMMAND = ( $(SED) -f ./bin/dic2iso | $(ASPELL) --encoding=iso8859-1 --lang=$(1) --local-data-dir=./aspell expand )
MUNCH_PFX =
endif

vpath %.txt ./dicts  ./hunspell ./myspell
.SUFFIXES: .txt .dic
.PHONY: clean pack unpack sort help dist hunspell-all
SUBDIRS = testdir

# to let `sort' behave right: setting LC_ALL ist not enough, because
# UTF-8 locales won't get overwritten by that, we also need to reset LANG!
# That's strange and might have been a bug which is fixed in the meantime.
# Otherwise locale depending sorting, grepping etc. which is slow as hell
# (like for de_DE) would be used, we don't need that anyway. See
# http://mail.nl.linux.org/linux-utf8/2003-11/msg00041.html

export LANG=C
export LC_ALL=C
export LC_COLLATE=C
export LANGUAGE=en_US:en


#$(addprefix dicts/,$(WORTE)): unpack
#	echo x
#	test -e $@ || (echo Wortliste $@ nicht vorhanden ; exit 1)



###
## Ispell stuff:
###

ispell/de_AT.aff ispell/de_DE.aff: ispell/de_DE.aff.in
	$(CP) ispell/de_DE.aff.in $@

ispell/de_CH.aff: ispell/de_DE.aff.in
	$(SED) "/swiss-del/d" ispell/de_DE.aff.in |$(SED) "/swiss-convert/s/sS/SS/g" |$(SED) '/\#swiss-only/s/^\#//' |$(SED) '/stringchar/!s/sS//g' > $@


define LANG_ispell_dict_template

ispell/$(1).hash: ispell/$(1).aff all.words.munch.$(1).tmp
	$(BUILDHASH) all.words.munch.$(1).tmp ./ispell/$(1).aff $$@

all.words.$(1).tmp: $$(WORDS_$(1)) $$(WORDS_de_all) dicts/abkuerzpunkt.txt
	$(SED) "s/qq//g;s/\.//;s/\-.*//" dicts/abkuerzpunkt.txt $$(WORDS_$(1)) $$(WORDS_de_all) \
	| (test -e ./bin/conv_dict_$(1) && ./bin/conv_dict_$(1) || cat) \
	| grep -v "\/.*d" | grep -v "##" | $(SED) "s/#.*//" | ./bin/myspellfixprefix.pl | $(SORT) -u > $$@

all.words.munch.$(1).tmp: all.words.$(1).tmp ispell/$(1).aff
	./bin/test-working-grep.sh
	@# the munched way to overcome "Hash table overflowed by xxxx words" error:
	munchlist -l ./ispell/$(1).aff all.words.$(1).tmp > $$@
	@# the unmunched way:
	@#$(CP) all.words.$(1).tmp $$@

ispell/$(1)_null.hash: ispell/$(1)_null.aff
	test -e all.words.placebo.tmp || echo a > all.words.placebo.tmp
	$(BUILDHASH) all.words.placebo.tmp ispell/$(1)_null.aff $$@

isowordlist-$(1): $(AFFIX_EXPAND_PREREQ) all.words.$(MUNCH_PFX)$(1).tmp
	$(AFFIX_EXPAND_COMMAND) < all.words.$(MUNCH_PFX)$(1).tmp |tr ' ' '\n' |$(SED) -f ./bin/dic2iso | $(SORT) -u > $$@

endef
$(foreach langcode,$(LANGS),$(eval $(call LANG_ispell_dict_template,$(langcode))))




###
## old Aspell stuff, new aspell/ stuff support for aspell 0.60 later down...
###
#
#help.hash: german.aff all.words2 .copyright
#	$(BUILDHASH) all.words2 ./german.aff $@
#
#all.words2:
#	cd dicts; sed s/qq//g $(WORTE) | $(SORT) -u > ../$@
#
#aspell: help.hash
#	#cat all.words2 dicts/abkuerzpunkt.txt |$(ISPELL) -e -d./help |sed -f ./bin/dic2iso |sort -u |$(ASPELL) --lang=german create master ./german
#	sed "s/\.//g" all.words2 dicts/abkuerzpunkt.txt |$(ISPELL) -e -d./help |sed -f ./bin/dic2iso | $(SORT) -u |$(ASPELL) --lang=german create master ./german
#
#swiss-aspell: swiss
#	cat all.words.swiss |$(ISPELL) -e -d./swiss |sed -f ./bin/dic2iso | $(SORT) -u |$(ASPELL) --lang=swiss create master ./swiss
#



define LANG_myspell_template

aspell/$(1)_affix.dat: myspell/$(1).aff
	$(CP) myspell/$(1).aff $$@

aspell/$(1).multi: aspell/de_all.multi.in
	$(SED) "s/LANG_REPLACE/$(1)/g" < aspell/de_all.multi.in > $$@

aspell/$(1).alias: aspell/de_all.alias.in
	$(SED) "s/LANG_REPLACE/$(1)/g" < aspell/de_all.alias.in > $$@

aspell/$(1).dat: aspell/de_all.dat.in
	$(SED) "s/LANG_REPLACE/$(1)/g" < aspell/de_all.dat.in > $$@

aspell/$(1).rws: myspell/$(1).dic aspell/$(1)_affix.dat aspell/$(1).multi aspell/$(1).dat aspell/$(1).alias
	# the warnings about skipped words should be ignorable...
	$(ASPELL) --lang=$(1) --dict-dir=./aspell/ --local-data-dir=./aspell/ create master $(1).rws < myspell/$(1).dic

aspell/$(1)-special.wl: $$(WORDS_$(1)) aspell/$(1).multi aspell/$(1).alias
	cat $$(WORDS_$(1)) \
		| (test -e ./bin/conv_dict_$(1) && ./bin/conv_dict_$(1) || cat) \
		| ./bin/myspell-generic-process.sh \
		| $(SED) -f ./bin/dic2iso \
		> $$@

myspell/$(1).dic: $$(WORDS_$(1)) $$(WORDS_de_all) dicts/abkuerzpunkt.txt
	./bin/test-working-grep.sh
	cat $$(WORDS_$(1)) $$(WORDS_de_all) dicts/abkuerzpunkt.txt \
		| (test -e ./bin/conv_dict_$(1) && ./bin/conv_dict_$(1) || cat) \
		| ./bin/myspell-generic-process.sh  > $$@.tmp
	$$(WCL) < $$@.tmp > $$@
	cat myspell/de_all.dic.header | $(SED) "s/AFF_VERSION_REPLACE/$(VERSION_STRING)/;s/LANG_REPLACE/$(1)/" >> $$@
	$(SED) -f ./bin/dic2iso < $$@.tmp >> $$@
	$(RM_OR_NOT) $$@.tmp

endef
$(foreach langcode,$(LANGS) liglist,$(eval $(call LANG_myspell_template,$(langcode))))

aspell/de-common-szlig.wl: $(WORDS_de_all)
	cat $(WORDS_de_all) | ./bin/myspell-generic-process.sh \
		| $(SED) -f ./bin/dic2iso \
		| sort -u > $@

aspell/szlig.wl: aspell/de-common-szlig.wl
	grep  $< > $@

aspell/ss.wl: aspell/szlig.wl
	$(SED) 's//ss/g' < $< > $@

aspell/de-common.wl: aspell/de-common-szlig.wl aspell/de.dat aspell/de_affix.dat aspell/de_phonet.dat
	grep -v  aspell/de-common-szlig.wl > $@

aspell/de_DE-only.wl: aspell/szlig.wl aspell/de_DE-special.wl
	sort -u $? > $@

aspell/de_AT-only.wl: aspell/szlig.wl aspell/de_AT-special.wl
	sort -u $? > $@

aspell/de_CH-only.wl: aspell/ss.wl aspell/de_CH-special.wl
	sort -u $? > $@

aspell/de.dat: aspell/de_all.dat.in
	$(SED) "s/LANG_REPLACE/de/g" < aspell/de_all.dat.in > $@

aspell/de_affix.dat: myspell/de_DE.aff
	$(CP) $< $@

aspell/de_phonet.dat: aspell/de_all_phonet.dat.in
	$(CP) $< $@

%.cwl: %.wl
	$(PREZIP) < $< > $@

define LANG_aff_template

myspell/$(1).aff: myspell/de_all.aff.in myspell/de_all.aff.header
	cat myspell/de_all.aff.header myspell/de_all.aff.in | $(SED) "s/AFF_VERSION_REPLACE/$(VERSION_STRING)/;s/LANG_REPLACE/$(1)/" > $$@

hunspell/$(1).aff: hunspell/de_all.aff.hunspell_additions myspell/de_all.aff.in hunspell/de_all.aff.header
	cat hunspell/de_all.aff.header myspell/de_all.aff.in hunspell/de_all.aff.hunspell_additions | $(SED) "s/AFF_VERSION_REPLACE/$(VERSION_STRING)/;s/LANG_REPLACE/$(1)/" > $$@

ispell/$(1)_null.aff: ispell/$(1).aff
	$(CP) ispell/$(1).aff $$@

endef
$(foreach langcode,$(LANGS) liglist,$(eval $(call LANG_aff_template,$(langcode))))


define LANGS2_hunspell_dicts_template

HUNSPELL_DICTS_BASE_$(1) = hunspell-capmain-small_$(1).tmp hunspell-compdic_$(1).tmp hunspell-end-compdic_$(1).tmp hunspell-middle-compdic_$(1).tmp hunspell-end-compdic_$(1).tmp

#HUNSPELL_DICTS_BASE_$(1) = hunspell-capmain-small_$(1).tmp hunspell-compdic_$(1).tmp hunspell-end-compdic_$(1).tmp hunspell-middle-compdic_$(1).tmp hunspell-end-compdic_$(1).tmp hunspell-capmain-small_de_all.tmp hunspell-compdic_de_all.tmp hunspell-end-compdic_de_all.tmp hunspell-middle-compdic_de_all.tmp hunspell-middle-compdic_de_all.tmp hunspell-end-compdic_de_all.tmp

hunspell-capmain-small_$(1).tmp: $$(WORDS_CAPMAIN_SMALL_$(1))
	# limited dictionary without any *-x* files used to sort out all known words from -xx files
	rm -f $$@.tmp
	echo $$(WORDS_CAPMAIN_SMALL_$(1)) | xargs cat >> $$@.tmp
	./bin/hunspell-capmain $$@.tmp > $$@
	$(RM_OR_NOT) $$@.tmp


hunspell-nocapmain_$(1).tmp: $$(WORDS_NOCAPMAIN_$(1)) $$(WORDS_NOCAPMAIN_de_all)
	# limited dictionary of all -x (but not -xx) files
	rm -f $$@.tmp
	#find dicts/ -name "*x*.txt" ! -name "*-xx*" -print | xargs cat >> $@.tmp
	echo $$(WORDS_NOCAPMAIN_$(1)) $$(WORDS_NOCAPMAIN_de_all) | xargs cat >> $$@.tmp
	###TODO??? ./bin/dic2iso < $$@.tmp > $$@
	mv $$@.tmp $$@

hunspell-middle-compdic_$(1).tmp: dicts/middle-compound.txt
	# more TODO here ?
	$(SED) "s:$$$$:/hkem:;s:/\(.*\)/:/\1:"	< dicts/middle-compound.txt	>  $$@

hunspell-end-compdic_$(1).tmp: dicts/end-compound.txt
	# more TODO here ?
	$(SED) "s:$$$$:/oz:;s:/\(.*\)/:/\1:"		< dicts/end-compound.txt	>  $$@

hunspell-compdic_$(1).tmp: $$(WORDS_COMP_$(1)) $$(WORDS_COMP_de_all)
	# sed hack to add "/"to lines which don't have one yet:
	# sed "/^[^\/]*$$/s/$$/\//"
	echo DEBUG: WORDS_COMP_$(1) :: $$(WORDS_COMP_$(1)) :::
	echo DEBUG: WORDS_COMP_de_all :: $$(WORDS_COMP_de_all) :::
	echo $$(WORDS_COMP_$(1)) $$(WORDS_COMP_de_all) | xargs $(SED) "/^[^\/]*$$$$/s/$$$$/\// ; s/$$$$/hij/"	>  $$@
	echo >> $$@
	#	more TODO here ? (added myspellfixprefix...)
	cat $$(WORDS_COMP_$(1)) $$(WORDS_COMP_de_all) \
		| ./bin/myspellfixprefix.pl \
		| ./bin/lcfirst.pl \
		| $(SED) "/^[^\/]*$$$$/s/$$$$/\//;s/$$$$/hke/"			>> $$@
	echo >> $$@

endef
$(foreach langcode,$(LANGS2),$(eval $(call LANGS2_hunspell_dicts_template,$(langcode))))

define LANG_hunspell_template

HUNSPELL_DICTS_ALL_$(1) = $$(HUNSPELL_DICTS_BASE_$(1)) hunspell-capmain-plus_$(1).tmp hunspell-nocapmain_$(1).tmp dicts/abkuerzpunkt.txt hunspell-blacklist_$(1).tmp \
	$$(HUNSPELL_DICTS_BASE_de_all)

hunspell-blacklist_$(1).tmp: $$(WORDS_BLACKLISTS_$(1)) $$(WORDS_BLACKLISTS_de_all)
	# sed hack to merge /f/g to /fg : sed "s:/\(.*\)/:/\1:"
	cat $$(WORDS_BLACKLISTS_$(1)) $$(WORDS_BLACKLISTS_de_all) >$$@

hunspell-capmain-plus_$(1).tmp: $(AFFIX_EXPAND_PREREQ) hunspell/$(1)_small.dic hunspell/$(1)_small.aff $$(WORDS_CAPMAIN_PLUS_$(1)) $$(WORDS_CAPMAIN_PLUS_de_all)
	echo DEBUG: WORDS_CAPMAIN_PLUS_$(1) :: $$(WORDS_CAPMAIN_PLUS_$(1)) :::
	echo DEBUG: WORDS_CAPMAIN_PLUS_de_all :: $$(WORDS_CAPMAIN_PLUS_de_all) :::
	# limited dictionary of *-xx* files containing compounds not generated by capmain-small
	rm -f $$@.unfiltered-list0.tmp
	#find dicts/ -name "*-xx*.txt" -print | xargs cat >> $$@.unfiltered-list.tmp
	echo $$(WORDS_CAPMAIN_PLUS_$(1)) $$(WORDS_CAPMAIN_PLUS_de_all) | xargs cat >> $$@.unfiltered-list0.tmp
	./bin/myspellfixprefix.pl < $$@.unfiltered-list0.tmp | (test -e ./bin/conv_dict_$(1) && ./bin/conv_dict_$(1) || cat) | grep -v '^$$$$' > $$@.unfiltered-list.tmp
	cat $$@.unfiltered-list.tmp | $(AFFIX_EXPAND_COMMAND) > $$@.unfiltered-list-expanded.tmp
	$(SED) -f ./bin/dic2iso < $$@.unfiltered-list-expanded.tmp |$(SED) "s/qq//g" | $(NL) | $(HUNSPELL) -d hunspell/$(1)_small -L > $$@.unknown.tmp
	$(SED) "s/^ *\([0-9]*\)\t.*$$$$/\1/" $$@.unknown.tmp > $$@.list-unknown-lines.tmp
	./bin/extractlines.pl $$@.list-unknown-lines.tmp $$@.unfiltered-list.tmp > $$@.tmp
	./bin/hunspell-capmain $$@.tmp | $(SED) -f ./bin/iso2dic > $$@
	$(RM_OR_NOT) $$@.unfiltered-list0.tmp $$@.unfiltered-list.tmp $$@.unfiltered-list-expanded.tmp $$@.unknown.tmp $$@.list-unknown-lines.tmp $$@.tmp


hunspell/$(1)_small.dic: $$(HUNSPELL_DICTS_BASE_$(1)) $$(HUNSPELL_DICTS_BASE_de_all) myspell/de_all.dic.header
	echo $$(HUNSPELL_DICTS_BASE_$(1))
	echo $$(HUNSPELL_DICTS_BASE_de_all)
	cat $$(HUNSPELL_DICTS_BASE_$(1)) $$(HUNSPELL_DICTS_BASE_de_all) \
		| (test -e ./bin/conv_dict_$(1) && ./bin/conv_dict_$(1) || cat) \
		| ./bin/hunspell-generic-process.sh \
		> $$@.tmp
	$$(WCL) < $$@.tmp > $$@
	cat myspell/de_all.dic.header | \
		$(SED) "s/AFF_VERSION_REPLACE/$(VERSION_STRING)/;s/LANG_REPLACE/$(1)/;s/Myspell/Hunspell/" >> $$@
	$(SED) -f ./bin/dic2iso < $$@.tmp >> $$@
	$(RM_OR_NOT) $$@.tmp

hunspell/$(1)_small.aff: hunspell/$(1).aff
	$(CP) hunspell/$(1).aff $$@

hunspell/$(1).dic: $$(HUNSPELL_DICTS_ALL_$(1)) $$(HUNSPELL_DICTS_ALL_de_all) myspell/de_all.dic.header
	./bin/test-working-grep.sh
	echo a $$(HUNSPELL_DICTS_ALL_$(1))
	echo b $$(HUNSPELL_DICTS_ALL_de_all)
	cat $$(HUNSPELL_DICTS_ALL_$(1)) $$(HUNSPELL_DICTS_ALL_de_all) \
		| (test -e ./bin/conv_dict_$(1) && ./bin/conv_dict_$(1) || cat) \
		| ./bin/hunspell-generic-process.sh	\
		| ./bin/hunspell-optimize-roothelper.pl	\
		> $$@.tmp
	$$(WCL) < $$@.tmp > $$@
	cat myspell/de_all.dic.header | $(SED) "s/AFF_VERSION_REPLACE/$$(VERSION_STRING)/;s/LANG_REPLACE/$(1)/;s/Myspell/Hunspell/" >> $$@
	$(SED) -f ./bin/dic2iso < $$@.tmp >> $$@
	$(RM_OR_NOT) $$@.tmp



endef
$(foreach langcode,$(LANGS),$(eval $(call LANG_hunspell_template,$(langcode))))

hunspell-all: hunspell/de_DE.aff hunspell/de_DE.dic hunspell/de_AT.aff hunspell/de_AT.dic hunspell/de_CH.aff hunspell/de_CH.dic

# -x dictionaries should not be compounded via capmain
# -xx dictionaries should be "cleaned up" before being compounded via capmain


myspell-zip: myspell/de_DE.aff myspell/de_DE.dic myspell/de_AT.aff myspell/de_AT.dic myspell/de_CH.aff myspell/de_CH.dic
	echo "$(VERSION_STRING)" > myspell/VERSION
	VERSION=`cat VERSION` ; cd myspell; \
	for lang in $(LANGS) ; do \
		rm -f $$lang-$$VERSION.zip ; \
		$(ZIP) $(ZIP_OPTS) $$lang-$$VERSION.zip -i@$$lang.zip.files ; \
	done

mozilla-xpi: hunspell-all mozilla/install.rdf.in
	export VER=$(VERSION) ; \
	rm -fr mozilla/*.tmp ; \
	for lang in DE AT CH ; do \
		mkdir mozilla/de-$$lang.tmp && mkdir mozilla/de-$$lang.tmp/dictionaries ; \
		$(SED) "s/ADDON_LANG_REPLACE/$$lang/g;s/ADDON_VERSION_REPLACE/$$VER/g" mozilla/install.rdf.in > mozilla/de-$$lang.tmp/install.rdf ; \
		$(CP) hunspell/de_$$lang.aff mozilla/de-$$lang.tmp/dictionaries/de-$$lang.aff ; \
		$(CP) hunspell/de_$$lang.dic mozilla/de-$$lang.tmp/dictionaries/de-$$lang.dic ; \
		rm -f mozilla/de-$$lang-$$VER.xpi ; \
		(cd mozilla/de-$$lang.tmp ; $(ZIP) $(ZIP_OPTS) ../de-$$lang-$$VER.xpi . ); \
	done

hunspell-zip: hunspell-all
	echo "$(VERSION_STRING)" > hunspell/VERSION
	VERSION=`cat VERSION` ; cd hunspell; \
	for lang in $(LANGS) ; do \
		rm -f $$lang-$$VERSION.zip ; \
		$(ZIP) $(ZIP_OPTS) $$lang-$$VERSION.zip -i@$$lang.zip.files ; \
	done

huntest: hunspell/hunspell-test.txt
	# huntest fails with "BREAK -" but that is needed for US-Wirtschaft etc.
	# so this is the lesser evil. No perfect solution found so far...
	cat hunspell/hunspell-test.txt |$(HUNSPELL) -L -d hunspell/de_DE > $@.tmp 2>&1
	@if `grep -q "^0 " $@.tmp`;then echo "Huntest NICHT bestanden:"; cat $@.tmp; exit 1;fi
	@if ! test "`$$(WCL) < $@.tmp`" = "`tail -n 1 $@.tmp | cut -f1 -d:`";then echo "Huntest NICHT bestanden (Zu viele als korrekt erkannte Wrter):"; cat $@.tmp; exit 1;fi


###
## ligature stuff:
###

define liglist_template

ispell/liglist.aff: ispell/de_DE.aff.in
	$(SED) '/\#qqq/s/^\#//g;/\#nnn/d' ispell/de_DE.aff.in > $$@

ispell/liglist_null.hash: ispell/liglist_null.aff
	test -e all.words.placebo.tmp || echo a > all.words.placebo.tmp
	$(BUILDHASH) all.words.placebo.tmp ispell/$(1)_null.aff $$@

all.words.liglist.tmp: $(foreach langcode,$(LANGS2),$(WORDS_$(langcode)))
	$(SED) "s/\.//" $(foreach langcode,$(LANGS2),$(WORDS_$(langcode))) | \
	grep -v "\/.*d" | grep -v "##" | $(SED) "s/#.*//" | \
	$(SORT) -u > $$@


liglist.tmp: $(AFFIX_EXPAND_PREREQ) all.words.liglist.tmp
	cat ligature/oldspell.liglist all.words.liglist.tmp \
	| $(AFFIX_EXPAND_COMMAND)			\
	| tr \  '\n'					\
	| grep qq					\
	| $(SORT) -u					\
	| $(SED) 's/fqqf/f\|f/g;s/fqql/f\|l/g;s/fqqi/f\|i/g'	\
	| grep \|					\
	| $(SED) s/qq//g				\
	| $(SED) -f ./bin/dic2iso			\
	| tr A-Z a-z					\
	| $(SORT) -u					\
	> $$@

ligature/rmligs: liglist.tmp ligature/rmligs.skel
	cat ligature/rmligs.skel liglist.tmp > $$@
	chmod 755 $$@

endef
$(eval $(call liglist_template,liglist))




###
## misc stuff:
###

clean:
	rm -f all.words* igerman98*.tar.bz2 isowordlist*
	#sort liglist.aff  MD5sums myspell/*.dic de_DE.zip de_CH.zip myspell/VERSION *.tmp
	rm -f ispell/*.aff ispell/*.hash
	rm -f myspell/*.dic  myspell/*.aff  myspell/*.zip myspell/VERSION
	rm -f hunspell/*.dic hunspell/*.aff hunspell/*.zip hunspell/VERSION
	rm -f ligature/liglist.* ligature/rmligs
	rm -f mozilla/*.xpi
	$(FIND) aspell/ -type f ! -name "*.in" -print |xargs rm -fr
	$(FIND) . -name "*tmp*" -print |xargs rm -fr

sort:
	@if grep [] dicts/*.txt ;then echo "!!! illegal ISO-8859-1 characters in dictionary files !!!";exit 1;fi
	@if LC_ALL=de_DE.UTF-8 grep [`echo -n ""|iconv -f iso8859-1 -t utf-8`] dicts/*.txt ;then echo "!!! illegal UTF-8 characters in dictionary files !!!";exit 1;fi
	@if grep -q -v "/.*d" dicts/blacklist* ; then echo "missing d in blacklist?" ; exit 1 ; fi
	$(FIND) ./dicts/ -name "*.txt" -print -o -name "blacklist*" -print | while read i; do $(SORT) -u -o "$$i" "$$i"; done

pack: sort
	exit 1
	rm -f unpack
	cd dicts; $(FIND) . -name "*.txt" -print |while read i; do test -e $$i.sq && exit 1; $(SQ) < $$i > $$i.sq && rm $$i; done

unpack:
	exit 1
	cd dicts; $(FIND) . -name "*.sq" -print | while read i; do test -e `basename $$i .sq` && exit 1; $(UNSQ) < $$i > `basename $$i .sq` && rm $$i; done
	touch unpack

dist: sort clean
	echo $(DATE) > VERSION
	$(FIND) . -xtype f ! -name ".*" -a ! -name grep -print | xargs sha256sum | gpg --clearsign > .SHA256sums
	mv .SHA256sums SHA256sums
	ls > .files
	echo igerman98-`cat VERSION` > .name
	mkdir `cat .name`
	mv `cat .files` `cat .name`
	$(TAR) cvf - --exclude "grep" * | bzip2 -9 > `cat .name`.tar.bz2
	mv `cat .name`/* .
	rmdir `cat .name`





###########################
### TEST TRASH follows: ###
###########################

help_test:
	grep "^[[:alpha:]\-]*:"  Makefile | cut -d " " -f 1

test0:
	export BLA=FOO

LIST_FOO = eins zwei drei

eins:

#zwei: $($(WORTE_NEU))
# $(addprefix dicts/,$(WORTE))
zwei: $(WORDS_GENERIC)
	echo $(WORDS_GENERIC)
	touch zwei

drei:
	echo $(WORDS_NOCAPMAIN)
	$(RM_OR_NOT) bla

test1: test0 $(LIST_FOO) testdir/de_DE.dic
	echo $$BLA
	echo $(LIST_FOO)

#FOO_de_DE FOO_de_AT FOO_de_CH FOO_de_all: WORDS_$(subst FOO_,,$@)
#FOO_de_DE FOO_de_AT FOO_de_CH FOO_de_all : MYLANG=$(subst FOO_,,$@)
#FOO_de_DE FOO_de_AT FOO_de_CH FOO_de_all : MYLANG=$(shell echo $@ |sed s/.*_\(de_.*\)/\1/)
#FOO_de_DE FOO_de_AT FOO_de_CH FOO_de_all : MYLANG=$(shell echo $@|sed "s/^.*_\(de_.*$$\)/\1/")
#FOO_de_DE FOO_de_AT FOO_de_CH FOO_de_all: $(FOO_%: WORDS_%)
FOO_de_DE FOO_de_AT FOO_de_CH FOO_de_all: $(WORDS_$(MYLANG)) $(HUNSPELL_DICTS_BASE_$(MYLANG))
	#set MYLANG=$(subst FOO_,,$@)
	echo target: $@
	echo MYLANG: $(MYLANG)
	#echo $(WORDS_$(subst FOO_,,$@))
	echo $(WORDS_$(MYLANG))
	echo $<

WORDS_de_aa = $(WORDS_shell)
WORDS_de_bb = $(WORDS_shell)

SUB_de_aa SUB_de_bb: $(WORDS_$(MYLANG))
	@echo SUB says WORDS is: $(MYLANG)
	@echo SUB says lang is: $(lang)

define MYDEF
$(1): lang_def=hallo
endef

test2_de_aa test2_de_bb: lang=$(MYLANG)
#test2_de_aa: SUB_
#test2_de_aa test2_de_bb: $$(SUB_$(MYLANG))
test2_de_aa test2_de_bb: $(eval $(call MYDEF,$(@)))
	#$(subst LANG,$(lang),SUB_LANG)
	@echo MYLANG: $(MYLANG)
	@echo lang: $(lang)
	@echo lang_def: $(lang_def)
	@echo I think WORDS is: $(WORDS_$(MYLANG))

TESTLANGS=de_aa de_bb de_DE

define LANG_testtemplate
$(1): $$($(1)_OBJS) $$($(1)_LIBS:%=-l%)
	echo aa
test3_$(1): SUB_$(1)
	@echo MYLANG: $(MYLANG)
	@echo I think WORDS is: $(WORDS_$(MYLANG))
	@echo I think I am $$@

ALL_OBJS   += $$($(1)_OBJS)
endef

$(foreach langcode,$(TESTLANGS),$(eval $(call LANG_testtemplate,$(langcode))))