# Makefile for web2c --kb@mail.tug.org. Public domain.
version = @WEB2CVERSION@

# These lines define the memory dumps that fmts/bases/mems will make and
# install-fmts/install-bases/install-mems will install. plain.* is
# created automatically (as a link).  See the Formats node in
# doc/web2c.texi for details on the fmts.
@TEX@fmts = #latex.fmt # amstex.fmt eplain.fmt texinfo.fmt
@ETEX@efmts = #elatex.efmt
@CTEX@cfmts = #latex.efmt
@PTEX@pdffmts = #pdflatex.fmt
@PETEX@pdfefmts = #pdfelatex.efmt
@OMEGA@ofmts = #lambda.fmt
bases = # I do not recommend building cmmf.base.
mems =  # mfplain.mem is probably not generally useful.

# The name of the file that defines your local devices for Metafont.
# (Only relevant during `make bases'.)  I recommend `modes.mf', which
# defines all known modes, plus useful definitions for all fonts.  It's
# available from ftp://ftp.tug.org/tex/modes.mf, among other places.
localmodes = modes

ac_include ../make/paths.mk

# Used for triptrap.
DIFF = diff
DIFFFLAGS =

.SUFFIXES: # get rid of .p.o
ac_include ../make/common.mk
ac_include ../make/programs.mk

CXX = @CXX@
CXXLD = $(CXX)
cxx_link_command = $(CXXLD) -o $@ $(LDFLAGS) 
kpathsea_cxx_link = $(LIBTOOL) link $(cxx_link_command)

@MAINT@ifeq ($(CC), gcc)
@MAINT@XDEFS = -Wimplicit -Wreturn-type -Wcomment -Wformat
@MAINT@endif

# Make `#include <X11/...>' and `-lX...' work.
# This matches xdvik.
# wlibs is substituted by web2c's configure, LIBS by general configure
# routines, and the others by AC_PATH_XTRA.
# All the x_... variables will be empty if we aren't supporting X.
x_cppflags = @X_CFLAGS@
x_ldflags = @X_LIBS@
x_pre_libs = @X_PRE_LIBS@
x_extra_libs = @X_EXTRA_LIBS@
x_tool_libs = @x_tool_libs@
x_ext_lib = @x_ext_lib@
wlibs = @wlibs@
# Follow the library order used in X11R6 itself:
#   -lXaw -lXmu -lXt -lSM -lICE -lXext -lX11 (some may not be present).
windowlink = $(windowlib) $(x_ldflags) $(x_tool_libs) $(x_pre_libs) $(x_ext_lib) $(wlibs) $(x_extra_libs)

# With --enable-ipc, TeX may need to link with -lsocket.
socketlibs = @socketlibs@

common_makeargs = $(MFLAGS) CC='$(CC)' CFLAGS='$(CFLAGS)' $(XMAKEARGS)
window_makeargs = x_cppflags='$(x_cppflags)' $(common_makeargs)
install_makeargs = INSTALL='$(INSTALL)' INSTALL_DATA='$(INSTALL_DATA)' \
  INSTALL_PROGRAM='$(INSTALL_PROGRAM)' \
  $(makevars) $(common_makeargs)  

proglib = lib/lib.a
windowlib = window/window.a
@PTEX@ZLIBDIR=../../libs/zlib
@PTEX@ZLIBSRCDIR=$(srcdir)/$(ZLIBDIR)
@PTEX@LIBPNGDIR=../../libs/libpng
@PTEX@LIBPNGSRCDIR=$(srcdir)/$(LIBPNGDIR)
@PTEX@pdflib = pdftexdir/libpdf.a
@PTEX@LIBPNGDEP = @LIBPNGDEP@
@PTEX@LDLIBPNG = @LDLIBPNG@
@PTEX@LDZLIB = @LDZLIB@
@PTEX@ZLIBDEP = @ZLIBDEP@
@PTEX@xpdfroot = pdftexdir/xpdf-0.80
@PTEX@xpdfdir  = $(xpdfroot)/xpdf
@PTEX@xpdflib  = $(xpdfdir)/pdftoepdf.a
@PTEX@xpdfextradir = $(xpdfroot)/goo
@PTEX@xpdfextralib = $(xpdfextradir)/libGoo.a
@PTEX@pdftexlibs = $(pdflib) $(LDLIBPNG) $(LDZLIB) $(xpdflib) $(xpdfextralib)
@PTEX@pdftexlibsdep = $(pdflib) $(LIBPNGDEP) $(ZLIBDEP) $(xpdflib) $(xpdfextralib)

# The sh script that does the conversion:
web2c = srcdir=$(srcdir) $(shared_env) $(SHELL) $(srcdir)/web2c/convert
# Additional dependencies:
web2c_aux = web2c/convert web2c/common.defines
web2c_programs = web2c/fixwrites web2c/splitup web2c/web2c

# Unfortunately, suffix rules can't have dependencies, or multiple
# targets, and we can't assume all makes supports pattern rules.
.SUFFIXES: .p .c .ch .p
.p.c: # really depends on $(web2c_programs), and generates .h.
	$(web2c) $*
.ch.p: # really depends on ./tangle; for mf/mp/tex, also generates .pool
	$(shared_env) ./tangle $(srcdir)/$*.web $<

# These definitions have to come before the rules that expand them.
# The *{ini,[0-2]}.c files are created by splitup, run as part of convert.
# {mf,mp,tex}extra.c are created from lib/texmfmp.c, below.
mf_c = mfini.c mf0.c mf1.c mf2.c
mf_o = mfini.o mf0.o mf1.o mf2.o mfextra.o
mf_nowin_o = mfini.o mf0.o mf1.o mf2.o mfnowin.o
mp_c = mpini.c mp0.c mp1.c mp2.c
mp_o = mpini.o mp0.o mp1.o mp2.o mpextra.o
tex_c = texini.c tex0.c tex1.c tex2.c
tex_o = texini.o tex0.o tex1.o tex2.o texextra.o

other_c = bibtex.c dvicopy.c dvitomp.c dvitype.c gftodvi.c gftopk.c gftype.c \
  mft.c patgen.c pktogf.c pktype.c pltotf.c pooltype.c tangle.c tftopl.c \
  vftovp.c vptovf.c weave.c
all_c = $(other_c) $(mf_c) $(mp_c) $(tex_c) $(etex_c) $(pdftex_c) $(omega_c) \
  $(omegaware_c)

# Prevent Make from deleting the intermediate forms.
.PRECIOUS: %.ch %.p %.c

@TEX@tex = tex
@ETEX@etex = etex
@PTEX@pdftex = pdftex
@PTEX@ttf2afm = ttf2afm
@PETEX@pdfetex = pdfetex
@OMEGA@omega = omega
@OMEGA@odvicopy = odvicopy
@OMEGA@odvitype = odvitype
@OMEGA@ofm2opl = ofm2opl
@OMEGA@opl2ofm = opl2ofm
@OMEGA@ovf2ovp = ovf2ovp
@OMEGA@ovp2ovf = ovp2ovf
@OMEGA@otangle = otangle
@MFW@mfw = mf
@MFN@mfn = mf
@MFW@@MFN@mfw = mfw
programs = tie bibtex dvicopy dvitomp dvitype $(etex) gftodvi gftopk \
gftype $(mfn) $(mfw) mft mpost $(odvicopy) $(odvitype) $(ofm2opl) $(omega) \
$(opl2ofm) $(ovf2ovp) $(ovp2ovf) $(otangle) patgen $(pdftex) $(pdfetex) \
pktogf pktype pltotf pooltype tangle $(tex) tftopl $(ttf2afm) vftovp \
vptovf weave

mpware = mpware/dmp mpware/makempx mpware/mpto mpware/newer
mpware_sources = mpware/dmp.c mpware/makempx.in mpware/mpto.c mpware/newer.c

@OMEGA@otps_programs = otps/otp2ocp otps/outocp

#  
default all: programs dumps manpages doc/web2c.info
programs: $(programs) $(mpware) $(otps_programs)

# Makefile fragments:
ac_include etexdir/etex.mk
ac_include omegadir/omega.mk
ac_include pdftexdir/pdftex.mk
ac_include pdfetexdir/pdfetex.mk

# Rules to link each program. I wish we could use a suffix rule for
# this, since it's so repetitive, but null suffixes don't work. And old
# makes don't support pattern rules. Doomed to forever cater to obsolesence.
bibtex: bibtex.o
	$(kpathsea_link) bibtex.o $(LOADLIBES)
dvicopy: dvicopy.o
	$(kpathsea_link) dvicopy.o $(LOADLIBES)
dvitomp: dvitomp.o
	$(kpathsea_link) dvitomp.o $(LOADLIBES)
dvitype: dvitype.o
	$(kpathsea_link) dvitype.o $(LOADLIBES)
etex: $(etex_o)
	$(kpathsea_link) $(etex_o) $(socketlibs) $(LOADLIBES)
gftodvi: gftodvi.o
	$(kpathsea_link) gftodvi.o $(LOADLIBES)
gftopk: gftopk.o
	$(kpathsea_link) gftopk.o $(LOADLIBES)
gftype: gftype.o
	$(kpathsea_link) gftype.o $(LOADLIBES)
@MFW@$(mfw): $(mf_o) $(windowlib)
@MFW@	$(kpathsea_link) $(mf_o) $(windowlink) $(LOADLIBES)
@MFN@mfnowin.o: mfnowin.c
@MFN@	$(compile) -DMFNOWIN $<
@MFN@$(mfn): $(mf_nowin_o) window/trap.o
@MFN@	$(kpathsea_link) $(mf_nowin_o) window/trap.o $(LOADLIBES)
mft: mft.o
	$(kpathsea_link) mft.o $(LOADLIBES)
mpost: $(mp_o)
	$(kpathsea_link) $(mp_o) $(LOADLIBES)
odvicopy: odvicopy.o
	$(kpathsea_link) odvicopy.o $(LOADLIBES)
odvitype: odvitype.o
	$(kpathsea_link) odvitype.o $(LOADLIBES)
ofm2opl: ofm2opl.o
	$(kpathsea_link) ofm2opl.o $(LOADLIBES)
omega: $(omega_o)
	$(kpathsea_link) $(omega_o) $(socketlibs) $(LOADLIBES)
opl2ofm: opl2ofm.o
	$(kpathsea_link) opl2ofm.o $(LOADLIBES)
ovf2ovp: ovf2ovp.o
	$(kpathsea_link) ovf2ovp.o $(LOADLIBES)
ovp2ovf: ovp2ovf.o
	$(kpathsea_link) ovp2ovf.o $(LOADLIBES)
patgen: patgen.o
	$(kpathsea_link) patgen.o $(LOADLIBES)
pdftex: $(pdftex_o) $(pdftexextra_o) $(pdftexlibsdep)
	$(kpathsea_cxx_link) $(pdftex_o) $(pdftexextra_o) $(pdftexlibs) $(socketlibs) $(LOADLIBES)
pdfetex: pdftexd.h $(pdfetex_o) $(pdfetexextra_o) $(pdftexlibsdep)
	$(kpathsea_cxx_link) $(pdfetex_o) $(pdfetexextra_o) $(pdftexlibs) $(socketlibs) $(LOADLIBES)
pktogf: pktogf.o
	$(kpathsea_link) pktogf.o $(LOADLIBES)
pktype: pktype.o
	$(kpathsea_link) pktype.o $(LOADLIBES)
pltotf: pltotf.o
	$(kpathsea_link) pltotf.o $(LOADLIBES)
pooltype: pooltype.o
	$(kpathsea_link) pooltype.o $(LOADLIBES)
tex: $(tex_o)
	$(kpathsea_link) $(tex_o) $(socketlibs) $(LOADLIBES)
tie: tie.o
	$(kpathsea_link) tie.o
tftopl: tftopl.o
	$(kpathsea_link) tftopl.o $(LOADLIBES)
vftovp: vftovp.o
	$(kpathsea_link) vftovp.o $(LOADLIBES)
vptovf: vptovf.o
	$(kpathsea_link) vptovf.o $(LOADLIBES)
weave: weave.o
	$(kpathsea_link) weave.o $(LOADLIBES)

# We put some programs (written directly in C) in a subdirectory.
$(mpware): $(mpware_sources)
	cd mpware && $(MAKE) $(common_makeargs)

# Additional dependencies for retangling.
bibtex.p dvicopy.p dvitomp.p dvitype.p etex.p gftopk.p gftodvi.p gftype.p \
  mf.p mft.p mp.p odvicopy.p odvitype.p ofm2opl.p omega.p opl2ofm.p \
  ovf2ovp.p ovp2ovf.p patgen.p pdfetex.p pdftex.p pktogf.p pktype.p \
  pltotf.p pooltype.p tex.p tftopl.p vftovp.p vptovf.p weave.p: tangle
# We need to be explicit for a number of programs because there is a
# $(srcdir) in the suffix rule.  This also means we can use a different
# suffix for the change file than .ch, if we want to.
bibtex.p: bibtex.web bibtex.ch
dvicopy.p: dvicopy.web dvicopy.ch
dvitomp.p: dvitomp.web dvitomp.ch
dvitype.p: dvitype.web dvitype.ch
etex.p etex.pool: etex.web etex.ch
	$(shared_env) ./tangle etex.web etex.ch
gftodvi.p: gftodvi.web gftodvi.ch
gftopk.p: gftopk.web gftopk.ch
gftype.p: gftype.web gftype.ch
mf.p mf.pool: mf.web mf.ch
mp.p mp.pool: mp.web mp.ch
mft.p: mft.web mft.ch
odvicopy.p: odvicopy.web odvicopy.ch
	$(shared_env) ./tangle odvicopy.web odvicopy.ch
odvitype.p: odvitype.web odvitype.ch
	$(shared_env) ./tangle odvitype.web odvitype.ch
ofm2opl.p: ofm2opl.web ofm2opl.ch
	$(shared_env) ./tangle ofm2opl.web ofm2opl.ch
omega.p omega.pool: otangle omega.web omega.ch
	$(shared_env) ./otangle omega.web omega.ch
opl2ofm.p: opl2ofm.web opl2ofm.ch
	$(shared_env) ./tangle opl2ofm.web opl2ofm.ch
ovf2ovp.p: ovf2ovp.web ovf2ovp.ch
	$(shared_env) ./otangle ovf2ovp.web ovf2ovp.ch
ovp2ovf.p: ovp2ovf.web ovp2ovf.ch
	$(shared_env) ./otangle ovp2ovf.web ovp2ovf.ch
patgen.p: patgen.web patgen.ch
pdftex.p pdftex.pool: pdftex.web pdftex.ch
	$(shared_env) ./tangle pdftex.web pdftex.ch
pdfetex.p pdfetex.pool: pdfetex.web pdfetex.ch
	$(shared_env) ./tangle pdfetex.web pdfetex.ch
pktogf.p: pktogf.web pktogf.ch
pktype.p: pktype.web pktype.ch
pltotf.p: pltotf.web pltotf.ch
pooltype.p: pooltype.web pooltype.ch
tex.p tex.pool: tex.web tex.ch
tftopl.p: tftopl.web tftopl.ch
vftovp.p: vftovp.web vftovp.ch
vptovf.p: vptovf.web vptovf.ch
weave.p: weave.web weave.ch

# Additional dependencies for reconverting to C.
$(other_c): $(web2c_aux) $(web2c_programs)
bibtex.c: web2c/cvtbib.sed
c-sources: $(all_c)

# Metafont and TeX generate more than .c file.
web2c_texmf = $(web2c_aux) $(web2c_programs) web2c/texmf.defines web2c/coerce.h
$(etex_c) etexcoerce.h etexd.h: etex.p $(web2c_texmf)
	$(web2c) etex
$(mf_c) mfcoerce.h mfd.h: mf.p $(web2c_texmf) web2c/cvtmf1.sed web2c/cvtmf2.sed
	$(web2c) mf
$(mp_c) mpcoerce.h mpd.h: mp.p $(web2c_texmf) web2c/cvtmf1.sed web2c/cvtmf2.sed
	$(web2c) mp
$(omega_c) omegacoerce.h omegad.h: omega.p $(web2c_texmf)
	$(web2c) omega
$(pdftex_c) pdftexcoerce.h pdftexd.h: pdftex.p $(web2c_texmf)
	$(web2c) pdftex
$(pdfetex_c) pdfetexcoerce.h pdfetexd.h: pdfetex.p $(web2c_texmf)
	$(web2c) pdfetex
$(tex_c) texcoerce.h texd.h: tex.p $(web2c_texmf)
	$(web2c) tex

# As long as we have to have separate rules to create these, might as well do
# a little work to avoid separate compilation rules, too.
etexextra.c: lib/texmfmp.c
	sed s/TEX-OR-MF-OR-MP/etex/ $(srcdir)/lib/texmfmp.c >$@
mfextra.c: lib/texmfmp.c
	sed s/TEX-OR-MF-OR-MP/mf/ $(srcdir)/lib/texmfmp.c >$@
mfnowin.c: lib/texmfmp.c
	sed s/TEX-OR-MF-OR-MP/mf/ $(srcdir)/lib/texmfmp.c >$@
mpextra.c: lib/texmfmp.c
	sed s/TEX-OR-MF-OR-MP/mp/ $(srcdir)/lib/texmfmp.c >$@
omegaextra.c: lib/texmfmp.c
	sed s/TEX-OR-MF-OR-MP/omega/ $(srcdir)/lib/texmfmp.c >$@
pdftexextra.c: lib/texmfmp.c
	sed s/TEX-OR-MF-OR-MP/pdftex/ $(srcdir)/lib/texmfmp.c >$@
pdfetexextra.c: lib/texmfmp.c
	sed s/TEX-OR-MF-OR-MP/pdfetex/ $(srcdir)/lib/texmfmp.c >$@
texextra.c: lib/texmfmp.c
	sed s/TEX-OR-MF-OR-MP/tex/ $(srcdir)/lib/texmfmp.c >$@

# A special rule for tie
tie.c: tiedir/tie.c
	-rm -f $@
	$(LN) $(srcdir)/tiedir/tie.c $@

# Additional dependencies for recompiling the C code are generated
# automatically, included at the end.

# Additional dependencies for relinking.
$(web2c_programs) $(programs) otangle otangleboot tangle tangleboot: \
  $(kpathsea) $(proglib)

# 
# Bootstrapping tangle requires making it with itself.  We use the opportunity
# to create an up-to-date tangleboot as well.
tangle: tangle.o
	$(kpathsea_link) tangle.o $(LOADLIBES)
	$(MAKE) $(common_makeargs) tangleboot.p
# tangle.p is a special case, since it is needed to compile itself.  We
# convert and compile the (distributed) tangleboot.p to make a tangle
# which we use to make the other programs.
tangle.p: tangleboot tangle.web tangle.ch
	$(shared_env) ./tangleboot $(srcdir)/tangle.web $(srcdir)/tangle.ch
tangle.web:
	@echo "You seem to be missing tangle.web, perhaps because you" >&2
	@echo "didn't retrieve web.tar.gz, only web2c.tar.gz." >&2
	@echo "You need both." >&2
	@echo >&2
	@echo "web.tar.gz should be available from the" >&2
	@echo "same place that you got web2c.tar.gz." >&2
	@echo "In any case, you can get it from" >&2
	@echo "ftp://ftp.tug.org/tex/web.tar.gz." >&2
	false

tangleboot: tangleboot.o
	$(kpathsea_link) tangleboot.o $(LOADLIBES)
tangleboot.c tangleboot.h: stamp-tangle $(web2c_programs) $(web2c_aux)
	$(web2c) tangleboot
# tangleboot.p is in the distribution
stamp-tangle: tangleboot.p
	date >stamp-tangle
# This is not run unless tangle.web or tangle.ch is changed.
tangleboot.p: tangle.web tangle.ch
	$(shared_env) ./tangle $(srcdir)/tangle.web $(srcdir)/tangle.ch
	mv tangle.p tangleboot.p
	date >stamp-tangle
	$(MAKE) $(common_makeargs) tangle

# Even web2c itself uses the library.
# It's annoying to have to give all the filenames here, 
# but texmfmp.c is an exception.
lib_sources = lib/alloca.c lib/basechsuffix.c lib/chartostring.c \
  lib/eofeoln.c lib/fprintreal.c lib/input2int.c lib/inputint.c lib/main.c \
  lib/openclose.c lib/printversion.c lib/uexit.c lib/usage.c lib/version.c \
  lib/zround.c 
$(proglib): $(lib_sources) stamp-auto
	cd lib && $(MAKE) $(common_makeargs)

# No exceptions in this library.
window_sources = $(srcdir)/window/*.c
$(windowlib): mfd.h $(window_sources)
	cd window && $(MAKE) $(window_makeargs)
window/trap.o: $(srcdir)/window/trap.c
	cd window && $(MAKE) $(common_makeargs) trap.o
@PTEX@pdflib_sources = $(srcdir)/pdftexdir/*.c
@PTEX@pdftexdir/libpdf.a: $(pdflib_sources)
@PTEX@	cd pdftexdir && $(MAKE) $(common_makeargs) libpdf.a
@PTEX@$(LIBPNGDIR)/libpng.a: $(LIBPNGSRCDIR)/*.c
@PTEX@	cd $(LIBPNGDIR) && $(MAKE) $(common_makeargs) libpng.a
@PTEX@$(ZLIBDIR)/libz.a: $(ZLIBSRCDIR)
@PTEX@	cd $(ZLIBDIR) && $(MAKE) $(common_makeargs) libz.a
@PTEX@$(xpdfdir)/pdftoepdf.a: $(srcdir)/$(xpdfdir)/*.c* \
@PTEX@  $(srcdir)/pdftexdir/epdf.[ch] $(srcdir)/pdftexdir/pdftoepdf.cc
@PTEX@	rm -f $(xpdfdir)/pdftoepdf.cc $(xpdfdir)/epdf.h
@PTEX@	cp $(srcdir)/pdftexdir/epdf.h $(xpdfdir)
@PTEX@	cp $(srcdir)/pdftexdir/pdftoepdf.cc $(xpdfdir)
@PTEX@	cd $(xpdfdir) && $(MAKE) $(common_makeargs) pdftoepdf.a
@PTEX@$(xpdfextradir)/libGoo.a: $(srcdir)/$(xpdfextradir)/*.c*
@PTEX@	cd $(xpdfextradir) && $(MAKE) $(common_makeargs) libGoo.a

# The web2c program consists of several executables.
web2c/fixwrites: web2c/fixwrites.c
	cd web2c && $(MAKE) $(common_makeargs) fixwrites
web2c/splitup: web2c/splitup.c
	cd web2c && $(MAKE) $(common_makeargs) splitup
web2c/web2c: web2c/main.c web2c/web2c.h web2c/web2c.l web2c/web2c.y
	cd web2c && $(MAKE) $(common_makeargs) web2c

ac_include ../make/tkpathsea.mk

# 
# Making dumps.
@TEX@all_fmts = #tex.fmt $(fmts)
@ETEX@all_efmts = #etex.efmt $(efmts)
@CTEX@all_cfmts = #tex.efmt $(cfmts)
@OMEGA@all_ofmts = #omega.fmt $(ofmts)
@PTEX@all_pdffmts = #pdftex.fmt $(pdffmts)
@PETEX@all_pdfefmts = #pdfetex.efmt $(pdfefmts)
all_formats = $(all_fmts) $(all_efmts) $(all_cfmts) $(all_ofmts) $(all_pdffmts) $(all_pdfefmts)
all_bases = #mf.base $(bases)
all_mems = #mpost.mem $(mems)

dumpenv = TEXMFCNF=../kpathsea TEXMF=$(texmf)

dumps: fmts efmts cfmts ofmts pdffmts pdfefmts bases mems
fmts: $(all_fmts)
efmts: $(all_efmts)
cfmts: $(all_cfmts)
ofmts: $(all_ofmts)
pdffmts: $(all_pdffmts)
pdfefmts: $(all_pdfefmts)
bases: $(all_bases)
mems: $(all_mems)

tex.fmt: tex
	$(dumpenv) $(MAKE) $(makeargs) files="--progname=tex plain.tex cmr10.tfm" prereq-check
	$(dumpenv) ./tex --fmt=tex --ini \\input plain \\dump </dev/null

latex.fmt: tex
	$(dumpenv) $(MAKE) $(makeargs) files="--progname=latex latex.ltx" prereq-check
	$(dumpenv) ./tex --progname=latex --ini \\input latex.ltx </dev/null

etex.efmt: etex
	$(dumpenv) $(MAKE) files="--progname=etex etex.src plain.tex cmr10.tfm" prereq-check
	$(dumpenv) ./etex --efmt=etex --ini \*\\input etex.src \\dump </dev/null

elatex.efmt: etex
	$(dumpenv) $(MAKE) files="--progname=elatex latex.ltx" prereq-check
	$(dumpenv) ./etex --efmt=elatex --ini \*\\input latex.ltx </dev/null

tex.efmt: etex
	$(dumpenv) $(MAKE) files="--progname=tex plain.tex cmr10.tfm" prereq-check
	$(dumpenv) ./etex --efmt=tex --ini \\input plain \\dump </dev/null

latex.efmt: etex
	$(dumpenv) $(MAKE) files="--progname=latex latex.ltx" prereq-check
	$(dumpenv) ./etex --progname=latex --ini \\input latex.ltx </dev/null

omega.fmt: omega
	$(dumpenv) $(MAKE) files="--progname=omega omega.tex" prereq-check
	$(dumpenv) ./omega --ini \\input omega.tex \\dump </dev/null

lambda.fmt: omega
	$(dumpenv) $(MAKE) files="--progname=lambda lambda.tex" prereq-check
	$(dumpenv) ./omega --ini --progname=lambda \\input lambda.tex </dev/null

pdftex.fmt: pdftex
	$(dumpenv) $(MAKE) files="--progname=pdftex plain.tex cmr10.tfm" prereq-check
	$(dumpenv) ./pdftex --fmt=pdftex --ini \\pdfoutput=1 \\input plain \\dump </dev/null

pdflatex.fmt: pdftex
	$(dumpenv) $(MAKE) files="--progname=pdflatex latex.ltx" prereq-check
	$(dumpenv) ./pdftex --fmt=pdflatex --ini \\pdfoutput=1 \\input latex.ltx </dev/null

pdftexinfo.fmt: pdftex
	$(dumpenv) $(MAKE) files="--progname=pdftexinfo pdftexinfo.ini" prereq-check
	$(dumpenv) ./pdftex --progname=pdftexinfo --ini pdftexinfo.ini </dev/null

pdfetex.efmt: pdfetex
	$(dumpenv) $(MAKE) files="--progname=pdfetex etex.src plain.tex cmr10.tfm" prereq-check
	$(dumpenv) ./pdfetex --efmt=pdfetex --ini \*\\pdfoutput=1\\input etex.src \\dump </dev/null

pdfelatex.efmt: pdfetex
	$(dumpenv) $(MAKE) files="--progname=pdfelatex latex.ltx" prereq-check
	$(dumpenv) ./pdfetex --efmt=pdfelatex --ini \*\\pdfoutput=1\\input latex.ltx </dev/null

mltex.fmt: tex
	$(dumpenv) $(MAKE) files="--progname=mltex plain.tex cmr10.tfm" prereq-check
	$(dumpenv) ./tex --mltex --fmt=mltex --ini \\input plain \\dump </dev/null

mllatex.fmt: tex
	$(dumpenv) $(MAKE) files="--progname=mllatex latex.ltx" prereq-check
	$(dumpenv) ./tex --mltex --fmt=mllatex --ini \\input latex.ltx </dev/null

mf.base: mf
	$(dumpenv) $(MAKE) $(makeargs) files="plain.mf cmr10.mf $(localmodes).mf" prereq-check
	$(dumpenv) ./mf --base=mf --ini \\input plain input $(localmodes) dump </dev/null

mpost.mem: mpost
	$(dumpenv) $(MAKE) $(makeargs) files=plain.mp prereq-check
	$(dumpenv) ./mpost --mem=mpost --ini \\input plain dump </dev/null

# This is meant to be called recursively, with $(files) set.
prereq-check: $(kpathsea_dir)/kpsewhich
	$(kpathsea_dir)/kpsewhich $(files) >/dev/null || $(MAKE) prereq-lose >/dev/null

prereq-lose:
	@echo "You seem to be missing input files necessary to make the" >&2
	@echo "basic formats (some or all of: $(files))." >&2
	@echo "Perhaps you've defined the default paths incorrectly, or" >&2
	@echo "perhaps you have environment variables set pointing" >&2
	@echo "to an incorrect location.  See ../kpathsea/BUGS." >&2
	@echo >&2
	@echo "If you simply do not have the files, you can" >&2
	@echo "retrieve a minimal set of input files from" >&2
	@echo "ftp://ftp.tug.org/tex/texklib.tar.gz, mirrored on" >&2
	@echo "CTAN hosts in systems/web2c." >&2
	false

$(kpathsea_dir)/kpsewhich: $(kpathsea)

amstex.fmt: tex
	$(dumpenv) ./tex --progname=amstex --ini amstex.ini </dev/null

# Texinfo changes the escape character from `\' to `@'.
texinfo.fmt: tex.fmt
	$(dumpenv) ./tex --progname=texinfo --ini texinfo @dump </dev/null

eplain.fmt: tex.fmt
	touch eplain.aux # Makes cross-reference warnings work right.
	$(dumpenv) ./tex --progname=eplain --ini \&./tex eplain \\dump </dev/null

# 
install: install-exec install-data
install-exec:: install-links
install-data:: install-dumps

# The actual binary executables and pool files.
install-programs: $(programs)
	$(SHELL) $(top_srcdir)/../mkinstalldirs $(bindir) $(texpooldir) \
	  $(mfpooldir) $(mppooldir)
	cd mpware && $(MAKE) $(install_makeargs) install-exec
	for p in $(programs); do $(INSTALL_LIBTOOL_PROG) $(bindir) $$p; done
@OMEGA@	cd otps && $(MAKE) $(install_makeargs) install-programs

# The links to {mf,mp,tex} for each format and for {ini,vir}{mf,mp,tex},
# plus the equivalents for e-TeX, Omega, pdfTeX, and pdfeTeX.
install-links: install-programs
@TEX@	cd $(bindir) && (rm -f initex virtex; \
@TEX@	  $(LN) tex initex; $(LN) tex virtex)
@ETEX@	cd $(bindir) && (rm -f einitex evirtex; \
@ETEX@	  $(LN) etex einitex; $(LN) etex evirtex)
@CTEX@	cd $(bindir) && (rm -f tex initex virtex; \
@CTEX@	  $(LN) etex tex; $(LN) etex initex; $(LN) etex virtex)
@OMEGA@	cd $(bindir) && (rm -f iniomega viromega; \
@OMEGA@	  $(LN) omega iniomega; $(LN) omega viromega)
@PTEX@	cd $(bindir) && (rm -f pdfinitex pdfvirtex; \
@PTEX@	  $(LN) pdftex pdfinitex; $(LN) pdftex pdfvirtex)
@PETEX@	cd $(bindir) && (rm -f pdfeinitex pdfevirtex; \
@PETEX@	  $(LN) pdfetex pdfeinitex; $(LN) pdfetex pdfevirtex)
	cd $(bindir) && (rm -f inimf virmf; \
	  $(LN) mf inimf; $(LN) mf virmf)
	cd $(bindir) && (rm -f inimpost virmpost; \
	  $(LN) mpost inimpost; $(LN) mpost virmpost)
# The ugly "" avoids a syntax error in case the lists are empty.
	test -z "$(fmts)" || \
	  for f in ""$(fmts); do base=`basename $$f .fmt`; \
	    (cd $(bindir) && (rm -f $$base; $(LN) tex $$base)); done
	test -z "$(efmts)" || \
	  for f in ""$(efmts); do base=`basename $$f .efmt`; \
	    (cd $(bindir) && (rm -f $$base; $(LN) etex $$base)); done
	test -z "$(cfmts)" || \
	  for f in ""$(cfmts); do base=`basename $$f .efmt`; \
	    (cd $(bindir) && (rm -f $$base; $(LN) etex $$base)); done
	test -z "$(ofmts)" || \
	  for f in ""$(ofmts); do base=`basename $$f .fmt`; \
	    (cd $(bindir) && (rm -f $$base; $(LN) omega $$base)); done
	test -z "$(pdffmts)" || \
	  for f in ""$(pdffmts); do base=`basename $$f .fmt`; \
	    (cd $(bindir) && (rm -f $$base; $(LN) pdftex $$base)); done
	test -z "$(pdfefmts)" || \
	  for f in ""$(pdfefmts); do base=`basename $$f .efmt`; \
	    (cd $(bindir) && (rm -f $$base; $(LN) pdfetex $$base)); done
	test -z "$(bases)" || \
	  for f in ""$(bases); do base=`basename $$f .base`;\
	    (cd $(bindir) && (rm -f $$base; $(LN) mf $$base)); done
	test -z "$(mems)" || \
	  for f in ""$(mems); do base=`basename $$f .mem`; \
            (cd $(bindir) && (rm -f $$base; $(LN) mpost $$base)); done

# Always do plain.*, so examples from the TeXbook (etc.) will work.
install-dumps: install-fmts install-bases install-mems
install-fmts: $(all_formats)
	$(SHELL) $(top_srcdir)/../mkinstalldirs $(fmtdir)
	echo "$(all_formats)" | grep '^[ ]*$$' >/dev/null || \
	  for f in ""$(all_formats); do $(INSTALL_DATA) $$f $(fmtdir)/$$f; done
@TEX@	#cd $(fmtdir) && (rm -f plain.fmt; $(LN) tex.fmt plain.fmt)
@CTEX@	#cd $(fmtdir) && (rm -f plain.efmt; $(LN) tex.efmt plain.efmt)

install-bases: $(all_bases)
	$(SHELL) $(top_srcdir)/../mkinstalldirs $(basedir)
	test -z "$(all_bases)" || \
	  for f in ""$(all_bases); do $(INSTALL_DATA) $$f $(basedir)/$$f; done
	#cd $(basedir) && (rm -f plain.base; $(LN) mf.base plain.base)

install-mems: $(all_mems)
	$(SHELL) $(top_srcdir)/../mkinstalldirs $(memdir)
	test -z "$(all_mems)" || \
	  for f in ""$(all_mems); do $(INSTALL_DATA) $$f $(memdir)/$$f; done
	#cd $(memdir) && (rm -f plain.mem; $(LN) mpost.mem plain.mem)

# Auxiliary files.
install-data::
	$(SHELL) $(top_srcdir)/../mkinstalldirs $(texpooldir) $(mfpooldir) $(mppooldir) $(web2cdir) $(fontnamedir)
@TEX@	$(INSTALL_DATA) tex.pool $(texpooldir)/tex.pool
@ETEX@	$(INSTALL_DATA) etex.pool $(texpooldir)/etex.pool
@OMEGA@	$(INSTALL_DATA) omega.pool $(texpooldir)/omega.pool
@PTEX@	$(INSTALL_DATA) pdftex.pool $(texpooldir)/pdftex.pool
@PETEX@	$(INSTALL_DATA) pdfetex.pool $(texpooldir)/pdfetex.pool
	$(INSTALL_DATA) mf.pool $(mfpooldir)/mf.pool
	$(INSTALL_DATA) mp.pool $(mppooldir)/mp.pool
	cd $(srcdir)/share && for f in *.tcx; do \
	  $(INSTALL_DATA) $$f $(web2cdir)/$$f; done
	cd $(srcdir)/share && for f in *.map; do \
	  $(INSTALL_DATA) $$f $(fontnamedir)/$$f; done
	cd doc && $(MAKE) $(install_makeargs) install-data
	cd man && $(MAKE) $(install_makeargs) install-data
	$(INSTALL_DATA) $(srcdir)/tiedir/tie.1 $(mandir)/tie.$(manext)
	$(INSTALL_DATA) fmtutil.cnf $(web2cdir)/fmtutil.cnf

# The distribution comes with up-to-date .info* files,
# so this should never be used unless something goes wrong
# with the unpacking, or you modify the manual.
doc/web2c.info:
	cd doc && $(MAKE) info
info dvi:
	cd doc && $(MAKE) $@

# Manual pages
manpages:
	cd man && $(MAKE) all

# 
# make dist won't work for anyone but me. Sorry.

@MAINT@all-dist: dist web-dist etex-dist omega-dist pdftex-dist
@MAINT@
@MAINT@distname = web2c
@MAINT@program_files = PROJECTS *.ac *.ch tangleboot.p
@MAINT@# The files that omega places in the main directory.
@MAINT@omega_files = omegamem.h otangleboot.p \
@MAINT@ {odvicopy,odvitype,ofm2opl,opl2ofm,otangle,ovf2ovp,ovp2ovf}.{web,ch}
@MAINT@
@MAINT@triptrapdiffs: triptrap/trip.diffs triptrap/mftrap.diffs triptrap/mptrap.diffs
@MAINT@triptrap/trip.diffs: tex
@MAINT@	$(MAKE) trip | tail +1 >triptrap/trip.diffs
@MAINT@triptrap/mftrap.diffs: mf
@MAINT@	$(MAKE) trap | tail +1 >triptrap/mftrap.diffs
@MAINT@triptrap/mptrap.diffs: mpost
@MAINT@	$(MAKE) mptrap | tail +1 >triptrap/mptrap.diffs
@MAINT@
@MAINT@tests/check.log: $(programs)
@MAINT@	$(MAKE) check | tail +1 >tests/check.log
@MAINT@
@MAINT@dist_subdirs = doc lib mpware share tests web2c window
@MAINT@pre-dist-$(distname): depend triptrapdiffs tests/check.log tangleboot.p
@MAINT@	cd web2c && $(MAKE) lex.yy.c y_tab.c
@MAINT@	cd doc && $(MAKE) doc dvi
@MAINT@
@MAINT@post-dist-$(distname): 
@MAINT@# Make the subdirectories.
@MAINT@	for d in $(dist_subdirs); do \
@MAINT@	  mkdir -p $(texk_distdir)/$(distname)/$$d; done
@MAINT@# Link files in subdirectories.
@MAINT@	for f in `find $(dist_subdirs)		\
@MAINT@		       \(    -name README	\
@MAINT@			  -o -name convert	\
@MAINT@			  -o -name ChangeLog	\
@MAINT@			  -o -name 'coerce.*'	\
@MAINT@			  -o -name ref.aux	\
@MAINT@			  -o -name ref.bbl	\
@MAINT@			  -o -name ref.tex	\
@MAINT@			  -o -name ref.txi	\
@MAINT@			  -o -name texinfo.bst	\
@MAINT@			  -o -name web2c.cps	\
@MAINT@			  -o -name web2c.aux	\
@MAINT@			  -o -name '*.asm'	\
@MAINT@			  -o -name '*.[chly]'	\
@MAINT@			  -o -name '*.defines'	\
@MAINT@			  -o -name '*.in'	\
@MAINT@			  -o -name '*.info*'	\
@MAINT@	                  -o -name '*.map'	\
@MAINT@			  -o -name '*.sed'	\
@MAINT@			  -o -name '*.tcx'	\
@MAINT@			  -o -name '*.texi'	\
@MAINT@		       \) -print`; do		\
@MAINT@	  ln $$f $(distdir)/`dirname $$f`; done
@MAINT@# Handle the dependeny files in the subdirectories.
@MAINT@	for d in lib mpware web2c window; do \
@MAINT@          cp -p $$d/depend.mk $(texk_distdir)/$(distname)/$$d; done
@MAINT@# Other subdirectories.
@MAINT@	mkdir $(distdir)/triptrap && cd $(distdir)/triptrap && \
@MAINT@	  for i in ../../../../triptrap/*; do \
@MAINT@	    if test -f $$i; then ln -s $$i .; fi; done
@MAINT@	mkdir $(distdir)/tiedir && cd $(distdir)/tiedir && \
@MAINT@	  for i in ../../../../tiedir/*; do \
@MAINT@	    if test -f $$i; then ln -s $$i .; fi; done
@MAINT@	mkdir $(distdir)/man && cd $(distdir)/man && \
@MAINT@	  for i in ../../../../man/*; do \
@MAINT@	    if test -f $$i; then ln -s $$i .; fi; done;
@MAINT@	cd $(distdir)/man && rm -f *.1 Makefile sedscript
@MAINT@	rm -f $(distdir)/window/x11.c
@MAINT@	rm -f $(distdir)/tests/patgen.in
@MAINT@	cd $(distdir)/tests && (rm just.texi; ln -s ../../../../tests/* .; rm -f x* CVS)
@MAINT@	cd $(distdir)/tests && ln -s $klib/bibtex/bib/xampl.bib
@MAINT@	cd $(distdir)/tests && rm -f missfont.log ptmr.mpx io.tex exampl.b??
@MAINT@# We supply the flex/bison output in case the user can't generate them.
@MAINT@	cd $(distdir)/web2c; ../../../../../rename 's/$$/-dist/' lex.yy.c y_tab.[ch]
@MAINT@# Remove cruft.
@MAINT@	cd $(distdir); rm -f $(addsuffix .c, $(programs) tangleboot otangleboot)
@MAINT@	cd $(distdir); rm -f $(addsuffix .h, $(programs) tangleboot otangleboot)
@MAINT@	cd $(distdir); rm -f etex.ch pdftex.ch pdfetex.ch omega.ch
@MAINT@	cd $(distdir); bash -c "rm -f tests/x* tests/allbib.{bbl,blg,dvi,log}"
@MAINT@	cd $(distdir); bash -c "rm -f $(omega_files)"
@MAINT@	cd $(distdir); bash -c "rm -f *.c *{coerce,d}.h"
@MAINT@	touch $(distdir)/doc/*.info*
@MAINT@
@MAINT@web-dist:
@MAINT@	rm -rf $(top_distdir)
@MAINT@	mkdir -p $(distdir)
@MAINT@	for f in *.web; do ln $$f $(distdir); done
@MAINT@	rm -f $(distdir)/etex.web $(distdir)/omega.web
@MAINT@	rm -f $(distdir)/pdftex.web $(distdir)/pdfetex.web
@MAINT@	cd $(distdir); bash -c "rm -f $(omega_files)"
@MAINT@	chmod -w $(distdir)/*
@MAINT@	GZIP=-9 tar czf web-$(version).tar.gz $(top_distdir)
@MAINT@	rm -rf $(top_distdir)
@MAINT@
@MAINT@etex-dist:
@MAINT@	rm -rf $(top_distdir)
@MAINT@	mkdir -p $(distdir)/etexdir
@MAINT@	cp -rp etexdir/* $(distdir)/etexdir
@MAINT@	rm -rf $(distdir)/etexdir/CVS $(distdir)/etexdir/*/CVS
@MAINT@	GZIP=-9 tar czf web2c-$(version)-etex-`cat etexdir/etex.version`.tar.gz $(top_distdir)
@MAINT@	rm -rf $(top_distdir)
@MAINT@
@MAINT@omega-dist:
@MAINT@	rm -rf $(top_distdir)
@MAINT@	mkdir -p $(distdir)/omegadir $(distdir)/omegaware $(distdir)/otps
@MAINT@	cp -p omegadir/* $(distdir)/omegadir
@MAINT@	cp -p omegaware/* $(distdir)/omegaware
@MAINT@	cd otps && $(MAKE) lex.yy.c y_tab.c
@MAINT@	for f in otps/*.[chly] otps/*.in; do cp -p $$f $(distdir)/otps; done
@MAINT@	cp -p otps/mkocp otps/mkofm $(distdir)/otps
@MAINT@# We supply the flex/bison output in case the user can't generate them.
@MAINT@	cd $(distdir)/otps; ../../../../../rename 's/$$/-dist/' lex.yy.c y_tab.[ch]
@MAINT@	GZIP=-9 tar czf web2c-$(version)-omega-`cat omegadir/omega.version`.tar.gz $(top_distdir)
@MAINT@	rm -rf $(top_distdir)
@MAINT@
@MAINT@pdftex-dist:
@MAINT@	rm -rf $(top_distdir)
@MAINT@	mkdir -p $(distdir)/pdftexdir $(distdir)/pdfetexdir
@MAINT@	cp -rp pdftexdir/* $(distdir)/pdftexdir
@MAINT@	cp -rp pdfetexdir/* $(distdir)/pdfetexdir
@MAINT@	rm -rf $(distdir)/pdf*texdir/CVS $(distdir)/pdf*texdir/*/CVS
@MAINT@	rm -f $(distdir)/pdf*texdir/Makefile
@MAINT@	rm -f $(distdir)/pdf*texdir/*.[oa]
@MAINT@	rm -f $(distdir)/pdf*texdir/*/config.*
@MAINT@	rm -f $(distdir)/pdf*texdir/*/Makefile
@MAINT@	rm -f $(distdir)/pdf*texdir/*/*.[oa]
@MAINT@	rm -f $(distdir)/pdf*texdir/*/*/Makefile
@MAINT@	rm -f $(distdir)/pdf*texdir/*/*/*.[ao]
@MAINT@	rm -f $(distdir)/pdf*texdir/*/*/pdftoepdf.cc
@MAINT@	rm -f $(distdir)/pdf*texdir/*/*/epdf.h
@MAINT@	GZIP=-9 tar czf web2c-$(version)-pdftex-`cat pdftexdir/pdftex.version`.tar.gz $(top_distdir)
@MAINT@	rm -rf $(top_distdir)

ac_include ../make/dist.mk

ac_include ../make/config.mk

# 
# Testing, including triptrap. The `x' filenames are for output.
@TEX@tex_check = tex-check
@ETEX@etex_check = etex-check
check: bibtex-check dvicopy-check dvitomp-check dvitype-check \
       $(etex_check) gftodvi-check gftopk-check gftype-check \
       mf-check mft-check mpost-check patgen-check pktogf-check \
       pktype-check pltotf-check pooltype-check $(tex_check) tftopl-check \
       vftovp-check vptovf-check weave-check

@TEX@trip = trip
@ETEX@etrip = etrip
triptrap: $(trip) trap mptrap $(etrip)
testdir = $(srcdir)/triptrap
testenv = TEXMFCNF=$(testdir)
dvitype_args = -output-level=2 -dpi=72.27 -page-start='*.*.*.*.*.*.*.*.*.*'
trip: pltotf tftopl tex dvitype
	@echo ">>> See $(testdir)/trip.diffs for example of acceptable diffs." >&2
	./pltotf $(testdir)/trip.pl trip.tfm
	./tftopl ./trip.tfm trip.pl
	-diff $(testdir)/trip.pl trip.pl
	rm -f trip.tex; $(LN) $(testdir)/trip.tex . # get same filename in log
	-$(SHELL) -c '$(testenv) ./tex --progname=initex <$(testdir)/trip1.in >tripin.fot'
	mv trip.log tripin.log
	-diff $(testdir)/tripin.log tripin.log
# May as well test non-ini second time through.
	-$(SHELL) -c '$(testenv) ./tex <$(testdir)/trip2.in >trip.fot'
	-diff $(testdir)/trip.fot trip.fot
# We use $(DIFF) instead of `diff' only for those files where there
# might actually be legitimate numerical differences.
	-$(DIFF) $(DIFFFLAGS) $(testdir)/trip.log trip.log
	$(SHELL) -c '$(testenv) ./dvitype $(dvitype_args) trip.dvi >trip.typ'
	-$(DIFF) $(DIFFFLAGS) $(testdir)/trip.typ trip.typ

# Can't run trap and mptrap in parallel, because both write trap.{log,tfm}.
trap: mf tftopl gftype
	@echo ">>> See $(testdir)/mftrap.diffs for example of acceptable diffs." >&2
	rm -f trap.mf; $(LN) $(testdir)/trap.mf . # get same filename in log
	-$(SHELL) -c '$(testenv) ./mf --progname=inimf <$(testdir)/mftrap1.in >mftrapin.fot'
	mv trap.log mftrapin.log
	-diff $(testdir)/mftrapin.log mftrapin.log
	-$(SHELL) -c '$(testenv) ./mf <$(testdir)/mftrap2.in >mftrap.fot'
	mv trap.log mftrap.log
	mv trap.tfm mftrap.tfm
	-diff $(testdir)/mftrap.fot mftrap.fot
	-diff $(testdir)/mftrap.log mftrap.log
	./tftopl ./mftrap.tfm mftrap.pl
	-diff $(testdir)/mftrap.pl mftrap.pl
	$(SHELL) -c '$(testenv) ./gftype -m -i ./trap.72270gf >trap.typ'
	-diff $(testdir)/trap.typ trap.typ

mptrap: pltotf mpost tftopl
	@echo ">>> See $(testdir)/mptrap.diffs for example of acceptable diffs." >&2
	rm -f mtrap.mp; $(LN) $(testdir)/mtrap.mp . # get same filename in log
	./pltotf $(testdir)/trapf.pl trapf.tfm
	-$(SHELL) -c '$(testenv) ./mpost --progname=inimpost mtrap'
	-diff $(testdir)/mtrap.log mtrap.log
	-diff $(testdir)/mtrap.0 mtrap.0
	-diff $(testdir)/mtrap.1 mtrap.1
	-diff $(testdir)/writeo writeo
	-diff $(testdir)/writeo.2 writeo.2
	rm -f trap.mp; $(LN) $(testdir)/trap.mp .
	rm -f trap.mpx; $(LN) $(testdir)/trap.mpx .
	-$(SHELL) -c '$(testenv) ./mpost --progname=inimpost <$(testdir)/mptrap1.in >mptrapin.fot'
	mv trap.log mptrapin.log
	-diff $(testdir)/mptrapin.log mptrapin.log
# Must run inimp or font_name[null_font] is not initialized, leading to diffs.
	-$(SHELL) -c '$(testenv) ./mpost --progname=inimpost <$(testdir)/mptrap2.in >mptrap.fot'
	mv trap.log mptrap.log
	mv trap.tfm mptrap.tfm
	-diff $(testdir)/mptrap.fot mptrap.fot
	-diff $(testdir)/mptrap.log mptrap.log
	-diff $(testdir)/trap.5 trap.5
	-diff $(testdir)/trap.6 trap.6
	-diff $(testdir)/trap.148 trap.148
	-diff $(testdir)/trap.149 trap.149
	-diff $(testdir)/trap.150 trap.150
	-diff $(testdir)/trap.151 trap.151
	-diff $(testdir)/trap.197 trap.197
	-diff $(testdir)/trap.200 trap.200
	./tftopl ./mptrap.tfm mptrap.pl
	-diff $(testdir)/mptrap.pl mptrap.pl

# Ad hoc tests.
bibtex-check: bibtex
	test -f tests/exampl.aux || \
	  cp $(srcdir)/tests/exampl.aux tests/exampl.aux
	BSTINPUTS=$(srcdir)/tests ./bibtex tests/exampl

dvicopy-check: dvicopy
	./dvicopy $(srcdir)/tests/story tests/xstory.dvi
# Redirect stderr so the terminal output will end up in the log file.
	(TFMFONTS=$(srcdir)/tests: ./dvicopy <$(srcdir)/tests/pplr.dvi \
	  >tests/xpplr.dvi) 2>&1

dvitomp-check: dvitomp
	./dvitomp $(srcdir)/tests/story.dvi tests/xstory.mpx
	TFMFONTS=$(srcdir)/tests: VFFONTS=$(srcdir)/tests: \
	  ./dvitomp $(srcdir)/tests/ptmr 
	mv ptmr.mpx tests/xptmr.mpx

dvitype-check: dvitype
	./dvitype -show-opcodes $(srcdir)/tests/story >tests/xstory.dvityp
	./dvitype --p=\*.\*.2 $(srcdir)/tests/pagenum.dvi >tests/xpagenum.typ

gftodvi-check: gftodvi
	TFMFONTS=$(srcdir)/tests: ./gftodvi -verbose \
	  $(srcdir)/tests/cmr10.600gf
	mv cmr10.dvi tests/xcmr10.dvi

gftopk-check: gftopk
	./gftopk -verbose $(srcdir)/tests/cmr10.600gf tests/xcmr10.pk
	./gftopk $(srcdir)/tests/cmr10.600gf cmr10.pk && rm cmr10.pk

gftype-check: gftype
	./gftype $(srcdir)/tests/cmr10.600gf >tests/xcmr10.gft1
	./gftype -m -i $(srcdir)/tests/cmr10.600gf >tests/xcmr10.gft2

mf-check: trap mf.base
	./mf '&./mf \tracingstats:=1; end.'
	./mf $(srcdir)/tests/online
	./mf $(srcdir)/tests/one.two
	./mf $(srcdir)/tests/uno.dos

mft-check: mft
	./mft $(srcdir)/tests/io; mv io.tex tests/io.tex

mpost-check: mptrap mpost.mem
	./mpost '&./mpost \tracingstats:=1; end.'
	MAKEMPX_BINDIR=`pwd`:`pwd`/mpware MPXCOMMAND=mpware/makempx \
	  ./mpost $(srcdir)/tests/mptest
	./mpost $(srcdir)/tests/one.two
	./mpost $(srcdir)/tests/uno.dos

patgen-check: patgen
	./patgen $(srcdir)/tests/dict $(srcdir)/tests/patterns tests/xout \
	   $(srcdir)/tests/translate <$(srcdir)/tests/patgen.in

pktogf-check: pktogf
	./pktogf -verbose $(srcdir)/tests/cmr10.pk tests/xcmr10.600gf
	./pktogf $(srcdir)/tests/cmr10.pk && rm cmr10.gf

pktype-check: pktype
	./pktype $(srcdir)/tests/cmr10.pk >tests/xcmr10.pktyp

pltotf-check: pltotf
	./pltotf -verbose $(srcdir)/tests/cmr10 tests/xcmr10

# When tex.pool has not been generated we pooltype etex.pool
pooltype-check: pooltype
@TEX@	./pooltype tex.pool >tests/xtexpool.typ
@CTEX@	./pooltype etex.pool >tests/xtexpool.typ

# No need for tangle-check, since we run it to make everything else.

tex-check: trip tex.fmt
# Test truncation (but don't bother showing the warning msg).
	./tex --output-comment="`cat $(srcdir)/PROJECTS`" \
	    $(srcdir)/tests/hello 2>/dev/null \
	  && ./dvitype hello.dvi | grep olaf@infovore.xs4all.nl >/dev/null
# \openout should show up in \write's.
	./tex $(srcdir)/tests/openout && grep xfoo openout.log
# one.two.tex -> one.two.log
	./tex $(srcdir)/tests/one.two && ls -l one.two.log
# uno.dos -> uno.log
	./tex $(srcdir)/tests/uno.dos && ls -l uno.log
	./tex $(srcdir)/tests/just.texi && ls -l just.log
	-./tex $(srcdir)/tests/batch.tex
	./tex --shell $(srcdir)/tests/write18 | grep echo
# tcx files test (to be included)
#	./tex --translate-file=$(srcdir)/share/isol1-t1.tcx \
#	  $(srcdir)/tests/eight && ./dvitype eight.dvi >eigh.typ
	./tex --mltex --progname=initex $(srcdir)/tests/mltextst
	-./tex </dev/null
	-PATH=`pwd`:$(kpathsea_dir):$(kpathsea_srcdir):$$PATH \
	  WEB2C=$(kpathsea_srcdir) TMPDIR=.. \
	  ./tex '\nonstopmode\font\foo=nonesuch\end'

tftopl-check: tftopl
	./tftopl -verbose $(srcdir)/tests/cmr10 tests/xcmr10

vftovp-check: vftovp
	TFMFONTS=$(srcdir)/tests ./vftovp -verbose $(srcdir)/tests/ptmr ptmr tests/xptmr

vptovf-check: vptovf
	./vptovf $(srcdir)/tests/ptmr tests/xptmr tests/xptmr

weave-check: weave
	./weave $(srcdir)/pooltype

installcheck:
	cd $(srcdir)/tests && bibtex allbib
	mf '\mode:=ljfour; input logo10' && tftopl logo10.tfm >/dev/null
	tex '\nonstopmode \tracingstats=1 \input story \bye'

# 
# Cleaning.
@PTEX@pdftexdir = pdftexdir
@PETEX@pdfetexdir = pdfetexdir
@OMEGA@otps = otps
all_subdirs = doc lib man mpware web2c window $(otps) $(pdftexdir) $(pdfetexdir) $(xpdfdir) $(xpdfextradir)

# Having a multiple-target rule with the subdir loop fails because of
# the dependencies introduced by clean.mk.  Yet, we want the
# dependencies here at the top level so that distclean will run the
# clean rules, etc.  So, sigh, put the subdir loop in each target and
# only run it if we have a Makefile.  Alternatively, we could do as
# Automake does.

mostlyclean::
	test ! -r lib/Makefile \
	  || for d in $(all_subdirs); do (cd $$d && $(MAKE) $@); done
	rm -f otangleboot tangleboot
clean::
	test ! -r lib/Makefile \
	  || for d in $(all_subdirs); do (cd $$d && $(MAKE) $@); done
	rm -f *.aux *.c *.dvi *.fot *.log *.pl *.tfm *.typ 
	rm -f *.base *.fmt *.efmt *.mem
	rm -rf tfm
# Have to list generated .h's explicitly since our real headers,
# e.g., help.h, are in this directory too.
	rm -f *coerce.h *d.h bibtex.h dvicopy.h dvitomp.h dvitype.h gftodvi.h
	rm -f gftopk.h gftype.h mft.h odvicopy.h odvitype.h ofm2opl.h
	rm -f opl2ofm.h otangle.h ovf2ovp.h ovp2ovf.h patgen.h pktogf.h
	rm -f pktype.h pltotf.h pooltype.h tangle.h tftopl.h vftovp.h vptovf.h
	rm -f weave.h
# Cleanup from triptrap.
	rm -f trip.tex trap.mf mtrap.mp trap.mp trap.mpx
	rm -f trip.* tripin.* tripos.tex 8terminal.tex
	rm -f trap.* mftrap.* mftrapin.* mptrap.* mptrapin.*
	rm -f trapf.* mtrap.* writeo* missfont.log
distclean::
	test ! -r lib/Makefile \
	  || for d in $(all_subdirs); do (cd $$d && $(MAKE) $@); done
	rm -f *.pool *extra.c *.fm
# Have to list .p's explicitly because we can't remove tangleboot.p.
	rm -f bibtex.p dvicopy.p dvitomp.p dvitype.p etex.p gftodvi.p gftopk.p
	rm -f gftype.p mf.p mft.p mp.p odvicopy.p odvitype.p ofm2opl.p omega.p
	rm -f opl2ofm.p otangle.p ovf2ovp.p ovp2ovf.p patgen.p pdftex.p
	rm -f pdfetex.p pktogf.p pktype.p pltotf.p pooltype.p tangle.p
	rm -f tex.p tftopl.p vftovp.p vptovf.p weave.p
	rm -f otangleboot.c otangleboot.h tangleboot.c tangleboot.h
# And we clean up generated web and change files.
	rm -f etex.web omega.web pdftex.web pdfetex.web
	rm -f etex.ch  omega.ch  pdftex.ch  pdfetex.ch
	rm -f odvicopy.web odvitype.web ofm2opl.web opl2ofm.web otangle.web
	rm -f odvicopy.ch  odvitype.ch  ofm2opl.ch  opl2ofm.ch  otangle.ch 
	rm -f ovf2ovp.web ovp2ovf.web
	rm -f ovf2ovp.ch  ovp2ovf.ch
# And some miscellaneous files
	rm -f etrip.tex otangleboot.p omega.c omegamem.h
@PTEX@	rm -f macnames.c ttf2afm.c; cd $(xpdfroot); rm -f c++-auto.h c-auto.h config.log config.status xpdf/pdftoepdf.cc xpdf/epdf.h
	rm -f fmtutil.cnf

extraclean::
	test ! -r lib/Makefile \
	  || for d in $(all_subdirs); do (cd $$d && $(MAKE) $@); done
# Remove triptrap junk here too.
	rm -f trip.tex trap.mf mtrap.mp trap.mp trap.mpx
	rm -f trip.* tripin.* tripos.tex 8terminal.tex
	rm -f trap.* mftrap.* mftrapin.* mptrap.* mptrapin.*
	rm -f trapf.* mtrap.* writeo* missfont.log
	rm -f *.out *.typ *.fot
# And etrip junk as well.
	rm -f etrip.tex
	rm -f etrip.* etripin.*
maintainer-clean::
	test ! -r lib/Makefile \
	  || for d in $(all_subdirs); do (cd $$d && $(MAKE) $@); done

ac_include ../make/clean.mk

@MAINT@depend::
@MAINT@	for d in lib mpware web2c window $(otps); do \
@MAINT@	  (cd $$d && $(MAKE) depend); done

ac_include ../make/rdepend.mk
ac_include depend.mk

# 
# Local variables:
# page-delimiter: "^# \f"
# End:
