# Makefile for BibTeX 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, March 23, 1995.

# With this SMakefile several different versions of MetaFont can be
# created (one at a time!).  The standard is No20BibTeX.
# It is as close to the Web2C implementation as possible.
#
#     CHANGEFILE = cbibtex.ch
#     HEADERFILE = stamp-nomem
#     DEFS       = cpu=ANY data=FAR code=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 a resident version of BibTeX.
#
#     CHANGEFILE = mbibtex.ch
#     HEADERFILE = stamp-mem
#     DEFS       = cpu=ANY define=VARMEM code=FAR
#     PS         = no20
#     LOBJ       = lib:cres.o
#     LIBRARIES  = lib:scmieee.lib lib:sc.lib
#
# Advanced hardware configurations work with BibTeX.  This uses
# the runtime memory configuration as well.
#
CHANGEFILE = mbibtex.ch
HEADERFILE = stamp-mem
DEFS       = cpu=68020 define=VARMEM code=FAR
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 introduced by hand.
bindir = TeXMF:bin/web2c61
configdir = TeXMF:web2c61/config

# 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
commonh = $(srcdir)/../lib/andyconfig.h $(kpathsea_dir)/paths.h
commono = ../lib/lib.lib $(kpathsea)
commono_20 = ../lib/lib_20.lib $(kpathsea_20)

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

# Routines for dynamic memory allocation.
memoryh = $(srcdir)/../lib/bibtexmemory.h

program = $(PS)bibtex

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

CCLD = slink
LN = copy

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

INSTALL = copy
INSTALL_PROGRAM = copy

.SUFFIXES:
.SUFFIXES: .o .c .p .ch
.p.c:
	$(SHELL) $(srcdir)/../bibtex/convert.rexx $*.p $*.c
.ch.p:
	../web/tangle $*.web $(CHANGEFILE)
.c.o:
	$(CC) $(CPPFLAGS) $(CFLAGS) $*.c

default: all
all: $(program)

bibtex: bibtex.o $(commono_20) $(fileioo)
	$(CCLD) to $(program) from $(LOBJ) $(program).o \
	lib $(libs_20) $(LDFLAGS)
bibtex.o: bibtex.c $(commonh) $(HEADERFILE)
bibtex.c: bibtex.p $(commondefines) convert.rexx
bibtex.p: bibtex.web $(CHANGEFILE)

no20bibtex: no20bibtex.o $(commono) $(fileioo)
	$(CCLD) to $(program) from $(LOBJ) $(program).o \
	lib $(libs) $(LDFLAGS)
no20bibtex.o: no20bibtex.c
no20bibtex.c: bibtex.c $(commonh) $(HEADERFILE)
	copy bibtex.c no20bibtex.c

stamp-nomem:
	echo "" > stamp-nomem

stamp-mem: $(memoryh)
	- delete bibtex.temp openinout.temp
	$(SED) -f bibtexmemory.sed < bibtex.c > bibtex.temp
	- delete bibtex.safe
	rename bibtex.c bibtex.safe
	rename bibtex.temp bibtex.c
	echo "" > stamp-mem

cbibtex.ch: bibtex.ch bibtex.chch
	- delete $@
	$(TIE) -c $@ bibtex.web bibtex.ch bibtex.chch

mbibtex.ch: bibtex.ch bibtex.chch bibtexmemory.ch
	- delete $@
	$(TIE) -c $@ bibtex.web bibtex.ch bibtex.chch bibtexmemory.ch

openinout.o: openinout.c
openinout.c: $(fileioc)
	- delete openinout.c
	$(LN) $(fileioc) openinout.c

c-sources: bibtex.c openinout.c
.PHONY: c-sources

install: install-exec install-data
install-exec: all
	$(INSTALL_PROGRAM) $(program) $(bindir)/$(program)
install-data: $(srcdir)/../config/bibtex.mcf
	$(INSTALL) $(srcdir)/../config/bibtex.mcf $(configdir)/bibtex.mcf

clean:
	- delete \#?.(bak|o|lnk|log|fmt)

veryclean: clean
	- delete \#?.(dvi|pool|c|p|h|safe) cbibtex.ch mbibtex.ch

extraclean: veryclean
	- delete \#?.(aux|bbl|blg|orig|pl|rej)
	- delete \#?.(i|s|tfm|vf|vpl)
	- delete CONTENTS.tex texput.\#? patch\#? mfput.\#? stamp-\#?
	- delete $(program)
