File: Makefile

package info (click to toggle)
norwegian 2.2-4
  • links: PTS
  • area: main
  • in suites: bookworm, bullseye, buster, forky, sid, trixie
  • size: 26,448 kB
  • sloc: perl: 2,695; makefile: 1,678; sh: 209
file content (1212 lines) | stat: -rwxr-xr-x 44,260 bytes parent folder | download | duplicates (2)
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
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
# Makefile for the Norwegian dictionary for Ispell v. 2.0
# Copyright (C) 2000, Rune Kleveland, 2005-2006 the spell-norwegian
# maintainers
#
# Maintainer: The spell-norwegian maintainer group
# Email : i18n-no@lister.ping.uio.no
# License : GNU General Public License v2 or later

VERSION         = 2.2
PACKAGE         = spell-norwegian

prefix          = /usr
libdir          = $(prefix)/lib
sharedir        = $(prefix)/share
bindir          = $(prefix)/bin
docdir          = $(sharedir)/doc/$(PACKAGE)
wordsdir        = $(sharedir)/dict
ispelldir       = $(libdir)/ispell
myspelldir      = $(sharedir)/myspell/dicts
hyphendir       = $(myspelldir)
thesdir         = $(myspelldir)
aspelldir       = $(libdir)/aspell

# Make sure we work with a known locale setting.
export LC_ALL=C

SHELL = /bin/sh
MAKE = make
INSTALL      = install -m 755
INSTALL_DATA = install -m 644

PATHADDER	=	../..
BUILDHASH	=	buildhash
ASPELL          =       aspell
ISPELL          =       ispell
ISPELLAFF2MYSPELL =     ispellaff2myspell
MUNCHLIST       =       munchlist
AWK		=	awk
SED		=	sed
PERL            =       perl
GREP            =       grep -a
EGREP           =       egrep

# List of characters used in the thesaurus files
theschars = abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-()\#

ECHO            =       echo

export PATH:=$(PATHADDER):$(PATH)

DOC = \
	COPYING \
	NEWS \
	README \
	README.myspell \
	thesaurus-README.txt

# Files to include in tarball
EXTRA_DIST = \
	$(DOC) \
	ispell-3.1.20.no.patch \
	ispell-3.2.06.no.patch \
	aspell-nb.info.in \
	aspell-nn.info.in \
	aspell-proc.pl \
	aspell-phonet.dat \
	bokmaal \
	forkort-nb.txt \
	forkort-nn.txt \
	inorsk-compwordsmaybe \
	inorsk-hyphenmaybe \
	Makefile \
	Makefile.new \
	nohyphbc.tex \
	nohyphb.tex \
	nb.aff.in \
	nn.aff.in \
	norsk.cfg \
	norsk.words \
	missing.nb \
	rejected-words.nb \
	missing.nn \
	words_clean.nynorsk \
	thesaurus-nb.txt \
	thesaurus-nn.txt \
	nb_NO.myheader \
	nn_NO.myheader \
	iaff2myaff.pl


# Directories to include in tarball
SUBDIRS = \
	missing \
	scripts \
	patterns \
	ooo-hyph

srcdir      := .
distdir     := $(PACKAGE)-$(VERSION)
top_distdir := $(distdir)
DISTFILES    = $(EXTRA_DIST)
TAR          = tar
GZIP_ENV     = --best

# The following variables make it easy to adapt this Makefile to
# numerous languages.
#
LANGUAGE	=	norsk

#
#	Set this to "-vx" in the make command line if you need to
#	debug the complex shell commands.
#
SHELLDEBUG = +vx

# Some technical variables for managing hyphen points and the header

# CATNOHEADER=$(SED) -e '/^\#/ D' -e 's/[	]*\#.*//' ${LANGUAGE}.words
CATNOHEADER=$(GREP) -v '^\#' ${LANGUAGE}.words
ALPHASUBST=tr '=' ''
ALPHASUBSTSED=s/=//g
STREKSUBST=tr '' '='
STREKSUBSTSED=s//=/g
STREKREM=tr -d ''
STREKREMSED=s/[]//g

# What characters and flags do we use for Norwegian?

# Not including dash (-) in LCH and UCH, as - has special meaning in
# regex and need to be listed first and only one.  Adding it to CH
# instead.

LCH=\"a-z
UCH=A-Z
CH=-${LCH}${UCH}
PRE=a-s
SUFFNORM=][t-zA-Z^
SUFFCOMP=\\\\\\\`_
SUFF=${SUFFNORM}${SUFFCOMP}
#SUFF=][t-zA-Z\\\\\\\`^_


# The awk scripts below tells which words from in each category that
# should be in the dictionary.  The line

# /^[${LCH}=]{4}\[${SUFF}]/   {if ($$2>4) {print $$1,$$2}}

# says that words with length 4 containing only lowercase letters with
# frequency greater then 5 should be included.  Edit the scripts as
# you like, but please don't make syntactic errors.  Awk forgives
# nothing.  Remember that it is more likely that a mistyping turns out
# to be a legal word if the word is short.  `re' is legal!

# The CHOOSEFLAG script sets the limit for flag inclusion.  Example:
# adgangs-tegn is a common word, but the form adgangstegnenes scores 0
# on frequency.  It will be excluded by the script below if you don't
# change it.

# The CHOOSEROOT script selects the root words to be included after
# the uncommonly used flags have been deleted.  The key used is the
# frequency category of of the union of all words this root and its
# flags generates.

# The reason for the two pass system is that the space required by a
# root word is much bigger than what is required by just a flag.

# You are of course free to change the selection system.

# The B file contains all kinds of words.


CATHEGORIES=B A N M K D O C

# Configuration for the words file.

# The words file is a plain text file containing words in alphabetical
# order.  It is used by ispell via the look/grep programs to display
# words starting with a specific string or matching a specific
# pattern.  It is also useful if one want to make a dictionary for
# some stupid spell-checker in a word processor.

# Lets make this simple.

WORDSFILTER='{if ($$2>=0) {print $$1}}'

# Configuration for building ispell dictionaries.

# The frequency category works best for B, A and N categories.

# Very young people and people which don't speak Norwegian natively
# will probably be much more happy with a smaller dictionary than the
# complete one.  A smaller dictionary should also be considered if the
# machine is low on memory.  Below is a quite advanced system for
# building such dictionaries.

# It is possible to remove all words that is accepted by ispell in
# controlled compoundwords mode with frequency indicator less than
# COMPOUNDLIMIT.  Thus if `naturvern' and `direktorat' are words which
# is marked as allowed in compounds, it might not be nessesary to
# include `naturverndirektorat' in the dictionary.

# However, if one misspells `naturverndirektorat', ispell will not be
# able to make a suggestion for this word.  And one must use the
# controlled compoundwords mode to accept this word, and that is not
# as secure as the -B mode.

# In sum; It is nice if ispell can make a suggestion words like
# `angrefrisperiode', but it consumes space and memory.

COMPOUNDLIMIT=0

# There is a system for selecting words to include in the Ispell
# dictionary.  Unfortunately it is rather complex and not too easy to
# use, but this was what I came up with, so you must use it or invent
# your own.  The good thing is that one can select both flags and
# roots, depending on how the root word looks line and the frequency
# og all forms coming from the flag or the root.

# Somewhere in the long pipe making the input file for buildhash, the
# data looks like
#
# gutte=drm/ 17
# gutte=drm/A 18
# gutte=drm/E 14
# gutte=drm/G 7
#
# thus the frequenzy indicator for each flag is availiable.  Awk is
# used to pick the flags we want, and the variable holding the program
# is CHOOSEFLAG[CATHEGORY]. Don't throw away the root, since that
# messes things up badly.
#
# Later in the pipe the data looks like
#
# gutte=drm/17A18E14G7 19
#
# The second field (19) is the frequenzy indicator for all words
# coming from the root gutt.  So here we can throw away a root with
# all its derivied forms if we like.

DEFAULTROOTFILTER='{print $$1,$$2}' # This selects all words in a file

# Don't include all rare words allowed in compounds.

define DEFAULTFLAGFILTER
'!/[${SUFFCOMP}]/      {print $$1,$$2} \
/\/[${SUFFCOMP}]/      {if ($$2>6) {print $$1,$$2}}'
endef

# Select all words by default.  Then override with more elaborate
# rules if desired.

CHOOSEFLAGA=${DEFAULTFLAGFILTER} # `newspaper' words, but very useful.
CHOOSEFLAGB=${DEFAULTFLAGFILTER} # Normal words
CHOOSEFLAGC=${DEFAULTFLAGFILTER} # Sammendragning
CHOOSEFLAGD=${DEFAULTFLAGFILTER} # Words from Dagbladet
CHOOSEFLAGK=${DEFAULTFLAGFILTER} # Conservative writing
CHOOSEFLAGM=${DEFAULTFLAGFILTER} # Words from mathematics
CHOOSEFLAGN=${DEFAULTFLAGFILTER} # Words from NOU
CHOOSEFLAGO=${DEFAULTFLAGFILTER} # Words from technical oil business
CHOOSEFLAGS=${DEFAULTFLAGFILTER} # Samnorsk, radical forms

CHOOSEROOTA=${DEFAULTROOTFILTER} # `newspaper' words, but very useful.
CHOOSEROOTB=${DEFAULTROOTFILTER} # Normal words
CHOOSEROOTC=${DEFAULTROOTFILTER} # Sammendragning
CHOOSEROOTD=${DEFAULTROOTFILTER} # Words from Dagbladet
CHOOSEROOTK=${DEFAULTROOTFILTER} # Conservative writing
CHOOSEROOTM=${DEFAULTROOTFILTER} # Words from mathematics
CHOOSEROOTN=${DEFAULTROOTFILTER} # Words from NOU
CHOOSEROOTO=${DEFAULTROOTFILTER} # Words from technical oil business
CHOOSEROOTS=${DEFAULTROOTFILTER} # Samnorsk, radical forms

# Here is an example of an awk script that excludes some short
# uncommon words, and some long very uncommon words.  It is most
# likely that you want to exclude short uncommon words, since those
# are most likely to be typed by mistake.  Exclude long words to save
# memory.  Also see the COMPOUNDLIMIT variable above if you want to
# make a resource-friendly dictionary.

# define CHOOSEFLAGB
# '/\/[ ${PRE}]/                                  {print $$1,$$2}  \
# /^[${LCH}=]{1,2}\/[${SUFF}]/        {if ($$2>6) {print $$1,$$2}} \
# /^[${LCH}=]{3}\/[${SUFF}]/          {if ($$2>5) {print $$1,$$2}} \
# /^[${LCH}=]{4}\/[${SUFF}]/          {if ($$2>3) {print $$1,$$2}} \
# /^[${LCH}=]{5,7}\/[${SUFF}]/        {if ($$2>1) {print $$1,$$2}} \
# /^[${LCH}=]{8,}\/[${SUFF}]/         {if ($$2>=0) {print $$1,$$2}} \
# /^[${UCH}][${CH}=]{1,2}\/[${SUFF}]/ {if ($$2>4) {print $$1,$$2}} \
# /^[${UCH}][${CH}=]{3}\/[${SUFF}]/   {if ($$2>3) {print $$1,$$2}} \
# /^[${UCH}][${CH}=]{4}\/[${SUFF}]/   {if ($$2>2) {print $$1,$$2}} \
# /^[${UCH}][${CH}=]{5,7}\/[${SUFF}]/ {if ($$2>1) {print $$1,$$2}} \
# /^[${UCH}][${CH}=]{8,}\/[${SUFF}]/  {if ($$2>=0) {print $$1,$$2}}'
# endef

# define CHOOSEROOTB
# '/^[${LCH}=]{1,2}\//       {if ($$2>8) {print $$1,$$2}} \
# /^[${LCH}=]{3}\//          {if ($$2>6) {print $$1,$$2}} \
# /^[${LCH}=]{4}\//          {if ($$2>5) {print $$1,$$2}} \
# /^[${LCH}=]{5,7}\//        {if ($$2>2) {print $$1,$$2}} \
# /^[${LCH}=]{8,}\//         {if ($$2>1) {print $$1,$$2}} \
# /^[${UCH}][${CH}=]{1,2}\// {if ($$2>8) {print $$1,$$2}} \
# /^[${UCH}][${CH}=]{3}\//   {if ($$2>6) {print $$1,$$2}} \
# /^[${UCH}][${CH}=]{4}\//   {if ($$2>3) {print $$1,$$2}} \
# /^[${UCH}][${CH}=]{5,7}\// {if ($$2>2) {print $$1,$$2}} \
# /^[${UCH}][${CH}=]{8,}\//  {if ($$2>1) {print $$1,$$2}}'
# endef

# Try to make it easier to change the OOo2 build variables
# and to make them consistent
TH_NB1 = th_nb_NO
TH_NN1 = th_nn_NO
TH_NB2 = th_nb_NO_v2
TH_NN2 = th_nn_NO_v2
TH_NB1_DICT = 'THES nb NO' $(TH_NB1)
TH_NN1_DICT = 'THES nn NO' $(TH_NN1)
TH_NB2_DICT = 'THES nb NO' $(TH_NB2)
TH_NN2_DICT = 'THES nn NO' $(TH_NN2)



all: words ispell myspell aspell
ispell: nb.hash nn.hash nb.aff nn.aff
words: words.nb words.nn

install: install-ispell install-words install-aspell install-myspell install-scripts install-doc

install-doc: $(DOC)
	$(INSTALL) -d $(DESTDIR)$(docdir)
	for d in $(DOC) ; do \
		$(INSTALL_DATA) $$d $(DESTDIR)$(docdir)/$$d ; \
	done

install-ispell: install-ispell-nb install-ispell-nn
install-ispell-nb: nb.hash nb.aff
	$(INSTALL) -d $(DESTDIR)$(ispelldir)
	$(INSTALL_DATA) nb.hash $(DESTDIR)$(ispelldir)/nb.hash
	$(INSTALL_DATA) nb.aff $(DESTDIR)$(ispelldir)/nb.aff
	if true ; then \
	    ln -sf $(ispelldir)/nb.hash $(DESTDIR)$(ispelldir)/bokmaal.hash ; \
	    ln -sf $(ispelldir)/nb.aff $(DESTDIR)$(ispelldir)/bokmaal.aff ; \
	fi
	if true ; then \
	    ln -sf $(ispelldir)/nb.hash $(DESTDIR)$(ispelldir)/norsk.hash ; \
	    ln -sf $(ispelldir)/nb.aff $(DESTDIR)$(ispelldir)/norsk.aff ; \
	fi

install-ispell-nn: nn.hash nn.aff
	$(INSTALL) -d $(DESTDIR)$(ispelldir)
	$(INSTALL_DATA) nn.hash $(DESTDIR)$(ispelldir)/nn.hash
	$(INSTALL_DATA) nn.aff $(DESTDIR)$(ispelldir)/nn.aff
	if true ; then \
	    ln -sf $(ispelldir)/nn.hash $(DESTDIR)$(ispelldir)/nynorsk.hash ; \
	    ln -sf $(ispelldir)/nn.aff $(DESTDIR)$(ispelldir)/nynorsk.aff ; \
	fi

install-words: install-words-nb install-words-nn
install-words-nb: words.nb
	$(INSTALL) -d $(DESTDIR)$(wordsdir)
	$(INSTALL_DATA) words.nb $(DESTDIR)$(wordsdir)/bokmaal
	ln -sf bokmaal $(DESTDIR)$(wordsdir)/bokml
install-words-nn: words.nn
	$(INSTALL) -d $(DESTDIR)$(wordsdir)
	$(INSTALL_DATA) words.nn $(DESTDIR)$(wordsdir)/nynorsk

install-scripts:  inorsk-compwordsmaybe inorsk-hyphenmaybe
	$(INSTALL) -d $(DESTDIR)$(bindir)
	$(INSTALL) inorsk-compwordsmaybe inorsk-hyphenmaybe $(DESTDIR)$(bindir)

nb.hash nn.hash: %.hash: %.mch %.aff
	rm -f $@
	${BUILDHASH} $< $(subst .hash,.aff,$@) $@

nb.aff nn.aff: %.aff: %.aff.in
	$(SED) -e 's/stringchar * *//' -e '$(STREKREMSED)' $< > $@.new && \
	  mv $@.new $@

nb.aff.munch nn.aff.munch: %.aff.munch: %.aff.in
	( \
	  $(SED) -e 's/\(.*> *[-,${UCH}]*\)    \( *#~.*$$\)/\1XXXX\2 *HACK*/' \
	    -e 's/-ZYZYZY,-\( *#-.*$$\)/-ZYZYZY,ZYZYZY\1/' \
	    -e 's/\(^flag  *\)~\(..\?:\)/\1\2/'  \
	    -e 's/^\(compoundwords\) controlled z/\1 off/' $< ; \
	  $(ECHO) ; \
	  $(ECHO) ; \
	  $(ECHO) 'flag z: # Brukes for  bevare z-flagg gjennom munchlist' ;\
	  $(ECHO) '    .              >       YYYY            # *HACK*' \
	) > $@.new && mv $@.new $@

nb.munch.hash nn.munch.hash: %.munch.hash: %.aff.munch
	echo 'QQQQQQQQ' > FAKEDICT
	${BUILDHASH} -s FAKEDICT $< $@
	rm -f FAKEDICT FAKEDICT.cnt FAKEDICT.stat

nb.aff.null nn.aff.null: %.aff.null: %.aff.in
	$(SED) -e '/^prefixes.*/,//d' $< > $@.new
	$(ECHO) 'suffixes' >> $@
	$(ECHO) 'flag *z:' >> $@
	$(ECHO) 'Y Y Y Y Y   >   YYYYYY' >> $@.new
	mv $@.new $@

# The following ugly code munches a part of the base file, keeping the
# indications of the frequency of the words.  It also removes some
# redundant flags that munchlist does not find.  That part could be
# improved.


munched.%: ${LANGUAGE}.words nb.aff.munch nb.munch.hash
# The first pipe produces a list of all words in the % category, with
# each root word followed by one line for each flag containing the
# root word and the flag.  The prefix flags are treated as part of the
# root word, except that there is one line containing just the root
# word (the last bug I catched...) The hyphen character is ignored
# when the list is sorted.  Some redundant flags are also removed.
# Isn't it amazing how much you can do with sed?

# If we try to munch the whole B dictionary in one run, ispell will
# probably dump core.  This happens when one gets `hash overflows'.
# Check the log, and change the splitting (^[${UCH}]) if nessesary.
# Nasty bug, and very silent.
	${CATNOHEADER} \
	  | $(GREP) -e '$(subst munched.,,$@)$$' \
	  | $(SED) -e 's/ .*//' -e '$(ALPHASUBSTSED)' -e 's/ \*//' \
	  | $(GREP) '^[${UCH}]' \
	  | $(MUNCHLIST) -v -l nb.aff.munch \
	  > munch1.tmp
	${CATNOHEADER} \
	  | $(GREP) -e '$(subst munched.,,$@)$$' \
	  | $(SED) -e 's/ .*//' -e '$(ALPHASUBSTSED)' -e 's/ \*//' \
	  | $(GREP) -v '^[${UCH}]' \
	  | $(MUNCHLIST) -v -l nb.aff.munch \
	  >> munch1.tmp
	cat munch1.tmp \
	  | $(SED) -e 's/\(zyzyzy\|ZYZYZY\)/\1\/\` /' \
	  | $(SED) -e 's/^\(.*\)$$/----\1\*\1/' \
	  | tr '*' '\n' \
	  | $(SED) -e '/----/ $(STREKREMSED)' \
	  | $(SED) -e N -e 's/\n/ ----/' \
	  | sort  '-t/' -u +0f -1 +0 \
	  | $(SED) -e 's/.*----//' \
	  | $(SED) -e 's/\(et\/.*T.*\)V/\1/' \
		-e 's/\(e\/.*T.*\)W/\1/' \
		-e 's/\(er\/.*I.*\)V/\1/' \
		-e 's/\(e\/.*B.*\)W/\1/' \
		-e 's/\([^ei]um\/.*B.*\)I/\1/' \
	  | $(SED) -e N -e 's/^\(\([${CH}=]\)*\([^e][^r]\|[e][^r]\|[r][^e]\)\)\/\([A-Zt-z]*\)\n\1e\/\([A-Zt-z]*\)R\([A-Zt-z]*\)$$/\1\/\4\*\1e\/\5\6/g' \
		 -e '$$ p' -e '$$ d' -e P -e D \
	  | tr '*' '\n' \
	  | $(SED) -e N -e 's/^\(\([${CH}=]\)*\)\(\/[AB]*\)E\(.*\)\n\1er\/AI/\1\3\4\*\1er\/AI/' \
		-e '$$ p' -e '$$ d' -e P -e D \
	  | tr '*' '\n' \
	  | $(SED) -e '$(STREKSUBSTSED)' \
		-e 's/\/\([${SUFF}]*\)\([${PRE}]*\)/\/\2\1/' \
		-e 's/\(\([${CH}=]\)*\)\/\([${PRE}]*\)\([${SUFF}]\+\)$$/\1\/\3\*\1\/\3\4/' \
		-e 's/^\([${CH}=]*\)$$/\1\/ /' \
	  | tr '*' '\n' \
	  | $(SED) -e ':START' \
		-e 's/^\([${CH}=]\+\)\/\([${PRE}]*\)\([${SUFF}]\+\)\([${SUFF}]\)/\1\/\2\3\*\1\/\2\4/' \
		-e 't START' \
		-e 's/^\([${CH}=]\+\)\/\([${PRE}]\+\)\(\*\|$$\)/\1\/\*\1\/\2\3/'\
	  |  tr '*' '\n' > munch2.tmp
# This pipe produce a file containing the a line number of munch2.tmp and
# the frequency indicator for that line.  Note that the summation rule
# is not the usual one.
	cat munch2.tmp \
	  | tr -d ' ' \
	  | $(ISPELL) -e -d ./nb.munch.hash \
	  | $(SED) -e 's/^[${CH}=]\+ //' -e '$(STREKSUBSTSED)' \
	  | $(AWK) --source '{i=0; while (i<NF) {i=i+1;print $$i,NR}}' \
	  | sort \
	  | join - ${LANGUAGE}.words \
	  | $(SED) -e 's/\* //' \
	  | cut -d ' ' -f2,3 \
	  | sort -n \
	  | $(SED) -e '$$ p' -e '$$ D' -e ':START' -e '$$ ! N' \
		-e 's/^\([0-9]\+\)\([0-9 ]\+\)\n\1\( [0-9]\+\)$$/\1\2\3/' \
		-e 't START' -e P -e D \
	  | $(AWK) --source '\
		{i = 1;\
		s = 0;\
		{while (i<NF)\
		{i=i+1;\
		if ($$i<5) {s=s+$$i} else {s = s + exp(exp(($$i+9)/15)-1)}}};\
		if (s<=5) {t=s} else {t=-9+15*log(1+log(s))};\
		print $$1, int(t)}' \
	  > munch3.tmp
# This pipe produce the file containing the munched list of words,
# where the rare words we don't want are removed.  What we don't want
# depends on the category of words, and is defined at the start of
# this Makefile.
	cat -n munch2.tmp \
	  | join - munch3.tmp \
	  | cut -d ' ' -f2,3 \
	  | $(AWK) --re-interval --source ${$(subst munched.,CHOOSEFLAG,$@)} \
	  | uniq \
	  | tr -d ' ' \
	  | $(SED) -e '$$ p' -e '$$ D' -e ':START' -e '$$ ! N' \
		-e 's/^\(\([${CH}=]\)\+\)\/\([0-9]*\)\n\1\/\([${SUFF}${PRE}0-9]*\)$$/\1\/\3\4/' \
		-e 's/^\(\([${CH}=]\)\+\/\)\([0-9]*\)\([${PRE}]*\)\([${SUFF}0-9]*\)\n\1\4\([${SUFF}0-9]\+\)$$/\1\3\4\5\6/' \
		-e 't START' -e P -e D \
	  | $(SED) -e 's/\/\([${SUFF}0-9${PRE}]*\)/\/\1\* \1/' \
	  | tr '*' '\n' \
	  | $(SED) -e '/ .*/ s/[^0-9 ]\+/ /g' \
	  | $(SED) -e N -e 's/\n//' \
	  | $(AWK) --source '\
		{i = 1;\
		s = 0;\
		{while (i<NF)\
		{i++;\
		if ($$i<5) {s=s+$$i} else {s = s + exp(exp(($$i+9)/15)-1)}}};\
		if (s<=5) {t=s} else {t=-9+15*log(1+log(s))};\
		print $$1, int(t)}' \
	  | $(AWK) --re-interval --source ${$(subst munched.,CHOOSEROOT,$@)} \
	  | uniq \
	  > $@
#	Comment out the next line if you are debugging.
	rm munch[123].tmp


nb.mch: forkort-nb.txt $(patsubst %,munched.%,${CATHEGORIES}) nb.aff
# Here we make the dictionary that is read by the ispell's buildhash
# program.  The main difficulty is to delete compound words with
# frequency indicator less than COMPOUNDLIMIT accepted in controlled
# compoundwords mode.

# First make a list of words with some compound flag, and a hash-file.
	cat forkort-nb.txt $(patsubst %,munched.%,${CATHEGORIES}) \
	  | tr -d '\=0-9 ' \
	  | $(GREP) "\/.*[z\\_\`]" \
	  > comp1.tmp
	$(BUILDHASH) comp1.tmp nb.aff comp.hash


# Make a list of candidates to be removed.  Exclude all words with
# compound flags and those with frequency indicator bigger than
# COMPOUNDLIMIT.  This could be improved.  One could insist that the
# words forming a word that should be deleted are separated by a
# hyphen at the correct point.  That would complicate things.

	cat -n forkort-nb.txt $(patsubst %,munched.%,${CATHEGORIES}) \
	  | $(GREP) -v "\/.*[z\\_\`]" \
	  | $(AWK) --source '/=/ {if ($$3<${COMPOUNDLIMIT}) {print $$1,$$2,$$3}}' \
	  > comp2.tmp
# Test which words are accepted by ispell.  Output is a list of line
# numbers indicating the lines that can be removed from the munched
# file.
	cat comp2.tmp \
	  | tr -d '\=0-9 ' \
	  | $(ISPELL) -e -d ./comp.hash \
	  | $(SED) -e 's/$$/ xyxyxyxy/' \
	  | $(ISPELL) -l -d ./comp.hash \
	  | $(SED) -e 's/xyxyxyxy//' \
	  | tr '\n' ' \n' \
	  | paste comp2.tmp - \
	  | $(GREP) '	 $$' \
	  | $(SED) -e 's/ .*//' \
	  > comp3.tmp
	@echo Removing `cat comp3.tmp | wc -l` compound root words
# Remove all the line numbers that is found twice, and all words
# containing xxxx and yyyy.  Those words didn't fit in in the munching,
# and since it is few words I don't want to fiddle with them.
	cat -n forkort-nb.txt $(patsubst %,munched.%,${CATHEGORIES}) \
	  | sort -n -m -s +0 -1  comp3.tmp - \
	  | $(SED) -e '/^[0-9]\+$$/,/.*/ D' -e '/\(xxxx\|yyyy\)\// D' \
	  | tr -d '\= 	0-9' \
	  | LC_COLLATE=C sort > $@
	rm -f comp.hash comp[123].tmp*

# TODO:
# If a rare word lies close to a common word, it might be wise to
# remove it from the dictionary.  One possible way is to use a patched
# version of ispell that tries to find matches for all words, also
# those in the dictionary.  Then find the frequency for those words,
# and produce a closeness index from this.  This shouldn't be too hard
# to implement.  The patch for the required ispell flag (-s) is only
# a few lines.  The trickery to use it is more.




nn.mch: ${LANGUAGE}.words nn.aff.munch forkort-nn.txt
	${CATNOHEADER} \
	  | $(GREP) '\*' \
	  | $(SED) -e 's/ .*//' \
	  | tr -d '=' \
	  | $(GREP) '^[${UCH}]' \
	  | $(MUNCHLIST) -v -l nn.aff.munch \
	  > munch1.tmp
	${CATNOHEADER} \
	  | $(GREP) '\*' \
	  | $(SED) -e 's/ .*//' \
	  | tr -d '=' \
	  | $(GREP) -v '^[${UCH}]' \
	  | $(MUNCHLIST) -v -l nn.aff.munch \
	  >> munch1.tmp
	cat forkort-nn.txt munch1.tmp \
	  | $(SED) -e N -e 's/^\(\([${CH}=]\)*\)er\/\(.*F.*\)\n\1rar\/M$$/\1er\/\3D/' \
		-e '$$ p' -e '$$ d' -e P -e D \
	  | LC_COLLATE=C sort > $@.new && mv $@.new $@
	rm munch1.tmp

words.nb: ${LANGUAGE}.words
# Here is a rule to make a list of the most common Norwegian words.
# Which words to include is defined at the top of this Makefile.  Such
# a file is needed to make the word competition work for Norwegian.
# Stupid spell checkers might also want such a file.
	${CATNOHEADER} \
	  | $(GREP) '[BANDS]$$' \
	  | tr -d '*' \
	  | $(AWK) --re-interval --source ${WORDSFILTER} \
	  | tr -d '\"=' \
	  | $(GREP) -v '\(xxxx\|yyyy\|zyzyzy\)' \
	  | sort -f \
	  > $@.new && mv $@.new $@

words.nn: ${LANGUAGE}.words
# No frequency information availiable yet for nynorsk.  So all we can
# do is poick the words marked with a star.
	${CATNOHEADER} \
	  | $(GREP) '\*' \
	  | $(SED) -e 's/ .*//' \
	  | tr -d '\"=' \
	  | $(GREP) -v '\(xxxx\|yyyy\|zyzyzy\)' \
	  | sort -f \
	  > $@.new && mv $@.new $@

# Here is a target that picks words with given frequency.
words.${LANGUAGE}.%: ${LANGUAGE}.words
	${CATNOHEADER} \
	  | $(GREP) '[BANDS]$$' \
	  | $(GREP)  ' $(patsubst words.${LANGUAGE}.%,%,$@) ' \
	  | $(SED) -e 's/ .*//' \
	  | tr -d = \
	  | $(GREP) -v '\(xxxx\|yyyy\|zyzyzy\)' \
	  | sort -f \
	  > $@.new && mv $@.new $@


##########################################################################
# aspell
##########################################################################
aspell: nb.rws nn.rws

nb.dat: Makefile
	rm -f $@
	echo "name    nb"   > $@
	echo "charset iso8859-1"         >> $@
	echo "run-together true"         >> $@
	#echo "special ' =*= = =*= ."     >> $@ # unchanged
	#echo "soundslike none"           >> $@ # unchanged
	echo "special ' =** = =** . =**" >> $@ # like in the Danish file
	echo "soundslike nb"             >> $@ # like in the Danish file
nn.dat: Makefile
	rm -f $@
	echo "name    nn"  > $@
	echo "charset iso8859-1"         >> $@
	echo "run-together true"         >> $@
	#echo "special ' =*= = =*="       >> $@ # unchanged
	#echo "soundslike none"           >> $@ # unchanged
	echo "special ' =** = =** . =**" >> $@ # like in the Danish file
	echo "soundslike nn"             >> $@ # like in the Danish file

nb.rws: nb.mch nb.dat
	rm -f nb_phonet.dat ; ln -s aspell-phonet.dat nb_phonet.dat
	$(ISPELL) -d ./nb -e < nb.mch \
	  | $(PERL) -lane 'for (@F) {s/"(.)/$$1$$1=/g; print; s/($$1)$$1=/$$1/g; print }' \
	  | $(ASPELL) --local-data-dir=`pwd` --lang=nb create master ./nb.rws
	rm nb_phonet.dat
nn.rws: nn.mch nn.dat
	rm -f nn_phonet.dat; ln -s aspell-phonet.dat nn_phonet.dat
	$(ISPELL) -d ./nn -e < nn.mch \
	  | $(PERL) -lane 'for (@F) {s/"(.)/$$1$$1=/g; print; s/($$1)$$1=/$$1/g; print }' \
	  | $(ASPELL) --local-data-dir=`pwd` --lang=nn create master ./nn.rws
	rm nn_phonet.dat

install-aspell: install-aspell-nb install-aspell-nn
nb.multi:
	echo add nb.rws > $@
nn.multi:
	echo add nn.rws > $@
install-aspell-nb: nb.rws nb.dat nb.multi
	$(INSTALL) -d $(DESTDIR)$(aspelldir)/
	$(INSTALL_DATA) nb.multi $(DESTDIR)$(aspelldir)/nb.multi

	$(INSTALL_DATA) nb.dat $(DESTDIR)$(aspelldir)/nb.dat
	$(INSTALL_DATA) nb.rws $(DESTDIR)$(aspelldir)/nb.rws
	echo "add no.multi" > $(DESTDIR)$(aspelldir)/norwegian.alias
	$(INSTALL_DATA) aspell-phonet.dat $(DESTDIR)$(aspelldir)/nb_phonet.dat

install-aspell-nn: nn.rws nn.dat nn.multi
	$(INSTALL) -d $(DESTDIR)$(aspelldir)/
	$(INSTALL_DATA) nn.multi $(DESTDIR)$(aspelldir)/nn.multi

	$(INSTALL_DATA) nn.dat $(DESTDIR)$(aspelldir)/nn.dat
	$(INSTALL_DATA) nn.rws $(DESTDIR)$(aspelldir)/nn.rws
	$(INSTALL_DATA) aspell-phonet.dat $(DESTDIR)$(aspelldir)/nn_phonet.dat

##########################################################################
# Myspell (OpenOffice.org)
##########################################################################

# Generate list of all nb and nn words to be used when generating the
# munched lists.
nb.munch: ${LANGUAGE}.words Makefile
	${CATNOHEADER} \
	  | $(GREP) -e '[A-Z]$$' \
	  | $(SED) -e 's/ .*//' -e '$(ALPHASUBSTSED)' -e 's/ \*//' \
	  | $(GREP) '^[${CH}]' > $@.new && mv $@.new $@
nn.munch: ${LANGUAGE}.words Makefile
	${CATNOHEADER} \
	  | $(GREP) '\*' \
	  | $(SED) -e 's/ .*//' -e '$(ALPHASUBSTSED)' -e 's/ \*//' \
	  | $(GREP) '^[${CH}]' > $@.new && mv $@.new $@

myspell: nb_NO.mydict nb_NO.myaff nn_NO.mydict nn_NO.myaff $(TH_NB2).idx $(TH_NN2).idx
nb_NO.myaff.munch: nb_NO.myheader nb.aff.munch
	$(ISPELLAFF2MYSPELL) --charset=latin1 --split=200 \
		--myheader=nb_NO.myheader nb.aff.munch > nb_NO.myaff.munch
nn_NO.myaff.munch: nn_NO.myheader nn.aff.munch
	$(ISPELLAFF2MYSPELL) --charset=latin1 --split=200 \
		--myheader=nn_NO.myheader nn.aff.munch > nn_NO.myaff.munch
nb_NO.myaff: nb_NO.myheader nb.aff
	$(ISPELLAFF2MYSPELL) --charset=latin1 --split=200 \
		--myheader=nb_NO.myheader nb.aff > nb_NO.myaff
nn_NO.myaff: nn_NO.myheader nn.aff
	$(ISPELLAFF2MYSPELL) --charset=latin1 --split=200 \
		--myheader=nn_NO.myheader nn.aff > nn_NO.myaff
nb.munched: nb.munch nb_NO.myaff.munch
	munch nb.munch nb_NO.myaff.munch > $@
nn.munched: nn.munch nn_NO.myaff.munch
	munch nn.munch nn_NO.myaff.munch > $@
slow.nb_NO.mydict: nb.munched
	cat forkort-nb.txt nb.munched \
	  | $(SED) -e '$(STREKREMSED)' -e 's/"//g' \
	  | LC_COLLATE=C ./scripts/sortflags | LC_COLLATE=C sort > $@.new && \
	  mv $@.new $@
slow.nn_NO.mydict: nn.munched
	cat forkort-nn.txt nn.munched \
	  | $(SED) -e '$(STREKREMSED)' -e 's/"//g' \
	  | LC_COLLATE=C ./scripts/sortflags | LC_COLLATE=C sort > $@.new && \
	  mv $@.new $@
nb_NO.mydict: nb.mch
	( wc -l nb.mch|$(AWK) '{print $$1}'; cat nb.mch ) | $(SED) 's/"//g' > $@
nn_NO.mydict: nn.mch
	( wc -l nn.mch|$(AWK) '{print $$1}'; cat nn.mch ) | $(SED) 's/"//g' > $@

# Build OpenOffice (myspell) thesaurus files from the word list.  Need the
# thescoder program from
# <URL:https://sourceforge.net/project/showfiles.php?group_id=128318>
# These rules are for OpenOffice 1.x, and do not work for OpenOffice.org 2.x.
$(TH_NB1).idx:  thesaurus-nb.txt
	thescoder thesaurus-nb.txt $(TH_NB1)
$(TH_NN1).idx: thesaurus-nn.txt
	thescoder thesaurus-nn.txt $(TH_NN1)
$(TH_NB2).idx:	thesaurus-nb.txt scripts/thes_to_dat
	scripts/thes_to_dat < thesaurus-nb.txt > $(TH_NB2).dat
	# Using th_gen_idx.pl from libmythes-dev
	/usr/share/mythes/th_gen_idx.pl -o $(TH_NB2).idx < $(TH_NB2).dat
$(TH_NN2).idx:	thesaurus-nn.txt scripts/thes_to_dat
	scripts/thes_to_dat < thesaurus-nn.txt > $(TH_NN2).dat
	# Using th_gen_idx.pl from libmythes-dev
	/usr/share/mythes/th_gen_idx.pl -o $(TH_NN2).idx < $(TH_NN2).dat

install-myspell: install-myspell-nb \
		 install-myspell-hyph-nb \
		 install-myspell-nn \
		 install-myspell-hyph-nn
install-myspell-nb: nb_NO.mydict nb_NO.myaff
	$(INSTALL) -d $(DESTDIR)$(myspelldir)/
	$(INSTALL_DATA) nb_NO.mydict $(DESTDIR)$(myspelldir)/nb_NO.dic
	$(INSTALL_DATA) nb_NO.myaff $(DESTDIR)$(myspelldir)/nb_NO.aff

install-myspell-thes1-nb: $(TH_NB1).idx
	$(INSTALL) -d $(DESTDIR)$(thesdir)/
	$(INSTALL_DATA) $(TH_NB1).dat $(DESTDIR)$(thesdir)/$(TH_NB1).dat
	$(INSTALL_DATA) $(TH_NB1).idx $(DESTDIR)$(thesdir)/$(TH_NB1).idx
	# Need to be done after the package installation
	@echo "remember to add $(TH_NB1_DICT) to $(DESTDIR)$(thesdir)/dictionary.lst"

install-myspell-thes1-nn: $(TH_NN1).idx
	$(INSTALL) -d $(DESTDIR)$(thesdir)/
	$(INSTALL_DATA) $(TH_NN1).dat $(DESTDIR)$(thesdir)/$(TH_NN1).dat
	$(INSTALL_DATA) $(TH_NN1).idx $(DESTDIR)$(thesdir)/$(TH_NN1).idx
	# Need to be done after the package installation
	@echo "remember to add $(TH_NN1_DICT) to $(DESTDIR)$(thesdir)/dictionary.lst"

install-myspell-thes2-nb: $(TH_NB2).idx
	$(INSTALL) -d $(DESTDIR)$(thesdir)/
	$(INSTALL_DATA) $(TH_NB2).dat $(DESTDIR)$(thesdir)/$(TH_NB2).dat
	$(INSTALL_DATA) $(TH_NB2).idx $(DESTDIR)$(thesdir)/$(TH_NB2).idx
install-myspell-thes2-nn: $(TH_NN2).idx
	$(INSTALL) -d $(DESTDIR)$(thesdir)/
	$(INSTALL_DATA) $(TH_NN2).dat $(DESTDIR)$(thesdir)/$(TH_NN2).dat
	$(INSTALL_DATA) $(TH_NN2).idx $(DESTDIR)$(thesdir)/$(TH_NN2).idx

# Remove hyphenation{} block, as it is unsupported by OpenOffice.org as far as I
# know.  Convert and document charset.
hyph_no_NO.dic: nohyphb.tex Makefile
	( \
	  echo ISO8859-1 ; \
	  $(SED) \
		-e '/^\\hyphenation{/ , /^}/ D' \
		-e 's/\^\^e5//g' \
		-e 's/\^\^f8//g' \
		-e 's/\^\^e6//g' \
		-e 's/\^\^e9//g' \
		-e 's/\^\^e8//g' \
		-e 's/\^\^ea//g' \
		-e 's/\^\^f2//g' \
		-e 's/\^\^f3//g' \
		-e 's/\^\^f4//g' \
		-e 's/\^\^fc//g' < nohyphb.tex \
	  | $(EGREP) -v '^%|^\\|\}' \
	) > $@

install-myspell-hyph-nb:  hyph_no_NO.dic
	$(INSTALL) -d $(DESTDIR)$(hyphendir)/
	$(INSTALL_DATA) hyph_no_NO.dic $(DESTDIR)$(hyphendir)/hyph_nb_NO.dic
	@echo "remember to add 'HYPH nb NO hyph_nb_NO' to $(DESTDIR)$(hyphendir)/dictionary.lst"

install-myspell-nn: nn_NO.mydict nn_NO.myaff # $(TH_NN1).idx
	$(INSTALL) -d $(DESTDIR)$(myspelldir)/
	$(INSTALL_DATA) nn_NO.mydict $(DESTDIR)$(myspelldir)/nn_NO.dic
	$(INSTALL_DATA) nn_NO.myaff $(DESTDIR)$(myspelldir)/nn_NO.aff

install-myspell-hyph-nn: hyph_no_NO.dic
	$(INSTALL) -d $(DESTDIR)$(hyphendir)/
	$(INSTALL_DATA) hyph_no_NO.dic $(DESTDIR)$(hyphendir)/hyph_nn_NO.dic
	@echo "remember to add 'HYPH nn NO nn_NO' to $(DESTDIR)$(hyphendir)/dictionary.lst"

# Check which words in missing.<lang> are also in the word list, and
# thus can be removed from missing.<lang>.
check-missing: words.nb words.nn
	for l in nb nn; do \
		echo "Words listed in missing.$$l also listed in words.$$l:" ;\
		(for w in `$(GREP) -v '#' missing.$$l`; do \
			$(GREP) "^$$w\$$" words.$$l; \
		done) | $(SED) 's/^/  /'; \
	done

#
# Update frequency information based on the available information.
#
ordlistf.zip:
	rm -f ordlistf.zip
	wget http://helmer.aksis.uib.no/nta/ordlistf.zip
ORDLISTF.TXT: ordlistf.zip
	rm -f ORDLISTF.TXT
	unzip -o ordlistf.zip
	fromdos ORDLISTF.TXT
freq-update: ORDLISTF.TXT
	scripts/freq-update ORDLISTF.TXT ${LANGUAGE}.words > ${LANGUAGE}.words.updated
	mv ${LANGUAGE}.words.updated ${LANGUAGE}.words

#
NBSPELINGSTATUS = http://tyge.sslug.dk/~korsvoll/nb.speling.org/htdocs/status
NNSPELINGSTATUS = http://tyge.sslug.dk/~korsvoll/nn.speling.org/htdocs/status

web-update: source-nb
source-nb.gz:
	wget $(NBSPELINGSTATUS)/source.gz -O $@.new && mv $@.new $@
source-nn.gz:
	wget $(NNSPELINGSTATUS)/source.gz -O $@.new && mv $@.new $@
source-nb: source-nb.gz Makefile
	gunzip < source-nb.gz > $@.new && mv $@.new $@
source-nn: source-nn.gz Makefile
	gunzip < source-nn.gz > $@.new && mv $@.new $@

# Update thesaurus files from no.speling.org.  These rules are now obsolete

thesaurus-nb.new: source-nb scripts/speling-extract-synonyms Makefile
	echo '$(theschars)' > thesaurus-nb.new
	scripts/speling-extract-synonyms < source-nb >> thesaurus-nb.new

	@echo "============================================================="
	@echo "warning: Obsolete rule $@.  Use thes-nb-update instead"
	@echo "============================================================="
thesaurus-nn.new: source-nn scripts/speling-extract-synonyms Makefile
	echo '$(theschars)' > thesaurus-nn.new
	scripts/speling-extract-synonyms < source-nn >> thesaurus-nn.new
# Not obsolete yet.  merg.net do not have nn lists
#	@echo "============================================================="
#	@echo "warning: Obsolete rule $@.  Use thes-nb-update instead"
#	@echo "============================================================="

##########################################################################
# OpenOffice.org distribution file (zip-files)
##########################################################################

ooo-dist: no_NO-pack2.zip # no_NO-pack1.zip 
no_NO-pack: myspell
	rm -rf ooo-dist
	mkdir ooo-dist

	$(MAKE) ooo-dist/nb_NO.zip ooo-dist/nn_NO.zip
	( \
	  echo "nb,NO,nb_NO,Norwegian Bokml (Norway),nb_NO.zip" ; \
	  echo "nn,NO,nn_NO,Norwegian Nynorsk (Norway),nn_NO.zip" ; \
	) > ooo-dist/spell.txt

	$(MAKE) ooo-dist/hyph_nb_NO.zip ooo-dist/hyph_nn_NO.zip
	( \
	  echo "nb,NO,hyph_nb_NO,Norwegian Bokml (Norway),hyph_nb_NO.zip" ; \
	  echo "nn,NO,hyph_nn_NO,Norwegian Nynorsk (Norway),hyph_nn_NO.zip" ; \
	) > ooo-dist/hyph.txt

	$(INSTALL_DATA) README NEWS ooo-dist/.

# Pack for OpenOffice.org v1, with thesaurus using the old format
no_NO-pack1.zip: no_NO-pack
	$(MAKE) ooo-dist/$(TH_NB1).zip ooo-dist/$(TH_NN1).zip
	( \
	  echo "nb,NO,$(TH_NB1),Norwegian Bokml (Norway),$(TH_NB1).zip" ; \
	  echo "nn,NO,$(TH_NN1),Norwegian Nynorsk (Norway),$(TH_NN1).zip" ; \
	) > ooo-dist/thes1.txt

	rm -f ../no_NO-pack-$(VERSION).zip
	(cd ooo-dist; zip ../no_NO-pack1-$(VERSION).zip \
	    README NEWS \
	    spell.txt nb_NO.zip nn_NO.zip \
	    thes1.txt $(TH_NB1).zip $(TH_NN1).zip \
	    hyph.txt hyph_nb_NO.zip  hyph_nn_NO.zip)

# Pack for OpenOffice.org v2, with thesaurus using the new format
no_NO-pack2.zip: no_NO-pack
	$(MAKE) ooo-dist/$(TH_NB2).zip ooo-dist/$(TH_NN2).zip
	( \
	  echo "nb,NO,$(TH_NB2),Norwegian Bokml (Norway),$(TH_NB2).zip" ; \
	  echo "nn,NO,$(TH_NN2),Norwegian Nynorsk (Norway),$(TH_NN2).zip" ; \
	) > ooo-dist/thes2.txt

	rm -f ../no_NO-pack-$(VERSION).zip
	(cd ooo-dist; zip ../no_NO-pack2-$(VERSION).zip \
	    README NEWS \
	    spell.txt nb_NO.zip nn_NO.zip \
	    thes2.txt $(TH_NB2).zip $(TH_NN2).zip \
	    hyph.txt hyph_nb_NO.zip  hyph_nn_NO.zip)


ooo-dist/nb_NO.zip:
	$(MAKE) install-myspell-nb DESTDIR= myspelldir=ooo-dist/nb_NO
	( \
	  echo Myspell dictionary ; \
	  echo ------------------ ; \
	  echo ; \
	  echo "Language: Norwegian Bokml (nb NO)" ; \
	  echo "Origin:   Generated from the spell-norwegian source v$(VERSION)" ; \
	  echo "License:  GNU General Public license" ; \
	  echo "Author:   The spell-norwegian project, <URL:https://alioth.debian.org/projects/spell-norwegian/>" ; \
	  echo ; \
	  echo "DICT nb NO nb_NO" ; \
	) > ooo-dist/nb_NO/README_nb_NO.txt
	(cd ooo-dist/nb_NO; zip ../nb_NO.zip *)

ooo-dist/$(TH_NB1).zip: $(TH_NB1).idx
	$(MAKE) install-myspell-thes1-nb DESTDIR= myspelldir=ooo-dist/$(TH_NB1)
	( \
	  echo Myspell thesaurus for OpenOffice.org v1 ; \
	  echo ----------------- ; \
	  echo ; \
	  echo "Language: Norwegian Bokml (nb NO)" ; \
	  echo "Origin:   Generated from the spell-norwegian source v$(VERSION)" ; \
	  echo "License:  GNU General Public license" ; \
	  echo "Author:   The spell-norwegian project, <URL:https://alioth.debian.org/projects/spell-norwegian/>" ; \
	  echo ; \
	  echo $(TH_NB1_DICT) ; \
	) > ooo-dist/$(TH_NB1)/README_$(TH_NB1).txt
	(cd ooo-dist/$(TH_NB1); zip ../$(TH_NB1).zip *)

ooo-dist/$(TH_NB2).zip: $(TH_NB2).idx
	$(MAKE) install-myspell-thes2-nb DESTDIR= myspelldir=ooo-dist/$(TH_NB2)
	( \
	  echo Myspell thesaurus for OpenOffice.org v2 ; \
	  echo ----------------- ; \
	  echo ; \
	  echo "Language: Norwegian Bokml (nb NO)" ; \
	  echo "Origin:   Generated from the spell-norwegian source v$(VERSION)" ; \
	  echo "License:  GNU General Public license" ; \
	  echo "Author:   The spell-norwegian project, <URL:https://alioth.debian.org/projects/spell-norwegian/>" ; \
	  echo ; \
	  echo $(TH_NB2_DICT) ; \
	) > ooo-dist/$(TH_NB2)/README_$(TH_NB2).txt
	(cd ooo-dist/$(TH_NB2); zip ../$(TH_NB2).zip *)

ooo-dist/hyph_nb_NO.zip:
	$(MAKE) install-myspell-hyph-nb DESTDIR= myspelldir=ooo-dist/hyph_nb_NO
	( \
	  echo Myspell hyphenation ; \
	  echo ------------------- ; \
	  echo ; \
	  echo "Language: Norwegian Bokml (nb NO)" ; \
	  echo "Origin:   Generated from the spell-norwegian source v$(VERSION)" ; \
	  echo "License:  GNU General Public license" ; \
	  echo "Author:   The spell-norwegian project, <URL:https://alioth.debian.org/projects/spell-norwegian/>" ; \
	  echo ; \
	  echo "HYPH nb NO nb_NO" ; \
	) > ooo-dist/hyph_nb_NO/README_hyph_nb_NO.txt
	(cd ooo-dist/hyph_nb_NO; zip ../hyph_nb_NO.zip *)

ooo-dist/nn_NO.zip:
	$(MAKE) install-myspell-nn DESTDIR= myspelldir=ooo-dist/nn_NO
	( \
	  echo Myspell dictionary ; \
	  echo ------------------ ; \
	  echo ; \
	  echo "Language: Norwegian Nynorsk (nn NO)" ; \
	  echo "Origin:   Generated from the spell-norwegian source v$(VERSION)" ; \
	  echo "License:  GNU General Public license" ; \
	  echo "Author:   The spell-norwegian project, <URL:https://alioth.debian.org/projects/spell-norwegian/>" ; \
	  echo ; \
	  echo DICT nn NO nn_NO ; \
	) > ooo-dist/nn_NO/README_nn_NO.txt
	(cd ooo-dist/nn_NO; zip ../nn_NO.zip *)

ooo-dist/$(TH_NN1).zip: $(TH_NB1).idx
	$(MAKE) install-myspell-thes1-nn DESTDIR= myspelldir=ooo-dist/$(TH_NN1)
	( \
	  echo Myspell thesaurus for OpenOffice.org v1 ; \
	  echo ----------------- ; \
	  echo ; \
	  echo "Language: Norwegian Nynorsk (nn NO)" ; \
	  echo "Origin:   Generated from the spell-norwegian source v$(VERSION)" ; \
	  echo "License:  GNU General Public license" ; \
	  echo "Author:   The spell-norwegian project, <URL:https://alioth.debian.org/projects/spell-norwegian/>" ; \
	  echo ; \
	  echo $(TH_NN1_DICT) ; \
	) > ooo-dist/$(TH_NN1)/README_$(TH_NN1).txt
	(cd ooo-dist/$(TH_NN1); zip ../$(TH_NN1).zip *)

ooo-dist/$(TH_NN2).zip: $(TH_NB2).idx
	$(MAKE) install-myspell-thes2-nn DESTDIR= myspelldir=ooo-dist/$(TH_NN2)
	( \
	  echo Myspell thesaurus for OpenOffice.org v2 ; \
	  echo ----------------- ; \
	  echo ; \
	  echo "Language: Norwegian nynorsk (nn NO)" ; \
	  echo "Origin:   Generated from the spell-norwegian source v$(VERSION)" ; \
	  echo "License:  GNU General Public license" ; \
	  echo "Author:   The spell-norwegian project, <URL:https://alioth.debian.org/projects/spell-norwegian/>" ; \
	  echo ; \
	  echo $(TH_NN2_DICT) ; \
	) > ooo-dist/$(TH_NN2)/README_$(TH_NN2).txt
	(cd ooo-dist/$(TH_NN2); zip ../$(TH_NN2).zip *)

ooo-dist/hyph_nn_NO.zip:
	$(MAKE) install-myspell-hyph-nn DESTDIR= myspelldir=ooo-dist/hyph_nn_NO
	( \
	  echo Myspell hyphenation ; \
	  echo ------------------- ; \
	  echo ; \
	  echo "Language: Norwegian Nynorsk (nn NO)" ; \
	  echo "Origin:   Generated from the spell-norwegian source v$(VERSION)" ; \
	  echo "License:  GNU General Public license" ; \
	  echo "Author:   The spell-norwegian project, <URL:https://alioth.debian.org/projects/spell-norwegian/>" ; \
	  echo ; \
	  echo "HYPH nn NO nn_NO" ; \
	) > ooo-dist/hyph_nn_NO/README_hyph_nn_NO.txt
	(cd ooo-dist/hyph_nn_NO; zip ../hyph_nn_NO.zip *)

##########################################################################
# Compare to speling.org database
##########################################################################

speling-good.nb:
	GET $(NBSPELINGSTATUS)/words.good.gz     | gunzip|sort > $@
speling-new.nb: words.nb
	GET $(NBSPELINGSTATUS)/words.disputed.gz | gunzip|sort > speling-disputed.nb
	sort words.nb      > tmp-nb
	sort speling-good.nb speling-disputed.nb > tmp-nb-new-full
	comm -13 tmp-nb  speling-good.nb > $@
	comm -23 tmp-nb  tmp-nb-new-full > speling-missing.nb
	@echo -n "nye p speling.no:     "; wc -l $@
	@echo -n "mangler p speling.no: "; wc -l speling-missing.nb
	@echo -n "omstridt p speling.no: "; wc -l speling-disputed.nb
	rm tmp-nb  tmp-nb-new-full

speling-good.nn:
	GET $(NNSPELINGSTATUS)/words.good.gz     | gunzip|sort > $@
speling-new.nn: words.nn
	GET $(NNSPELINGSTATUS)/words.disputed.gz | gunzip|sort > speling-disputed.nn
	sort words.nn      > tmp-nn
	sort speling-good.nn speling-disputed.nn > tmp-nn-new-full
	comm -13 tmp-nn  speling-good.nn > $@
	comm -23 tmp-nn  tmp-nn-new-full > speling-missing.nn
	@echo -n "nye p speling.no:     "; wc -l $@
	@echo -n "mangler p speling.no: "; wc -l speling-missing.nn
	@echo -n "omstridt p speling.no: "; wc -l speling-disputed.nn
	rm tmp-nn tmp-nn-new-full

update-from-spelingorg:
	$(RM) source-nb* speling-good.nb source-nn* speling-good.nn
	$(MAKE) spelingorg2norskwords

spelingorg2norskwords: norsk.words source-nb speling-good.nb source-nn speling-good.nn
	scripts/speling2words norsk.words \
		source-nb speling-good.nb \
		source-nn speling-good.nn > $@.tmp && mv $@.tmp norsk.words

##########################################################################
# Compare to synonymer.merg.net database
##########################################################################

THES_URL = http://synonymer.merg.net/download/thesaurus.txt

thesaurus-nb-mergnet.txt:
	wget $(THES_URL) -O - > thesaurus-nb-mergnet.txt.new && \
	  mv thesaurus-nb-mergnet.txt.new thesaurus-nb-mergnet.txt

synonymer-new.nb: words.nb thesaurus-nb-mergnet.txt
	$(GREP) -v '#' thesaurus-nb-mergnet.txt | tr ";/ " "\n\n\n"| \
		sort -u > thesaurus-words.txt
	sort words.nb > words.nb.sorted
	comm -13 words.nb.sorted thesaurus-words.txt > $@
	wc -l $@
#	rm words.nb.sorted thesaurus-words.txt

thesaurus-nb.txt-update: thesaurus-nb-mergnet.txt
	( \
	echo '$(theschars)' && \
	$(GREP) -v '#' thesaurus-nb-mergnet.txt | sed 's/;/; /g' \
	) > thesaurus-nb.txt.new && \
	mv thesaurus-nb.txt.new thesaurus-nb.txt

##########################################################################
# Make tarball
##########################################################################

dist: $(distdir).tar.gz ooo-dist
$(distdir).tar.gz: distdir
	-chmod -R a+r $(distdir)
	GZIP=$(GZIP_ENV) $(TAR) chozf $(distdir).tar.gz $(distdir)
	-rm -rf $(distdir)

distcheck: dist
	tar zxf $(distdir).tar.gz && \
		$(MAKE) -C $(distdir) && \
		$(MAKE) -C $(distdir) DESTDIR=destdir install && \
		rm -rf $(distdir)

distdir: $(DISTFILES)
	-rm -rf $(distdir)
	mkdir $(distdir)
	-chmod 777 $(distdir)
	for file in $(DISTFILES); do \
	  d=$(srcdir); \
	  if test -d $$d/$$file; then \
	    cp -pr $$d/$$file $(distdir)/$$file; \
	  else \
	    test -f $(distdir)/$$file \
	    || ln $$d/$$file $(distdir)/$$file 2> /dev/null \
	    || cp -p $$d/$$file $(distdir)/$$file || :; \
	  fi; \
	done
	for subdir in $(SUBDIRS); do \
	  if test "$$subdir" = .; then :; else \
	    test -d $(distdir)/$$subdir \
	    || mkdir $(distdir)/$$subdir \
	    || exit 1; \
	    chmod 777 $(distdir)/$$subdir; \
	    (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) top_distdir=../$(distdir) distdir=../$(distdir)/$$subdir distdir) \
	      || exit 1; \
	  fi; \
	done

current-stats.txt:
	./speling-stats | iconv -f latin1 -t utf-8 > current-stats.txt

##########################################################################
# Clean up generated files
##########################################################################

clean:
	rm -f core *.hash *.stat *.cnt munch[123].tmp \
	      nb.mch nn.mch \
	      nb.aff nn.aff \
	      nb.aff.munch nn.aff.munch \
	      words.nb words.nn \
	      nb_NO.myaff nn_NO.myaff \
	      nb_NO.mydict nn_NO.mydict \
	      $(TH_NB1).dat $(TH_NB1).idx \
	      $(TH_NN1).dat $(TH_NN1).idx \
	      $(TH_NB2).dat $(TH_NB2).idx \
	      $(TH_NN2).dat $(TH_NN2).idx \
	      nb.multi nn.multi \
	      nb.dat nn.dat \
	      nb.rws nn.rws \
	      comp[123].tmp* munched.*
	rm -f nb.munch nn.munch nb_NO.myaff.munch nn_NO.myaff.munch
	rm -f nb.munched nn.munched nb.multi nn.multi
	rm -f hyph_no_NO.dic
	rm -f .#* *~
distclean: clean
	rm -f ORDLISTF.TXT ordlistf.zip
	rm -f source-nb.gz source-nb source-nn.gz source-nn
	rm -f thesaurus-nb.new thesaurus-nn.new
	rm -f $(distdir).tar.gz
	rm -fr ooo-dist no_NO-pack1-$(VERSION).zip no_NO-pack2-$(VERSION).zip


#	The following target is used in the English makefile, and is
#	required to be present in all other language Makefiles as
#	well, even though it doesn't have to do anything in those
#	directories.
#
kitclean:

#
#	The following target is used in the English makefile, and is
#	required to be present in all other language Makefiles as
#	well, even though it doesn't have to do anything in those
#	directories.
#
dictclean:
	rm -f $(patsubst %,munched.%,${CATHEGORIES}) \
	      words.nb words.nn