#
# $Id: Makefile,v 1.14 2003/08/24 11:50:58 ed Exp $
#
# Copyright 1992, 1993, 1999, 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.
#
# You will have to create a local.h file before building; look over
# config.X to learn what things you may need to define, or use one of
# the sample local.h files shipped.
#
# the argument syntax for buildhash to make alternate dictionary files
# is simply:
#
#   buildhash <dictfile> <affix-file> <outfile>

# $Log: Makefile,v $
# Revision 1.14  2003/08/24 11:50:58  ed
# Replaced local.h.samp with local.h.{bsd,linux,sysv}.
#
# Revision 1.13  2003/08/23 10:56:26  ed
# Purging my old email address.
#
# Revision 1.12  2002/09/02 23:33:51  ed
# Use set -e for those long shell commands, so that the failure of one part
# gets noticed.
#
# Revision 1.11  2002/05/19 17:04:24  ed
# Changed all 'ln' commands in language makefiles to use the macro SYMLINK,
# which can be passed down from the top-level makefile.  (Part of SuSE's
# 3.2.06-languages.patch, generalized.)
#
# Revision 1.10  2002/05/19 16:19:45  ed
# Added a test case for ispell's various deformatters.  This involved
# creating a new dictionary, test_dict, which contains only a few words.  For
# whatever reason this new test_dict is not included in 'all-languages', it
# has its own Makefile targets which are used only by 'test' and 'clean'.
#
# With that dictionary available, test_deformatters runs ispell four times
# on the sample input test_data/test_deformatters.in, with four different
# deformatters (TeX, nroff, HTML and 'ordinary'), and compares the results
# to expected values.
#
# Also changed 'make test' to clean up after itself, since the ispell binary
# left over from testing installation is no use.
#
# Revision 1.9  2001/11/08 13:25:57  ed
# The  'clean' and 'test' targets are passed down to the languages/
# directory.
#
# Revision 1.8  2001/10/16 16:55:43  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.7  2001/10/16 15:19:07  ed
# Merged some of SuSE's ispell-3.2.06-config.patch: local.h depends on
# local.h.samp.
#
# Revision 1.6  2001/10/16 15:14:14  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.5  2001/10/08 12:09:39  ed
# Purge all traces of 'sq' and 'unsq'.  (Apart from the log entries :-))
#
# Revision 1.4  2001/10/08 12:00:00  ed
# Parameterize ln(1) to $(SYMLINK).
#
# Revision 1.3  2001/10/05 14:28:47  ed
# Make sure that realclean removes all files generated: remove config.sh
# and test output.
#
# Revision 1.2  2001/10/05 14:22:25  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.5  2001/09/22 11:36:30  edward
# Test suite uses expansion_diff instead of diff, since some
# differences in the output (different ordering of expansions)
# are acceptable - in fact have changed from ispell 3.1 to 3.2.
#
# Revision 1.4  2001/09/20 22:28:16  edward
# Added test for -e5.
#
# Revision 1.3  2001/09/16 17:18:18  edward
# make test: save the generated output to a file first
# before diffing it, so the output is kept if diff fails.
# (tee wouldn't work, presumably because of broken pipe.)
#
# Revision 1.2  2001/09/16 14:37:19  edward
# Added dependency on exp_table.c; started a 'test' target.
#
# Revision 1.1  2001/09/15 17:31:53  edward
# Initial revision
#
# Revision 1.111  2001/07/25 21:51:45  geoff
# Minor license update.
#
# Revision 1.110  2001/07/23 20:24:02  geoff
# Update the copyright and the license.
#
# Revision 1.109  2001/06/07 19:06:33  geoff
# When creating local.h, make it user-writable.
#
# Revision 1.108  2001/06/07 08:02:18  geoff
# Add the deformatters to the default dependencies.
#
# Revision 1.107  1999/01/13 01:34:15  geoff
# Get rid of some leftover references to emacs stuff.
#
# Revision 1.106  1999/01/08  04:32:31  geoff
# Don't try to build or install ispell.el and ispell.info.
#
# Revision 1.105  1999/01/07  01:22:29  geoff
# Update the copyright.  Get rid of old shar-based dictionary building.
#
# Revision 1.104  1995/11/08  05:09:06  geoff
# When invoking "showversion", ignore any errors that happen.  Fix a
# place where I forgot to double a dollar sign in install-languages.
#
# Revision 1.103  1995/10/25  03:35:38  geoff
# Don't assume the presence of "head" in the showversion dependency; use
# old reliable sed instead.  Also make showversion depend on ispell
# itself, since it uses it.
#
# Revision 1.102  1995/10/11  04:30:25  geoff
# Allow DEFHASH and MASTERHASH to be the same.
#
# Revision 1.101  1995/08/05  23:19:33  geoff
# Add the showversion target to ease the job of debugging people's make
# output.  Make sure SHELLDEBUG is set for the entire process of making
# config.sh.
#
# Revision 1.100  1995/03/06  02:42:39  geoff
# Run iwhich explicitly from the shell, so that we don't have to worry
# about PATH problems and whether it's executable or not.  Also fix a
# place where -nw was not removed from the batch emacs switch list.
#
# Revision 1.99  1995/01/08  23:23:23  geoff
# Get rid of an obsolete etags flag.  Add some new variables to config.sh.
#
# Revision 1.98  1994/12/27  23:08:43  geoff
# Use the new "iwhich" script to decide whether to install emacs-related
# stuff.  Make correct.o depend on version.h so that "ispell -a" always
# reports the correct version.
#
# Revision 1.97  1994/11/21  07:02:51  geoff
# Specify default values for the BUILD macros, so that some systems
# don't accidentally override them and make ispell think that the
# dictionaries are missing.
#
# Revision 1.96  1994/10/25  05:45:54  geoff
# Make the installation command configurable.
#
# Revision 1.95  1994/10/18  04:03:17  geoff
# Get rid of DICTVARIANTS, which is obsolete.  Compile term.o first, so
# that errors in it (which are common) will show up first.  Improve the
# rules for generation of msgs.h.
#
# Revision 1.94  1994/09/16  05:06:55  geoff
# Split installation up into basic and dictionary-building tools, so
# that we can have a partial-install target.
#
# Revision 1.93  1994/09/16  04:51:28  geoff
# Handle installations that have ELISPDIR but not TEXINFODIR
#
# Revision 1.92  1994/09/16  02:45:52  geoff
# Don't strip non-binaries.  Fix an accidentally-doubled backslash.
#
# Revision 1.91  1994/08/31  05:58:27  geoff
# Strip binaries before installing them.  Create directories before
# installing into them.  Make sure manual pages are installed with the
# correct protection modes.
#
# Revision 1.90  1994/05/25  04:29:16  geoff
# Don't remove english.4 after the English makefile has carefully
# installed it.
#
# Revision 1.89  1994/05/24  05:31:22  geoff
# Return to the old sed-based method of parsing LANGUAGES, so that things
# will work on broken systems like BSDI.
#
# Revision 1.88  1994/05/24  04:54:30  geoff
# Fix the emacs installation to use emacs batch mode properly, so that a
# terminal isn't required.
#
# Revision 1.87  1994/03/21  01:55:17  geoff
# If a hard link can't be made to msgs.h, copy it instead
#
# Revision 1.86  1994/02/22  06:09:03  geoff
# Add SHELLDEBUG.  Change the language-subdirs target to use the shell
# IFS variable to parse things, simplifying things and improving
# efficiency (thanks to Hagen Ross for the idea and implemenation).
#
# Revision 1.85  1994/02/13  23:25:31  geoff
# Fix multiple-language processing to not pass subsequent specifications to
# the first Makefile.  Also fix the language shell loop to be more flexible.
#
# Revision 1.84  1994/02/07  08:10:40  geoff
# When processing the LANGUAGES configuration variable (from local.h),
# use sed instead of expr to process it.  This gets around versions of
# expr that have 127-character limitations (though it probably still
# limits us to 512 characters with some versions of sed, so further work
# may be needed here).
#
# Revision 1.83  1994/02/07  06:31:20  geoff
# Clarify how to change variables in local.h
#
# Revision 1.82  1994/02/07  06:29:31  geoff
# Add a dummy else clause to shell if-test for Ultrix
#
# Revision 1.81  1994/02/07  05:35:34  geoff
# Make realclean run dictclean
#
# Revision 1.80  1994/01/26  07:44:43  geoff
# Make yacc configurable through local.h.
#
# Revision 1.79  1994/01/25  07:11:11  geoff
# Get rid of all old RCS log lines in preparation for the 3.1 release.
#
#

#
# !!!DO NOT EDIT HERE!!!
#
# Unlike previous versions of ispell, there should be no need to edit
# your Makefile.  Instead, #define the corresponding variables in your
# local.h file; the Makefile will automatically pick them up.  The
# only reason you should need to edit the Makefile might to be to add
# non-English dictionary support.
#
# For example, if you want to set CFLAGS to "-g -Wall", don't put it
# here.  Put:
#
#	#define CFLAGS	"-g -Wall"
#
# in local.h.  Otherwise, it won't have any effect.
#
EXTRADICT = Use_config.sh

SHELL = /bin/sh
MAKE = make

#
#	Not all systems support these, but where they are available we
#	should use them.
#
SYMLINK = ln -sf
MKDIR = mkdir -p

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

all:	config.sh
all:	programs deformatter-programs showversion ispell.1 ispell.5
all:	all-languages

programs: buildhash findaffix tryaffix ispell
programs: icombine ijoin munchlist
programs: subset zapdups

showversion:	ispell
	-./ispell -v | sed 1q

.c.o:
	@. ./config.sh; \
	  set -xe; \
	  $$CC $$CFLAGS -c $<

.y.o:
	@. ./config.sh; \
	  set -xe; \
	  $$YACC $<; \
	  $$CC $$CFLAGS -c y.tab.c; \
	  mv y.tab.o $@; \
	  rm -f y.tab.c

# All 'real' languages, but not test_dict.
all-languages:	munchable
	$(MAKE) LANGUAGE_TARGET=all SHELLDEBUG=$(SHELLDEBUG) language-subdirs

languages/test_dict/test_dict.hash: munchable
	cd languages/test_dict && $(MAKE) test_dict.hash

install: config.sh all install-basic install-deformatters
install: install-dictbuild install-languages

partial-install: config.sh all install-basic install-languages

install-basic:
	@. ./config.sh; \
	  set -xe; \
	  [ -d $$BINDIR ]  ||  ($(MKDIR) $$BINDIR; chmod 755 $$BINDIR); \
	  cd $$BINDIR; \
	  rm -f ispell
	@. ./config.sh; \
	  set -xe; \
	  $$INSTALL ispell $$BINDIR
	@. ./config.sh; \
	  set -xe; \
	  cd $$BINDIR; \
	  strip ispell; \
	  chmod 755 ispell
	@. ./config.sh; \
	  set -xe; \
	  [ -d $$MAN1DIR ]  || ($(MKDIR) $$MAN1DIR; chmod 755 $$MAN1DIR); \
	  [ -d $$MANFFDIR ] || ($(MKDIR) $$MANFFDIR; chmod 755 $$MANFFDIR); \
	  (cd $$MAN1DIR; rm -f ispell$$MAN1EXT); \
	  (cd $$MANFFDIR; rm -f ispell$$MANFFEXT)
	@. ./config.sh; \
	  set -xe; \
	  $$INSTALL ispell.1 $$MAN1DIR/ispell$$MAN1EXT; \
	  $$INSTALL ispell.5 $$MANFFDIR/ispell$$MANFFEXT
	@. ./config.sh; \
	  set -xe; \
	  (cd $$MAN1DIR; chmod 644 ispell$$MAN1EXT); \
	  (cd $$MANFFDIR; chmod 644 ispell$$MANFFEXT)

install-dictbuild:
	@. ./config.sh; \
	  set -xe; \
	  [ -d $$BINDIR ]  ||  ($(MKDIR) $$BINDIR; chmod 755 $$BINDIR); \
	  cd $$BINDIR; \
	  rm -f buildhash icombine ijoin \
	    munchlist findaffix tryaffix; \
	  rm -f $$LIBDIR/icombine
	@. ./config.sh; \
	  set -xe; \
	  $$INSTALL buildhash icombine ijoin munchlist findaffix tryaffix \
	    $$BINDIR
	@. ./config.sh; \
	  set -xe; \
	  cd $$BINDIR; \
	  strip buildhash icombine ijoin; \
	  chmod 755 buildhash icombine ijoin \
	    munchlist findaffix tryaffix
	@. ./config.sh; \
	  set -xe; \
	  [ -d $$MAN1DIR ]  ||  ($(MKDIR) $$MAN1DIR; chmod 755 $$MAN1DIR); \
	  [ -d $$MANFFDIR ]  ||  ($(MKDIR) $$MANFFDIR; chmod 755 $$MANFFDIR);
	@. ./config.sh; \
	  set -xe; \
	  for m in buildhash munchlist findaffix tryaffix; do \
	    echo ".so `basename $$MAN1DIR`/ispell$$MAN1EXT" \
	      > $$MAN1DIR/$$m$$MAN1EXT; \
	  done
	@. ./config.sh; \
	  set -xe; \
	  cd $$MAN1DIR; \
	  chmod 644 buildhash$$MAN1EXT \
	    munchlist$$MAN1EXT findaffix$$MAN1EXT tryaffix$$MAN1EXT

install-languages:
	$(MAKE) LANGUAGE_TARGET=install SHELLDEBUG=$(SHELLDEBUG) \
	  language-subdirs
	. ./config.sh; \
	  [ -d $$LIBDIR ]  ||  ($(MKDIR) $$LIBDIR; chmod 755 $$LIBDIR); \
	  set -xe; \
	  cd $$LIBDIR; \
	  if [ $$MASTERHASH != $$DEFHASH ]; then \
	    rm -f $$DEFHASH; \
	    $(SYMLINK) $$MASTERHASH $$DEFHASH; \
	  fi

munchable:	findaffix tryaffix munchlist buildhash ispell icombine
munchable:	ijoin

#
#	The following auxiliary dependency is used to make targets in
#	the language directories.  Do you find it intimidating?  No
#	surprise;  remember that this is by the guy who wrote munchlist.
#
LANGUAGE_TARGET	=   Do_not_try_to_make_this_target_yourself
BUILD	=	build
CBUILD	=	build
DBUILD	=	build

language-subdirs:	config.sh
	@. ./config.sh; \
	    set $(SHELLDEBUG); \
	    set +e; \
	    while [ "X$$LANGUAGES" != X ]; do \
		( \
		descriptor=`echo "$$LANGUAGES" \
		  | sed 's/[^{]*{\([^}]*\)}.*/\1/'`; \
		dir=`echo "$$descriptor" | sed 's/\([^,]*\).*/\1/'`; \
		descriptor=`echo "$$descriptor" \
		  | sed 's/[^,]*,*\(.*\).*/\1/'`; \
		makeargs=''; \
		while [ "X$$descriptor" != X ]; \
		do \
		    nextvar=`echo "$$descriptor" | sed 's/\([^,]*\).*/\1/'`; \
		    makeargs="$$makeargs '$$nextvar'"; \
		    descriptor=`echo "$$descriptor" \
		      | sed 's/[^,]*,*\(.*\).*/\1/'`; \
		done; \
		set -xe; \
		cd languages/$$dir; \
		eval $(MAKE) BUILD=$(BUILD) DBUILD=$(DBUILD) CBUILD=$(CBUILD) \
		  SHELLDEBUG=$(SHELLDEBUG) '"SYMLINK=ln -sf"' "$$makeargs" $(LANGUAGE_TARGET) \
		    ||  exit 1; \
		)  ||  exit 1; \
		LANGUAGES=`echo "$$LANGUAGES" \
		  | sed 's/[^{]*{[^}]*}[^{]*\(.*\)$$/\1/'`; \
		case "$$LANGUAGES" in \
		    ''|*{*}*) \
			;; \
		    *) \
			echo "Bad language specification: '$$LANGUAGES'" \
			  1>&2; \
			exit 2 \
			;; \
		esac; \
	    done; \
	    exit 0

buildhash: config.sh buildhash.o hash.o makedent.o parse.o
	@. ./config.sh; \
	  set -xe; \
	  $$CC $$CFLAGS -o buildhash buildhash.o hash.o makedent.o parse.o \
	    $$LIBES

icombine: config.sh icombine.o makedent.o parse.o
	. ./config.sh; \
	  set -xe; \
	  $$CC $$CFLAGS -o icombine icombine.o makedent.o parse.o \
	    $$LIBES

ijoin: config.sh ijoin.o fields.o
	@. ./config.sh; \
	  set -xe; \
	  $$CC $$CFLAGS -o ijoin ijoin.o fields.o $$LIBES

EDITFILE	=	notthere
OUTFILE		=	/dev/null

config.sh:  config.X local.h
	set $(SHELLDEBUG); \
	for var in BINDIR CC CFLAGS COUNTSUFFIX DEFDICT DEFHASH DEFLANG \
	  HASHSUFFIX INSTALL \
	  LANGUAGES LIBDIR LIBES LINT LINTFLAGS \
	  MAKE_SORTTMP MAN1DIR MAN1EXT MANFFDIR MANFFEXT MASTERHASH \
	  MSGLANG REGLIB STATSUFFIX MANFFSECT \
	  TERMLIB YACC TIB_XREF SPELL_XREF WORDS \
	  ; do \
	    cat config.X local.h \
	      | sed -n -e "s/^#define[ 	]*$$var[ 	]*"'"'"/$$var=/p" \
	      | sed -e 's/".*$$/'"'/" -e "s/=/='/" \
	      | tail -1; \
	  done > config.sh; \
	echo 'case "$$MAKE_SORTTMP" in "") \
	  SORTTMP="-e /!!SORTTMP!!/s/=.*$$/=/";; *) SORTTMP=;; esac' \
	  >> config.sh

doedit:
	. ./config.sh; \
	  sed -e "s@!!LIBDIR!!@$$LIBDIR@" -e "s@!!DEFDICT!!@$$DEFDICT@" \
	    -e "s@!!DEFHASH!!@$$DEFHASH@" -e "s@!!DEFLANG!!@$$DEFLANG@" \
	    -e "s@!!COUNTSUFFIX!!@$$COUNTSUFFIX@g" \
	    -e "s@!!HASHSUFFIX!!@$$HASHSUFFIX@g" \
	    -e "s@!!STATSUFFIX!!@$$STATSUFFIX@g" \
	    -e "s@!!MANFFSECT!!@$$MANFFSECT@g" \
	    -e "s@!!TIB_XREF!!@$$TIB_XREF@g" \
	    -e "s@!!SPELL_XREF!!@$$SPELL_XREF@g" \
	    -e "s@!!WORDS!!@$$WORDS@g" \
	    $$SORTTMP < $(EDITFILE) > $(OUTFILE)

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

ispell.1:	ispell.1X config.sh
	@$(MAKE) EDITFILE=ispell.1X OUTFILE=ispell.1 SHELLDEBUG=$(SHELLDEBUG) \
	  doedit

ispell.5:	ispell.5X config.sh
	@$(MAKE) EDITFILE=ispell.5X OUTFILE=ispell.5 SHELLDEBUG=$(SHELLDEBUG) \
	  doedit

munchlist:	munchlist.X config.sh
	@$(MAKE) EDITFILE=munchlist.X OUTFILE=munchlist \
	  SHELLDEBUG=$(SHELLDEBUG) doedit
	chmod +x munchlist

subset:	subset.X config.sh
	@$(MAKE) EDITFILE=subset.X OUTFILE=subset SHELLDEBUG=$(SHELLDEBUG) \
	  doedit
	chmod +x subset

tryaffix:	tryaffix.X config.sh
	@$(MAKE) EDITFILE=tryaffix.X OUTFILE=tryaffix \
	  SHELLDEBUG=$(SHELLDEBUG) doedit
	chmod +x tryaffix

zapdups:	zapdups.X config.sh
	@$(MAKE) EDITFILE=zapdups.X OUTFILE=zapdups SHELLDEBUG=$(SHELLDEBUG) \
	  doedit
	chmod +x zapdups

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

ispell: config.sh $(OBJS)
	@. ./config.sh; \
	  set -xe; \
	  $$CC $$CFLAGS -o ispell $(OBJS) $$TERMLIB $$REGLIB $$LIBES

$(OBJS) buildhash.o icombine.o hash.o parse.o: config.h ispell.h local.h
$(OBJS) buildhash.o icombine.o hash.o parse.o: proto.h msgs.h
ijoin.o: config.h ispell.h local.h
ijoin.o: proto.h fields.h
buildhash.o correct.o ispell.o: version.h
exp_table.o: exp_table.h

config.h:	config.X local.h
	cp config.X config.h
	chmod u+w config.h
	echo '' >> config.h
	echo '/* AUTOMATICALLY-GENERATED SYMBOLS */' >> config.h
	cat local.h config.X \
	  | egrep '^#define[ 	]*SIGNAL_TYPE' \
	  | sed -e 's/TYPE[ 	]*/TYPE_STRING "/' -e 's/$$/"/' -e 1q \
	  >> config.h
	cat local.h config.X \
	  | egrep '^#define[ 	]*MASKTYPE' \
	  | sed -e 's/TYPE[ 	]*/TYPE_STRING "/' -e 's/$$/"/' -e 1q \
	  >> config.h

local.h:
	@echo local.h does not exist, please choose one of: >&2
	@ls local.h.* >&2
	@echo copy it to local.h, maybe edit it, and run 'make' again. >&2
	@false

msgs.h:	config.sh FRC
	@. ./config.sh; \
	  set $(SHELLDEBUG); \
	  set +e; \
	  if [ -r languages/$$MSGLANG/msgs.h ]; then \
	    msgs=languages/$$MSGLANG/msgs.h; \
	  else \
	    msgs=languages/english/msgs.h; \
	  fi; \
	  if cmp -s msgs.h $$msgs; then \
	    :; \
	  else \
	    set -xe; \
	    rm -f msgs.h; $(SYMLINK) $$msgs msgs.h  ||  cp $$msgs msgs.h; \
	  fi

FRC:

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 *.[chy]
	sed -e s/config.h/config.X/ TAGS > NTAGS
	mv NTAGS TAGS

lint:	languages/*/msgs.h
lint:	config.sh config.h ispell.h proto.h *.[cy]
	@. ./config.sh; \
	  $$LINT $$LINTFLAGS ispell.c correct.c defmt.c dump.c good.c \
	    hash.c lookup.c makedent.c tgood.c exp_table.c exp_table.h \
	    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; \
	  $$LINT $$LINTFLAGS ijoin.c fields.c
	@rm -f y.tab.c

# Beginnings of a test suite.
test_data/english.hash: all-languages
	cd test_data; \
	$(SYMLINK) `ls ../languages/american/*.hash | head -1` english.hash
test: ispell test_data/english.hash languages/test_dict/test_dict.hash
# First test the -e expansion options.
	./ispell -d ./test_data/english.hash -e1 \
		<test_data/input >test_data/e1.out
	./expansion_diff test_data/e1.expected test_data/e1.out
	./ispell -d ./test_data/english.hash -e2 \
		<test_data/input >test_data/e2.out
	./expansion_diff test_data/e2.expected test_data/e2.out
	./ispell -d ./test_data/english.hash -e3 \
		<test_data/input >test_data/e3.out
	./expansion_diff -e3 test_data/e3.expected test_data/e3.out
	./ispell -d ./test_data/english.hash -e4 \
		<test_data/input >test_data/e4.out
	./expansion_diff -e4 test_data/e4.expected test_data/e4.out
	./ispell -d ./test_data/english.hash -e5 \
		<test_data/input >test_data/e5.out
	./expansion_diff -e5 test_data/e5.expected test_data/e5.out
# Now test the various deformatters (uses test_dict).
	./test_deformatters
# Then the installation and manual page munging.  This has the
# unfortunate side effect of rebuilding ispell itself (because it
# changes local.h), so it should probably come last.
	./test_inst
# Test the languages/ directory (actually, fix8bit.c).
	cd languages; $(MAKE) test
# The ispell lying around is no use to anyone, it has test paths
# hardcoded.  Clean up.
	$(MAKE) clean

clean-test:
	cd test_data; rm -f e1.out e2.out e3.out e4.out e5.out

clean:	config.sh clean-deformatters clean-languages clean-test clean-test-dict
	@. ./config.sh; \
	  set -xe; \
	  rm -f $$DEFHASH $$FOREIGNHASHES
	rm -f *.o core a.out mon.out hash.out y.tab.c *.stat *.cnt \
		config.h msgs.h unpacked
	rm -f buildhash findaffix tryaffix ispell icombine ijoin \
		munchlist subset zapdups ispell.1 ispell.5 ispell.info
	cd languages; make clean

# Clean all languages except test_dict.
clean-languages:
	$(MAKE) LANGUAGE_TARGET=clean SHELLDEBUG=$(SHELLDEBUG) language-subdirs

clean-test-dict:
	cd languages/test_dict && $(MAKE) clean

realclean veryclean:	clean dictclean
	rm -f config.sh local.h

#
#	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:
	$(MAKE) LANGUAGE_TARGET=dictclean SHELLDEBUG=$(SHELLDEBUG) \
	  language-subdirs
	rm -f test_data/english.hash

#
#	deformatters/ directory
#
DEFORMATTER_PROGRAMS = deformatters/deformat-c deformatters/deformat-sh
deformatter-programs: $(DEFORMATTER_PROGRAMS)

install-deformatters:
	@. ./config.sh; \
	  set -xe; \
	  [ -d $$BINDIR ]  ||  ($(MKDIR) $$BINDIR; chmod 755 $$BINDIR); \
	  cd $$BINDIR; \
	  for i in $(DEFORMATTER_PROGRAMS); do rm -f `basename $$i`; done
	@. ./config.sh; \
	  set -xe; \
	  $$INSTALL $(DEFORMATTER_PROGRAMS) $$BINDIR
	@. ./config.sh; \
	  set -xe; \
	  cd $$BINDIR; \
	  for i in $(DEFORMATTER_PROGRAMS); do \
	    b=`basename $$i`; \
	    strip $$b; \
	    chmod 755 $$b; \
	  done

clean-deformatters:
	cd deformatters; rm -f *.o core a.out mon.out
	rm -f $(DEFORMATTER_PROGRAMS)
