# -*- Mode: Text -*-
#
# $Id: Makefile,v 1.58 1992/01/10 10:54:06 geoff Exp $
#
# Copyright 1987, 1988, 1989, by Geoff Kuenning, Manhattan Beach, CA
# Permission for non-profit use is hereby granted.
# All other rights reserved.
# See "version.h" for a more complete copyright notice.
#
# $Log: Makefile,v $
# Revision 1.58  1992/01/10  10:54:06  geoff
# Install the sq(1) manual page with the correct extension.
#
# Revision 1.57  1992/01/04  22:08:06  geoff
# Add sq and unsq to BINDIR at installation time, and add the manual
# page for them to MANDIR.  Make the sample german dictionary a bit more
# configurable.  Fix calls to unsq so they don't assume that the current
# directory is in the path.  Add sq and unsq to the clean dependency.
#
# Revision 1.56  91/09/11  23:22:20  geoff
# Add some more foreign-language support, including sample dependencies
# for German.
# 
# Revision 1.55  91/09/04  18:00:44  geoff
# Remove old installed files before copying over them; this may help if
# the owner differs.
# 
# Revision 1.54  91/09/04  17:33:29  geoff
# Make emacs be a variable
# 
# Revision 1.53  91/08/10  14:09:23  geoff
# Add a "defaultdict" target which allows the user to make the chosen
# dictionary without typing a convoluted command line.
# 
# Revision 1.52  91/07/28  20:20:33  geoff
# Fix some silly typos in the dictionary-building stuff
# 
# Revision 1.51  91/07/27  20:48:05  geoff
# Add DICTVARIANTS.  Fix MAKE_SORTTMP to attempt to obey TMPDIR if it
# exists.  Add a warning about /usr/dict/web2's size.  Add zapdups.  Fix
# the emacs installation to work even if getcwd doesn't.  Major changes
# to the way dictionaries are built, adding the BUILD, CBUILD, and
# DBUILD macros to make ispell much easier to install and maintain.  Add
# the "kitclean" and "dictclean" dependencies.
# 
# Revision 1.50  91/07/15  19:26:35  geoff
# Fix the installation of the texinfo file to make use of @setfilename,
# rather than using a dummy file.  Add a TAGS dependency for emacs
# users.
# 
# Revision 1.49  91/07/05  19:51:32  geoff
# Remove some comments that really belong in config.X.  Fix a typo in
# the lint command.
# 
# Revision 1.48  91/07/05  16:48:23  geoff
# Add automatic installation for the emacs support (on systems that
# have emacs)
# 
# Revision 1.47  91/05/27  21:47:49  geoff
# Separate the "make clean" target into a "garbage files" removal and an
# executables removal step.  This will make maintenance a bit simpler.
# 
# Revision 1.46  90/09/06  03:13:03  geoff
# Rename dictionaries to english.{sml,med,lrg}, so that their names aren't
# tied to word counts that change.  Add the makecomponents and makeenglish.?
# dependencies so that dictionary maintenance is under better control.
# 
# Revision 1.45  90/09/05  02:37:29  geoff
# Add a separate "programs" dependency so a make can be done without
# rebuilding the hash file.
# 
# Revision 1.44  90/09/04  01:53:11  geoff
# Change the dictionary names to reflect their actual sizes.  Remove some
# commentary related to development on the Callan, and make the default
# SORTTMP directory be /usr/tmp.
# 
# Revision 1.43  90/04/17  15:30:22  geoff
# Port to NeXT;  also fix a bug in install
# 
# Revision 1.42  89/12/27  03:24:50  geoff
# Add msgs.h
# 
# Revision 1.41  89/07/11  00:17:48  geoff
# Add the three new routines that ispell.c was broken up into:  correct.c,
# defmt.c, and dump.c.  Also add REGLIB.
# 
# Revision 1.40  89/06/09  15:51:08  geoff
# Add support for my new "llint" shell script.
# 
# Revision 1.39  89/04/27  23:51:01  geoff
# Fix the tags dependency to include the yacc grammar file.
# 
# Revision 1.38  89/02/27  02:19:16  geoff
# Instead of creating a null local.h, create it from local.h.samp.
# 
# Revision 1.37  89/02/22  23:23:21  geoff
# Install english.4 in the manual page directory.
# 
# Revision 1.36  88/12/26  02:22:18  geoff
# Add a copyright notice.  Make a couple of minor improvements to the
# commentary.  Warn about the inaccuracies in english.92k.
# 
# Revision 1.35  88/11/25  19:50:04  geoff
# Make the LIBES macro correct for this installation (oversight in last
# change).
# 
# Revision 1.34  88/11/16  02:19:04  geoff
# Add comments about how to build foreign hash files, and the LIBES
# macro.  Rename the "plus" dictionaries to take out the "k", for name
# length reasons.  Change the dictionary-making dependencies to require
# explicit invocation, rather than remaking the dictionaries whenever
# anything else is remade.  Add dependencies to make all hash files.  Change
# the making of the "k" dictionaries to use sort, instead of munchlist, so
# they run faster.  Add a dependency that creates a null local.h if none
# exists.
# 
# Revision 1.33  88/04/30  22:11:36  geoff
# Add the lint dependency.
# 
# Revision 1.32  88/04/11  01:32:34  geoff
# Add icombine and sq/unsq to the munchable list.  Change the dictionary
# builds so that they unsqueeze the distributed dictionaries.
# 
# Revision 1.31  88/03/27  00:55:28  geoff
# Add icombine back in.
# 
# Revision 1.30  88/03/12  02:42:14  geoff
# Correct a hardwired usage of cc to use the macro.
# 
# Revision 1.29  88/02/20  23:09:09  geoff
# Drop icombine, and add tryaffix.  Numerous other changes to support
# the new "makedent" module and the new capitalization format.  Add a
# tags dependency.
# 
# Revision 1.28  87/09/26  15:52:11  geoff
# Add EXTRADICT, the "munchable" dependency, subset.X, and the
# dictionary-making dependencies.
# 
# Revision 1.27  87/09/14  22:58:20  geoff
# Add buildhash to the install list
# 
# Revision 1.26  87/09/09  00:14:59  geoff
# Fix a couple of typos, and install findaffix in BINDIR.
# 
# Revision 1.25  87/09/03  19:22:43  geoff
# Make objects depend on local.h
# 
# Revision 1.24  87/09/03  17:32:04  geoff
# Add dependencies to run munchlist and fixdict
# 
# Revision 1.23  87/09/02  21:56:54  geoff
# Install icombine in LIBDIR
# 
# Revision 1.22  87/08/28  21:19:38  geoff
# Change the argument order for buildhash.
# 
# Revision 1.21  87/07/20  23:20:08  geoff
# Simplify some comments, and add SORTTMP.  Change the hash file name
# to reflect the language.  Add support for the modules involved in
# table-driving.  Dump isexpand and the four sed scripts.  Add findaffix.
# 
# Revision 1.20  87/06/27  12:18:40  geoff
# Add some more stuff to the make clean list (Michael Wester).
# 
# Revision 1.19  87/06/07  14:50:33  geoff
# Integrate Gary Johnson's suggestions into the main branch
# 
# Revision 1.18  87/06/07  14:17:54  geoff
# Add patch2's comments, also some comments to try to prevent another posting
# that has CC defined to lcc
# 
# Revision 1.17  87/05/30  16:54:22  geoff
# Add support for the ispell.4 man page.
# 
# Revision 1.16  87/05/27  23:34:25  geoff
# Add TERMLIB to the what-to-change list
# 
# Revision 1.15  87/05/25  21:58:15  geoff
# Make ispell.o depend on version.h
# 
# Revision 1.14  87/05/25  21:09:42  geoff
# Add xgets to the source list.
# 
# Revision 1.13  87/05/18  00:21:55  geoff
# Add isexpand.
# 
# Revision 1.12  87/04/19  22:50:33  geoff
# Make things depend on more header files.
# 
# Revision 1.11  87/04/01  17:38:42  geoff
# Build ispell shared-text
# 
# Revision 1.10  87/03/28  22:40:33  geoff
# Document the need for -DUSG
# 
# Revision 1.9  87/03/27  17:20:13  geoff
# Add icombine and munchlist.
# 
# Revision 1.8  87/03/26  00:30:17  geoff
# Integrate Rich Salz's changes/improvements
# 
# Revision 1.7  87/03/22  23:55:58  geoff
# Fix minor bugs found by Dave Mason
# 
# Revision 1.6  87/03/10  23:46:55  geoff
# Add munchlist and expand to the install dependency
# 
# Revision 1.5  87/02/28  00:59:17  geoff
# Add CC, long cc support, SHELL, and header file dependencies
# 
# Revision 1.4  87/02/26  00:53:32  geoff
# Integrate McQueer's and Ries's changes into the main branch,
# including changes needed to make it run on my system, and one
# bug fix (in the chmod command for make install).
# 
# Revision 1.3  87/01/19  00:05:22  geoff
# Modify to work on System V and with my pathnames.
# 
# Revision 1.2  87/01/17  13:11:14  geoff
# Add RCS ID keywords
# 
#

# Look over config.X before building.
#
# You will probably want to edit where it says "EDIT HERE" below;
# the Makefile will update all other files to match.
#
# If you want to build non-English hash files, search for the string
# "foreignhashes" and add command lines there.
#
# the argument syntax for buildhash to make alternate dictionary files
# is simply:
#
#   buildhash <dictfile> <affix-file> <outfile>

# EDIT HERE
#
CC = cc
EMACS = emacs
LINT = lint
DEFINES =
CFLAGS = -O $(DEFINES)
LINTFLAGS = $(DEFINES)
#
# If you need any special libraries to get things to link, put them here.
#
LIBES =
#
# BINDIR - where to install user-executable binaries
#
# Don't forget CC above!
BINDIR = /usr/local/bin
#
# LIBDIR - where library files (notably the hash file) go.
#
LIBDIR = /usr/local/lib
#
# EMACSDIR - where emacs files go
#
EMACSDIR = /usr/lib/emacs
ELISPDIR = $(EMACSDIR)/lisp
TEXINFODIR = $(EMACSDIR)/info
#
# DEFHASH - default name for the hash file
# FOREIGNHASHES - list of other hash files
#
DEFHASH = english.hash
#FOREIGNHASHES = german.hash
FOREIGNHASHES =
#
# DEFLANG - default language file to use when building DEFHASH
# FOREIGNLANGS - list of other language files to use when building
# FOREIGNHASHES.
#
DEFLANG	= english.aff
#FOREIGNLANGS = german.aff
FOREIGNLANGS =
#
# DEFDICT - default dictionary to use to build DEFHASH.  Choices, in
# approximate order of increasing size: english.sml, english.sml+,
# english.med, english.med+, english.lrg, english.lrg+.  Note that larger
# dictionaries increase ispell's startup time.
#
# Note that making the "+" dictionaries requires LOTS of temp file space
# (in either /usr/tmp or wherever your environment variable TMPDIR points).
# The biggest, "english.lrg+", takes up to 30000 blocks of temp file space
# to create.  (By contrast, the non-"+" versions take temp space of about
# twice the size of the completed dictionary, except for "sml", which needs
# no temp space at all).
#
# Also, you should be aware that the two smaller dictionaries are much more
# accurate than the "lrg" and "lrg+" dictionaries.  The smaller dictionaries
# have been checked for errors and are believed to be error-free, but the
# ones based on "english.lrg" are known to contain spelling errors.  Because
# of the nature of ispell, these errors are not fatal flaws, but you should
# still be aware that they exist and be suspicious of the "lrg*" dictionaries.
#
# FOREIGNDICTS - list of foreign dictionaries.
#
DEFDICT = english.med+
#FOREIGNDICTS = german.med
FOREIGNDICTS =
GERMANDICTS = german.0
#
# DICTVARIANTS - variants of the English dictionary that are desired.
# Choose from "british", "american", or "altamer".  (The latter is an
# extension to the American dictionary, with alternate spellings, and
# should be used together with the American list).  It is possible to
# include all three variants, or to add your own, if you wish.
# British users should be a bit suspicious of the British lists,
# especially the larger ones, as the final versions were compiled by
# an American.
#
DICTVARIANTS = american altamer
#
# EXTRADICT - system dictionary (dictionaries) to be included with
# the distributed dictionaries to make the "+" versions above.  Usually
# /usr/dict/words, /usr/dict/web2, or both.  (Warning:  /usr/dict/web2 is
# extremely big.  You don't want it in most cases.)
#
EXTRADICT = /usr/dict/words
#
# MAN1DIR - where chapter-1 man pages go
#
MAN1DIR	= /usr/local/man/man1
#
# MAN4DIR - where chapter-4 man pages go
#
MAN4DIR	= /usr/local/man/man4
#
# MAN1EXT - what extension to put on chapter-1 man pages
#
MAN1EXT	= .1
#
# MAN4EXT - what extension to put on chapter-4 man pages
#
MAN4EXT	= .4
#
# TERMLIB - where to get the termcap library.  Should be -ltermcap or -lcurses
# on most systems.
#
# TERMLIB = -lcurses
TERMLIB = -ltermcap
#
# REGLIB - where to get the regular-expression routines, if SYSTEM_LOOKUP is
# not defined.  Should be -lPW on USG systems, null (I think) on BSD systems.
#
REGLIB =
#
# If your sort command accepts the -T switch to set temp file locations
# (try it out;  it exists but is undocumented on some systems), make the
# following variable null.  Otherwise make it the sed script.
#
#SORTTMP = -e '/!!SORTTMP!!/s/=.*$$/=/'
SORTTMP =
#
# If your sort command accepts the -T switch (see above), make the following
# variable refer to a temporary directory with lots of space.  Otherwise
# make it null.
#
MAKE_SORTTMP = -T $${TMPDIR-/usr/tmp}
#
#	END OF EDITING
#
SHELL = /bin/sh

all: programs ispell.info
all: $(DEFHASH)
all: foreignhashes

programs: buildhash findaffix tryaffix fixdict ispell icombine munchlist
programs: subset sq unsq zapdups

$(DEFHASH): buildhash $(DEFDICT) $(DEFLANG)
	./buildhash $(DEFDICT) $(DEFLANG) $(DEFHASH)

#
# The following target provides an easy way to rebuild your default
# dictionary when you wish to do so.  This dependency isn't all that
# smart, but it tries to handle the possibility that you might have
# run "make dictclean" or "make kitclean".
#
defaultdict:
	if [ -r english.0 ]; then \
	    $(MAKE) DBUILD= $(DEFDICT); \
	else \
	    $(MAKE) BUILD= $(DEFDICT); \
	fi

install: all
	cd $(BINDIR); rm -f ispell buildhash munchlist findaffix tryaffix
	cp ispell buildhash munchlist findaffix tryaffix sq unsq $(BINDIR)
	cd $(LIBDIR); rm -f $(DEFHASH) $(DEFLANG) $(FOREIGNHASHES) \
	  $(FOREIGNLANGS) icombine
	cp $(DEFHASH) $(DEFLANG) $(FOREIGNHASHES) $(FOREIGNLANGS) icombine \
	  $(LIBDIR)
	chmod 755 $(LIBDIR)/icombine $(BINDIR)/ispell $(BINDIR)/munchlist \
	  $(BINDIR)/findaffix $(BINDIR)/tryaffix $(BINDIR)/buildhash \
	  $(BINDIR)/sq $(BINDIR)/unsq
	cd $(LIBDIR); chmod 644 $(DEFHASH) $(DEFLANG) \
	  $(FOREIGNHASHES) $(FOREIGNLANGS)
	rm -f $(MAN1DIR)/ispell$(MAN1EXT) $(MAN4DIR)/ispell$(MAN4EXT) \
	  $(MAN4DIR)/english$(MAN4EXT)
	cp ispell.1 $(MAN1DIR)/ispell$(MAN1EXT)
	cp sq.1 $(MAN1DIR)/sq$(MAN1EXT)
	cp ispell.4 $(MAN4DIR)/ispell$(MAN4EXT)
	cp english.4 $(MAN4DIR)/english$(MAN4EXT)
	if [ -d $(ELISPDIR) ]; then \
	    rm -f $(TEXINFODIR)/ispell $(ELISPDIR)/ispell.el; \
	    cp ispell.info $(TEXINFODIR)/ispell; \
	    chmod 644 $(TEXINFODIR)/ispell; \
	    cp ispell.el $(ELISPDIR); \
	    echo '(byte-compile-file "$(ELISPDIR)/ispell.el")' \
	      > /tmp/emi$$$$; \
	    $(EMACS) -batch $(ELISPDIR)/ispell.el -l /tmp/emi$$$$; \
	    rm -f /tmp/emi$$$$; \
	    chmod 644 $(ELISPDIR)/ispell.el $(ELISPDIR)/ispell.elc; \
	fi

ispell.info:	ispell.texinfo
	if [ -d $(ELISPDIR) ]; then \
	    $(EMACS) -batch dummy -i ispell.texinfo \
	      -f texinfo-format-buffer -f save-buffer; \
	    rm -f ispell.info~; \
	fi

fix-dictionary:	all
	PATH=:$$PATH sh fixdict $(DEFDICT)

munchable:	findaffix tryaffix munchlist buildhash ispell icombine sq unsq

munch-dictionary:	munchable
	PATH=:$$PATH munchlist -l $(DEFLANG) $(DEFDICT)

#
#	Dependencies to build extra hash files
#
allhashes:	normhashes plushashes foreignhashes
normhashes:	sml.hash med.hash lrg.hash
plushashes:	sml+.hash med+.hash lrg+.hash

#
#	Add dependencies here to build non-English hash files.
#
foreignhashes: $(FOREIGNHASHES)

german.hash:	buildhash german.aff german.med
	rm -f german.hash
	if [ "$(DEFDICT)" = german.med ]; then \
	    make $(DEFHASH); ln $(DEFHASH) $@; \
	else \
	    ./buildhash german.med german.aff $@; \
	fi

$(DBUILD)german.med:	munchable $(GERMANDICTS)
	PATH=:$$PATH munchlist -l german.aff $(GERMANDICTS) > german.med

#
# Note that we don't use $(MAKE) in the following dependencies.  There
# is a good reason for this -- if we did, "make -n" would still run buildhash.
#
sml.hash:	buildhash english.aff english.sml
	rm -f sml.hash
	if [ "$(DEFDICT)" = english.sml ]; then \
	    make $(DEFHASH); ln $(DEFHASH) $@; \
	else \
	    ./buildhash english.sml english.aff $@; \
	fi

sml+.hash:	buildhash english.aff english.sml+
	rm -f sml+.hash
	if [ "$(DEFDICT)" = english.sml+ ]; then \
	    make $(DEFHASH); ln $(DEFHASH) $@; \
	else \
	    ./buildhash english.sml+ english.aff $@; \
	fi

med.hash:	buildhash english.aff english.med
	rm -f med.hash
	if [ "$(DEFDICT)" = english.med ]; then \
	    make $(DEFHASH); ln $(DEFHASH) $@; \
	else \
	    ./buildhash english.med english.aff $@; \
	fi

med+.hash:	buildhash english.aff english.med+
	rm -f med+.hash
	if [ "$(DEFDICT)" = english.med+ ]; then \
	    make $(DEFHASH); ln $(DEFHASH) $@; \
	else \
	    ./buildhash english.med+ english.aff $@; \
	fi

lrg.hash:	buildhash english.aff english.lrg
	rm -f lrg.hash
	if [ "$(DEFDICT)" = english.lrg ]; then \
	    make $(DEFHASH); ln $(DEFHASH) $@; \
	else \
	    ./buildhash english.lrg english.aff $@; \
	fi

lrg+.hash:	buildhash english.aff english.lrg+
	rm -f lrg+.hash
	if [ "$(DEFDICT)" = english.lrg+ ]; then \
	    make $(DEFHASH); ln $(DEFHASH) $@; \
	else \
	    ./buildhash english.lrg+ english.aff $@; \
	fi

#
#	The six dictionaries, english.sml through english.lrg+, are built
#	by the following dependencies.  The macros "CBUILD" and
#	"DBUILD" are a sneaky trick used to keep make from trying to
#	run munchlist every time a minor change is made to one of the
#	C programs.  If you define these macros as null, "make all"
#	will automatically build the dictionaries.  If you leave them
#	with their default definitions, "make all" will leave the
#	dictionaries alone, and you will have to type something like
#	"make buildenglish.med+" to build the dictionary using
#	munchlist.
#
#	Why two macros?  So you can delete {eng,amer,altamer,brit}.[012].??
#	to save space, and still type "make DBUILD= all".
#
#	The following dependencies are convenient ways to make some or
#	all of the dictionaries.
#
BUILD	=	build
CBUILD	=	$(BUILD)
DBUILD	=	$(BUILD)

alldicts:	normdicts plusdicts
normdicts:	$(DBUILD)english.sml $(DBUILD)english.med $(DBUILD)english.lrg
plusdicts:	$(DBUILD)english.sml+ $(DBUILD)english.med+
plusdicts:	$(DBUILD)english.lrg+

dictcomponents:	$(CBUILD)english.0 $(CBUILD)english.1 $(CBUILD)english.2
dictcomponents: $(CBUILD)american.0 $(CBUILD)american.1 $(CBUILD)american.2
dictcomponents: $(CBUILD)altamer.0 $(CBUILD)altamer.1 $(CBUILD)altamer.2
dictcomponents: $(CBUILD)british.0 $(CBUILD)british.1 $(CBUILD)british.2

$(CBUILD)english.0:	unsq eng.0.??
	cat eng.0.?? | ./unsq > english.0

$(CBUILD)english.1:	unsq eng.1.??
	cat eng.1.?? | ./unsq > english.1

$(CBUILD)english.2:	unsq eng.2.??
	cat eng.2.?? | ./unsq > english.2

$(CBUILD)american.0:	unsq amer.0.??
	cat amer.0.?? | ./unsq > american.0

$(CBUILD)american.1:	unsq amer.1.??
	cat amer.1.?? | ./unsq > american.1

$(CBUILD)american.2:	unsq amer.2.??
	cat amer.2.?? | ./unsq > american.2

$(CBUILD)altamer.0:	unsq altamer.0.??
	cat altamer.0.?? | ./unsq > altamer.0

$(CBUILD)altamer.1:	unsq altamer.1.??
	cat altamer.1.?? | ./unsq > altamer.1

$(CBUILD)altamer.2:	unsq altamer.2.??
	cat altamer.2.?? | ./unsq > altamer.2

$(CBUILD)british.0:	unsq brit.0.??
	cat brit.0.?? | ./unsq > british.0

$(CBUILD)british.1:	unsq brit.1.??
	cat brit.1.?? | ./unsq > british.1

$(CBUILD)british.2:	unsq brit.2.??
	cat brit.2.?? | ./unsq > british.2

$(DBUILD)english.sml:	english.0 american.0 altamer.0 british.0
	dicts="english.0"; \
	    for i in $(DICTVARIANTS); do \
		dicts="$$dicts $$i.0"; \
	    done; \
	    set -x; \
	    sort -u -t/ +0f -1 +0 $(MAKE_SORTTMP) -o english.sml $$dicts

$(DBUILD)english.sml+:	munchable $(EXTRADICT)
$(DBUILD)english.sml+:	english.0 american.0 altamer.0 british.0
	dicts="english.0 $(EXTRADICT)"; \
	    for i in $(DICTVARIANTS); do \
		dicts="$$dicts $$i.0"; \
	    done; \
	    set -x; \
	    PATH=:$$PATH munchlist -l $(DEFLANG) $$dicts > english.sml+

$(DBUILD)english.med:	english.0 american.0 altamer.0 british.0
$(DBUILD)english.med:	english.1 american.1 altamer.1 british.1
	dicts="english.0 english.1"; \
	    for i in $(DICTVARIANTS); do \
		dicts="$$dicts $$i.0 $$i.1"; \
	    done; \
	    set -x; \
	    sort -u -t/ +0f -1 +0 $(MAKE_SORTTMP) -o english.med $$dicts

$(DBUILD)english.med+:	munchable $(EXTRADICT)
$(DBUILD)english.med+:	english.0 american.0 altamer.0 british.0
$(DBUILD)english.med+:	english.1 american.1 altamer.1 british.1
	dicts="english.0 english.1 $(EXTRADICT)"; \
	    for i in $(DICTVARIANTS); do \
		dicts="$$dicts $$i.0 $$i.1"; \
	    done; \
	    set -x; \
	    PATH=:$$PATH munchlist -l $(DEFLANG) $$dicts > english.med+

$(DBUILD)english.lrg:	english.0 american.0 altamer.0 british.0
$(DBUILD)english.lrg:	english.1 american.1 altamer.1 british.1
$(DBUILD)english.lrg:	english.2 american.2 altamer.2 british.2
	dicts="english.0 english.1 english.2"; \
	    for i in $(DICTVARIANTS); do \
		dicts="$$dicts $$i.0 $$i.1 $$i.2"; \
	    done; \
	    set -x; \
	    sort -u -t/ +0f -1 +0 $(MAKE_SORTTMP) -o english.lrg $$dicts

$(DBUILD)english.lrg+:	munchable $(EXTRADICT)
$(DBUILD)english.lrg+:	english.0 american.0 altamer.0 british.0
$(DBUILD)english.lrg+:	english.1 american.1 altamer.1 british.1
$(DBUILD)english.lrg+:	english.2 american.2 altamer.2 british.2
	dicts="english.0 english.1 english.2 $(EXTRADICT)"; \
	    for i in $(DICTVARIANTS); do \
		dicts="$$dicts $$i.0 $$i.1 $$i.2"; \
	    done; \
	    set -x; \
	    PATH=:$$PATH munchlist -l $(DEFLANG) $$dicts > english.lrg+

buildhash: buildhash.o hash.o makedent.o parse.o
	$(CC) $(CFLAGS) -o buildhash buildhash.o hash.o makedent.o parse.o \
	  $(LIBES)

icombine: icombine.o makedent.o parse.o
	$(CC) $(CFLAGS) -o icombine icombine.o makedent.o parse.o \
	  $(LIBES)

EDITFILE	=	notthere
OUTFILE		=	/dev/null

doedit:
	sed -e 's@!!LIBDIR!!@$(LIBDIR)@' -e 's@!!DEFDICT!!@$(DEFDICT)@' \
	    -e 's@!!DEFHASH!!@$(DEFHASH)@' -e 's@!!DEFLANG!!@$(DEFLANG)@' \
	    $(SORTTMP) < $(EDITFILE) > $(OUTFILE)

findaffix:	findaffix.X Makefile
	@$(MAKE) EDITFILE=findaffix.X OUTFILE=findaffix doedit
	chmod +x findaffix

fixdict:	fixdict.X Makefile
	@$(MAKE) EDITFILE=fixdict.X OUTFILE=fixdict doedit
	chmod +x fixdict

munchlist:	munchlist.X Makefile
	@$(MAKE) EDITFILE=munchlist.X OUTFILE=munchlist doedit
	chmod +x munchlist

subset:	subset.X Makefile
	@$(MAKE) EDITFILE=subset.X OUTFILE=subset doedit
	chmod +x subset

tryaffix:	tryaffix.X Makefile
	@$(MAKE) EDITFILE=tryaffix.X OUTFILE=tryaffix doedit
	chmod +x tryaffix

zapdups:	zapdups.X Makefile
	@$(MAKE) EDITFILE=zapdups.X OUTFILE=zapdups doedit
	chmod +x zapdups

OBJS	=	ispell.o correct.o defmt.o dump.o good.o lookup.o hash.o \
		makedent.o term.o tgood.o tree.o xgets.o

ispell: $(OBJS)
	$(CC) $(CFLAGS) -o ispell $(OBJS) $(TERMLIB) $(REGLIB) $(LIBES)

$(OBJS) buildhash.o icombine.o hash.o parse.o: config.h ispell.h local.h msgs.h
ispell.o: version.h

config.h:	config.X Makefile
	@$(MAKE) EDITFILE=config.X OUTFILE=config.h doedit

#	Create a sample local.h if no such file currently exists
local.h:
	[ -r local.h ]  ||  cp local.h.samp local.h

tags:	config.h *.[chy]
	ctags -w -t *.[chy]
	sed -e s/config.h/config.X/ tags > ntags
	mv ntags tags

TAGS:	config.h *.[chy]
	etags -t *.[chy]
	sed -e s/config.h/config.X/ TAGS > NTAGS
	mv NTAGS TAGS

lint:	config.h ispell.h msgs.h *.[cy]
	@$(LINT) $(LINTFLAGS) ispell.c correct.c defmt.c dump.c good.c \
	    hash.c lookup.c makedent.c tgood.c term.c tree.c xgets.c
	@yacc parse.y
	@$(LINT) $(LINTFLAGS) buildhash.c hash.c makedent.c y.tab.c
	@$(LINT) $(LINTFLAGS) icombine.c makedent.c y.tab.c
	@rm -f y.tab.c

clean:
	rm -f *.o core a.out mon.out hash.out \
		*.stat *.cnt config.h $(DEFHASH) $(FOREIGNHASHES)
	rm -f buildhash findaffix tryaffix fixdict ispell icombine \
		munchlist subset sq unsq zapdups

#
#	The following target allows you to clean out the leftover raw
#	files gotten from unpacking the kit.  It makes sure that you
#	have the combined files first, so it may take a little while
#	to run.
#
kitclean:
	$(MAKE) dictcomponents
	rm -f eng.[012].?? amer.[012].?? altamer.[012].?? brit.[012].??

#
#	The following target allows you to clean out the combined
#	dictionary files.  For safety, so you don't lose your files,
#	it makes sure that there is something to work from, but it can
#	only be so smart, so be careful!
#
dictclean:
	rm -f english.sml english.sml+ english.med english.med+
	rm -f english.lrg english.lrg+
	ok=yes; \
	    for i in eng amer altamer brit; do \
		for j in 0 1 2; do \
		    [ -r $$i.$$j.aa ]  ||  ok=no; \
		done; \
	    done; \
	    if [ $$ok = yes ]; then \
		rm -f english.[012] american.[012]; \
		rm -f altamer.[012] british.[012]; \
	    fi
