# ======================================================================
# Makefile for files in ~beebe/tex/tugboat
#
# This constructs the tugboat.bib file from the TUGboat table of
# contents (tb*.cnt) files using the awk program tugboat.awk, and then
# produces complete test bibliography files in alpha and unsrt form.  A
# kwic index of the bibliography is also produced:
#
# Current target list:
#       all                     tugbib + tugbib2 + tugboat-kwic
#       clean                   remove most files that can be recreated
#                               by running make again
#       clobber                 remove files that can be recreated by
#                               running make again
#       distclean               same as clobber
#       install-ftp             install public files in anonymous ftp
#                               directory
#       install-sys             install public files in system TeX
#                               directory tree
#       tugboat-kwic            keyword-in-context index to tugboat.bib;
#                               must be printed in landscape orientation.
#       tugboat-kwic.dvi        output of LaTeX
#       maintainer-clean        do distclean, then remove tugboat.bib
#       mostlyclean             same as clean
#       tugbib                  bibliography in alpha order
#       tugbib.bbl              output of BibTeX
#       tugbib.dvi              output of LaTeX
#       tugbib2                 bibliography in unsrt order
#       tugbib2.bbl             output of BibTeX
#       tugbib2.dvi             output of LaTeX
#       tugboat.bib             TUGboat bibliography
#       tugboat.kwic            permuted index file (LaTeX form)
#       tugboat.ptx             permuted index file (raw form)
#
# This Makefile requires minor updates as each new issue of TUGboat
# appears: add an entry to TUGCONTENTS, and possibly to TUGSUMMARY.
#
# [15-Nov-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

DISTILL                 = distill

DVIALW-TYPE1            = $(HOME)/bin/dvialw-type1

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

FTPFILES                = tugboat-kwic-bib.awk tugboat-kwic.dvi \
                         tugboat-kwic.ltx landscape.sty ptx.sed \
                         $(TUGCONTENTS) tbcont.def $(TUGSUMMARY) tugbib.bbl \
                         tugbib.dvi tugbib.ltx tugbib2.bbl tugbib2.dvi \
                         tugbib2.ltx tugboat.awk tugboat.bib tugboat.def \
                         tugboat.kwic tugboat.ptx tugboat.ver tugbib.ps \
                         tugbib2.ps.gz tugboat-kwic.ps.gz \
                         tugboat-kwic-times.ps.gz tugbib.pdf.gz \
                         tugbib2.pdf.gz tugboat-kwic.pdf.gz \
                         tugboat-kwic-times.pdf.gz

GZIP                    = gzip

LATEX                   = latex2e

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 tugboat-kwic-bib.awk \
                         tugboat-kwic.aux tugboat-kwic.log \
                         tugboat-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 $(TUGSUMMARY) \
                         tugbib.blg tugbib.ltx tugbib2.blg \
                         tugbib2.ltx tugboat.awk tugboat.bib \
                         tugboat.def tugboat.kwic tugboat.ptx

TEX                     = tex

# NB: Update this list with each new TUGboat issue:
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 tb1695.cnt \
                         tb1796.cnt

# NB: Update this list every 5 years
TUGSUMMARY              = tbcv05.tex  tbcv10.tex  tbcv15.tex  tbcv20.tex

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

SUFFIXES:

SUFFIXES:        .pdf .ps .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 tugboat-kwic-bib.awk <$< | $(PTX) -r -f >$@

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

dvi.ps:
       $(DVIALW-TYPE1) $<

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

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

ps.pdf:
       $(DISTILL) $<

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

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

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

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

all:    tugbib tugbib2 tugboat-kwic tugboat-kwic-times

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

clobber distclean:      clean
       -$(RM) tugbib.ps tugbib2.ps tugboat-kwic-times.ps tugboat-kwic.ps
       -$(RM) tugbib.ps.gz tugbib2.ps.gz tugboat-kwic-times.ps.gz tugboat-kwic.ps.gz
       -$(RM) tugbib.pdf tugbib2.pdf tugboat-kwic-times.pdf tugboat-kwic.pdf
       -$(RM) tugbib.pdf.gz tugbib2.pdf.gz tugboat-kwic-times.pdf.gz tugboat-kwic.pdf.gz

install-ftp:    $(FTPFILES)
       $(CP) $? $(FTPDIR)
       $(CP) Makefile $(FTPDIR)/makefile
       date >FTP

install-sys:    $(SYSFILES)
       $(CP) $? $(SYSDIR)
       date >SYS

tugboat-kwic:   tugboat-kwic.dvi

tugboat-kwic.dvi:       tugboat.kwic

tugboat-kwic-times:     tugboat-kwic-times.dvi

tugboat-kwic-times.dvi: tugboat.kwic

maintainer-clean: distclean
       @echo "This command is intended for maintainers to use;"
       @echo "it deletes files that may require special tools to rebuild."
       -$(RM) tugboat.bib

tugboat.kwic:   tugboat.ptx ptx.sed

tugboat.ptx:    tugboat.bib tugboat-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 {printf(\"%.2f\", `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

tugbib.pdf.gz:  tugbib.pdf
       $(GZIP) <tugbib.pdf >tugbib.pdf.gz

tugbib2.pdf.gz: tugbib2.pdf
       $(GZIP) <tugbib2.pdf >tugbib2.pdf.gz

tugboat-kwic.pdf.gz:    tugboat-kwic.pdf
       $(GZIP) <tugboat-kwic.pdf >tugboat-kwic.pdf.gz

tugboat-kwic-times.pdf.gz:      tugboat-kwic-times.pdf
       $(GZIP) <tugboat-kwic-times.pdf >tugboat-kwic-times.pdf.gz

tugbib.ps.gz:   tugbib.ps
       $(GZIP) <tugbib.ps >tugbib.ps.gz

tugbib2.ps.gz:  tugbib2.ps
       $(GZIP) <tugbib2.ps >tugbib2.ps.gz

tugboat-kwic.ps.gz:     tugboat-kwic.ps
       $(GZIP) <tugboat-kwic.ps >tugboat-kwic.ps.gz

tugboat-kwic-times.ps.gz:       tugboat-kwic-times.ps
       $(GZIP) <tugboat-kwic-times.ps >tugboat-kwic-times.ps.gz