#=======================================================================
# Makefile for BibTeX .bib file prettyprinter
#
# Current target list:
#	all			build bibclean
#	bclproto		obsolete; build an early prototype of bibclean
#	bibclean		executable for bibclean
#	bibclean.shar		shar bundle for email distribution
#	bibclean.tar		tar archive file for ftp distribution
#	bibclean.hlp		VAX VMS help file (automatically converted
#				from bibclean.txt)
#	bibclean.txt		nroff'ed bibclean.man file
#	bibclean.zip		Info-zip archive file for ftp distribution
#	bibclean.zoo		zoo archive file for ftp distribution
#	clean			clean up all but executables and time stamps
#	clobber			clean up everything
#	install			install executable and man pages
#	install.time		internal target for install
#	install-ftp		install .tar, .zip, and .zoo files in ftp tree
#	install-ftp.time	internal target for install-ftp
#
# [01-Aug-1992]
#=======================================================================

# Change these two directories to match local conventions:
BINDIR		= /usr/local/bin
MANDIR		= /usr/local/man
FTPDIR		= /usr/spool/ftp/pub/tex/bib

# Need new awk (nawk) or gawk here:
AWK		= nawk

CC		= cc

# When HOST, USER, __DATE__, and __TIME__ are available,
# bibclean preserves them for its version output
CFLAGS		= $(OPT) -DHOST=\"${HOST}\" -DUSER=\"${USER}\"

COMPRESS	= compress

CP		= /bin/cp -p

DIST-FILES	= Makefile bibclean.c bibclean.hlp bibclean.man \
		  bibclean.txt os.h rofvms.awk vmswild.c xerrno.h \
		  xstddef.h xstdlib.h xstring.h xtypes.h

LN		= ln -s

# Define this symbol for additional link libraries
LOADLIBES	=

OPT		= -g

RM		= /bin/rm -f

UNZIP		= unzip

VERSION		= `${AWK} '/^[ \t]*version *= *"[0-9.]+", *$$/ \
		{ gsub(/[^0-9.]/,"",$$3); print $$3 }' bibclean.c`

ZIP		= zip

ZOO		= zoo

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

.SUFFIXES:

.SUFFIXES: .o .c .bib-new .bib-old .bib

.bib.bib-new:
	./bibclean <$< >$@

.bib.bib-old:
	./bclproto <$< >$@

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

all:	bibclean

# Original ad hoc prototype
bclproto:	bclproto.o
	$(CC) $(CFLAGS) -o bclproto bclproto.o

# New grammar-based prototype
bibclean:	bibclean.o
	$(CC) $(CFLAGS) -o bibclean bibclean.o $(LOADLIBES)

# VAX VMS help file format from bibclean.txt
bibclean.hlp:	bibclean.txt rofvms.awk
	$(AWK) -f rofvms.awk <bibclean.txt >bibclean.hlp

bibclean.shar:	$(DIST-FILES)
	shar -b -c -v $(DIST-FILES) >bibclean.shar

bibclean.tar:	${DIST-FILES}
	-${RM} bibclean.tar bibclean.tar-lst
	tar chf bibclean.tar ${DIST-FILES}
	-mkdir bibclean-${VERSION}
	cd bibclean-${VERSION}; tar xf ../bibclean.tar
	tar cf bibclean-${VERSION}.tar bibclean-${VERSION}
	-${RM} -r bibclean-${VERSION}
	-${RM} bibclean.tar
	${LN} bibclean-${VERSION}.tar bibclean.tar

bibclean.txt:	bibclean.man
	nroff -man bibclean.man | col -b >$@

bibclean.zip:	${DIST-FILES}
	-${RM} bibclean*.zip
	-${RM} bibclean*.zip-lst
	${ZIP} bibclean-${VERSION}.zip ${DIST-FILES}
	${UNZIP} -v bibclean-${VERSION}.zip >bibclean-${VERSION}.zip-lst
	${LN} bibclean-${VERSION}.zip bibclean.zip

bibclean.zoo:	${DIST-FILES}
	-${RM} bibclean*.zoo
	-${RM} bibclean*.zoo-lst
	${ZOO} a bibclean-${VERSION}.zoo ${DIST-FILES}
	${ZOO} v bibclean-${VERSION}.zoo >bibclean-${VERSION}.zoo-lst
	${LN} bibclean-${VERSION}.zoo bibclean.zoo

clean:
	-${RM} *.o
	-${RM} *.tar
	-${RM} *.tar-lst
	-${RM} *.zip
	-${RM} *.zip-lst
	-${RM} *.zoo
	-${RM} *.zoo-lst
	-${RM} *~
	-${RM} \#*
	-${RM} core

clobber:	clean
	-${RM} bclproto bibclean install.time install-ftp.time
	-${RM} bibclean.txt
	-${RM} bibclean.hlp
	
install:	install.time

install.time:	bibclean bibclean.man
	install -s -m 755 bibclean $(BINDIR)/bibclean
	install -m 644 bibclean.man $(MANDIR)/man1/bibclean.1
	touch install.time

install-ftp:	install-ftp.time

install-ftp.time:	bibclean.tar bibclean.zip bibclean.zoo
	tar tvf bibclean-${VERSION}.tar >${FTPDIR}/bibclean-${VERSION}.tar-lst
	${COMPRESS} <bibclean-${VERSION}.tar \
		>${FTPDIR}/bibclean-${VERSION}.tar.z
	${CP} bibclean-${VERSION}.zip ${FTPDIR}
	${CP} bibclean-${VERSION}.zip-lst ${FTPDIR}
	${CP} bibclean-${VERSION}.zoo ${FTPDIR}
	${CP} bibclean-${VERSION}.zoo-lst ${FTPDIR}
	ls -l ${FTPDIR}/bibclean*
	date >install-ftp.time
