# Generated automatically from Makefile.os2 by configure.
# Makefile for TeX.

O = .obj
A = .lib
X = .exe
S = .dll

xlibs = tex.def

SHELL = /bin/sh
srcdir = .
VPATH = .

# 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$A

# Routines used everywhere.
commondefines = $(srcdir)/../lib/common.defines $(srcdir)/../lib/texmf.defines
commonh = $(srcdir)/../lib/config.h
commono = ../lib/lib$A $(kpathsea)

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

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

objs = $(fileioo) tex0$O tex1$O tex2$O tex3$O tex4$O tex5$O tex6$O \
  tex7$O tex8$O tex9$O $(extra_tex_obj)
iobjs = iextra$O initex$O
vobjs = vextra$O itex$O

# Where the test files are.
texsrcdir = $(srcdir)/../tex
tripdir = $(texsrcdir)/TeXtrip

program = initex virtex patgen

# The -DTeX here is used for patgen, too, but that doesn't hurt anything.
CC = gcc
CFLAGS = -g
CPPFLAGS = -DTeX -I$(srcdir)/../lib -I../..

CCLD = $(CC)
LDFLAGS = $(CFLAGS) $(XLDFLAGS)
LIBS =  $(extralibs)
libs = $(commono) $(LIBS) $(xlibs)

INSTALL = install -c
INSTALL_PROGRAM = $(INSTALL) -m 755
INSTALL_DATA = $(INSTALL) -m 644

LN = cp -p

# spiff -r5e-8 gives cleaner results than just `diff', but because it
# also produces backspaces and other verbiage, I haven't taught
# configure about it.
DIFF = diff
DIFFFLAGS =

# The formats we know how to make.
fmts =

# And how to make them.
initex = TEXPOOL=. ./initex


# What to pass to submakes.
makeargs=SHELL='$(SHELL)' CC='$(CC)' CFLAGS='$(CFLAGS)' CCLD='$(CCLD)' \
LDFLAGS='$(LDFLAGS)' LIBS='$(LIBS)' LN='$(LN)'


# Need the web rules for patgen.
.SUFFIXES:
.SUFFIXES: $O .c .p .ch
.p.c:
	$(SHELL) $(srcdir)/../lib/convert $*.p $*.c
.ch.p:
	../web/tangle $*.web $*.ch
.c$O:
	$(CC) $(CPPFLAGS) $(CFLAGS) -c $*.c


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

initex: $(iobjs) $(objs) $(commono)
	$(CCLD) -o initex $(LDFLAGS) $(iobjs) $(objs) $(libs)

virtex: $(vobjs) $(objs) $(commono)
	$(CCLD) -o virtex $(LDFLAGS) $(vobjs) $(objs) $(libs)

check: run-trip
run-trip: triptex
	-rm -f trip.tex
	-$(LN) $(tripdir)/trip.tex .
	../fontutil/pltotf $(tripdir)/trip.pl trip.tfm
	../fontutil/tftopl ./trip.tfm trip.pl
	-diff $(tripdir)/trip.pl trip.pl
	-$(SH) -c '. ./tripenv; \
          ./triptex < $(tripdir)/trip1.in >/dev/nul 2>&1'
	-diff $(tripdir)/tripin.log trip.log
	-$(SH) -c '. ./tripenv; ./triptex < $(tripdir)/trip2.in > trip.fot'
# 
# We use $(DIFF) instead of `diff' only for those files where there
# might actually be legitimate numerical differences.
	-$(DIFF) $(DIFFFLAGS) $(tripdir)/trip.log trip.log
	-diff $(tripdir)/trip.fot trip.fot
	$(SH) -c '. ./tripenv; \
	  ../dviutil/dvitype trip.dvi < $(tripdir)/dvitype.in > trip.typ'
	-$(DIFF) $(DIFFFLAGS) $(tripdir)/trip.typ trip.typ


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

# AMSLaTeX requires that you
# 1) move Lamport's lfonts.tex out of TeX's way (I use the lfonts.tex I
# distribute with the sauter CM parameter files, and call it lfonts.sauter),
# 2) say `lfonts.new' when lplain.tex can't find lfonts.tex,
# 3) choose a ``fontdef'' file (I use fontdef.ori),
# 4) a ``preload'' file, (I use preload.ori),
# 5) and a ``basefont'' file.  (I use basefont).
# How automatic, huh?  I can hardly wait for LaTeX 3.
amslatex.fmt: initex
	$(initex) lplain \\dump
	mv lplain.fmt amslatex.fmt
	mv lplain.log amslatex.log

# As of AMSTeX 2.1, the initialization file is named `amstex.ini'.
# Because it explicitly reads plain.tex, we cannot use &./tex; that
# produces a `Too late for \patterns' error.
amstex.fmt: initex
	$(initex) amstex.ini

etex.fmt: tex.fmt
	touch eplain.aux # Makes cross-reference warnings work right.
	$(initex) \&./tex eplain \\dump
	mv eplain.fmt etex.fmt
	mv eplain.log etex.log

inrstex.fmt: initex
	$(initex) inrstex \\dump

latex.fmt: initex
	$(initex) lplain \\dump
	mv lplain.fmt latex.fmt
	mv lplain.log latex.log

picplus.fmt: tex.fmt
	$(initex) \&./tex picplus \\dump

slitex.fmt: initex
	$(initex) splain \\dump
	mv splain.fmt slitex.fmt
	mv splain.log slitex.log

tex.fmt: initex
	$(initex) plain \\dump
	mv plain.fmt tex.fmt
	mv plain.log tex.log

# Texinfo changes the escape character from `\' to `@'.
texinfo.fmt: tex.fmt
	$(initex) \&./tex texinfo @dump


# We change texd.h instead of the change file, to avoid retangling.
triptex: stamp-trip
	$(MAKE) $(makeargs) initex
	mv initex triptex
	-mv initex$X triptex$X

stamp-trip: texd.h $(texsrcdir)/trip.sed
	-rm -f *$O texd.h.bak temp
	sed -f $(texsrcdir)/trip.sed < texd.h > temp
	mv texd.h texd.h.bak
	mv temp texd.h
	touch stamp-trip

clean-trip:
	-rm -f *$O texd.h triptex triptex$X stamp-trip
# Don't reinstall a texd.h with the test constants.
	-if grep 'memmax 2999' texd.h.bak >/dev/nul 2>&1; then \
          rm -f texd.h*; else mv texd.h.bak texd.h; fi

tex.p: tex.web ctex.ch
	../web/tangle tex.web ctex.ch

# If you're building mltex, reportedly have to add:
#        sed -e 's/xiiix/(/;s/xtttx/)/' tex.p >tex.pp
#        mv tex.pp tex.p

ctex.ch: $(texsrcdir)/tex.ch
	-rm -f ctex.ch
	cp $(texsrcdir)/tex.ch ctex.ch

# The convert script produces the following. Touch texd.h to ensure its
# timestamp is later than the rest.
tex0.c tex1.c tex2.c tex3.c tex4.c tex5.c tex6.c tex7.c tex8.c tex9.c \
itex.c coerce.h texd.h: tex.p coerce.add $(commondefines)
	$(SH) $(texsrcdir)/convert
	touch texd.h

# The (hand-coded) file $(extrac) and the (generated) file itex.c have
# #ifdefs for INITEX, so we compile them differently.
iextra$O: iextra.c $(commonh) $(extrah)
	$(CC) $(CPPFLAGS) -DINITEX -DINI $(CFLAGS) -c iextra.c

initex$O: initex.c $(commonh) $(extrah)
	$(CC) $(CPPFLAGS) -DINITEX $(CFLAGS) -c initex.c

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

initex.c: itex.c
	-rm -f initex.c
	$(LN) itex.c initex.c

vextra.c: $(extrac)
	-rm -f vextra.c
	$(LN) $(extrac) vextra.c

openinout.c: $(fileioc)
	-rm -f openinout.c
	$(LN) $(fileioc) openinout.c

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

tex0$O: tex0.c
tex1$O: tex1.c
tex2$O: tex2.c
tex3$O: tex3.c
tex4$O: tex4.c
tex5$O: tex5.c
tex6$O: tex6.c
tex7$O: tex7.c
tex8$O: tex8.c
tex9$O: tex9.c


patgen: patgen$O $(commono)
	$(CCLD) -o patgen $(LDFLAGS) patgen$O $(libs)
patgen$O: patgen.c $(commonh)
patgen.c: patgen.p $(commondefines)
patgen.p: patgen.web patgen.ch


Makefile: Makefile.os2 ../config.status
	(cd ..; $(SH) config.status)


c-sources: texd.h patgen.c
.PHONY: c-sources

install: install-exec install-data

install-exec: all
	$(SH) $(srcdir)/../../mkdirchain $(texpooldir) $(texdatadir) $(fontdir)
	for p in $(program); do $(INSTALL_PROGRAM) $$p$X $(bindir)/$$p$X; done

# The dependency should really be tex.pool, but can't do that in suffix rules.
install-data: tex0.c
	$(SH) $(srcdir)/../../mkdirchain $(texpooldir) $(fontdir)
	-if test -s tex.pool; then \
	  $(INSTALL_DATA) tex.pool $(texpooldir)/tex.pool; else true; fi
	if test ! -f $(fontdir)/texfonts.map				\
	   || grep 'original texfonts.map --' $(fontdir)/texfonts.map	\
              >/dev/nul 2>&1; then					\
         $(INSTALL_DATA) $(texsrcdir)/texfonts.map $(fontdir)/texfonts.map;\
        else true; fi

TAGS: *.c *.h
	etags -t *.c *.h


mostlyclean::
	-rm -f *$O *$X $(program) $(lib) $(programs)

clean:: mostlyclean
	-rm -f *.dvi *.pool

distclean:: clean
	-rm -f Makefile config.status c-auto.h

# Although we can remake configure and c-auto.h.in, we don't remove
# them, since many people may lack Autoconf.  Use configclean for that.
realclean:: distclean
	-rm -f TAGS *.info*

extraclean::
	-rm -f *.aux *.bak *.bbl *.blg *.dvi *.log *.orig *.pl *.rej
	-rm -f *.i *.s *.tfm *.vf *.vpl *\#* *gf *pk *~
	-rm -f CONTENTS.tex a.out core mfput.* patch* texput.*

configclean:
	-rm -f configure c-auto.h.in c-auto.h


# Prevent GNU make 3 from overflowing arg limit on system V.
.NOEXPORT:

mostlyclean::
	-rm -f stamp-* triptex
	-rm -f texd.h texd.h.bak coerce.h *.log *.fmt
	-rm -f 8terminal.tex tripos.tex trip.typ trip.dvi trip.fot
	-rm -f trip.pl trip.tfm trip.tex

clean::
	-rm -f *.c *.h *.p

distclean:: clean
	-rm -f ctex.ch
