WORTE = \
	adjektive-a.txt \
	anglizismen-a.txt \
	verben-a.txt \
	klein-a.txt \
	worte-a.txt \
	\
	adjektive-n.txt \
	anglizismen-n.txt \
	klein-n.txt \
	verben-n.txt \
	worte-n.txt \
	\
	abkuerzungen.txt \
	abkuerz2.txt \
	adjektive.txt \
	alphabeta.txt \
	anglizismen.txt \
	compeng.txt \
	elektronik.txt \
	geografie.txt \
	infoabk.txt \
	informatik.txt \
	klein.txt \
	latein.txt \
	marken.txt \
	mathematik.txt \
	namen.txt \
	orgabk.txt \
	roemisch.txt \
	seltenes.txt \
	technik.txt \
	verben.txt \
	vornamen.txt \
	worte.txt \
	worte2.txt \
	zahlen.txt \
	zusammen.txt \
	vornamen2.txt \
	namen2.txt \
	medizin.txt \
	geografie2.txt
# not used:   austriazismen.txt
#             helvetismen.txt (automatically used by "make swiss.hash")
#             fixwords.txt (used below)
#             abkuerzpunkt.txt (special treatment below)

ISPELLIBDIR = $$(ispell -vv |grep "LIBDIR" |sed "s/.*\=//" |tr -d \")
DESTDIR =
MAKE = make
BUILDHASH = buildhash
ISPELL = ispell
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
vpath %.txt ./dicts
.SUFFIXES: .txt

# 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!
LANG = C
LC_ALL = C
LC_COLLATE = C





###
## Ispell stuff:
###

german.hash: german.aff all.words .copyright
	$(BUILDHASH) all.words ./german.aff $@

all.words.raw: unpack $(addprefix dicts/,$(WORTE))
	cd dicts; sed "s/qq//g;s/\.//" abkuerzpunkt.txt $(WORTE) |sort -u |../bin/uniqflag.pl > ../$@.tmp
	mv $@.tmp $@

all.words: all.words.raw german.aff
	munchlist -l ./german.aff all.words.raw > $@

install: german.hash
	mkdir -p $(DESTDIR)$(ISPELLIBDIR)
	cp german.aff german.hash $(DESTDIR)$(ISPELLIBDIR)

## Swiss Ispell stuff:

swiss.aff:
	sed "/swiss-del/d" german.aff |sed "/swiss-convert/s/sS/SS/g" |sed '/\#swiss-only/s/^\#//' |sed '/stringchar/!s/sS//g' > swiss.aff

all.words.swiss.raw: unpack $(addprefix dicts/,$(WORTE))
	cd dicts; sed "s/qq//g;s/sS/ss/g;s/\.//g" $(WORTE) helvetismen.txt abkuerzpunkt.txt |sort -u > ../$@

all.words.swiss: all.words.swiss.raw swiss.aff
	munchlist -l ./swiss.aff all.words.swiss.raw > $@

swiss.hash: swiss.aff all.words.swiss .copyright
	$(BUILDHASH) all.words.swiss ./swiss.aff swiss.hash

swiss-install: swiss.hash
	mkdir -p $(DESTDIR)$(ISPELLIBDIR)
	cp swiss.aff swiss.hash $(DESTDIR)$(ISPELLIBDIR)


###
## Aspell stuff:
###

help.hash: german.aff all.words2 .copyright
	$(BUILDHASH) all.words2 ./german.aff $@

all.words2: unpack
	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




###
## myspell stuff:
###

myspelldic: all.words
#	cd dicts; sed "s/qq//g" abkuerzpunkt.txt $(WORTE) |sort -u |../bin/myspellfixprefix.pl |sort -u |../bin/uniqflag.pl > ../all.words.myspell
	cat all.words dicts/abkuerzpunkt.txt |sort -u |./bin/myspellfixprefix.pl |sort -u  > all.words.myspell
	wc -l all.words.myspell |sed "s/ *\([0-9]*\) .*/\1/g" >myspell/de_DE.dic
	./bin/dic2iso <all.words.myspell >>myspell/de_DE.dic
	sed "s/qq//g" dicts/austriazismen.txt |sort -u |./bin/myspellfixprefix.pl |sort -u |./bin/uniqflag.pl > all.words.myspell.aust
	wc -l all.words.myspell.aust |sed "s/ *\([0-9]*\) .*/\1/g" >myspell/de_AT.dic
	./bin/dic2iso <all.words.myspell.aust >>myspell/de_AT.dic
	
swiss-myspelldic: all.words.swiss
	cat all.words.swiss dicts/abkuerzpunkt.txt dicts/helvetismen.txt |sort -u |./bin/myspellfixprefix.pl |sort -u |./bin/uniqflag.pl > all.words.myspell.swiss
	wc -l all.words.myspell.swiss |sed "s/ *\([0-9]*\) .*/\1/g" >myspell/de_CH.dic
	./bin/dic2iso <all.words.myspell.swiss >>myspell/de_CH.dic




###
## ligature stuff:
###


liglist.aff:
	sed '/\#qqq/s/^\#//g;/\#nnn/d' german.aff > liglist.aff

all.words.liglist.raw: unpack $(addprefix dicts/,$(WORTE))
	cd dicts ; sed "s/\.//" *.txt |sort -u > ../$@

all.words.liglist: all.words.liglist.raw liglist.aff
	munchlist -l ./liglist.aff all.words.liglist.raw > $@

liglist.hash: liglist.aff all.words.liglist
	$(BUILDHASH) all.words.liglist ./liglist.aff $@

liglist: liglist.hash .copyright
	cat ligature/oldspell.liglist all.words.liglist    \
	| $(ISPELL) -e -d./liglist                         \
	| 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                                          \
	> liglist

rmligs: liglist
	cat ligature/rmligs.skel liglist > rmligs
	chmod 755 rmligs






###
## misc stuff:
###


.copyright:
	@echo 
	@cat Documentation/Copyright
	@sleep 0

isowordlist: german.hash
	cat all.words |$(ISPELL) -e -d./german |tr \  '\n' |sed -f ./bin/dic2iso |sort -u > isowordlist

swiss-isowordlist: swiss
	cat all.words.swiss |$(ISPELL) -e -d./swiss |tr \  '\n' |sed -f ./bin/dic2iso |sort -u > swiss-isowordlist

clean:
	rm -f all.words* *.hash swiss.aff igerman98*.tar.bz2 *isowordlist german swiss unpack sort liglist.aff liglist.hash liglist rmligs MD5sums myspell/*.dic *.tmp

sort:
	@if grep [] dicts/*.txt ;then echo "!!! wrong characters in dictionay files !!!";exit 1;fi
	cd dicts; find . -name "*.txt" |while read i; do sort -u -o $$i $$i; done

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

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

dist: sort pack clean
	date +%Y%m%d > VERSION
	md5sum `find . -name "*" -xtype f` |gpg --clearsign > .MD5sums
	mv .MD5sums MD5sums
	ls > .files
	echo igerman98-`cat VERSION` > .name
	mkdir `cat .name`
	mv `cat .files` `cat .name`
	tar cv * | bzip2 > `cat .name`.tar.bz2
	mv `cat .name`/* .
	rmdir `cat .name`

