#=======================================================================
# Makefile for bibclean TUBboat article and GNU Emacs info documentation
# [31-Dec-1993] -- final polishing of Makefile for public release
#                  after TUGboat publication
# [04-May-1993] -- add bundle, SHAR, SHARFILES, and add quoting of @
#		   in index
# [14-Jan-1993]
#=======================================================================
BIBTEX		= bibtex
CP		= /bin/cp
DETEX		= detex
LATEX		= latex
MAKEINDEX 	= makeindex
MV		= /bin/mv
RM		= /bin/rm -f
SED		= /bin/sed
SHAR		= shar -c -v
SHARFILES 	= Makefile bibclean.aux bibclean.bbl bibclean.bib \
		bibclean.idx bibclean.ind bibclean.isok bibclean.lot \
		bibclean.ltx bibclean.sok bibclean.sty bibclean.toc \
		is-plain.bst
TEXINDEX 	= texindex

ALL:	bibclean.dvi

all:	bibclean.spell dw bibclean.dvi

bundle:	$(SHARFILES)
	$(SHAR) $(SHARFILES) >$@

clean:
	$(RM) *.blg
	$(RM) *.dvi*
	$(RM) *.idw
	$(RM) *.ilg
	$(RM) *.log
	$(RM) *.o
	$(RM) *.spell
	$(RM) *.tmp
	$(RM) *~
	$(RM) \#*
	$(RM) core

clobber:	clean
	$(RM) *.aux
	$(RM) *.bbl
	$(RM) *.idx
	$(RM) *.ind
	$(RM) *.lof
	$(RM) *.lot
	$(RM) *.toc

# We strip \index{} entries first to avoid large numbers of bogus duplicate
# word warnings.
dw:
	@echo '==================== doubled words ===================='
	$(SED) -e 's/^ *\\index{.*$$//' bibclean.ltx | $(DETEX) | dw

bibclean.aux:
	if [ ! -f bibclean.aux ] ; then touch bibclean.aux ; fi

bibclean.bbl:	bibclean.bib bibclean.aux
	if [ ! -f bibclean.aux ] ; then touch bibclean.aux ; fi
	-$(BIBTEX) bibclean

bibclean.dvi:	bibclean.bbl bibclean.ltx bibclean.ind bibclean.sty
	$(LATEX) bibclean.ltx
	$(MAKE) bibclean.bbl bibclean.ind
	$(LATEX) bibclean.ltx
	$(LATEX) bibclean.ltx

bibclean.idx:
	if [ ! -f bibclean.idx ] ; then touch bibclean.idx ; fi

bibclean.ind:	bibclean.idx Makefile
	$(MV) bibclean.idx bibclean.idw
	$(SED) -e 's/{\\tt <}@/<@/' \
		-e 's/{\\tt >}@/>@/' \
		-e 's/{\\%\\%@{\\tt \\%\\%}}/{\\%\\%@{\\protect\\tt \\%\\%}}/' \
		-e 's/@@{\\tt @}/"@@{\\tt "@}/' \
		-e 's/{@@{\\tt @}}/{"@@{\\tt "@}}/' \
		-e 's/\\{ */\\{/g' \
		-e 's/\\} */\\}/g' \
		<bibclean.idw >bibclean.idx
	-$(MAKEINDEX) bibclean

bibclean.ispell:	bibclean.ltx bibclean.isok
	if [ ! -f bibclean.isok ] ; then touch bibclean.isok ; fi
	@echo '==================== spelling exceptions ===================='
	$(DETEX) bibclean.ltx | ispell -l | sort -u >bibclean.ispell
	-diff bibclean.ispell bibclean.isok

bibclean.spell:	bibclean.ltx bibclean.sok
	if [ ! -f bibclean.sok ] ; then touch bibclean.sok ; fi
	@echo '==================== spelling exceptions ===================='
	$(DETEX) bibclean.ltx | spell +bibclean.sok >bibclean.spell
	cat bibclean.spell

spell: bibclean.spell bibclean.ispell
