### ====================================================================
### Makefile for files in ~beebe/tex/bibextract.
###
### Current target list:
###	all			standard top-level target
###	bibextract.tar		tar archive file for ftp distribution
###	bibextract.zip		Info-zip archive file for ftp 
###				distribution
###	bibextract.zoo		zoo archive file for ftp distribution
###	clean			clean up temporary files
###	clobber			remove all files that can be remade by 
###				make
###	doc			make ps, txt and spell targets
###	install			install programs in system directories
###	install-ftp		install programs in anonymous ftp 
###				directories
###	spell			make *.ser files from *.man files
###	test-version
###	txt			make *.txt files from *.man files
###	uninstall		remove programs from system directories
###	uninstall-ftp		remove programs from anonymous ftp 
###				directories
###	verify-checksums	verify checksums in all files that have 
###				them
###
### [25-Aug-2001] -- update for autoconf support
### [27-Aug-1994]
### ====================================================================

### Change these to match local conventions:

prefix		= @prefix@

BINDIR		= $(prefix)/bin
FTPDIR		= /usr/spool/ftp/pub/tex/bib
FTPDIR		= /u/ftp/pub/tex/bib
LIBDIR		= $(prefix)/lib/bibextract
LIBDIR		= $(prefix)/share/lib/bibextract
MANDIR		= $(prefix)/man/man1
MANEXT		= 1

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

AWK		= @AWK@

AWKFILES	= bibextract.awk citefind.awk citetags.awk

BASENAMES	= $(AWKFILES:.awk=)

BINFILES	= $(AWKFILES:.awk=.sh)

CAT		= @CAT@

CHECKSUM	= @CHECKSUM@

CHMOD		= @CHMOD@

COL		= @COL@

CP		= @CP@

DEROFF		= @DEROFF@

DIST-FILES      = COPYING Makefile.in README configure configure.in \
		  $(BINFILES) $(AWKFILES) $(MANFILES) $(PSFILES) $(TXTFILES) \
		  $(AWKFILES:.awk=.sok)

EXPAND		= @EXPAND@

GZIP		= @GZIP@

HDRFILES	= $(BINFILES) $(AWKFILES) $(MANFILES)

LN		= @LN@

LS		= @LS@

MANFILES	= $(AWKFILES:.awk=.man)

MKDIR		= @MKDIR@

NROFF		= @NROFF@

PSFILES		= $(MANFILES:.man=.ps)

RM		= @RM@ -f

SED		= @SED@

SEDCMD		= $(SED) -e 's=@LIBDIR@=$(LIBDIR)=g' \
			 -e 's=@BINDIR@=$(BINDIR)=g' \
			 -e 's=/bin/sed=$(SED)=g'

SHELL		= @SHELL@

SPELL		= @SPELL@

SERFILES	= $(AWKFILES:.awk=.ser)

TAR		= @TAR@

TXTFILES	= $(AWKFILES:.awk=.txt)

UNZIP		= @UNZIP@

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

ZIP		= @ZIP@

ZOO		= @ZOO@

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

.SUFFIXES:	.txt .ser .ps .man

.man.ps:
	$(SEDCMD) $< | $(NROFF) -Tps -man - >$@

.man.ser:
	$(DEROFF) $< | $(SPELL) +$*.sok >$*.ser
	@if [ -s $*.ser ] ; \
	then \
		echo "Spelling exceptions in $*.ser" ; \
		$(CAT) $*.ser ; \
	fi

.man.txt:
	$(SEDCMD) $< | $(NROFF) -man - | $(COL) -b | $(EXPAND) >$@

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

all:	
	@echo 'There is nothing to make for this package: try "make check install"'

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

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

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

check:
	@echo This package does not yet have a validation suite.

clean:
	-$(RM) *.ps
	-$(RM) *.ser
	-$(RM) *.tar
	-$(RM) *.tar-lst
	-$(RM) *.txt
	-$(RM) *.zip
	-$(RM) *.zip-lst
	-$(RM) *.zoo
	-$(RM) *.zoo-lst
	-$(RM) *~
	-$(RM) \#*
	-$(RM) a.out core

clobber:	distclean

dist:	bibextract.tar bibextract.zip bibextract.zoo

distclean:	mostlyclean
	-$(RM) config.cache config.log config.status Makefile

doc:	spell txt ps

install:	uninstall $(AWKFILES) $(BINFILES) $(MANFILES)
	-if [ ! -d $(LIBDIR) ] ; then mkdir $(LIBDIR) ; fi
	for f in $(BASENAMES) ; \
	do \
		$(SEDCMD) $$f.sh | $(CHECKSUM) > $(BINDIR)/$$f ; \
		$(SEDCMD) $$f.awk | $(CHECKSUM) > $(LIBDIR)/$$f.awk ; \
		$(SEDCMD) $$f.man | $(CHECKSUM) > $(MANDIR)/$$f.$(MANEXT) ; \
		$(CHMOD) 775 $(BINDIR)/$$f ; \
		$(CHMOD) 664 $(LIBDIR)/$$f.awk ; \
		$(CHMOD) 664 $(MANDIR)/$$f.$(MANEXT) ; \
	done

install-ftp:	uninstall-ftp dist
	$(TAR) tvf bibextract-$(VERSION).tar >$(FTPDIR)/bibextract-$(VERSION).tar-lst
	$(GZIP) <bibextract-$(VERSION).tar \
		>$(FTPDIR)/bibextract-$(VERSION).tar.gz
	$(CP) bibextract-$(VERSION).zip $(FTPDIR)
	$(CP) bibextract-$(VERSION).zip-lst $(FTPDIR)
	$(CP) bibextract-$(VERSION).zoo $(FTPDIR)
	$(CP) bibextract-$(VERSION).zoo-lst $(FTPDIR)
	ls -l $(FTPDIR)/bibextract*

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

mostlyclean:	clean

ps:	$(PSFILES)

spell:	$(SERFILES)

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

txt:	$(TXTFILES)

uninstall:
	-for f in $(BINFILES) ; \
	do \
		$(RM) $(BINDIR)/$$f $(LIBDIR)/$$f $(MANDIR)/$$f.$(MANEXT) ; \
	done

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

verify-checksums:
	for f in $(HDRFILES) ; \
	do \
		echo $$f ; \
		$(CHECKSUM) -v $$f ; \
	done

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