# ======================================================================
# Makefile for files in ~beebe/tex/tugboat
# This constructs the tugboat.bib file from the tb*.cnt files using
# the awk program tugboat.awk, and then produces complete test
# bibliographies in alpha and unsrt form.  A kwic index of the
# bibliography is also produced:
#
# Targets:
# all		tugbib + tugbib2 + kwic
# FTP		install public files in anonymous ftp directory
# tugbib	bibliography in alpha order
# tugbib2	bibliography in unsrt order
# kwic		keyword-in-context index to tugboat.bib.  Must be printed
#		in landscape orientation.
# SYS		install public files in system TeX directory tree
# clean		remove files that can be recreated by running make again
# [17-May-1995]
# ======================================================================

AWK                     = nawk

# If you don't have bibclean, use cat instead
BIBCLEAN                = bibclean

# You need an enlarged version of BibTeX for this job
BIBTEX                  = bibtex

CHECKSUM                = checksum

CP                      = /bin/cp -p

DETEX                   = detex

DEV                     = alw

FTPDIR                  = /usr/spool/ftp/pub/tex/pub/tugboat
FTPDIR                  = /u/ftp/pub/tex/pub/tugboat

FTPFILES                = kwic-bib.awk kwic.dvi \
			  kwic.ltx landscape.sty ptx.sed \
			  $(TUGCONTENTS) tbcont.def tbcv05.tex \
			  tbcv10.tex tugbib.bbl tugbib.dvi tugbib.ltx \
			  tugbib2.bbl tugbib2.dvi tugbib2.ltx \
			  tugboat.awk tugboat.bib tugboat.def \
			  tugboat.kwic tugboat.ptx tugboat.ver

# We need a BIGG version of LaTeX to handle this big bibliography
LATEX                   = latex

MV			= mv

NAWK			= nawk

PTX			= /bin/ptx
PTX			= /usr/local/bin/ptx -G # GNU ptx in ptx-compatibility mode

RM                      = rm -f

SED                     = /bin/sed

SHELL                   = /bin/sh

SYSDIR                  = /usr/local/lib/tex/tugboat

SYSFILES                = Makefile kwic-bib.awk kwic.aux kwic.log \
			  kwic.ltx landscape.sty ptx.sed \
			  tables/bibxrf.awk tables/super.ltx \
			  tables/tab.ltx tables/test.ltx \
			  tables/tugboat.alf tables/tugboat.def \
			  tables/tugboat.num tables/tugboat.xrf \
			  $(TUGCONTENTS) tbcont.def tbcv05.tex \
			  tbcv10.tex tugbib.blg tugbib.ltx tugbib2.blg \
			  tugbib2.ltx tugboat.awk tugboat.bib \
			  tugboat.def tugboat.kwic tugboat.ptx

TEX                     = tex

TUGCONTENTS             = tb0180.cnt tb0281.cnt tb0382.cnt tb0483.cnt \
			  tb0584.cnt tb0685.cnt tb0786.cnt tb0887.cnt \
			  tb0988.cnt tb1089.cnt tb1190.cnt tb1291.cnt \
			  tb1392.cnt tb1493.cnt tb1594.cnt

# For temporary debugging
# TUGCONTENTS		= tb0988.cnt

#=======================================================================

.SUFFIXES:

.SUFFIXES:	.aux .dvi-$(DEV) .dvi .spell .ltx .tex .kwic .ptx .bbl .bib

.bib.bbl:
	-$(NBIBTEX) $*

# DECstation ULTRIX gets error return from ptx, so just ignore it
.bib.ptx:
	-nawk -f kwic-bib.awk <$< | $(PTX) -r -f >$@

.dvi.dvi-$(DEV):
	dvi$(DEV) -m$(MAG) $<
	cp $*.dvi-$(DEV) /$(DEV)
	rm -f $@

.ltx.aux .ltx.dvi:
	-$(LATEX) $<

.ltx.spell:
	$(DETEX) $< | spell >$@

.ptx.kwic:
	$(SED) -f ptx.sed <$< >$@

.tex.aux .tex.dvi:
	$(TEX) $<

.tex.spell:
	$(DETEX) $< | spell >$@

#=======================================================================

all:	tugbib tugbib2 kwic

FTP:	$(FTPFILES)
	$(CP) $? $(FTPDIR)
	date >FTP

kwic:	kwic.dvi

kwic.dvi:	tugboat.kwic

SYS:	$(SYSFILES)
	$(CP) $? $(SYSDIR)
	date >SYS

tugboat.kwic:	tugboat.ptx ptx.sed

tugboat.ptx:	tugboat.bib kwic-bib.awk

tugbib:	tugbib.dvi

# tugbib is in alpha order; this is preferable to plain (which gives
# the same reference order) so we can test the correctness of alphanumeric
# bibliography labels.
tugbib.dvi:	tugbib.ltx tugboat.bib
	-$(RM) tugbib.bbl
	-$(RM) tugbib.aux
	-$(LATEX) tugbib.ltx
	-$(BIBTEX) tugbib
	-$(LATEX) tugbib.ltx
	-$(LATEX) tugbib.ltx

tugbib.bbl:	tugbib.aux tugboat.bib
	$(BIBTEX) tugbib

tugbib2:	tugbib2.dvi

# tugbib2 is in unsrt order for checking the bibliography against the
# original TUGboat tables of contents
tugbib2.dvi:	tugbib2.ltx tugboat.bib
	-$(RM) tugbib2.bbl
	-$(RM) tugbib2.aux
	-$(LATEX) tugbib2.ltx
	-$(BIBTEX) tugbib2
	-$(LATEX) tugbib2.ltx
	-$(LATEX) tugbib2.ltx

tugbib2.bbl:	tugbib2.aux tugboat.bib
	-$(BIBTEX) tugbib2

# NB: We store the pipeline output in a temporary file, and only if
# the steps are successful do we rename it to the final target name.
# That way, a failure won't produce an incorrect target file.
tugboat.bib:	$(TUGCONTENTS) tugboat.awk Makefile tugboat.ver
	$(AWK) "BEGIN {print `cat tugboat.ver` + 0.01}" /dev/null >tugboat.tmp
	$(MV) tugboat.tmp tugboat.ver
	$(AWK) -f tugboat.awk $(TUGCONTENTS) | \
		$(BIBCLEAN) | \
		$(SED) -e '1r tugboat.hdr' | \
		$(SED) -e s/"@@TIME@@"/"`date +%T\ %Z`"/ \
			-e s/"@@DATE@@"/"`date +%d\ %B\ %Y`"/ \
			-e s/"@@VERSION@@"/"`cat tugboat.ver`"/ | \
		$(CHECKSUM) >tugboat.tmp
	$(MV) tugboat.tmp tugboat.bib

clean:
	-$(RM) *.aux
	-$(RM) *.blg
	-$(RM) *.bbl
	-$(RM) *.dvi*
	-$(RM) *.log
	-$(RM) *.lst
	-$(RM) *.ptx
	-$(RM) *.kwic
	-$(RM) *~*
	-$(RM) tugboat.tmp

clobber:	clean
	-$(RM) tugboat.bib