# Makefile for Metafont in its various incarnations.  It is appropriate
# for the SAS/C Development System Version 6.x by SAS Institute Inc.
# and was written by Andreas Scherer, April 12, 1995.

# With this SMakefile several different versions of MetaFont can be
# created (one at a time!).  The standard is No20IniMF/No20VirMF.
# It is as close to the Web2C implementation as possible.
#
#      CHANGEFILE = cmf.ch
#      HEADERFILE = mfd.h
#      DEFS       = cpu=ANY data=FAR
#      PS         = No20
#      LOBJ       = lib:c.o
#      LIBRARIES  = lib:scmieee.lib lib:scnb.lib
#
# An improved version for standard Amigas will provide a runtime
# memory configuration and resident versions of IniMF and Virmf.
#
#      CHANGEFILE = mmf.ch
#      HEADERFILE = mfmemory.h
#      DEFS       = cpu=ANY define=VARMEM
#      PS         = No20
#      LOBJ       = lib:cres.o
#      LIBRARIES  = lib:scmieee.lib lib:sc.lib
#
# Advanced hardware configurations work with IniMF/VirMF.  These use
# the runtime memory configuration as well.
#
CHANGEFILE = mmf_20.ch
HEADERFILE = mfmemory.h
DEFS       = cpu=68020 define=SPEEDUP define=VARMEM
PS         =
LOBJ       = lib:cres.o
LIBRARIES  = lib:scmieee.lib lib:sc.lib

SED = sed
SHELL = rx
TIE = tie
WMERGE = wmerge
srcdir = .
VPATH = .

# The missing `configure' mechanism requires this to be done by hand.
bindir = TeXMF:bin/web2c61
configdir = TeXMF:web2c61/config
mfpooldir = TeXMF:web2c61/pool

# This is so kpathsea will get remade automatically if you change
# something in it and recompile from the package directory.
kpathsea_parent = ../..
kpathsea_dir = $(kpathsea_parent)/kpathsea
kpathsea = $(kpathsea_dir)/kpathsea.lib
kpathsea_20 = $(kpathsea_dir)/kpathsea_20.lib

# Routines used everywhere.
commondefines = $(srcdir)/../lib/common.defines $(srcdir)/../lib/texmf.defines \
	$(srcdir)/../lib/texmfextras.defines
commonh = $(srcdir)/../lib/andyconfig.h
commono = ../lib/lib.lib $(kpathsea)
commono_20 = ../lib/lib_20.lib $(kpathsea_20)

# Routines used in TeX and Metafont.
extrac = $(srcdir)/../lib/andytexmf.c
extrah = $(srcdir)/../lib/andytexmf.h $(srcdir)/../lib/texmfmem.h $(HEADERFILE)

# Routines used in TeX, Metafont, and BibTeX.
fileioc = $(srcdir)/../lib/andyopeninout.c
fileioo = openinout.o

objs = $(fileioo) mf0.o mf1.o mf2.o mf3.o mf4.o mf5.o mf6.o mf7.o mf8.o \
       mf9.o mf10.o
iobjs = iextra.o inimf.o
vobjs = vextra.o imf.o

# Where the test files are.
mfsrcdir = $(srcdir)/../mf
trapdir = $(mfsrcdir)/MFtrap

program = $(PS)inimf $(PS)virmf

CC = sc
CFLAGS = $(DEFS) math=IEEE code=far stackcheck noicons optimize
CPPFLAGS = define=_STRICT_ANSI define=MF idir=$(srcdir)/../lib idir=../..

CCLD = slink
LN = type

LDFLAGS = noicons $(XLDFLAGS)
libs = $(commono) $(LIBRARIES)
libs_20 = $(commono_20) $(LIBRARIES)

# This code was written by Stefan Scherer especially for
# this Amiga implementation.
windowlib = MFwindow/amiga.o
speedup = 64bit/64bit.o

INSTALL = copy
INSTALL_PROGRAM = copy
INSTALL_DATA = copy

# The bases we know how to make.
bases = plain.base cmmf.base

# Name of the file that defines the local devices.
localmodes = modes.mf

# And how to make them.
inimf = MFPOOL=. ./$(PS)inimf

.SUFFIXES:
.SUFFIXES: .o .c
.c.o:
	$(CC) $(CPPFLAGS) $(CFLAGS) $*.c

default: all
all: $(program)
triptrap: trapmf

# It is a waste of disk space to have window support in inimf.
inimf: $(iobjs) $(objs) $(windowlib) $(commono_20) $(speedup)
	$(CCLD) to inimf from $(LOBJ) $(iobjs) $(objs) \
	$(windowlib) $(speedup) lib $(libs_20) $(LDFLAGS)

virmf: $(vobjs) $(objs) $(windowlib) $(commono_20) $(speedup)
	$(CCLD) to virmf from $(LOBJ) $(vobjs) $(objs) \
	$(windowlib) $(speedup) lib $(libs_20) $(LDFLAGS)

no20inimf: $(iobjs) $(objs) $(windowlib) $(commono)
	$(CCLD) to no20inimf from $(LOBJ) $(iobjs) $(objs) \
	$(windowlib) lib $(libs) $(LDFLAGS)

no20virmf: $(vobjs) $(objs) $(windowlib) $(commono)
	$(CCLD) to no20virmf from $(LOBJ) $(vobjs) $(objs) \
	$(windowlib) lib $(libs) $(LDFLAGS)

check: run-trap
run-trap: $(PS)inimf # trapmf 
	copy $(PS)inimf trapmf clone
	- delete quiet trap.mf
	-copy $(trapdir)/trap.mf .
	-execute settrapenv
	-./trapmf < $(trapdir)/trap1.in > NIL:
	-diff $(trapdir)/trapin.log trap.log
	-./trapmf < $(trapdir)/trap2.in > trap.fot
	-diff $(trapdir)/trap.log trap.log -l10000
	-diff $(trapdir)/trap.fot trap.fot
	../fontutil/tftopl ./trap.tfm trap.pl
	-diff $(trapdir)/trap.pl trap.pl
	../fontutil/gftype -m -i ./trap.72270gf > trap.typ
	-diff $(trapdir)/trap.typ trap.typ

# Make base files automatically.
bases: $(bases)

mf.base: $(PS)inimf
	$(inimf) "plain; input $(localmodes); dump"
	rename plain.base mf.base
	rename plain.log mf.log

cmmf.base: mf.base
	$(inimf) "&./mf cmbase dump"
	rename cmbase.base cmmf.base
	rename cmbase.log cmmf.log

# The `ini_to_trap' script changes mfd.h, instead of the change file, so
# retangling is not necessary.  After changing constants, making a
# trapmf means making an inimf.
#
# This target never gets executed on the Amiga.  It's kept here for
# reference only.
# 
trapmf: stamp-trap
	$(MAKE) $(makeargs) inimf
	mv inimf trapmf

stamp-trap: mfd.h $(mfsrcdir)/trap.sed
	rm -f *.o temp
	sed -f $(mfsrcdir)/trap.sed < mfd.h > temp
	mv mfd.h mfd.h.bak
	mv temp mfd.h
	touch stamp-trap

clean-trap:
	rm -f *.o mfd.h trapmf stamp-trap
# Don't reinstall mfd.h with the test constants.
	if grep 'memmax 3000' mfd.h.bak >/dev/null 2>&1; then \
          rm -f mfd.h*; else mv mfd.h.bak mfd.h; fi

mf.p mf.pool: mf.web $(CHANGEFILE)
	../web/tangle mf.web $(CHANGEFILE)

cmf.ch: $(mfsrcdir)/mf.ch $(mfsrcdir)/mf.chch ../lib/texmfhistory.ch
	- delete cmf.ch
	$(WMERGE) $(mfsrcdir)/mf.ch $(mfsrcdir)/mf.chch andymf.ch
	$(TIE) -c cmf.ch mf.web andymf.ch ../lib/texmfhistory.ch
mmf.ch: $(mfsrcdir)/mf.ch $(mfsrcdir)/mf.chch \
	 ../lib/texmfhistory.ch $(mfsrcdir)/mfmemory.ch
	- delete mmf.ch
	$(WMERGE) $(mfsrcdir)/mf.ch $(mfsrcdir)/mf.chch andymf.ch
	$(TIE) -c mmf.ch mf.web andymf.ch ../lib/texmfhistory.ch \
	$(mfsrcdir)/mfmemory.ch
mmf_20.ch: $(mfsrcdir)/mf.ch $(mfsrcdir)/mf.chch ../lib/texmfhistory.ch \
	$(mfsrcdir)/mfmemory.ch $(mfsrcdir)/mf_20.ch
	- delete mmf_20.ch
	$(WMERGE) $(mfsrcdir)/mf.ch $(mfsrcdir)/mf.chch andymf.ch
	$(TIE) -c mmf_20.ch mf.web andymf.ch $(mfsrcdir)/mf_20.ch \
	../lib/texmfhistory.ch $(mfsrcdir)/mfmemory.ch

# The convert script produces the following files:
mf0.c: mf.p andycoerce.add $(commondefines)
	$(SHELL) $(mfsrcdir)/convert.rexx
	touch mfd.h
mf1.c mf2.c mf3.c mf4.c mf5.c mf6.c mf7.c mf8.c mf9.c mf10.c \
imf.c coerce.h mfd.h: mf0.c

mfmemory.h: stamp-convert

stamp-convert: mfd.h
	copy mfd.h mfd.safe
	$(SED) -f $(mfsrcdir)/mfmemory.sed < mfd.h > mfd.temp
	copy mfd.temp mfd.h
	delete mfd.temp
	echo "" > stamp-convert

andycoerce.add: coerce.add coerce.add.ch
	$(WMERGE) coerce.add coerce.add.ch andycoerce.add

# The (hand-coded) file $(extrac) and the (generated) file imf.c have
# #ifdefs for INIMF, so we compile them differently.
iextra.o: iextra.c $(commonh) $(extrah)
	$(CC) $(CPPFLAGS) define=INIMF define=INI $(CFLAGS) iextra.c

inimf.o: inimf.c $(commonh) $(extrah)
	$(CC) $(CPPFLAGS) define=INIMF $(CFLAGS) inimf.c

# Avoid compiling files in another directory.
iextra.c: $(extrac)
	- delete iextra.c
	$(LN) $(extrac) >iextra.c

inimf.c: imf.c
	- delete inimf.c
	$(LN) imf.c > inimf.c

vextra.o: vextra.c
vextra.c: $(extrac)
	- delete vextra.c
	$(LN) $(extrac) > vextra.c

$(fileioo): openinout.c
openinout.c: $(fileioc)
	- delete openinout.c
	$(LN) $(fileioc) > openinout.c

$(iobjs) $(vobjs) $(objs): $(commonh) $(extrah)

mf0.o: mf0.c
mf1.o: mf1.c
mf2.o: mf2.c
mf3.o: mf3.c
mf4.o: mf4.c
	$(CC) $(CPPFLAGS) $(CFLAGS) NOOPTPEEP mf4.c # Don't try suicide!
mf5.o: mf5.c
mf6.o: mf6.c
mf7.o: mf7.c
mf8.o: mf8.c
mf9.o: mf9.c
mf10.o: mf10.c

$(windowlib): MFwindow/amiga.c
MFwindow/amiga.c: mfd.h $(commonh)

$(speedup): 64bit/64bit.a
	asm -iINCLUDE: -m2 64bit/64bit.a

c-sources: mfd.h
.PHONY: c-sources

install: install-exec install-data

install-exec: all
	$(INSTALL_PROGRAM) $(program) $(bindir)
install-data: mf.pool $(srcdir)/../config/mf.mcf
	$(INSTALL_DATA) mf.pool $(mfpooldir)/mf.pool
	$(INSTALL_DATA) $(srcdir)/../config/mf.mcf $(configdir)/mf.mcf

clean:
	- delete \#?.(bak|o|lnk|log|base) $(windowlib) $(speedup)

veryclean: clean
	- delete \#?.(dvi|pool|c|p|h|safe) andy\#? ?mf.ch ?mf_20.ch

extraclean: veryclean
	- delete \#?.(aux|bbl|blg|orig|pl|rej)
	- delete \#?.(i|s|tfm|vf|vpl) \#?(gf|pk)
	- delete CONTENTS.tex mfput.\#? patch\#? texput.\#? stamp-\#?
	- delete $(program) trapmf trap.mf mf.mcf trap.fot trap.typ
