###=======================================================================
### Makefile for biblabel package.
###
### Current target list:
###	all			Build package.
###	bib-new-files		Sample target for processing *.bib files.
###	biblabel.hlp		Make Unix manual pages in (Open)VMS help file
###				format.
###	biblabel.jar		Make Java archive distribution file.
###	biblabel.ps		Make Unix manual pages in PostScript format.
###	biblabel.shar		Make Unix shar distribution file.
###	biblabel.tar		Make Unix tar distribution file.
###	biblabel.txt		Make Unix manual pages in ASCII text format.
###	biblabel.zip		Make InfoZip distribution file.
###	biblabel.zoo 		Make zoo distribution file.
###	check			Run validation suite.
###	check-version		Display package version.
###	citesub			Utility for substituting citation labels.
###	citesub.hlp		Unix manual pages in (Open)VMS help file format.
###	citesub.ps		Unix manual pages in PostScript format.
###	citesub.txt		Unix manual pages in ASCII text format.
###	clean			Remove unneeded intermediate files after build.
###	clean-dist		Remove distribution archive files created by
###				"make install-ftp".
###	clean-test		Remove test output files created by
###				"make check".
###	clobber			Same as distclean.
###	config.h		Local C configuration header file.
###	config.status		Script to recreate current configuration.
###	configure		Script to create Makefile and config.h.
###	configure.time-stamp	Time stamp file.
###	distclean		Clean almost everything that make can
###				build.  This should restore the current
###				directory to its state after a fresh
###				unpacking of a master distribution
###				archive.
###	doc			Make documentation files from UNIX manual pages.
###	dw			Check for doubled words in documentation.
###	hlpfiles		Make (Open)VMS help files from UNIX manual
###				pages.
###	htmlfiles		Make HTML files from UNIX manual pages.
###	install			Install package on local system.
###	install-exe		Internal target for "make install".
###	install-exe-citesub	Internal target for "make install-exe".
###	install-exe-biblabel	Internal target for "make install-exe".
###	install-ftp		Install package archive distributions in FTP
###				tree (used only at the developer's site).
###	install-lib		Internal target for "make install".
###	install-man		Internal target for "make install".
###	install-man-citesub	Internal target for "make install-man".
###	install-man-biblabel	Internal target for "make install-man".
###	lint			Run lint syntax checks on C code.
###	maintainer-clean	Remove absolutely everything that make
###				can rebuild.  This is intended only for
###				the developer.  The README.ps file
###				requires manual building via the
###				print-to-PostScript-file function of a
###				Web browser, which sadly, cannot be done
###				in batch mode.
###	Makefile		Remake Makefile (by ./configure, from
###				Makefile.in).
###	mostlyclean		Same as clean.
###	pdffiles		Make Portable Document Format (PDF) files from
###				UNIX manual pages.
###	psfiles			Make PostScript files from UNIX manual pages.
###	README.ps		Make PostScript version of README.html file.
###	Reconfigure		Rerun ./configure with a new cache file.
###	reconfigure		Rerun ./configure with the current cache file.
###	spell			Run spelling checks on documentation.
###	TAGS			Make emacs TAGS file .
###	txtfiles		Make ASCII text files from UNIX manual pages.
###	uninstall		Remove installed package from local system.
###	uninstall-exe		Internal target for "make uninstall".
###	uninstall-exe-biblabel	Internal target for "make uninstall-exe".
###	uninstall-exe-citesub	Internal target for "make uninstall-exe".
###	uninstall-ftp		Remove installed package from FTP tree.
###	uninstall-lib		Internal target for "make uninstall".
###	uninstall-man		Internal target for "make uninstall".
###	uninstall-man-biblabel	Internal target for "make uninstall-man".
###	uninstall-man-citesub	Internal target for "make uninstall-man".
###
###	citesub$(O)		Object file.
###	hash$(O)		Object file.
###	strdup$(O)		Object file.
###	stricm$(O)		Object file.
###	xalloc$(O)		Object file.
###
### [09-Mar-2001] -- Major update for version 0.04.
### [18-Feb-1997] -- Update for version 0.03.
### [16-Oct-1996] -- Update for version 0.02.
### [11-Nov-1994] -- Update for version 0.01.
### [05-Nov-1994] -- Original version 0.00.
###=======================================================================

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

### Sun Solaris 2.x nawk often raises 'input record too long' errors
### from bibliographies with long string values.  gawk is better.  If
### you change this, set the V macro below to the appropriate value.
AWK		= /usr/local/bin/mawk

BIBCLEAN	= /usr/local/bin/bibclean

### This specific bibclean initialization file should always be used for
### the BibNet project!
BIBCLEANFLAGS	= -init-file bibnet.ini -delete-empty -remove-OPT-prefixes

### In this version, the filters BIBSORT, CHECKSUM, FIXDATETIME, and
### FIXNAMES are eliminated if BIBFILTER is an empty string, so that no
### additional processing is carried out on the output bibliography.

BIBFILTER	= | $(BIBSORT) | $(FIXDATETIME) | $(FIXNAMES) | $(CHECKSUM)
BIBFILTER	=

### This name is used only in the subdirectory ./tests, so it must
### refer to that subdirectory's parent, namely, this one:
BIBLABEL	= ../biblabel.sh

BIBSORT		= bibsort -byyear

CC		= gcc

CFILES		= citesub.c hash.c strdup.c stricm.c xalloc.c

### When HOST, USER, __DATE__, and __TIME__ are available,
### citesub preserves them for its version output
CFLAGS		= $(OPT) $(DEFINES) $(DEFSHOST) $(DEFSUSER) $(INCLUDES)

### This variable lists the basenames of the test files.  These map to
### test local files and test correct output as follows:
###
###	test/*.err	local stderr output from biblabel
###	test/*.esb	local stderr output from citesub
###	test/*.in	input files for biblabel and citesub
###	test/*.out	local stdout output from citesub
###	test/*.sub	local stdout output from biblabel
###	test/okay/*.err correct stderr output from biblabel
###	test/okay/*.esb correct stderr output from citesub
###	test/okay/*.out	correct stdout output from citesub
###	test/okay/*.sub	correct stdout output from biblabel
###
### The fuzz*.in files are random streams of binary garbage generated
### by the fuzz test package (see
### ftp://grilled.cs.wisc.edu/technical_papers).  On many UNIX
### systems, these nasty file streams have been found to crash many
### different utilities, and on occasion, even the entire operating
### system!
CHECKFILES	= check001 check002 check003 check004 check005 check006 \
		  check007 check008 check009 check010 check011 check012 \
		  fuzz001 fuzz002 fuzz003 fuzz004 fuzz005 fuzz006 fuzz007 \
		  fuzz008 fuzz009 fuzz010 fuzz011 fuzz012

CHECKSUM	= checksum

CHMOD		= chmod

### The C version of citesub is about 50 times faster than the awk
### version, but either can be used.
CITESUB		= $(AWK) -f citesub.awk
CITESUB		= ./citesub

CITESUBVER	= citesub-$(VERSIONNUMBER)

CMP		= cmp

COL		= col -b

CP		= scp -p

DATE		= 123

DEFINES		=

DEFSHOST	= -DHOST=\"$(HOST)\"

DEFSUSER	= -DUSER=\"$(USER)\"

DEROFF		= deroff

DIFF		= diff

DISTFILES       = COPYING ChangeLog Makefile.in README README.html README.pdf \
		  README.ps biblabel.awk biblabel.sin biblabel.sok bibnet.ini \
		  citesub.awk config.hin configure configure.in fixnames.sed \
		  man2ps rofvms.awk $(CFILES) $(HFILES) $(HLPFILES) \
		  $(HTMLFILES) $(MANFILES) $(PDFFILES) $(PSFILES) $(TXTFILES) \
		  $(SAVEFILES) $(TESTFILES)

DISTILL		= distill

DW		= dw

ETAGS		= etags

FIND		= find

FIXDATETIME     = $(SED) -e "s/%%% date =.*/%%% date = \
		  \"`$(GETDATE)`\",/" \
			-e "s/%%%     time            = \"..:..:..\",/%%%     time            = \"`$(GETTIME)`\",/"

### This pipeline stage takes care of the occasional changes of words,
### such as Bjoerstad -> Bjorstad, when the generic substitutions of
### the awk programs cannot do the desired job.
FIXNAMES	= $(SED) -f fixnames.sed

### Extra flags for gcc and g++ to get maximal checking
GCCFLAGS	= -Wall -Wshadow -Wcast-qual -Wpointer-arith \
		  -Wwrite-strings

GETDATE		= $(DATE) +%d\ %B\ %Y	# returns 05 May 1994

GETTIME		= $(DATE) +%T\ %Z	# returns "12:34:56 MDT"

GZIP		= gzip -9

### NB: This EXCLUDES the installation-dependent config.h file
HFILES		= acconfig.h args.h hash.h xalloc.h

HLPFILES	= $(MANFILES:.man=.hlp)

HTMLFILES	= $(MANFILES:.man=.html)

INCLUDES	= -I. 

ISPELL		= ispell

JAR		= jar

LDFLAGS		= 

LIBDIRNAME	= $(LIBDIR)/$(PACKAGENAME)

LIBDIRVER	= $(LIBDIRNAME)/$(VERSIONNUMBER)

LIBS		= 

LINT		= lint

LINTFLAGS	= -bchx -I.

LN		= ln

LS		= ls

MAN2HTML	= man2html

MAN2PS		= ./man2ps

MANFILES	= biblabel.man citesub.man

MKDIR		= mkdir

MV		= mv

NROFF		= nroff

### Object file extension
O		= .o

OPT		= -g

PACKAGENAME	= biblabel

PACKAGEVER	= $(PACKAGENAME)-$(VERSIONNUMBER)

PDFFILES	= $(PSFILES:.ps=.pdf)

PSFILES		= README.ps biblabel.ps citesub.ps

RM		= rm -f

RMDIR		= rmdir

SAVEFILES	= save/Makefile save/biblabel.sh save/config.h save/configure

SED		= sed

SHAR		= shar

SHELL		= /usr/local/bin/bash

### Some systems have different defaults for two environment variables
### that affect sort order.  Ensure that they are set identically on
### all systems, so that "make check" does not fail because of sort
### order differences, sigh...
SORT		= $(SORTENVIRONMENT) sort

SORTENVIRONMENT	= LC_ALL=C LC_COLLATE=C LC_CTYPE=C LC_MESSAGES=C LANG=C


SPELL		= spell

SPELL-FILTER	= $(SORTENVIRONMENT) $(SED) -e "s/[^a-zA-Z'-]/ /g"

srcdir          = .

TAGS-FILES	= $(CFILES) $(HFILES) config.h

TAR		= tar

TEST		= test

TESTFILES       = test/check001.in test/check001.opt \
		  test/check002.in test/check002.opt \
		  test/check003.in test/check003.opt \
		  test/check004.in test/check004.opt \
		  test/check005.in test/check005.opt \
		  test/check006.in test/check006.opt \
		  test/check007.in test/check007.opt \
		  test/check008.in test/check008.opt \
		  test/check009.in test/check009.opt \
		  test/check010.in test/check010.opt \
		  test/check011.in test/check011.opt \
		  test/check012.in test/check012.opt \
		  test/fuzz001.in test/fuzz001.opt \
		  test/fuzz002.in test/fuzz002.opt \
		  test/fuzz003.in test/fuzz003.opt \
		  test/fuzz004.in test/fuzz004.opt \
		  test/fuzz005.in test/fuzz005.opt \
		  test/fuzz006.in test/fuzz006.opt \
		  test/fuzz007.in test/fuzz007.opt \
		  test/fuzz008.in test/fuzz008.opt \
		  test/fuzz009.in test/fuzz009.opt \
		  test/fuzz010.in test/fuzz010.opt \
		  test/fuzz011.in test/fuzz011.opt \
		  test/fuzz012.in test/fuzz012.opt \
		  test/okay/check001.err test/okay/check001.esb \
		  test/okay/check001.out test/okay/check001.sub \
		  test/okay/check002.err test/okay/check002.esb \
		  test/okay/check002.out test/okay/check002.sub \
		  test/okay/check003.err test/okay/check003.esb \
		  test/okay/check003.out test/okay/check003.sub \
		  test/okay/check004.err test/okay/check004.esb \
		  test/okay/check004.out test/okay/check004.sub \
		  test/okay/check005.err test/okay/check005.esb \
		  test/okay/check005.out test/okay/check005.sub \
		  test/okay/check006.err test/okay/check006.esb \
		  test/okay/check006.out test/okay/check006.sub \
		  test/okay/check007.err test/okay/check007.esb \
		  test/okay/check007.out test/okay/check007.sub \
		  test/okay/check008.err test/okay/check008.esb \
		  test/okay/check008.out test/okay/check008.sub \
		  test/okay/check009.err test/okay/check009.esb \
		  test/okay/check009.out test/okay/check009.sub \
		  test/okay/check010.err test/okay/check010.esb \
		  test/okay/check010.out test/okay/check010.sub \
		  test/okay/check011.err test/okay/check011.esb \
		  test/okay/check011.out test/okay/check011.sub \
		  test/okay/check012.err test/okay/check012.esb \
		  test/okay/check012.out test/okay/check012.sub \
		  test/okay/fuzz001.err test/okay/fuzz001.esb \
		  test/okay/fuzz001.out test/okay/fuzz001.sub \
		  test/okay/fuzz002.err test/okay/fuzz002.esb \
		  test/okay/fuzz002.out test/okay/fuzz002.sub \
		  test/okay/fuzz003.err test/okay/fuzz003.esb \
		  test/okay/fuzz003.out test/okay/fuzz003.sub \
		  test/okay/fuzz004.err test/okay/fuzz004.esb \
		  test/okay/fuzz004.out test/okay/fuzz004.sub \
		  test/okay/fuzz005.err test/okay/fuzz005.esb \
		  test/okay/fuzz005.out test/okay/fuzz005.sub \
		  test/okay/fuzz006.err test/okay/fuzz006.esb \
		  test/okay/fuzz006.out test/okay/fuzz006.sub \
		  test/okay/fuzz007.err test/okay/fuzz007.esb \
		  test/okay/fuzz007.out test/okay/fuzz007.sub \
		  test/okay/fuzz008.err test/okay/fuzz008.esb \
		  test/okay/fuzz008.out test/okay/fuzz008.sub \
		  test/okay/fuzz009.err test/okay/fuzz009.esb \
		  test/okay/fuzz009.out test/okay/fuzz009.sub \
		  test/okay/fuzz010.err test/okay/fuzz010.esb \
		  test/okay/fuzz010.out test/okay/fuzz010.sub \
		  test/okay/fuzz011.err test/okay/fuzz011.esb \
		  test/okay/fuzz011.out test/okay/fuzz011.sub \
		  test/okay/fuzz012.err test/okay/fuzz012.esb \
		  test/okay/fuzz012.out test/okay/fuzz012.sub

TIME		= time

TOUCH		= touch

TXTFILES	= $(MANFILES:.man=.txt)

UNZIP		= unzip

VERSIONDATE	= 10-Mar-2001

VERSIONNUMBER	= 0.04

ZIP		= zip

ZOO		= zoo

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

.SUFFIXES:

.SUFFIXES: .bib-new .sub .bib .o .i .c .hlp .html .pdf .ps .txt .man

### .bib-new files have standardized tags, and may be sorted by citation
### key, depending on the definition of BIBFILTER.  They need to be
### tested manually with LaTeX and BibTeX before being accepted.

.bib.bib-new:
	$(TIME) $(MAKE) $*.sub
	$(TIME) $(CITESUB) $< $(BIBFILTER) >$@

.bib.sub:
	if [ -f $*.ini ] ; \
	then $(TIME) $(BIBCLEAN) $(BIBCLEANFLAGS) -no-check -no-warning \
		-max-width 0 -init-file $*.ini $< | \
		$(AWK) -f biblabel.awk -v FILENAME=$< >$*.sub ; \
	else $(TIME) $(BIBCLEAN) $(BIBCLEANFLAGS) -no-check -no-warning \
		-max-width 0 $< | \
		$(AWK) -f biblabel.awk -v FILENAME=$< >$*.sub ; \
	fi

### Preprocess only and eliminate lines with only white space.
.c.i:
	$(CC) $(CFLAGS) -E $< | grep -v '^[ 	]*$$' >$*.i

.man.html:
	$(MAN2HTML) $<

.man.ps:
	$(MAN2PS) $<

.man.hlp:
	$(AWK) -f rofvms.awk < $< > $@

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

.ps.pdf:
	$(DISTILL) $<

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

all:	citesub

bib-new-files:
	for f in *.bib ; \
	do \
	    $(TIME) $(MAKE) $$f-new ; \
	done

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

biblabel.jar:	$(DISTFILES)
	-$(RM) $@
	$(JAR) cf biblabel.jar $(DISTFILES)
	-$(MKDIR) $(PACKAGEVER)
	cd $(PACKAGEVER); $(JAR) xf ../biblabel.jar
	$(JAR) cf $(PACKAGEVER).jar $(PACKAGEVER)
	-$(RM) -r $(PACKAGEVER)
	-$(RM) $@
	$(LN) -s $(PACKAGEVER).jar $@

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

biblabel.sh: biblabel.sin
	./config.status

biblabel.shar:	$(DISTFILES)
	-$(RM) $@
	-$(MKDIR) $(PACKAGEVER)
	$(TAR) cf - $(DISTFILES) | (cd $(PACKAGEVER); $(TAR) xf -)
	$(SHAR) $(PACKAGEVER) >$(PACKAGEVER).shar
	-$(RM) -r $(PACKAGEVER)
	$(LN) -s $(PACKAGEVER).shar $@

biblabel.tar:	$(DISTFILES)
	-$(RM) $@
	-$(MKDIR) $(PACKAGEVER)
	$(TAR) cf - $(DISTFILES) | (cd $(PACKAGEVER); $(TAR) xf -)
	$(TAR) cf $(PACKAGEVER).tar $(PACKAGEVER)
	-$(RM) -r $(PACKAGEVER)
	$(LN) -s $(PACKAGEVER).tar $@
	$(TAR) tvf $(PACKAGEVER).tar > $(PACKAGEVER).tar-lst

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

### NB: It is essential to remove any existing .zip file first; otherwise,
### zip just adds to its contents, rather than replacing it.  We use tar to
### create the $(PACKAGEVER) subdirectory tree.
biblabel.zip:	$(DISTFILES)
	-$(RM) $@
	-$(MKDIR) $(PACKAGEVER)
	$(TAR) cf - $(DISTFILES) | (cd $(PACKAGEVER); $(TAR) xf -)
	$(ZIP) -r $(PACKAGEVER).zip $(PACKAGEVER)
	-$(RM) -r $(PACKAGEVER)
	$(LN) -s $(PACKAGEVER).zip $@
	$(UNZIP) -v $(PACKAGEVER).zip >$(PACKAGEVER).zip-lst

biblabel.zoo:	$(DISTFILES)
	-$(RM) $@
	-$(MKDIR) $(PACKAGEVER)
	$(TAR) cf - $(DISTFILES) | (cd $(PACKAGEVER); $(TAR) xf -)
	$(FIND) $(PACKAGEVER) -type f | $(SORT) | \
		$(ZOO) ahI $(PACKAGEVER).zoo
	-$(RM) -r $(PACKAGEVER)
	$(LN) -s $(PACKAGEVER).zoo $@
	$(ZOO) v $(PACKAGEVER).zoo >$(PACKAGEVER).zoo-lst

### Because biblabel execution depends on the particular implementation
### of awk, in the subdirectory test, we use the configured script,
### ../biblabel.sh, that will use $(AWK), just like an installed
### version.  An already-installed version can be tested as well, simply
### by "make check BIBLABEL=/path/to/biblabel".
check:	all biblabel.sh
	@echo "Begin validation test of $(PACKAGENAME)"
	@$(MAKE) -s check-version
	@echo "Built with:"
	@echo "	AWK = $(AWK)"
	@echo "	CC = $(CC)"
	@echo "	CFLAGS = $(CFLAGS)"
	@echo "Using test program:"
	@echo "	BIBLABEL = $(BIBLABEL)"
	@echo
	@echo "The following checks should produce no output other than their names."
	@echo "However, small differences in test fuzz009 are acceptable."
	@cd test ; \
	for f in $(CHECKFILES) ; \
	do \
		echo $$f ; \
		$(BIBLABEL) `cat $$f.opt` $$f.in >$$f.sub 2>$$f.err ; \
		../citesub -f $$f.sub $$f.in >$$f.out 2>$$f.esb ; \
		if $(CMP) okay/$$f.err $$f.err ; \
		then $(RM) $$f.err ; \
		else \
			echo Failure on $$f.err ... ; \
			$(LS) -l okay/$$f.err $$f.err ; \
			$(TEST) -s $$f.err && $(DIFF) okay/$$f.err $$f.err ; \
		fi ; \
		if $(CMP) okay/$$f.esb $$f.esb ; \
		then $(RM) $$f.esb ; \
		else \
			echo Failure on $$f.esb ... ; \
			$(LS) -l okay/$$f.esb $$f.esb ; \
			$(TEST) -s $$f.esb && $(DIFF) okay/$$f.esb $$f.esb ; \
		fi ; \
		if $(CMP) okay/$$f.out $$f.out ; \
		then $(RM) $$f.out ; \
		else \
			echo Failure on $$f.out ... ; \
			$(LS) -l okay/$$f.out $$f.out ; \
			$(TEST) -s $$f.out && $(DIFF) okay/$$f.out $$f.out ; \
		fi ; \
		if $(CMP) okay/$$f.sub $$f.sub ; \
		then $(RM) $$f.sub ; \
		else \
			echo Failure on $$f.sub ... ; \
			$(LS) -l okay/$$f.sub $$f.sub ; \
			$(TEST) -s $$f.sub && $(DIFF) okay/$$f.sub $$f.sub ; \
		fi ; \
	done
	@echo "End validation test of $(PACKAGENAME)"

check-version:
	@echo "This is $(PACKAGENAME) version $(VERSIONNUMBER) [$(VERSIONDATE)]"

citesub:	citesub$(O) hash$(O) strdup$(O) stricm$(O) xalloc$(O)
	$(CC) $(CFLAGS) -o citesub citesub$(O) hash$(O) strdup$(O) \
		stricm$(O) xalloc$(O) $(LDFLAGS) $(LIBS)

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

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

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

clean:	clean-dist clean-test
	-$(RM) *.blg
	-$(RM) *.dvi
	-$(RM) *.i
	-$(RM) *.idx
	-$(RM) *.ilg
	-$(RM) *.ln
	-$(RM) *.log
	-$(RM) *.o
	-$(RM) *.tmp
	-$(RM) *~
	-$(RM) \#*
	-$(RM) a.out
	-$(RM) core
	-$(RM) tg_[0-9][0-9][0-9][0-9][0-9].*

clean-dist:
	-$(RM) *.jar
	-$(RM) *.jar-lst
	-$(RM) *.shar
	-$(RM) *.tar
	-$(RM) *.tar-lst
	-$(RM) *.zip
	-$(RM) *.zip-lst
	-$(RM) *.zoo
	-$(RM) *.zoo-lst
	-$(RM) -r $(PACKAGEVER)

clean-test:
	-$(RM) test/*.err
	-$(RM) test/*.esb
	-$(RM) test/*.out
	-$(RM) test/*.sub
	-$(RM) test/*~
	-$(RM) test/\#*
	-$(RM) test/a.out
	-$(RM) test/core

clobber:	distclean

config.h:	 acconfig.h config.hin configure
	$(srcdir)/configure --srcdir=$(srcdir)

config.status: configure
	$(srcdir)/configure --srcdir=$(srcdir) --no-create

configure:	configure.in
	autoconf
	autoheader
	-$(RM) config.cache
	$(MAKE) configure.time-stamp

### Work around a serious flaw in GNU configure: it always inserts -g
### -O2 in CFLAGS and CXXFLAGS.  -g cannot be used with $(OPT) on many
### systems, and -O2 is not supported on many systems.
configure.time-stamp:	configure Makefile.in
	$(MV) configure configure.tmp
	$(SED)	\
		-e 's/CFLAGS=" *-g */CFLAGS="/' \
		-e 's/CFLAGS=" *-O2 */CFLAGS="/' \
		-e 's/CXXFLAGS=" *-g */CXXFLAGS="/' \
		-e 's/CXXFLAGS=" *-O2 */CXXFLAGS="/' \
		< configure.tmp > configure
	$(CHMOD) 775 configure
	$(TOUCH) configure.time-stamp
	-$(RM) configure.tmp

dist:	biblabel.jar biblabel.shar biblabel.tar biblabel.zip biblabel.zoo

distclean:	clean
	-$(RM) *.aux
	-$(RM) *.bbl
	-$(RM) *.hlp
	-$(RM) *.ind
	-$(RM) *.lof
	-$(RM) *.lot
	-$(RM) *.toc
	-$(RM) *.txt
	-$(RM) citesub
	-$(RM) config.cache config.h config.log config.status configure.time-stamp
	-$(RM) Makefile biblabel.sh

doc:	hlpfiles htmlfiles psfiles pdffiles txtfiles

dw:
	@for f in biblabel.man citesub.man ChangeLog README ; \
	do \
		echo "==================== doubled words in $$f\
====================" ; \
		$(DEROFF) $$f | $(DW) ; \
	done

hlpfiles:	$(HLPFILES)

htmlfiles:	$(HTMLFILES)

install:	citesub install-exe install-lib install-man

install-exe:	install-exe-biblabel install-exe-citesub

install-exe-citesub:	uninstall-exe-citesub
	$(CP) citesub $(BINDIR)/$(CITESUBVER)
	$(CHMOD) 755 $(BINDIR)/$(CITESUBVER)
	$(LN) -s $(CITESUBVER) $(BINDIR)/citesub

install-exe-biblabel:	uninstall-exe-biblabel
	$(SED)  -e 's@^BIBLABELAWK=.*$$@BIBLABELAWK=$(LIBDIRVER)/biblabel.awk@' \
		-e 's@^AWK=.*$$@AWK=$(AWK)@' biblabel.sh | \
		$(CHECKSUM) >$(BINDIR)/$(PACKAGEVER)
	$(CHMOD) 755 $(BINDIR)/$(PACKAGEVER)
	$(LN) -s $(PACKAGEVER) $(BINDIR)/biblabel

install-ftp:	uninstall-ftp clean-dist biblabel.jar biblabel.shar biblabel.tar biblabel.zip biblabel.zoo
	$(JAR) tvf $(PACKAGEVER).jar > $(FTPDIR)/$(PACKAGEVER).jar-lst 2>&1
	$(CP) $(PACKAGEVER).jar $(FTPDIR)/$(PACKAGEVER).jar
	$(TAR) tvf $(PACKAGEVER).tar > $(FTPDIR)/$(PACKAGEVER).tar-lst
	$(GZIP) < $(PACKAGEVER).shar > $(FTPDIR)/$(PACKAGEVER).shar.gz
	$(GZIP) < $(PACKAGEVER).tar  > $(FTPDIR)/$(PACKAGEVER).tar.gz
	$(CP) $(PACKAGEVER).zip $(FTPDIR)/
	$(CP) $(PACKAGEVER).zip-lst $(FTPDIR)/
	$(CP) $(PACKAGEVER).zoo $(FTPDIR)/
	$(CP) $(PACKAGEVER).zoo-lst $(FTPDIR)/
	ls -l $(FTPDIR)/biblabel*

install-lib:	uninstall-lib
	-$(MKDIR) $(LIBDIRNAME) $(LIBDIRVER)
	$(CP) biblabel.awk $(LIBDIRVER)/biblabel.awk
	$(CHMOD) 644 $(LIBDIRVER)/biblabel.awk

install-man:	install-man-citesub install-man-biblabel

install-man-citesub:	uninstall-man-citesub
	$(CP) citesub.man $(MANDIR)/$(CITESUBVER).$(MANEXT)
	$(CHMOD) 644 $(MANDIR)/$(CITESUBVER).$(MANEXT)
	$(LN) -s $(CITESUBVER).$(MANEXT) $(MANDIR)/citesub.$(MANEXT)

install-man-biblabel:	uninstall-man-biblabel
	$(CP) biblabel.man $(MANDIR)/$(PACKAGEVER).$(MANEXT)
	$(CHMOD) 644 $(MANDIR)/$(PACKAGEVER).$(MANEXT)
	$(LN) -s $(PACKAGEVER).$(MANEXT) $(MANDIR)/biblabel.$(MANEXT)

lint:
	$(LINT) $(LINTFLAGS) $(CFILES)

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

Makefile: Makefile.in
	./config.status

mostlyclean:	clean

pdffiles:	$(PDFFILES)

psfiles:	$(PSFILES)

README.ps:
	@echo "To convert README.html to README.ps, use your favorite Web browser to print to a local PostScript file."
	$(TEST) -f $@ || $(TOUCH) $@

### Like reconfigure, but discard the cache first
Reconfigure:    configure
	-$(RM) config.cache
	CC='$(CC)' ./configure

reconfigure:    configure
	CC='$(CC)' ./configure

spell:
	@echo Spelling check in biblabel.man ...
	@$(DEROFF) biblabel.man | $(SPELL-FILTER) | \
		$(SPELL) +biblabel.sok 2>/dev/null | $(SORT) -u >spell.tmp
	@$(DEROFF) biblabel.man | $(SPELL-FILTER) | \
		$(ISPELL) -l -pbiblabel.sok | $(SORT) -u >>spell.tmp
	@$(SORT) -u spell.tmp
	@echo ""
	@echo Spelling check in citesub.man ...
	@$(DEROFF) citesub.man | $(SPELL-FILTER) | \
		$(SPELL) +biblabel.sok 2>/dev/null | $(SORT) -u >spell.tmp
	@$(DEROFF) citesub.man | $(SPELL-FILTER) | \
		$(ISPELL) -l -pbiblabel.sok | $(SORT) -u >>spell.tmp
	@$(SORT) -u spell.tmp
	@echo ""
	@echo Spelling check in ChangeLog ...
	@$(SPELL-FILTER) < ChangeLog | $(SPELL) +biblabel.sok | $(SORT) -u >spell.tmp
	@$(SPELL-FILTER) < ChangeLog | $(ISPELL) -l -pbiblabel.sok | $(SORT) -u >>spell.tmp
	@$(SORT) -u spell.tmp
	@echo ""
	@echo Spelling check in README ...
	@$(SPELL-FILTER) < README | $(SPELL) +biblabel.sok | $(SORT) -u >spell.tmp
	@$(SPELL-FILTER) < README | $(ISPELL) -l -pbiblabel.sok | $(SORT) -u >>spell.tmp
	@$(SORT) -u spell.tmp
	-@$(RM) spell.tmp

TAGS:	Makefile $(TAGS-FILES)
	cd $(srcdir); $(ETAGS) $(TAGS-FILES)

txtfiles:	$(TXTFILES)

uninstall:	uninstall-exe uninstall-lib uninstall-man

uninstall-exe:	uninstall-exe-biblabel uninstall-exe-citesub

uninstall-exe-biblabel:
	-$(RM) $(BINDIR)/$(PACKAGEVER) $(BINDIR)/biblabel

uninstall-exe-citesub:
	-$(RM) $(BINDIR)/$(CITESUBVER) $(BINDIR)/citesub

uninstall-ftp:
	-$(RM) $(FTPDIR)/$(PACKAGEVER).jar
	-$(RM) $(FTPDIR)/$(PACKAGEVER).jar-lst
	-$(RM) $(FTPDIR)/$(PACKAGEVER).shar
	-$(RM) $(FTPDIR)/$(PACKAGEVER).shar.gz
	-$(RM) $(FTPDIR)/$(PACKAGEVER).tar
	-$(RM) $(FTPDIR)/$(PACKAGEVER).tar.gz
	-$(RM) $(FTPDIR)/$(PACKAGEVER).tar-lst
	-$(RM) $(FTPDIR)/$(PACKAGEVER).zip
	-$(RM) $(FTPDIR)/$(PACKAGEVER).zip-lst
	-$(RM) $(FTPDIR)/$(PACKAGEVER).zoo
	-$(RM) $(FTPDIR)/$(PACKAGEVER).zoo-lst

uninstall-lib:
	-$(RM) $(LIBDIRVER)/biblabel.awk
	-$(RMDIR) $(LIBDIRVER)
	-if $(TEST) "xx`$(LS) $(LIBDIRNAME)`" = "xx" ; then $(RMDIR) $(LIBDIRNAME); fi

uninstall-man:	uninstall-man-biblabel uninstall-man-citesub

uninstall-man-biblabel:
	-$(RM) $(MANDIR)/$(PACKAGEVER).$(MANEXT) $(MANDIR)/biblabel.$(MANEXT)
	-$(RM) $(CATDIR)/$(PACKAGEVER).$(MANEXT) $(CATDIR)/biblabel.$(MANEXT)

uninstall-man-citesub:
	-$(RM) $(MANDIR)/$(CITESUBVER).$(MANEXT) $(MANDIR)/citesub.$(MANEXT)
	-$(RM) $(CATDIR)/$(CITESUBVER).$(MANEXT) $(CATDIR)/citesub.$(MANEXT)

# DO NOT DELETE THIS LINE -- mkdep uses it.
# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY.

citesub$(O):	citesub.c config.h args.h
hash$(O):	hash.c hash.h config.h args.h
strdup$(O):	strdup.c config.h args.h
stricm$(O):	stricm.c config.h args.h
xalloc$(O):	xalloc.c xalloc.h config.h args.h

# IF YOU PUT ANYTHING HERE IT WILL GO AWAY
