DATA=`date +%Y%m%d`
DICS=eng-s.dic eng-irr.dic eng-np.dic

all:
	@ echo "Make..."
	@ echo "\tjspell - creates the hash file"
	@ echo "\tjspell-install - local old instalation"
	@ echo ""
	@ echo "\tjspell-dist - creates tgz file for Lingua::Jspell"
	@ echo "\tjspell-bin - creates binary distribution"
	@ echo "\tjspell-publish - copies dist and bin to Natura"
	@ echo ""

jspell: eng.hash

eng.dic: $(DICS)
	cat $(DICS) > eng.dic

eng.hash: eng.dic eng.aff
	jbuild eng.dic eng.aff eng.hash

jspell-install: eng.hash eng.yaml
	cp eng.hash `jspell -vv | grep LIBDIR | perl -ane 'if(/"(.*?)"/) {print $$1}' ` 
	cp eng.yaml `jspell -vv | grep LIBDIR | perl -ane 'if(/"(.*?)"/) {print $$1}' ` 

clean: 
	rm -f *.cnt *.stat *.hash eng.dic *.gz
tgz: clean
	mkdir jspell.en-${DATA}
	cp *.aff *.dic *.yaml makefile jspell.en-${DATA}
	tar cfz jspell.en-${DATA}.tar.gz jspell.en-${DATA}
	rm -rf jspell.en-${DATA}

jspell-dist: eng.aff eng.yaml $(DICS)
	mkdir -p jspell.en-$(DATA)
	cp -v eng.aff eng.yaml $(DICS) jspell.en-$(DATA)
	ls -1 jspell.en-$(DATA) > jspell.en-$(DATA)/MANIFEST
	tar zcvf jspell.en-$(DATA).tar.gz jspell.en-$(DATA)
	rm -vrf jspell.en-$(DATA)

jspell-bin: eng.hash
	mkdir jspell.en-$(DATA)-bin32
	cp eng.hash eng.yaml jspell.en-$(DATA)-bin32
	tar zcvf jspell.en-$(DATA)-bin32.tar.gz jspell.en-$(DATA)-bin32
	rm -fr jspell.en-$(DATA)-bin32

jspell-publish: jspell-bin jspell-dist
	scp -C jspell.en-$(DATA)-bin32.tar.gz natura.di.uminho.pt:/home/natura/download/sources/Dictionaries/jspell/
	scp -C jspell.en-$(DATA).tar.gz natura.di.uminho.pt:/home/natura/download/sources/Dictionaries/jspell/
	scp -C jspell.en-$(DATA)-bin32.tar.gz natura.di.uminho.pt:/home/natura/download/sources/Dictionaries/jspell/jspell.en-bin32-latest.tar.gz
	scp -C jspell.en-$(DATA).tar.gz natura.di.uminho.pt:/home/natura/download/sources/Dictionaries/jspell/jspell.en-latest.tar.gz