#
# makefile for grev
# (c) 1995,96 by Mihai Budiu
#
# This program is subject to Gnu Public License
#

INSTALLDIR = /usr/local
# files will go in ${INSTALLDIR}/bin, ${INSTALLDIR}/man
# and $(INSTALLDIR)/lib/grev/
# one may put here his own home directory

CFLAGS   = -ansi -pedantic -g
CC       = gcc
OBJFILES = tester.o word.o dict.o io.o btree.o #getopt.o
# getopt has to be included only if it is not in the standard library

all: grev freq.dict manual.ascii

grev: $(OBJFILES)
	$(CC) -o grev $(OBJFILES)

getopt.o: getopt.c getopt.h
	$(CC) $(CFLAGS) -c getopt.c

tester.o: tester.c glo.h word.h dict.h io.h params.h
	$(CC) $(CFLAGS)  -c tester.c

dict.o: dict.c dict.h glo.h io.h btree.h 
	$(CC) $(CFLAGS)  -c dict.c
 
word.o: word.c word.h glo.h io.h
	$(CC) $(CFLAGS)  -c word.c

io.o: io.c io.h glo.h
	$(CC) $(CFLAGS)  -c io.c

btree.o: btree.c btree.h 
	$(CC) $(CFLAGS)  -c btree.c

freq.dict: freq words  # Very high frequency words
	join freq words >freq.dict

manual.ascii: grev.1   # Watch out: there is a literal ^H in the next line!
	nroff -man grev.1 | sed s/.//g >manual.ascii

install: all
	cp ./grev ${INSTALLDIR}/bin/grev
	cp ./statistic ${INSTALLDIR}/bin/
	cp ./grev.1 ${INSTALLDIR}/man/man1/grev.1
	if [ \! -e ${INSTALLDIR}/lib/grev ]; then mkdir ${INSTALLDIR}/lib/grev; fi
	cp ./words ./freq ./freq.dict ${INSTALLDIR}/lib/grev
	@echo 
	@echo "The dictionaries are in ${INSTALLDIR}/lib/grev"
	@echo "Each user may (shoud?) make a private copy"

uninstall:
	@echo "Uninstalling 'grev' -- you have 5 seconds to cancel"
	sleep 5
	rm -f ${INSTALLDIR}/bin/grev ${INSTALLDIR}/bin/statistic
	rm -f ${INSTALLDIR}/man/man1/grev.1
	rm -rf ${INSTALLDIR}/lib/grev

clean:
	rm -f *.o core

distclean: clean
	rm -f grev freq.dict manual.ascii 
	cp /dev/null log
# WARNING: freq.dict & manual.ascii are built only on UNIX using
# some utilities; for DOS don't erase them
