#
# $Id: Makefile,v 1.10 2003/08/23 10:56:33 ed Exp $
#
# Copyright 1993, 2001, Geoff Kuenning, Claremont, CA
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
# 3. All modifications to the source code must be clearly marked as
#    such.  Binary redistributions based on modified source code
#    must be clearly marked as modified versions in the documentation
#    and/or other materials provided with the distribution.
# (clause 4 removed with permission from Geoff Kuenning)
# 5. The name of Geoff Kuenning may not be used to endorse or promote
#    products derived from this software without specific prior
#    written permission.
#
# THIS SOFTWARE IS PROVIDED BY GEOFF KUENNING AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED.  IN NO EVENT SHALL GEOFF KUENNING OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
# This Makefile is an example of how to build dictionaries for a
# complex language with many variants.  It supports both American and
# British English and four dictionary source files, and will build up
# to 8 dictionares from those 4 files by combining them with an
# optional installation-specific file.
#
# If you are building a new Makefile for your own language, this is
# probably not the right place to start.  Instead, you should select
# the "deutsch" Makefile, which is moderately complex, or one of the
# simple Makefiles for another language distributed with ispell.
#
# $Log: Makefile,v $
# Revision 1.10  2003/08/23 10:56:33  ed
# Purging my old email address.
#
# Revision 1.9  2002/09/02 22:45:22  ed
# Building the *.words files requires a working ispell, and for that you
# need a dictionary hash file.  Rather than add a dependency across
# directories we just prompt the user to symlink english.hash into the
# current directory.  (Good enough since this is a developers' facility
# anyway.)
#
# Also, building the files will now stop at the first error instead of
# continuing regardless.
#
# Revision 1.8  2002/06/15 11:39:19  ed
# Added a possible test for _all_ duplicates to the Makefile, but it's
# commented out at the moment.  This meant making the *.words files have
# duplicate lines when the same word can be generated two ways.
#
# Revision 1.7  2002/06/15 11:27:57  ed
# To check for 'obvious duplicates' (same base word appearing in two
# files) wrote a Perl script check_dups and a new 'check' target which
# runs it.
#
# Using this tool, removed duplicates from some of the lists, and words which
# were common to american and british have moved into english.  The generated
# dictionaries are the same, apart from 'whiskies' no longer being allowed
# in american (since 'whisky' is not).
#
# Revision 1.6  2002/06/05 21:18:06  ed
# When generating *.words, put one word per line and remove duplicates.
# These files are now removed by 'make clean'.
#
# Revision 1.5  2002/06/05 20:05:24  ed
# New 'words' target builds lists of all words in the various dictionaries.
# I plan to use this for testing my changes, looking at which words have
# been added to and removed from each dictionary.
#
# Revision 1.4  2001/10/16 16:55:58  ed
# Merged some more of SuSE's ispell-3.2.06-config.patch: the wordlist is
# in /usr/share/dict/ rather than /usr/dict/.  I changed this in all
# documentation, but the manual page ought to use the WORDS
# configuration variable rather than anything hardcoded.  Extended
# test_inst to check filenames mentioned in manual pages.
#
# Revision 1.3  2001/10/16 15:14:18  ed
# Merged some more patches from SuSE's ispell-3.2.06 package: parts of
# ispell-3.2.06-languages.patch.  This is to make the manual pages have
# the correct section (file formats go in section 5 not 4) and have
# correct cross-references (no xref to tib (1) or spell (1), which are
# not installed on SuSE).  I parameterized these changes as things in
# config.X.
#
# Makefile: Fixed bug creating directories by using mkdir -p instead of plain
# mkdir.  But -p isn't supported on all Unixes, so this is parameterized
# as the MKDIR variable.  Perhaps this should be a variable in config.X
# rather than the Makefile itself - but I don't know how to do that.
# Added ispell.5 as a target, it is generated from ispell.5X by applying
# substitutions.  This replaces the old ispell.4 which was installed
# as-is.
#
# Two new substitution variables TIB_XREF and SPELL_XREF are used in
# manual pages for making cross-references to tib and spell.  They
# should be defined as a fragment of troff code (ie, text) to be
# included in manual pages.  For example, TIB_XREF might be defined as
# 'tib (1)'.
#
# The section for file format manual pages is controlled by MANFFSECT,
# previously it was hardcoded as 4.  MANFFDIR and MANFFEXT replace
# MAN4DIR and MAN4EXT respectively.
#
# The target install-deformatters no longer calls a recursive Makefile
# inside the deformatters/ directory.  Instead the commands to build
# these two programs are included in the top-level Makefile.  Ditto
# clean-deformatters.
#
# To test the changes to installation, there is a new program test_inst
# which sets some variables in local.h, runs make install, and checks
# the installed files.  It concentrates on making sure the manual pages
# are okay, reading them and checking cross-references.  test_inst is
# now the last target of 'make test'.
#
# Dropped support for manual section 1L (local); now the executable
# commands go in plain old section 1.  It could be added back in using a
# similar mechanism to the section 4 / 5 choice if it is still needed.
#
# The Makefiles for the individual languages have also been changed to
# use MKDIR, and bugfixed to work when LIBDIR is a relative path.
# Previously, Makefiles in subdirectories would do 'cd $$LIBDIR', but
# that will fail if LIBDIR is something like '../install'.  They now go
# through some contortions to keep working whether LIBDIR is relative or
# absolute.  There is a lot of duplicated code across the language
# directories, it would be better factored out.  The english Makefile
# now builds the english.5 manual page by applying substitutions from
# english.5X, and its variants (altamer, american and british) now call
# english/Makefile to make this page and for 'make clean'.
#
# Revision 1.2  2001/10/05 14:22:30  ed
# Imported 3.2.06.epa1 release.  This was previously developed using
# sporadic RCS for certain files, but I'm not really bothered about
# rolling back beyond this release.
#
# Revision 1.26  2001/07/25 21:51:47  geoff
# *** empty log message ***
#
# Revision 1.25  2001/07/23 20:43:37  geoff
# *** empty log message ***
#
# Revision 1.24  1999/01/07 01:23:16  geoff
# Update the copyright.  Get rid of the old shar-based dictioary building.
#
# Revision 1.23  1995/08/05  23:19:50  geoff
# Add tests to detect and suppress accidentally-generated zero-length
# dictionaries.
#
# Revision 1.22  1994/08/31  05:58:43  geoff
# Create directories before installing into them, and be sure to set the
# proper modes on manual pages.
#
# Revision 1.21  1994/05/25  04:29:30  geoff
# Get rid of all references to DEFHASH and defhash.
#
# Revision 1.20  1994/05/24  04:47:33  geoff
# Work around an RS-6000 shell deficiency in environment setting
#
# Revision 1.19  1994/05/17  06:37:36  geoff
# Fix the remove-on-abort code for the derived dictionaries to be more
# robust.
#
# Revision 1.18  1994/02/23  04:52:30  geoff
# Remove dictionaries being built if make is aborted early.
#
# Revision 1.17  1994/02/22  06:09:06  geoff
# Add SHELLDEBUG.
#
# Revision 1.16  1994/02/13  23:55:20  geoff
# Get rid of the temporary line that zapped "english..4" for people who
# had 3.1.00.
#
# Revision 1.15  1994/02/07  08:01:57  geoff
# Allow multiple variants and extradicts
#
# Revision 1.14  1994/02/07  07:08:10  geoff
# Install english.4 with the right name, removing the wrong one if it exists
#
# Revision 1.13  1994/02/07  06:18:18  geoff
# Add dummy else clauses to shell tests to handle Ultrix problems.  Add an
# eval to all sort commands to make sure that MAKE_SORTTMP is handled
# correctly on all systems.
#
# Revision 1.12  1994/01/25  08:50:34  geoff
# Get rid of all old RCS log lines in preparation for the 3.1 release.
#
#

SHELL = /bin/sh
MAKE = make
MKDIR = mkdir -p

CONFIG		=	../../config.sh
PATHADDER	=	../..
BUILDHASH	=	../../buildhash

# The following variables should be set by the superior Makefile,
# based on the LANGUAGES variable in config.X.
#
# There are four progressively-larger English dictionaries distributed
# with ispell.  These are named english.sml, english.med, english.lrg,
# and english.xlg.  For each of these, you can also build a "plus"
# version (english.sml+, etc.)  which is created by combining the
# distributed version with an "extra" dictionary defined by EXTRADICT,
# usually /usr/share/dict/words.  The "plus" versions of dictionaries
# require lots of time and temporary file space; make sure you have
# set TMPDIR appropriately.
#
# The dictionaries to be built are listed in the MASTERDICTS variable,
# separated by spaces.  The hash files to be built (and installed) are
# listed in the HASHFILES variable.  Hash files are named by taking
# the suffix of the dictionary (e.g., "med+"), and adding ".hash".  As
# a general rule, the dictionaries needed to build the HASHFILES must
# be listed in the MASTERDICTS variable.
#
# British/American variants are supported by the VARIANTS variable.
# You should set VARIANTS to one of "american", "british", or
# "altamer".  The latter is a file of alternate American spellings,
# often British-derived.  I recommend against its use.  I also
# recommend against selecting more than one variant, because it tends
# to cause inconsistent or incorrect spellings to be hidden, although
# there is nothing to prevent such an unwise decision.
#
# If you change AFFIXES for english, you should consider also changing
# DEFLANG (in config.X) to match.
#
MASTERDICTS	=	Use_LANGUAGES_from_config.X
HASHFILES	=	Use_LANGUAGES_from_config.X
VARIANTS	=	Use_LANGUAGES_from_config.X
EXTRADICT	=	Use_LANGUAGES_from_config.X

#
# The following variables may be overridden by the superior Makefile,
# based on the LANGUAGES variable in config.X.
#
AFFIXES	=	english.aff

#
#	Set this to "-vx" in the make command line if you need to
#	debug the complex shell commands.
#
SHELLDEBUG = +vx

all:  $(CONFIG) english.5
	@set $(SHELLDEBUG); \
	if [ ! -r english.0 ]; \
	then \
	    $(MAKE) SHELLDEBUG=$(SHELLDEBUG) CBUILD= dictcomponents; \
	else \
	    : ; \
	fi
	@set $(SHELLDEBUG); \
	for dict in $(MASTERDICTS); do \
	    if [ ! -r $$dict ]; \
	    then \
		$(MAKE) DBUILD= 'VARIANTS=$(VARIANTS)' \
		  'EXTRADICT=$(EXTRADICT)' \
		  SHELLDEBUG=$(SHELLDEBUG) $$dict; \
	    else \
		: ; \
	    fi; \
	done
	$(MAKE) SHELLDEBUG=$(SHELLDEBUG) $(HASHFILES)

# Note the fooling around with LIBDIR.  It might be a relative path,
# relative to the top of the ispell source tree.  So we have to cd to
# ../.. before referring to $LIBDIR.  There must be a better way...
# 
install: all $(CONFIG)
	@. $(CONFIG); \
	  set -x; \
	  cd ../..; \
	  [ -d $$LIBDIR ]  ||  ($(MKDIR) $$LIBDIR; chmod 755 $$LIBDIR); \
	  cd $$LIBDIR; rm -f english.aff $(HASHFILES)
	@. $(CONFIG); \
	  set -x; \
	  cp english.aff $(HASHFILES) \
	    `cd ../..; cd $$LIBDIR; pwd`
	@. $(CONFIG); \
	  set -x; \
	  cd ../..; cd $$LIBDIR; \
	  chmod 644 english.aff $(HASHFILES)
	@. $(CONFIG); \
	  set -x; \
	  cd ../..; cd $$MANFFDIR; \
	  [ -d $$MANFFDIR ]  ||  ($(MKDIR) $$MANFFDIR; chmod 755 $$MANFFDIR); \
	    rm -f english$$MANFFEXT
	@. $(CONFIG); \
	  set -x; \
	  cp english.5 `cd ../..; cd $$MANFFDIR; pwd`/english$$MANFFEXT; \
	  cd ../..; \
	  chmod 644 $$MANFFDIR/english$$MANFFEXT

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

#
# 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:	$(CONFIG) $(BUILDHASH)
sml.hash:	$(AFFIXES)
sml.hash:	english.sml
	rm -f sml.hash
	@set +e; \
	. $(CONFIG); \
	set -ex; \
	$(BUILDHASH) english.sml $(AFFIXES) $@

sml+.hash:	$(CONFIG) $(BUILDHASH)
sml+.hash:	$(AFFIXES)
sml+.hash:	english.sml+
	rm -f sml+.hash
	@set +e; \
	. $(CONFIG); \
	set -ex; \
	$(BUILDHASH) english.sml+ $(AFFIXES) $@

med.hash:	$(BUILDHASH) $(CONFIG)
med.hash:	$(AFFIXES)
med.hash:	english.med
	rm -f med.hash
	@set +e; \
	. $(CONFIG); \
	set -ex; \
	$(BUILDHASH) english.med $(AFFIXES) $@

med+.hash:	$(BUILDHASH) $(CONFIG)
med+.hash:	$(AFFIXES)
med+.hash:	english.med+
	rm -f med+.hash
	@set +e; \
	. $(CONFIG); \
	set -ex; \
	$(BUILDHASH) english.med+ $(AFFIXES) $@

lrg.hash:	$(BUILDHASH) $(CONFIG)
lrg.hash:	$(AFFIXES)
lrg.hash:	english.lrg
	rm -f lrg.hash
	@set +e; \
	. $(CONFIG); \
	set -ex; \
	$(BUILDHASH) english.lrg $(AFFIXES) $@

lrg+.hash:	$(BUILDHASH) $(CONFIG)
lrg+.hash:	$(AFFIXES)
lrg+.hash:	english.lrg+
	rm -f lrg+.hash
	@set +e; \
	. $(CONFIG); \
	set -ex; \
	$(BUILDHASH) english.lrg+ $(AFFIXES) $@

xlg.hash:	$(BUILDHASH) $(CONFIG)
xlg.hash:	$(AFFIXES)
xlg.hash:	english.xlg
	rm -f xlg.hash
	@set +e; \
	. $(CONFIG); \
	set -ex; \
	$(BUILDHASH) english.xlg $(AFFIXES) $@

xlg+.hash:	$(BUILDHASH) $(CONFIG)
xlg+.hash:	$(AFFIXES)
xlg+.hash:	english.xlg+
	rm -f xlg+.hash
	@set +e; \
	. $(CONFIG); \
	set -ex; \
	$(BUILDHASH) english.xlg+ $(AFFIXES) $@

#
#	The eight dictionaries, english.sml through english.xlg+, 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
normdicts:	$(DBUILD)english.med
normdicts:	$(DBUILD)english.lrg
normdicts:	$(DBUILD)english.xlg
plusdicts:	$(DBUILD)english.sml+
plusdicts:	$(DBUILD)english.med+
plusdicts:	$(DBUILD)english.lrg+
plusdicts:	$(DBUILD)english.xlg+

dictcomponents:

$(DBUILD)english.sml:	$(CONFIG)
$(DBUILD)english.sml:	english.0
$(DBUILD)english.sml:	american.0
$(DBUILD)english.sml:	altamer.0
$(DBUILD)english.sml:	british.0
	@. $(CONFIG); \
	    set $(SHELLDEBUG); \
	    dicts=""; \
	    for i in english $(VARIANTS); do \
		dicts="$$dicts $$i.0"; \
	    done; \
	    trap "rm -f english.sml" 1 2 15; \
	    set -x; \
	    eval sort -u -t/ +0f -1 +0 $$MAKE_SORTTMP -o english.sml $$dicts

$(DBUILD)english.sml+:	$(CONFIG) $(EXTRADICT)
$(DBUILD)english.sml+:	english.0
$(DBUILD)english.sml+:	american.0
$(DBUILD)english.sml+:	altamer.0
$(DBUILD)english.sml+:	british.0
	@dicts="$(EXTRADICT)"; \
	set $(SHELLDEBUG); \
	for i in english $(VARIANTS); do \
	    dicts="$$dicts $$i.0"; \
	done; \
	trap "rm -f english.sml+" 1 2 15; \
	set -x; \
	PATH=$(PATHADDER):$$PATH; \
	export PATH; \
	munchlist -v -l $(AFFIXES) $$dicts \
	  > english.sml+ \
	    ||  rm -f english.sml+
	test -s english.sml+ \
	  ||  (echo 'error: zero-length dictionary generated'; \
	    rm -f english.sml+; exit 1)

$(DBUILD)english.med:	$(CONFIG)
$(DBUILD)english.med:	english.0
$(DBUILD)english.med:	american.0
$(DBUILD)english.med:	altamer.0
$(DBUILD)english.med:	british.0
$(DBUILD)english.med:	english.1
$(DBUILD)english.med:	american.1
$(DBUILD)english.med:	altamer.1
$(DBUILD)english.med:	british.1
	@. $(CONFIG); \
	    set $(SHELLDEBUG); \
	    dicts=""; \
	    for i in english $(VARIANTS); do \
		dicts="$$dicts $$i.[01]"; \
	    done; \
	    trap "rm -f english.med" 1 2 15; \
	    set -x; \
	    eval sort -u -t/ +0f -1 +0 $$MAKE_SORTTMP -o english.med $$dicts

$(DBUILD)english.med+:	$(CONFIG) $(EXTRADICT)
$(DBUILD)english.med+:	english.0
$(DBUILD)english.med+:	american.0
$(DBUILD)english.med+:	altamer.0
$(DBUILD)english.med+:	british.0
$(DBUILD)english.med+:	english.1
$(DBUILD)english.med+:	american.1
$(DBUILD)english.med+:	altamer.1
$(DBUILD)english.med+:	british.1
	@dicts="$(EXTRADICT)"; \
	set $(SHELLDEBUG); \
	for i in english $(VARIANTS); do \
	    dicts="$$dicts $$i.[01]"; \
	done; \
	trap "rm -f english.med+" 1 2 15; \
	set -x; \
	PATH=$(PATHADDER):$$PATH; \
	export PATH; \
	munchlist -v -l $(AFFIXES) $$dicts \
	  > english.med+ \
	    ||  rm -f english.med+
	test -s english.med+ \
	  ||  (echo 'error: zero-length dictionary generated'; \
	    rm -f english.med+; exit 1)

$(DBUILD)english.lrg:	$(CONFIG)
$(DBUILD)english.lrg:	english.0
$(DBUILD)english.lrg:	american.0
$(DBUILD)english.lrg:	altamer.0
$(DBUILD)english.lrg:	british.0
$(DBUILD)english.lrg:	english.1
$(DBUILD)english.lrg:	american.1
$(DBUILD)english.lrg:	altamer.1
$(DBUILD)english.lrg:	british.1
$(DBUILD)english.lrg:	english.2
$(DBUILD)english.lrg:	american.2
$(DBUILD)english.lrg:	altamer.2
$(DBUILD)english.lrg:	british.2
	@. $(CONFIG); \
	    set $(SHELLDEBUG); \
	    dicts=""; \
	    for i in english $(VARIANTS); do \
		dicts="$$dicts $$i.[012]"; \
	    done; \
	    trap "rm -f english.lrg" 1 2 15; \
	    set -x; \
	    eval sort -u -t/ +0f -1 +0 $$MAKE_SORTTMP -o english.lrg $$dicts

$(DBUILD)english.lrg+:	$(CONFIG) $(EXTRADICT)
$(DBUILD)english.lrg+:	english.0
$(DBUILD)english.lrg+:	american.0
$(DBUILD)english.lrg+:	altamer.0
$(DBUILD)english.lrg+:	british.0
$(DBUILD)english.lrg+:	english.1
$(DBUILD)english.lrg+:	american.1
$(DBUILD)english.lrg+:	altamer.1
$(DBUILD)english.lrg+:	british.1
$(DBUILD)english.lrg+:	english.2
$(DBUILD)english.lrg+:	american.2
$(DBUILD)english.lrg+:	altamer.2
$(DBUILD)english.lrg+:	british.2
	@dicts="$(EXTRADICT)"; \
	set $(SHELLDEBUG); \
	for i in english $(VARIANTS); do \
	    dicts="$$dicts $$i.[012]"; \
	done; \
	trap "rm -f english.lrg+" 1 2 15; \
	set -x; \
	PATH=$(PATHADDER):$$PATH; \
	export PATH; \
	munchlist -v -l $(AFFIXES) $$dicts \
	  > english.lrg+ \
	    ||  rm -f english.lrg+
	test -s english.lrg+ \
	  ||  (echo 'error: zero-length dictionary generated'; \
	    rm -f english.lrg+; exit 1)

$(DBUILD)english.xlg:	$(CONFIG)
$(DBUILD)english.xlg:	english.0
$(DBUILD)english.xlg:	american.0
$(DBUILD)english.xlg:	altamer.0
$(DBUILD)english.xlg:	british.0
$(DBUILD)english.xlg:	english.1
$(DBUILD)english.xlg:	american.1
$(DBUILD)english.xlg:	altamer.1
$(DBUILD)english.xlg:	british.1
$(DBUILD)english.xlg:	english.2
$(DBUILD)english.xlg:	american.2
$(DBUILD)english.xlg:	altamer.2
$(DBUILD)english.xlg:	british.2
$(DBUILD)english.xlg:	english.3
	@. $(CONFIG); \
	    set $(SHELLDEBUG); \
	    dicts=""; \
	    for i in english $(VARIANTS); do \
		dicts="$$dicts $$i.[0123]"; \
	    done; \
	    trap "rm -f english.xlg" 1 2 15; \
	    set -x; \
	    eval sort -u -t/ +0f -1 +0 $$MAKE_SORTTMP -o english.xlg $$dicts

$(DBUILD)english.xlg+:	$(CONFIG) $(EXTRADICT)
$(DBUILD)english.xlg+:	english.0
$(DBUILD)english.xlg+:	american.0
$(DBUILD)english.xlg+:	altamer.0
$(DBUILD)english.xlg+:	british.0
$(DBUILD)english.xlg+:	english.1
$(DBUILD)english.xlg+:	american.1
$(DBUILD)english.xlg+:	altamer.1
$(DBUILD)english.xlg+:	british.1
$(DBUILD)english.xlg+:	english.2
$(DBUILD)english.xlg+:	american.2
$(DBUILD)english.xlg+:	altamer.2
$(DBUILD)english.xlg+:	british.2
$(DBUILD)english.xlg+:	english.3
	@dicts="$(EXTRADICT)"; \
	set $(SHELLDEBUG); \
	for i in english $(VARIANTS); do \
	    dicts="$$dicts $$i.[0123]"; \
	done; \
	trap "rm -f english.xlg+" 1 2 15; \
	set -x; \
	PATH=$(PATHADDER):$$PATH; \
	export PATH; \
	munchlist -v -l $(AFFIXES) $$dicts \
	  > english.xlg+ \
	    ||  rm -f english.xlg+
	test -s english.xlg+ \
	  ||  (echo 'error: zero-length dictionary generated'; \
	    rm -f english.xlg+; exit 1)

# For tests you might want lists of all words in the various
# dictionaries.
#
# For american:
american.sml.words: english.0 american.0
american.med.words: english.0 english.1 american.0 american.1
american.lrg.words: english.0 english.1 english.2 american.0 american.1 american.2
american.xlg.words: english.0 english.1 english.2 english.3 american.0 american.1 american.2
# For american plus altamer:
american_loose.sml.words: english.0 american.0 altamer.0
american_loose.med.words: english.0 english.1 american.0 american.1 altamer.0 altamer.1
american_loose.lrg.words: english.0 english.1 english.2
american_loose.lrg.words: american.0 american.1 american.2
american_loose.lrg.words: altamer.0 altamer.1 altamer.2
american_loose.xlg.words: english.0 english.1 english.2 english.3
american_loose.xlg.words: american.0 american.1 american.2
american_loose.xlg.words: altamer.0 altamer.1 altamer.2
# For british:
british.sml.words: english.0 british.0
british.med.words: english.0 english.1 british.0 british.1
british.lrg.words: english.0 english.1 english.2 british.0 british.1 british.2
british.xlg.words: english.0 english.1 english.2 english.3 british.0 british.1 british.2
# One rule to build each of these.  Might require GNU make, I don't know.
%.words:
	@if ! test -f english.hash; then \
            echo english.hash not found - please symlink it here from ../american or somewhere; \
            exit 1; \
        fi
	PATH=$(PATHADDER)::$$PATH; cat $^ | ispell -d ./english.hash -e >$@.0
	tr -s ' ' '\n' <$@.0 | LC_ALL=C sort -u >$@
	rm $@.0
# Target to make all the .words files.
words: american.sml.words american.med.words american.lrg.words american.xlg.words
words: american_loose.sml.words american_loose.med.words
words:   american_loose.lrg.words american_loose.xlg.words
words: british.sml.words british.med.words british.lrg.words british.xlg.words

# This target is called 'check' rather than test because it doesn't
# really find bugs, just sanity-check data.
#
# We want to warn about duplicate words in individual wordlists.  But
# also to warn about cross-duplicates between british and american,
# because those words should move to english.
# 
.PHONY: check
check: words
# Find the 'obvious duplicates', sharing the same word-stem.
	./check_dups american altamer british english 'american british' \
'american english' 'american altamer' 'american altamer english' 'british english'
# Could use this to warn about _all_ duplicates, but that's probably excessive.
#	for i in *.words; do echo "Finding duplicates in $$i"; uniq -c <$$i | perl -ane 'if ($$F[0] > 1) { print; $$err = 1 }' -e 'END { exit $$err }' || exit 1; done

clean:
	rm -f core *.hash *.stat *.cnt english.5 *.words

#
#	The following target allows you to clean out the combined
#	dictionary files.
#
dictclean:
	rm -f english.sml english.sml+ english.med english.med+
	rm -f english.lrg english.lrg+ english.xlg english.xlg+

#
#	Manual page (apply substitutions).
#
#	FIXME why in so many places?
#
english.5:	english.5X $(CONFIG)
	cd ../..; \
	$(MAKE) EDITFILE=languages/english/english.5X \
	  OUTFILE=languages/english/english.5 SHELLDEBUG=$(SHELLDEBUG) \
	  doedit
