ISPELL_TGZ  = /usr/src/redhat/SOURCES/ispell-3.1.20.tar.gz
ELISP_DIR   = /usr/share/emacs/site-lisp

IPATH       = ./ispell-3.1
KITDIR      = ../save-kostya-dict

first:
	@echo "Edit Makefile and local.h; then type 'make all'"

all:    russian.hash russian.aff
	if [ -d $(ELISP_DIR) ] ; then \
	  cd emacs ; make ELISP_DIR=$(ELISP_DIR) ; cd .. ; \
        fi

russian.hash: $(IPATH)/unsq russian.sml russian.aff
	$(IPATH)/buildhash russian.sml russian.aff russian.hash

russian.sml: $(IPATH)/unsq russian.sq.gz
	gzip -dc russian.sq.gz | $(IPATH)/unsq > russian.sml

install: $(IPATH)/unsq russian.hash
	cd $(IPATH) ; make install ; cd ..
	cp russian.hash russian.aff \
	$(shell awk < $(IPATH)/local.h '/LIBDIR/ {print $$3}' | tr -d '"')
	if [ -d $(ELISP_DIR) ] ; then \
	  cd emacs ; make ELISP_DIR=$(ELISP_DIR) install ; cd .. ; \
        fi

$(IPATH): $(ISPELL_TGZ)
	tar xvzf $(ISPELL_TGZ) 

$(IPATH)/local.h: local.h
	make $(IPATH)
	cp local.h $(IPATH)

$(IPATH)/unsq: $(IPATH)/local.h
	cd $(IPATH) ; make ; cd ..

clean:
	rm -f russian.sml* russian.hash makedict
	if [ -d $(IPATH) ] ; then cd $(IPATH) ; make clean ; fi
	cd emacs ; make clean ; cd ..

realclean: 
	if [ -d $(IPATH) ] ; then rm -fr $(IPATH) ; fi
	make clean

russian.aff russian.sq.gz: 
	cp $(KITDIR)/russian.aff .
	$(IPATH)/sq < $(KITDIR)/russian.dic | gzip -9c > russian.sq.gz

makedict: makedict.cxx
	gcc -O6 -o makedict makedict.cxx


