
VERSION = 0.4.36
VER4RPM = 0.51-1
VERASPELL = 0.60
FILES = Makefile \
	wa_ispell.aff \
	wa_aspell.aff wa_phonet.dat wa.dat wa.multi \
	firefox.tar.bz2 \
	chrome.tar.bz2 \
	crxmake.sh \
	wa_hunspell.aff \
	ChangeLog Copyright LIJHOZMU README
LICENCES_DIR = LICENCE
LICENCES = LICENCE/GPLv3.txt LICENCE/LGPLv3.txt LICENCE/MPL-1.1.txt 

FILES_DOS = make.bat install.bat
EXTRA = extra/ER_viebes extra/HAUST extra/Cc
ASPELL_TOOLS_DIR = aspell_tools
ASPELL_TOOLS = \
	aspell_tools/configure \
	aspell_tools/Makefile.pre \
	aspell_tools/README \
	aspell_tools/walloon.alias \
	aspell_tools/walon.alias

# djivêye des rîles a n' *nén* copyî
WA_LIDJE=':wa-ae-a\|:wa-aa-a\|:wa-aajh-a\|:wa-aacion-a\|:wa-ea-ya\|:wa-ey-iy\|:wa-oen-w\|:wa-oe-w\|:wa-oi-o\|:wa-oi-wa\|:wa-sch-[sc]\|:wa-sh-ch\|:wa-h-_\|:wa-jh-j\|:wa-xh-ch\|:wa-o-ou\|:wa-owe-uwe\|:wa-u-ou'
WA_NAMEUR=':wa-ae-e\|:wa-aa-a\|:wa-aajh-a\|:wa-aacion-o\|:wa-ea-e\|:wa-ey-ey\|:wa-oen-o\|:wa-oe-e\|:wa-oi-o\|:wa-oi-we\|:wa-sch-[sh]\|:wa-sh-ss\|:wa-h-h\|:wa-jh-h\|:wa-xh-h\|:wa-o-o\>\|:wa-u-ou'
WA_HOUFALIJHE=':wa-ae-e\|:wa-aa-o\|:wa-aajh-o\|:wa-aacion-o\|:wa-ea-ya\|:wa-ey-iy\|:wa-oen-w\|:wa-oe-w\|:wa-oi-o\|:wa-oi-wa\|:wa-sch-[sh]\|:wa-sh-ch\|:wa-h-_\|:wa-jh-j\|:wa-xh-h\|:wa-o-ou\|:wa-owe-uwe\|:wa-u-ou'
WA_TCHALERWE=':wa-ae-e\|:wa-aa-a\|:wa-aajh-a\|:wa-aacion-o\|:wa-ea-e\|:wa-ey-ey\|:wa-oen-o\|:wa-oe-e\|:wa-oi-we\|:wa-oi-wa\|:wa-sch-[hc]\|:wa-sh-ch\|:wa-h-h\|:wa-jh-h\|:wa-xh-h\|:wa-o-o\>\|:wa-u-ou'
WA_NIVELE=':wa-ae-e\|:wa-aa-a\|:wa-aajh-a\|:wa-aacion-o\|:wa-ea-e\|:wa-ey-ey\|:wa-oen-o\|:wa-oe-e\|:wa-oi-we\|:wa-oi-o\|:wa-sch-[hc]\|:wa-sh-ss\|:wa-h-h\|:wa-jh-h\|:wa-xh-h\|:wa-o-o\>\|:wa-u-ou'


#all:	ispell
#all:	aspell
all:	hunspell


##########
# ispell # (deprecated)
##########################################################################
walon_lst_cp1252:
	if [ ! -r walon.lst -o -n "`find mots* -type f -newer walon.lst`" ] ; \
	then \
	  grep -v '^[# 	]' mots*/* ${EXTRA} |cut -d: -f2- |cut -d'	' -f1|\
	  iconv -f UTF-8 -t cp1252//TRANSLIT|\
	  tr ' ' '\n'|(LC_ALL=C sort -u) | grep -av '^$$' > walon.lst ; \
	fi

walon.hashed:	wa_ispell.aff walon_lst_cp1252
	buildhash walon.lst wa_ispell.aff walon.hash

walon.munched:	wa_ispell.aff walon_lst_cp1252
	rm -f walon.hash walon.txt 
	munchlist -v -l wa_ispell.aff walon.lst > walon.txt
	buildhash walon.txt wa_ispell.aff walon.hash

ispell: walon.munched

ispell_install: ispell
	install -m 644 walon.hash $(destdir)/usr/lib/ispell/
	install -m 644 wa_ispell.aff $(destdir)/usr/lib/ispell/walon.aff

##########
# aspell #
##########################################################################
walon_lst_utf8:
	if [ ! -r walon_utf8.lst -o -n "`find mots* -type f -newer walon_utf8.lst`" ] ; \
	then \
	  grep -v '^[#	 ]' mots*/* ${EXTRA} |cut -d: -f2- |cut -d'	' -f1|\
	  (LC_ALL=C sort -u) | grep -av '^$$' > walon_utf8.lst ; \
	fi

wa_crole_utf8: walon_lst_utf8
	if [ ! -r wa_crole_utf8.lst -o walon_utf8.lst -newer wa_crole_utf8.lst ] ; \
	then \
	  grep -a "'" walon_utf8.lst | sed "s/'/’/" > wa_crole_utf8.lst ; \
	fi

wa_lst_old: wa_affix_dat wa_crole_utf8 
	# i fåt côper åzès apostrofes+loyeure pol moumint, aspell ni sait nén
	# prinde des mots avou zeles ambedeus
	if [ ! -r wa.lst -o wa_affix.dat -nt wa.lst \
		-o -n "`find mots* wa_crole_utf8.lst -type f -newer wa.lst`" ] ; \
	then \
	  grep -v '^[# 	]' mots*/* ${EXTRA} wa_crole_utf8.lst |\
	  cut -d: -f2- |cut -d'	' -f1|\
	  sed 's/[\*]$$//' |\
	  iconv -f UTF-8 -t cp1252//TRANSLIT |\
	  tr ' ' '\n'|\
	  (LC_ALL=C sort -u) | grep -av '^$$' |\
	  LC_ALL=C sed "s/'-.*$$/'/" | \
	  aspell expand --encoding=cp1252 --lang=wa --local-data-dir=. |\
	  tr ' ' '\n' | \
	  iconv -t UTF-8 -f cp1252 |\
	  uniq > wa.tmp1.lst ; \
	  unmunch wa.tmp1.lst wa.aff 2> /dev/null | uniq > wa.tmp2.lst ; \
	  unmunch wa.tmp2.lst wa.aff 2> /dev/null | uniq > wak ; \
	  cat wak | iconv -f UTF-8 -t cp1252//TRANSLIT > wa.lst ; \
	fi

wa_lst: wa_lst_utf8
	if [ ! -r wa.lst -o wa.lst_utf8 -nt wa.lst -o wa_affix.dat -nt wa.lst \
		-o -n "`find mots* -type f -newer wa.lst`" ] ; \
	then \
	  cat wa.lst_utf8 | iconv -f UTF-8 -t cp1252//TRANSLIT |\
	  (LC_ALL=C sort -u) > wa.lst ; \
	fi

wa_lst_utf8: wa_affix_dat wa_crole_utf8 
	# i fåt côper åzès apostrofes+loyeure pol moumint, aspell ni sait nén
	# prinde des mots avou zeles ambedeus
	if [ ! -r wa.lst_utf8 -o wa_affix.dat -nt wa.lst_utf8 \
		-o -n "`find mots* wa_crole_utf8.lst -type f -newer wa.lst_utf8`" ] ; \
	then \
	  grep -v '^[# 	]' mots*/* ${EXTRA} wa_crole_utf8.lst |\
	  cut -d: -f2- |cut -d'	' -f1|\
	  sed 's/[\*]$$//' |\
	  tr ' ' '\n'|\
	  LC_ALL=C sed "s/\(’\|'\)-.*$$/\1/" | \
	  (LC_ALL=C sort -u) | grep -av '^$$' > wa.tmp0.lst ;\
	  unmunch wa.tmp0.lst wa.aff 2> /dev/null | uniq > wa.tmp1.lst ; \
	  unmunch wa.tmp1.lst wa.aff 2> /dev/null | uniq > wa.tmp2.lst ; \
	  unmunch wa.tmp2.lst wa.aff 2> /dev/null | tr -d '"' | \
	  LC_ALL=C sort -u > wa.lst_utf8 ; \
	fi

wa_rws: wa_lst
	if [ ! -r wa.rws -o wa.lst -nt wa.rws ] ; \
	then \
       	  rm -f wa.rws ; \
	  aspell --local-data-dir=. --lang=wa create master ./wa.rws < wa.lst ; \
	fi

wa_affix_dat: hunspell_replace
	if [ ! -r wa_affix.dat -o wa_aspell.aff -nt wa_affix.dat -o \
	        hunspell.replace -nt wa.aff -o \
		wa_hunspell.aff -nt wa_affix.dat ] ; \
	then \
       	  cp wa_aspell.aff wa_affix.dat ; \
	  echo -n "REP " >> wa_affix.dat ; \
	  wc -l hunspell.replace | awk '{ print $$1 }' >> wa_affix.dat ; \
	  cat hunspell.replace | iconv -t cp1252 >> wa_affix.dat ; \
	fi

aspell: wa_rws wa_affix_dat wa_phonet.dat wa.dat wa.multi 

aspell_install: aspell
	#install -m 644 wa.multi $(destdir)/usr/lib/aspell-${VERASPELL}/
	install -m 644 wa.dat $(destdir)/usr/lib/aspell-${VERASPELL}/
	install -m 644 wa_phonet.dat $(destdir)/usr/lib/aspell-${VERASPELL}/
	install -m 644 wa_affix.dat $(destdir)/usr/lib/aspell-${VERASPELL}/
	install -m 644 wa.rws $(destdir)/usr/lib/aspell-${VERASPELL}/
	install -m 644 wa.multi $(destdir)/usr/lib/aspell-${VERASPELL}/

aspellrpm: wa_lst wa_affix_dat
	if [ -d aspell-wa-${VER4RPM}/ ]; then rm -rf aspell-wa-${VER4RPM}/ ; fi
	mkdir aspell-wa-${VER4RPM}
	mkdir aspell-wa-${VER4RPM}/doc
	cp ${ASPELL_TOOLS} aspell-wa-${VER4RPM}/
	cp ChangeLog LIJHOZMU README aspell-wa-${VER4RPM}/doc/
	cp -var ${LICENCES_DIR} aspell-wa-${VER4RPM}/
	cp Copyright info wa.multi aspell-wa-${VER4RPM}/
	perl -pe "s/\@\@VERSION\@\@/$(VERSION)/" -i fspell-wa-${VER4RPM}/info
	cp wa.dat wa_phonet.dat aspell-wa-${VER4RPM}/
	cp wa_affix.dat aspell-wa-${VER4RPM}/
	word-list-compress c < wa.lst > aspell-wa-${VER4RPM}/wa.cwl
	tar jcvf aspell-wa-${VER4RPM}.tar.bz2 aspell-wa-${VER4RPM}/
	rm -rf aspell-wa-${VER4RPM}/

###########
# myspell # (deprecated)
##########################################################################
wa_crole_cp1252: walon_lst_cp1252
	grep "'$$" walon.lst | iconv -f cp1252 | sed "s/'$$/’/" | iconv -t cp1252 > wa_crole.lst

myspell: wa_crole_cp1252 wa_affix_dat 
	wc -l walon.lst wa_crole.lst | tail -1 | awk '{ print $$1 }' > wa_myspell.dic
	cat wa_crole.lst walon.lst >> wa_myspell.dic
	# myspell is unable to handle comments and tabs :-(
	grep -av '^#' wa_affix.dat | sed 's/	/    /g' > wa_myspell.aff

myspell_install: myspell
	install -m 644 wa_myspell.aff $(destdir)/usr/share/myspell/wa_BE.aff
	install -m 644 wa_myspell.dic $(destdir)/usr/share/myspell/wa_BE.dic

############
# hunspell #
##########################################################################
hunspell_lst:
	if [ ! -r hunspell.lst -o -n "`find mots* -type f -newer hunspell.lst`" ] ; \
	then \
	  grep -v '^[# 	]' mots*/* ${EXTRA} |cut -d: -f2- |\
	  sed 's/[	]\+/	/g' |\
	  (LC_ALL=C sort -u) | grep -v '^$$' > hunspell.lst ; \
	fi

hunspell_phonet:
	if [ ! -r hunspell.phone -o wa_phonet.dat -nt hunspell.phone ]; \
	then \
	  grep -v '^\($$\|[#a-z \t]\)' wa_phonet.dat |\
	  cut -d'#' -f1|\
	  sed 's/[ \t]\+/ /g' |\
	  iconv -f cp1252 -t utf-8 |\
	  sed 's/^/PHONE /' > hunspell.phone ; \
	fi

hunspell_replace:
	if [ ! -r hunspell.replace -o wa_replace.dat -nt hunspell.replace ]; \
	then \
	  grep '^REP' wa_replace.dat > hunspell.replace ; \
	  grep "^REP.*'" wa_replace.dat | sed "s/'/’/g" >> hunspell.replace ; \
	fi

hunspell_dic: hunspell_lst
	if [ ! -r wa.dic -o hunspell.lst -nt wa.dic ] ; \
	then \
	  wc -l hunspell.lst /dev/null | tail -1 | \
	  	awk '{ print $$1 }'> wa.dic ; \
		cat hunspell.lst >> wa.dic ; \
	fi

hunspell_aff: hunspell_phonet hunspell_replace
	# hunspell is unable to handle comments and tabs :-(
	if [ ! -r wa.aff -o wa_hunspell.aff -nt wa.aff -o \
	       hunspell.replace -nt wa.aff -o \
	       hunspell.phone -nt wa.aff ] ; \
	then \
	  grep -v '^#' wa_hunspell.aff | \
	  	sed 's/[	 ]\+/ /g' > wa.aff ; \
	  echo -n "REP " >> wa.aff ; \
	  wc -l hunspell.replace | awk '{ print $$1 }' >> wa.aff ; \
	  cat hunspell.replace >> wa.aff ; \
	  echo -n "PHONE " >> wa.aff ; \
	  wc -l hunspell.phone | awk '{ print $$1 }' >> wa.aff ; \
	  cat hunspell.phone >> wa.aff ; \
	fi

hunspell: hunspell_aff hunspell_dic

hunspell_firefox: hunspell_aff firefox_dic
	if [ ! -r wa.dic -o wa_firefox.dic -nt wa.dic ] ; \
	then \
	  	cat wa_firefox.dic > wa.dic ; \
	fi

#hunspell_install: hunspell_firefox
hunspell_install: hunspell
	install -m 644 wa.aff $(destdir)/usr/share/hunspell/wa_BE.aff
	install -m 644 wa.dic $(destdir)/usr/share/hunspell/wa_BE.dic

##########
# chrome #
##########################################################################
chrome: hunspell
	./convert_dict wa ; \
	mkdir -p chrome-hunspell-wa ; \
       	tar jxvf chrome.tar.bz2 -C chrome-hunspell-wa
	cp ${LICENCES} chrome-hunspell-wa/license/
	cp Copyright chrome-hunspell-wa/license/license.txt
	cp ./wa.bdic chrome-hunspell-wa/dictionaries/wa-BE.bdic
	perl -pe "s/\@\@VERSION\@\@/$(VERSION)/" -i chrome-hunspell-wa/*.*
	./crxmake.sh chrome-hunspell-wa private.pem $(VERSION)

###########
# firefox #
##########################################################################
firefox_lst: hunspell_lst wa_lst_utf8
	# Firefox doesn't handle apostrophes; we need to cut them :-(
	if [ ! -r wa_firefox.lst -o hunspell.lst -nt wa_firefox.lst ] ; \
	then \
          grep "’$$" hunspell.lst | sed "s/’$$//" > wa_firefox.lst ; \
          grep "'$$" hunspell.lst | sed "s/'$$//" >> wa_firefox.lst ; \
          grep "’[ 	]*\(st\|po\):.*$$" hunspell.lst | sed "s/’[ 	]*..:.*$$//" >> wa_firefox.lst ; \
          grep "'[ 	]*\(st\|po\):.*$$" hunspell.lst | sed "s/'[ 	]*..:.*$$//" >> wa_firefox.lst ; \
        fi

firefox_dic: firefox_lst
	if [ ! -r wa_firefox.dic -o wa_firefox.lst -nt wa_firefox.dic ] ; \
	then \
	  cat wa_firefox.lst hunspell.lst wa.tmp1.lst | \
	  sed 's/[ \t]\+po:.*$$//' | LC_ALL=c sort -u > wa_firefox.tmp.lst ; \
	  wc -l wa_firefox.tmp.lst | tail -1 | \
	  	awk '{ print $$1 }' > wa_firefox.dic ; \
	  cat wa_firefox.tmp.lst >> wa_firefox.dic ; \
	fi

firefox: firefox_dic hunspell_aff
	mkdir -p firefox ; tar jxvf firefox.tar.bz2 -C firefox
	cp ${LICENCES} firefox/license/
	cp Copyright firefox/license/license.txt
	cp wa_firefox.dic firefox/dictionaries/wa-BE.dic
	cp wa.aff firefox/dictionaries/wa-BE.aff
	perl -pe "s/\@\@VERSION\@\@/$(VERSION)/" -i firefox/*.*
	( cd firefox ; zip -r ../walloon_dictionary-$(VERSION)-fx+tb+sm.xpi * )

##########################################################################
clean:
	rm -f core *.stat *.cnt *.txt wa*.dic 
	if [ -d spell-wa-${VERSION}/ ]; then rm -rf spell-wa-${VERSION}/ ; fi

distclean: clean
	rm -f wa.aff wa_BE.aff wa_affix.dat wa_myspell.aff
	rm -f *.lst

dist:	dist.tar.bz2

distdir: distclean
	mkdir spell-wa-${VERSION}
	cp -var mots* extra spell-wa-${VERSION}/
	cp -v ${FILES} spell-wa-${VERSION}/
	mkdir spell-wa-${VERSION}/${ASPELL_TOOLS_DIR}
	cp -var ${ASPELL_TOOLS} spell-wa-${VERSION}/${ASPELL_TOOLS_DIR}/
	mkdir spell-wa-${VERSION}/${LICENCES_DIR}
	cp -var ${LICENCES} spell-wa-${VERSION}/${LICENCES_DIR}/

distdir_dos: wa_lst clean
	mkdir spell-wa-${VERSION}
	cp -var wa.lst extra spell-wa-${VERSION}/
	cp -v ${FILES} spell-wa-${VERSION}/
	cp -v ${FILES_DOS} spell-wa-${VERSION}/
	mkdir spell-wa-${VERSION}/${LICENCES_DIR}
	cp -var ${LICENCES} spell-wa-${VERSION}/${LICENCES_DIR}/

dist.tar.bz2: distdir
	tar jcvf spell-wa-${VERSION}.tar.bz2 spell-wa-${VERSION}/
	rm -rf spell-wa-${VERSION}/

dist.tar.gz: distdir
	tar zcvf spell-wa-${VERSION}.tar.gz spell-wa-${VERSION}/
	rm -rf spell-wa-${VERSION}/

dist.zip: distdir_dos
	zip -r spell-wa-${VERSION}.zip spell-wa-${VERSION}/
	rm -rf spell-wa-${VERSION}/

