#
# This file makes TeX in its various incarnations.
#
# The file ../common/texmf.h uses the symbol `TeX' to define certain
# things that are different for TeX and Metafont, hence the addition to
# CFLAGS.
# 

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


# The formats we know how to make.
# 
formats=lplain.fmt plain.fmt


.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


# We don't add `$(commono)' here, since it doesn't depend on anything in
# this directory, and we write a dependency for `$(objs)' below.
#
srcs=texd.h itex.c tex0.c tex1.c tex2.c tex3.c tex4.c tex5.c tex6.c tex7.c tex8.c
objs=$(fileioo) tex0.o tex1.o tex2.o tex3.o tex4.o tex5.o tex6.o tex7.o tex8.o 
iobjs=iextra.o initex.o $(objs)
vobjs=tex-extra.o itex.o $(objs)


default:        all

all:            initex virtex
triptrap:	triptex

docs:		tex.dvi


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

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

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

run-trip:
		execute run_trip


# Make format files automatically.
# 
fmts:		$(formats)

lplain.fmt:
		initex lplain \dump

plain.fmt:
		initex plain \dump


# The `ini_to_trip' script changes texd.h, instead of the change file, so
# retangling is not necessary.  After changing constants, making a
# triptex means making an initex.
#
triptex:	stamp-trip $(iobjs) $(commono)
		lmk initex
		copy initex triptex
		delete initex

stamp-trip:	stamp-convert
		run delete $(objs)
		edit texd.h WITH ini_to_trip
		copy memory.h stamp-trip

# tangle produces tex.p and tex.pool.
# 
tex.p:		tex.web ctex.ch
		/web/tangle tex.web ctex.ch


# The convert script produces tex[0-8].c, itex.c, coerce.h, and texd.h.
# The (hand-coded) memory.h is included in one of tex?.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:	tex.p memory.h fixcoerce.h $(commondefines)
		execute convert
		edit itex.c WITH fix_itex OPT W1000
		edit tex8.c WITH fix_tex8 OPT W1000
		copy memory.h stamp-convert

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


# The (hand-coded) file $(extrac) and the (generated) file itex.c have
# #ifdefs for INITEX, so we compile them differently.
#
iextra.o:	$(extrac) texd.h $(extrah) $(commonh)
		$(CC) $(CFLAGS) -i/tex/ -dINITEX -dINI -oiextra.o $(extrac)

initex.o:	itex.c texd.h $(extrah) $(commonh)
		$(CC) $(CFLAGS) -dINITEX -oinitex.o itex.c 

tex-extra.o:	$(extrac) texd.h $(extrah) $(commonh)
		$(CC) $(CFLAGS) -i/tex/ -otex-extra.o $(extrac)

itex.o:		itex.c texd.h $(extrah) $(commonh)
		$(CC) $(CFLAGS) -oitex.o itex.c 

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


tex0.o:		tex0.c texd.h
		$(CC) $(CFLAGS) $*.c
tex1.o:		tex1.c texd.h
		$(CC) $(CFLAGS) $*.c
tex2.o:		tex2.c texd.h
		$(CC) $(CFLAGS) $*.c
tex3.o:		tex3.c texd.h
		$(CC) $(CFLAGS) $*.c
tex4.o:		tex4.c texd.h
		$(CC) $(CFLAGS) $*.c
tex6.o:		tex6.c texd.h
		$(CC) $(CFLAGS) $*.c
tex7.o:		tex7.c texd.h
		$(CC) $(CFLAGS) $*.c
tex8.o:		tex8.c texd.h
		$(CC) $(CFLAGS) $*.c

clean:
		delete stamp-convert stamp-trip QUIET
		delete $(iobjs) QUIET
		delete $(vobjs) QUIET
		delete triptex initex virtex QUIET
		delete texd.h coerce.h plain.fmt lplain.fmt QUIET
		delete plain.log lplain.log tex.log trip.log tripin.log QUIET
		delete 8terminal.tex tripos.tex dvitype.out QUIET
		delete trip.dvi trip.fmt trip.fot trip.tex trip.tfm trip.typ QUIET

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