#
# This file makes Metafont in its various incarnations.
#

SITEDIR=/
CC=lc
OPT= -cw -f8 -j100i94i84i -m2
CFLAGS= -b0 -i$(SITEDIR) -r0 -v $(OPT)
BLINKCMDS=LIB lib:lcm881.lib lib:lcnb.lib


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

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

# System libraries for window support.
# 
wlibs=


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


# Routines used everywhere.
# 
commondefines=/common/common.defines /common/texmf.defines
commonh=/common/extra.h
commono=/common/extra.o

# Routines used in both TeX and Metafont.
# 
extrac=/common/texmf.c
extrah=/common/texmf.h
extrao=texmf.o

# Routines used in TeX, Metafont, and BibTeX.
# 
fileioc=/common/fileio.c
fileioh=/common/fileio.h
fileioo=fileio.o


windowlib=MFwindow/window.o
libs=$(windowlib) $(wlibs) 


# We don't add `$(commono)' here, since it doesn't depend on anything in
# this directory.
# 
srcs=mfd.h imf.c mf0.c mf1.c mf2.c mf3.c mf4.c mf5.c mf6.c mf7.c mf8.c mf9.c
objs=$(fileioo) mf0.o mf1.o mf2.o mf3.o mf4.o mf5.o mf6.o mf7.o mf8.o mf9.o
iobjs=iextra.o inimf.o $(objs)
vobjs=mf-extra.o imf.o $(objs)


default:	all

all:		inimf virmf
triptrap:	trapmf

docs:		mf.dvi


inimf:		stamp-convert $(iobjs) $(windowlib) $(commono)
		blink FROM lib:c.o $(iobjs) $(libs) $(commono) TO inimf $(BLINKCMDS)

virmf:		stamp-convert $(vobjs) $(windowlib) $(commono)
		blink FROM lib:c.o $(vobjs) $(libs) $(commono) TO virmf $(BLINKCMDS)

mf.dvi:		mf.tex
		virtex &plain. \language=\usenglish \input mf.tex
mf.tex:		mf.web cmf.ch
		/web/weave mf cmf


run-trap:
		execute run_trap


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

cm.base:
		inimf plain \input $(localmodes) \input cmbase \dump
		copy plain.base cm.base
		delete plain.base
		copy plain.log cm.log
		delete plain.log

plain.base:
		inimf plain \input $(localmodes) \dump


# 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.
#
trapmf:		stamp-trap $(iobjs) $(commono)
		lmk inimf
		copy inimf trapmf
		delete inimf

stamp-trap:	stamp-convert
		run delete $(objs)
		edit mfd.h WITH ini_to_trap
		copy memory.h stamp-trap


# tangle produces mf.p and mf.pool.
# 
mf.p:		mf.web cmf.ch memory.h
		/web/tangle mf.web cmf.ch


# The convert script produces mf[0-9].c, imf.c, coerce.h, and mfd.h.
# The (hand-coded) memory.h is included in one of mf?.c files; it isn't
# really necessary to `convert' again if it changes, only to recompile
# those files, but describing that relationship is ugly to do.
# (Furthermore, memory.h is stable.)
#
stamp-convert:	mf.p memory.h fixcoerce.h $(commondefines)
		execute convert
		edit mf9.c WITH fix_mf9 OPT W1000
		copy memory.h stamp-convert


$(srcs):	mf.p
		@ echo ""


# The (hand-coded) file $(extrac) and the (generated) file imf.c have
# #ifdefs for INIMF, so we have to compile them differently.
#
iextra.o:	$(extrac) mfd.h $(extrah) $(commonh)
		$(CC) $(CFLAGS) -O -i/mf/ -dINIMF -dINI -oiextra.o $(extrac)

inimf.o:	imf.c mfd.h $(extrah) $(commonh)
		$(CC) $(CFLAGS) -O -dINIMF -oinimf.o imf.c

mf-extra.o:	$(extrac) mfd.h $(extrah) $(commonh)
		$(CC) $(CFLAGS) -O -i/mf/ -omf-extra.o $(extrac)

imf.o:		imf.c mfd.h $(extrah) $(commonh)
		$(CC) $(CFLAGS) -O -oimf.o imf.c

$(fileioo):	$(fileioc) $(fileioh)
		$(CC) $(CFLAGS) -O -i/mf/ -o$(fileioo) $(fileioc)


mf0.o:		mf0.c mfd.h
		$(CC) $(CFLAGS) -O $*.c
mf1.o:		mf1.c mfd.h
		$(CC) $(CFLAGS) -O $*.c
mf2.o:		mf2.c mfd.h
		$(CC) $(CFLAGS)    $*.c
mf3.o:		mf3.c mfd.h
		$(CC) $(CFLAGS) -O $*.c
mf4.o:		mf4.c mfd.h
		$(CC) $(CFLAGS)    $*.c
mf5.o:		mf5.c mfd.h
		$(CC) $(CFLAGS) -O $*.c
mf6.o:		mf6.c mfd.h
		$(CC) $(CFLAGS) -O $*.c
mf7.o:		mf7.c mfd.h
		$(CC) $(CFLAGS) -O $*.c
mf8.o:		mf8.c mfd.h
		$(CC) $(CFLAGS) -O $*.c
mf9.o:		mf9.c mfd.h
		$(CC) $(CFLAGS) -O $*.c

$(windowlib):   MFwindow/amiga.c
		$(CC) $(CFLAGS) -O -o$(windowlib) MFwindow/amiga.c


clean:
		delete stamp-convert stamp-trap QUIET
		delete $(iobjs) QUIET
		delete $(vobjs) QUIET
		delete trapmf inimf virmf QUIET
		delete mfd.h coerce.h plain.base cm.base QUIET
		delete plain.log cm.log mf.log trap.log trapin.log QUIET
		delete trap.72270gf trap.base trap.fot trap.mf trap.pl trap.tfm trap.typ QUIET

veryclean:	clean
		delete $(srcs) QUIET
		delete imf.c mf.p mf.pool QUIET
		delete mf.dvi mf.tex CONTENTS.tex mf.log QUIET
