#=======================================================================
# Makefile for bibjoin, a BibTeX bibliography file field ordering
# utility.
#
# Current target list:
#	all			make documentation files
#	bibjoin.hlp		VAX VMS HELP file of manual pages
#	bibjoin.shar		UNIX shar bundle for e-mail distribution
#	bibjoin.ps		PostScript file of typeset manual pages
#	bibjoin.tar		UNIX tar archive bundle
#	bibjoin.txt		ASCII text file of manual pages
#	bibjoin.zip		Info-ZIP archive bundle
#	bibjoin.zoo		Zoo archive bundle
#	clean			remove temporary files
#	clobber			remove all automatically recreatable files
#	distclean		same as clobber
#	install			install bibjoin on system
#	install-ftp		install bibjoin on anonymous ftp directory
#	mostlyclean		same as clean
#	realclean		same as clobber
#	spell			check spelling (with two spellers)
#	test-version		test extraction of version number
#	uninstall		remove installed executable and man pages
#	uninstall-ftp		remove installed files in anonymous ftp
#				directory
# [16-Sep-1996]
#=======================================================================

# Change these two directories to match local conventions if you
# wish to do "make install" and "make install-ftp":
BINDIR		= /usr/local/bin
CATDIR		= /usr/local/man/cat1
MANDIR		= /usr/local/man/man1
MANEXT		= 1
FTPDIR		= /u/ftp/pub/tex/bib
FTPDIR		= /u/ftp/pub/tex/bib

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

CHMOD		= chmod

COL		= col -b

COMPRESS	= compress

CP		= /bin/cp

DIST-FILES	= CHANGELOG README Makefile bibjoin.man bibjoin.hlp \
		  bibjoin.ps bibjoin.sh bibjoin.sok bibjoin.txt man2ps \
		  rofvms.awk

ISPELL		= ispell

LN		= ln -s

MAN2PS		= ./man2ps

NROFF		= nroff

RM		= /bin/rm -f

SHELL		= /bin/sh

SORT		= sort

SPELL		= spell

UNZIP		= unzip

# NB: The version number of the FTP bibjoin archive files is extracted
# from that of bibjoin.sh.
VERSION		= `$(AWK) '/^\#\#\#[ \t]*version *= *"[0-9.]+", *$$/ \
		{ gsub(/[^0-9.]/,"",$$4); print $$4 }' bibjoin.sh`

ZIP		= zip

ZOO		= zoo

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

all:	bibjoin.txt bibjoin.hlp

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

bibjoin.ps:	bibjoin.man
	$(MAN2PS) <bibjoin.man >bibjoin.ps

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

bibjoin.tar:	$(DIST-FILES)
	-$(RM) bibjoin.tar bibjoin.tar-lst
	tar chf bibjoin.tar $(DIST-FILES)
	-mkdir bibjoin-$(VERSION)
	cd bibjoin-$(VERSION); tar xf ../bibjoin.tar
	tar cf bibjoin-$(VERSION).tar bibjoin-$(VERSION)
	-$(RM) -r bibjoin-$(VERSION)
	-$(RM) bibjoin.tar
	$(LN) bibjoin-$(VERSION).tar bibjoin.tar

bibjoin.txt:	bibjoin.man
	$(NROFF) -man $? | $(COL) >$@

bibjoin.zip:	$(DIST-FILES)
	-$(RM) bibjoin*.zip
	-$(RM) bibjoin*.zip-lst
	$(ZIP) bibjoin-$(VERSION).zip $(DIST-FILES)
	$(UNZIP) -v bibjoin-$(VERSION).zip >bibjoin-$(VERSION).zip-lst
	$(LN) bibjoin-$(VERSION).zip bibjoin.zip

bibjoin.zoo:	$(DIST-FILES)
	-$(RM) bibjoin*.zoo
	-$(RM) bibjoin*.zoo-lst
	$(ZOO) a bibjoin-$(VERSION).zoo $(DIST-FILES)
	$(ZOO) v bibjoin-$(VERSION).zoo >bibjoin-$(VERSION).zoo-lst
	$(LN) bibjoin-$(VERSION).zoo bibjoin.zoo

clean mostlyclean:
	-$(RM) *.o
	-$(RM) *.shar
	-$(RM) *.tar
	-$(RM) *.tar-lst
	-$(RM) *.zip
	-$(RM) *.zip-lst
	-$(RM) *.zoo
	-$(RM) *.zoo-lst
	-$(RM) *~
	-$(RM) \#*
	-$(RM) core

clobber distclean realclean:	clean
	-$(RM) bibjoin.hlp
	-$(RM) bibjoin.txt
	-$(RM) bibjoin.ps
	-$(RM) bibjoin.ser

install:
	$(CP) bibjoin.sh $(BINDIR)/bibjoin
	$(CHMOD) 755 $(BINDIR)/bibjoin
	$(CP) bibjoin.man $(MANDIR)/bibjoin.$(MANEXT)
	-$(RM) $(CATDIR)/bibjoin.$(MANEXT)
	$(CHMOD) 644 $(MANDIR)/bibjoin.$(MANEXT)

install-ftp:	bibjoin.tar bibjoin.zip bibjoin.zoo
	tar tvf bibjoin-$(VERSION).tar >$(FTPDIR)/bibjoin-$(VERSION).tar-lst
	$(COMPRESS) <bibjoin-$(VERSION).tar \
		>$(FTPDIR)/bibjoin-$(VERSION).tar.z
	$(CP) bibjoin-$(VERSION).zip $(FTPDIR)
	$(CP) bibjoin-$(VERSION).zip-lst $(FTPDIR)
	$(CP) bibjoin-$(VERSION).zoo $(FTPDIR)
	$(CP) bibjoin-$(VERSION).zoo-lst $(FTPDIR)
	ls -l $(FTPDIR)/bibjoin*

# Check the spelling in the bibjoin script and manual pages, leaving
# exceptions in bibjoin.ser.  Both spell and ispell are used.
SPELL-FILTER = cat bibjoin.man bibjoin.sh | sed -e "s/[^a-zA-Z'-]/ /g"
spell bibjoin.ser:
	-if [ ! -f bibjoin.sok ] ; then touch bibjoin.sok ; fi
	-$(SPELL-FILTER) | $(SPELL) +bibjoin.sok >/tmp/bibjoin.ser
	-$(SPELL-FILTER) | $(ISPELL) -l -p bibjoin.sok >>/tmp/bibjoin.ser
	-$(SORT) -u /tmp/bibjoin.ser >bibjoin.ser
#	-if [ ! -s bibjoin.ser ] ; then $(RM) bibjoin.ser ; fi
	-$(RM) /tmp/bibjoin.ser

test-version:
	@echo "Version number is ""'"$(VERSION)"'"

uninstall:
	-$(RM) $(BINDIR)/bibjoin $(MANDIR)/bibjoin.$(MANEXT)

uninstall-ftp:
	-$(RM) $(FTPDIR)/bibjoin-$(VERSION).tar
	-$(RM) $(FTPDIR)/bibjoin-$(VERSION).tar-lst
	-$(RM) $(FTPDIR)/bibjoin-$(VERSION).zip
	-$(RM) $(FTPDIR)/bibjoin-$(VERSION).zip-lst
	-$(RM) $(FTPDIR)/bibjoin-$(VERSION).zoo
	-$(RM) $(FTPDIR)/bibjoin-$(VERSION).zoo-lst
