#=======================================================================
# Makefile for BibTeX .bib file prettyprinter
#
# Current target list: (these include all GNU Project standard targets)
#	all			build bibclean
#	bclproto		obsolete; build an early prototype of bibclean
#	bibclean		executable for bibclean
#	bibclean.h		documentation strings for help() function
#	bibclean.hlp		VAX VMS help file (automatically converted
#				from bibclean.txt)
#	bibclean.i		C preprocessor output from bibclean.c
#	bibclean.ps		PostScript version of bibclean.man
#	bibclean.shr		shar bundle for email distribution
#	bibclean.tar		tar archive file for ftp distribution
#	bibclean.txt		nroff'ed bibclean.man manual page file
#	bibclean.zip		Info-zip archive file for ftp distribution
#	bibclean.zoo		zoo archive file for ftp distribution
#	check			same as test (see below)
#	clean			clean up all but executables and time stamps
#	clobber			clean up everything
#	distclean		same as clobber
#	docs			make bibclean.txt, bibclean.hlp, and bibclean.ps
#	install			install executable and man pages
#	install.time		internal target for install
#	install-exe		install executable
#	install-man		install man pages
#	install-ftp		install .tar, .zip, and .zoo files in ftp tree
#	install-ftp.time	internal target for install-ftp
#	mostlyclean		same as clean
#	realclean		bad grammar for reallyclean
#	reallyclean		clobber, and remove TAGS file
#	romtol			build and run test program for romtol()
#	TAGS			GNU Emacs tags file
#	test			test bibclean on BibTeX and Scribe
#				bibliographies
#	test-bibtex		test 1,2,3 bibclean on BibTeX bibliographies
#	test-bibtex-1		test 1 bibclean on BibTeX bibliographies
#	test-bibtex-2		test 2 bibclean on BibTeX bibliographies
#	test-bibtex-3		test 3 ISBN and ISSN verification
#	test-scribe		test 1,2,3 bibclean on Scribe bibliographies
#	test-scribe-1		test 1 bibclean on Scribe bibliographies
#	test-scribe-2		test 2 bibclean on Scribe bibliographies
#	test-scribe-3		test 3 bibclean on Scribe bibliographies
#	test-version		test extraction of version number
#	uninstall		remove files installed by "make install"
#	uninstall-ftp		remove installed files in anonymous ftp
#				directory
#	vms/vax/bibclean.uue	uuencoded version of VAX VMS bibclean.exe
#				for portable distribution
#
# In addition, the following convenience targets are provided for
# building bibclean on various systems.  They all take the form
# vendor-architecture-os-compiler, e.g. sun-sparc-solaris-g++.  The O/S
# release number is usually omitted unless it is necessary to have
# separate targets for different releases; when it is present,
# punctuation in the release number is dropped.  Thus SunOS 4.x.x is
# collapsed to sunos4.  For C++ compilers, the name usually ends in
# c++, even though the compiler may have some other name.  You can
# type
#	make machine-target TARGET=makefile-target
# if you want to select a Makefile target other than the default, all.
#
#	generic
#	cdc-mips-epix-cc
#	dec-alpha-osf1-c++
#	dec-alpha-osf1-cc
#	dec-alpha-osf1-g++
#	dec-alpha-osf1-gcc
#	dec-mips-ultrix-cc
#	dec-mips-ultrix-g++
#	dec-mips-ultrix-gcc
#	dec-mips-ultrix-lcc
#	hp-370-bsd43-c++
#	hp-370-bsd43-cc
#	hp-9000-hpux-c++
#	hp-9000-hpux-cc
#	ibm-370-aix-c++
#	ibm-370-aix-cc
#	ibm-ps2-aix-c++
#	ibm-ps2-aix-cc
#	ibm-rs6000-aix-c++
#	ibm-rs6000-aix-cc
#	ibm-rs6000-aix-g++
#	ibm-rs6000-aix-gcc
#	mips-mips-riscos-cc
#	next-motorola-mach-cc
#	next-motorola-mach-g++
#	next-motorola-mach-gcc
#	next-motorola-mach-lcc
#	sgi-mips-irix-c++
#	sgi-mips-irix-cc
#	sgi-mips-irix-g++
#	sgi-mips-irix-gcc
#	sgi-mips-irix-lcc
#	stardent-mips-os2-cc
#	sun-sparc-solaris1-acc
#	sun-sparc-solaris1-c++
#	sun-sparc-solaris2-apcc
#	sun-sparc-solaris2-c++
#	sun-sparc-solaris2-cc
#	sun-sparc-solaris2-g++
#	sun-sparc-solaris2-gcc
#	sun-sparc-sunos4-acc
#	sun-sparc-sunos4-c++
#	sun-sparc-sunos5-apcc
#	sun-sparc-sunos5-c++
#	sun-sparc-sunos5-cc
#	sun-sparc-sunos5-g++
#	sun-sparc-sunos5-gcc
#
# [31-Dec-1993] -- final polishing of Makefile for public release
#                  after TUGboat publication
# [24-Sep-1993]
#=======================================================================

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

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

# For testing purposes, make sure we always have the same
# initialization file
BIBCLEAN	= ./bibclean -init-file bibclean.ini

BIBTEX		= bibtex

BIBTEX-TESTS	= testbib1.org testbib2.org testbib3.org testbib4.org \
		  testisxn.org

# Use lcc or gcc with extra flags for extensive error checking, or use
# C++ compiler (g++ or CC).  DO NOT CHANGE ANY OF THESE VALUES:
# instead, copy one of these to the end of the CC list to select your
# compiler.  You may also set the DEFINES value below too, though that
# is rarely necessary.

CC	= c89			## DEC Alpha OSF/1 Standard C compiler
CC	= cxx			## DEC Alpha OSF/1 C++ compiler
CC	= CC			## C++ for BSD 4.3 UNIX on HP 370
CC	= CC +a1 -xansi +w	## C++ for SGI IRIX 4.0 (see LOADLIBES below)
CC	= cc -ansiposix -fullwarn -woff 22,24,183,205,262,269,302,303
                                ## C for SGI IRIX 4.0
CC	= CC +a1 +p +w -D_POSIX_SOURCE -Hansi -D__STDC__ -D_BSD -D_AIX -Dps2 \
	  -DHAVE_TERMIO_H
                                ## C++ on AIX 370 and PS/2: +a1 (ANSI
                                ## declarations), +p (no anachronisms), +w
                                ## (warnings) -D_BSD (to get toupper() and
                                ## tolower() declared in ctype.h).
                                ## Need -DHAVE_TERMIO_H because termios.h
                                ## has wrong prototypes for C++
CC	= CC +a1 +p +w -D_POSIX_SOURCE -Hansi -D__STDC__ -D_BSD -D_AIX -D_AIX370
                                ## C++ on AIX 370
CC	= /usr/CC/sun4/CC -I/usr/CC/incl -D__SUNCC__ ## C++ on SunOS 4.1.1
CC	= acc -Xc -vc -strconst -D__ACC__ -D_POSIX_SOURCE -DHAVE_TERMIOS_H
                                ## SunOS Standard C compiler (neither
                                ## -DHAVE_SGTTY_H nor -DHAVE_TERMIO_H gives
                                ## char-at-a-time input, sigh...; they work
                                ## fine on other systems).
CC	= c89 -D_POSIX_SOURCE -D_ALL_SOURCE	## IBM RS/6000
CC	= xlC			## IBM RS/6000 C++
CC	= c89 -D_HPUX_SOURCE	## HP 9000/8xx HP-UX A.08
CC	= cc			## most systems
CC	= cc			## Stardent (NB: remove -g in OPT below)
CC	= cc -systype bsd43 -D__CC__	## MIPS RCxxxx RISCos 4.52 and 5.2:
CC	= cc $(GCCFLAGS)	## NeXT (cc is really GNU C compiler)
                                ## NeXT (see EXTRA-OBJS below)
CC	= g++ $(GCCFLAGS)	## GNU C++
CC	= lcc -A -A -n		## Princeton/AT&T Standard C compiler
CC	= gcc $(GCCFLAGS)	## GNU C
CC	= cc -Xc -D__ACC__ -D__solaris -DHAVE_TERMIOS_H	## Sun Solaris 2.x cc in Standard C mode
CC	= apcc -Xc=ansi -D__ACC__ -D__solaris -DHAVE_TERMIOS_H	## Sun Solaris 2.x Apogee cc in Standard C mode

# Compiler for this site:
CC	= g++ $(GCCFLAGS)	## GNU C++
CC	= gcc $(GCCFLAGS)	## GNU C

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

CHMOD		= chmod

COMPRESS	= compress

# Use the -p flag where available to preserve file time stamps
CP		= /bin/cp -p
CP		= /bin/cp

# To select the value checking algorithms, you can define one of:
#
# HAVE_RECOMP		when re_comp() and re_exec() are available.
# HAVE_REGEXP		when compile() and step() are available.
# HAVE_PATTERNS		for internal pattern matching code (default)
# HAVE_OLDCODE		for old hard-wired value checking
#
# If you experience problems with compiling the terminal handling code,
# used for a `more' display of help, define one of:
#
# HAVE_SGTTY_H		for Berkeley style
# HAVE_TERMIO_H		for SVID2 and XPG2 style
# HAVE_TERMIOS_H	for XPG3, POSIX.1, FIPS 151-1 style
# SCREEN_LINES=0	to suppress all terminal handling
#
# Finally, you can customize file names and search paths:
# BIBCLEAN_INI=xxx	to change name of initfile environment variable
# BIBCLEAN_EXT=xxx	to change name of file extension environment variable
# INITFILE=xxx		to change the name of the initialization file
#			from .bibcleanrc.
# SYSPATH=xxx		to change the system search path name from PATH
# USERPATH=xxx		to change the user search path name from BIBINPUTS
#
# For most machines, the internal settings of these values are
# adequate, and they need not be set here.  See however the setting of
# HAVE_TERMIO_H for the IBM 3090 above.  On Sun systems, all 3 terminal
# handling mechanisms are supported.  However, on SunOS 4.1.2 at
# least, termios.h has incorrect function prototypes that prevent
# successful compilation with C++ compilers; gcc will work in such a case.

DEFINES		= -DHAVE_REGEXP		## SGI Irix 4.0, HP-UX

DEFINES		= -DHAVE_RECOMP		## IBM AIX PS/2, IBM AIX 370,
                                        ## NeXT, SunOS, ULTRIX

DEFINES		= -DHAVE_PATTERNS	## generic solution for all systems

DIST-FILES	= README Makefile bibclean.c bibclean.h bibclean.hlp  \
		bibclean.ini bibclean.man bibclean.ps bibclean.reg \
		bibclean.txt fndfil.c machdefs.h match.c match.h os.h \
		osatari.h ospcdos.h osprimos.h osrmx.h ostops20.h \
		osunix.h osvaxvms.h osvmcms.h rofvms.awk romtol.c \
		romtol.dat romtol.lok strtol.c unixlib.h vaxvms.c \
		vmswild.c xctype.h xerrno.h xlimits.h xpwd.h xstat.h \
		xstddef.h xstdlib.h xstring.h xtypes.h \
		$(BIBTEX-TESTS) \
		$(BIBTEX-TESTS:.org=.bok) \
		$(BIBTEX-TESTS:.org=.eok) \
		testbib2.ltx \
		$(SCRIBE-TESTS) \
		$(SCRIBE-TESTS:.org=.bok) \
		$(SCRIBE-TESTS:.org=.eok) \
		testscr2.bo2 testscr2.eo2 \
		doc/Makefile doc/bibclean.aux doc/bibclean.bbl \
		doc/bibclean.bib doc/bibclean.idx doc/bibclean.ilg \
		doc/bibclean.ind doc/bibclean.isok doc/bibclean.log \
		doc/bibclean.lot doc/bibclean.ltx doc/bibclean.sok \
		doc/bibclean.sty doc/bibclean.toc doc/is-plain.bst \
		doc/ltugboat.sty doc/path.sty doc/texnames.sty \
		doc/tugboat.cmn \
		ibmpc/bibclean.uue ibmpc/ibmtest.bat \
		ibmpc/makefile.msc ibmpc/makefile.tcc \
		ibmpc/msc51bld.bat ibmpc/msc51pth.bat \
		ibmpc/msc60bld.bat ibmpc/msc60pth.bat \
		ibmpc/msc70bld.bat ibmpc/msc70pth.bat \
		ibmpc/tcc20bld.bat ibmpc/tcc20pth.bat \
		ibmpc/tcc30bld.bat ibmpc/tcc30pth.bat \
		vms/alpha/bibclean.uue vms/alpha/recomp.com \
		vms/alpha/vmsclean.com vms/alpha/vmsmake.com \
		vms/alpha/vmstest.com \
		vms/vax/bibclean.uue vms/vax/recomp.com \
		vms/vax/vmsclean.com vms/vax/vmsmake.com \
		vms/vax/vmstest.com

DIST-FILES-BIN	= doc/bibclean.dvi ibmpc/bibclean.exe \
		vms/alpha/bibclean.exe vms/vax/bibclean.exe

DITROFF		= ditroff	## AT&T
DITROFF		= groff		## GNU

EXTRA-OBJS	=		## NeXT
EXTRA-OBJS	= strtol.o	## most systems

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

# Some systems define HOST or HOSTNAME, but others don't, so we
# generate it at compile time with the hostname utility.
HOST		= `hostname`

LATEX		= latex

LN		= ln -s

# Define this symbol for additional link libraries
LOADLIBES	= -lC -lc_s		## SGI IRIX 4.0 for shared libraries
LOADLIBES	=

NROFF		= nroff

OPT		= -g

RM		= /bin/rm -f

SCRIBE-TESTS-1	= testscr1.org testscr2.org

# Do NOT use SCRIBE-TESTS-1 in this list, because MIPS 6280 RISCos 5.0
# make then fails to correctly expand $(SCRIBE-TESTS:.org=.xyz).
SCRIBE-TESTS	= testscr1.org testscr2.org testscr3.org

SED		= /bin/sed

SHELL		= /bin/sh

STRIP		= strip

TAGS-FILES	= bibclean.c bibclean.h fndfil.c match.c match.h \
		romtol.c strtol.c vaxvms.c vmswild.c

UNZIP		= unzip

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

ZIP		= zip

ZOO		= zoo

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

.SUFFIXES:

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

.bib.bib-new:
	-$(BIBCLEAN) <$< >$@

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

.c.i:
	$(CC) $(CFLAGS) -E $< 2>&1 | grep -v '^[ 	]*$$' >$@

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

all:	bibclean test docs

# Original (and now very obsolete) ad hoc prototype
bclproto:	bclproto.o
	$(CC) $(CFLAGS) -o bclproto bclproto.o

bclproto.o:	bclproto.c os.h xerrno.h xstddef.h xstdlib.h xstring.h \
		xtypes.h

# New grammar-based program.  Although strtol() is a Standard C
# function, it is missing in older systems, including BSD 4.3,
# so we simply use our own version.
bibclean:	bibclean.o fndfil.o match.o romtol.o $(EXTRA_OBJS)
	$(CC) $(CFLAGS) -o bibclean bibclean.o fndfil.o match.o \
		romtol.o $(EXTRA_OBJS) $(LOADLIBES)

# This target converts the option descriptions from the manual pages
# to C code for inclusion in bibclean.c.  The first awk command
# augments the bibclean.man file in a pipe with some small changes
# after the .TH line (which sets page dimensions) to get longer
# unhyphenated ragged-right lines without page headers, and reduces
# the option description indentation.
#
# Here are the magic nroff incantations:
#
# .pl 100i	set page length to 100in
# .nr LL 7.2i	set LL register (page width) to 7.2in
# .nh		no hyphenation
# .na		no right-adjusting
#
# That output feeds into nroff for formatting, col for removal of
# underlining and escape sequences, expand for tab removal, sed to
# backslash all quotes, and a final awk step to select the lines
# between OPTIONS and ERROR headers for conversion to C code.

bibclean.h:	bibclean.man
	-$(RM) $@
	echo '/* WARNING: Do NOT edit this file.  It was created automatically'\
		>$@
	echo '   with the command "make bibclean.h" by '$$USER@`hostname` \
		>>$@
	echo '   in '$$PWD' on '`date`' */' >>$@
	echo >>$@
	$(AWK) '{ if ($$0 ~ /^.TH/) \
		printf("%s\n.pl 100i\n.nr LL 7.2i\n.nh\n.na",$$0); \
	    else if ($$0 ~ /^.TP .*remove-OPT-prefixes.*/) \
		print ".TP 1in"; \
	    else \
			print $$0}' <bibclean.man | \
	$(NROFF) -man | col -b | expand | $(SED) -e 's/"/\\"/g' | \
		$(SED) -e 's/\\n/|n/g' -e 's/\\"/|"/g' \
			-e 's/\\/\\\\/g' -e 's/|n/\\n/g' -e 's/|"/\\"/g' | \
		$(AWK) '/^OPTION/,/^ERROR/ {if ($$0 !~ /^[A-Z]/) \
			printf("\t\"%s\\n\",\n",substr($$0,6))}' >>$@
	echo '	(const char*)NULL,' >>$@

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

bibclean.i bibclean.o::	bibclean.c bibclean.h match.h os.h unixlib.h \
		xctype.h xerrno.h xlimits.h xstat.h xstddef.h \
		xstdlib.h xstring.h xtypes.h

bibclean.i::	Makefile

bibclean.ps:	bibclean.man
	$(DITROFF) -Tps -man $? >$@

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

bibclean.tar:	$(DIST-FILES) $(DIST-FILES-BIN)
	-$(RM) bibclean.tar bibclean.tar-lst
	tar chf bibclean.tar $(DIST-FILES) $(DIST-FILES-BIN)
	-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 | expand >$@

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

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

clean mostlyclean:
	-$(RM) $(BIBTEX-TESTS:.org=.bib)
	-$(RM) $(SCRIBE-TESTS:.org=.bib)
	-$(RM) *.aux
	-$(RM) *.bbl
	-$(RM) *.blg
	-$(RM) *.dvi
	-$(RM) *.err
	-$(RM) *.i
	-$(RM) *.log
	-$(RM) *.o
	-$(RM) *~
	-$(RM) \#*
	-$(RM) bibclean.shr
	-$(RM) bibclean.tar bibclean-?.??.tar
	-$(RM) bibclean.tar-lst
	-$(RM) bibclean.zip bibclean-?.??.zip
	-$(RM) bibclean.zip-lst bibclean-?.??.zip-lst
	-$(RM) bibclean.zoo bibclean-?.??.zoo
	-$(RM) bibclean.zoo-lst bibclean-?.??.zoo-lst
	-$(RM) core
	-$(RM) romtol romtol.lst
	-$(RM) testisxn.bib
	-$(RM) testscr2.bi2 testscr2.er2

clobber distclean:	clean
	-$(RM) bclproto bibclean match
	-$(RM) bibclean.hlp
	-$(RM) bibclean.ps
	-$(RM) bibclean.txt
	-$(RM) install.time install-ftp.time

docs:	bibclean.txt bibclean.hlp bibclean.ps

fndfil.i:	fndfil.c machdefs.h os.h ospcdos.h osrmx.h osunix.h \
		osvmcms.h osatari.h osprimos.h ostops20.h osvaxvms.h \
		unixlib.h xctype.h xpwd.h xstdlib.h xstring.h Makefile

fndfil.o:	fndfil.c machdefs.h os.h ospcdos.h osrmx.h osunix.h \
		osvmcms.h osatari.h osprimos.h ostops20.h osvaxvms.h \
		unixlib.h xctype.h xpwd.h xstdlib.h xstring.h

install:	install.time

install.time:	install-exe install-man
	touch install.time

install-exe:	bibclean
	$(CP) bibclean $(BINDIR)/bibclean
	-$(STRIP) $(BINDIR)/bibclean
	$(CHMOD) 755 $(BINDIR)/bibclean
	$(CP) bibclean.ini $(BINDIR)/.bibcleanrc

install-man:	bibclean.man
	$(CP) bibclean.man $(MANDIR)/bibclean.$(MANEXT)
	-$(RM) $(MANDIR)/../cat$(MANEXT)/bibclean.$(MANEXT)
	$(CHMOD) 644 $(MANDIR)/bibclean.$(MANEXT)

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).trz
	$(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

match.i:	match.c match.h os.h xctype.h xstdlib.h xstring.h Makefile

match.o:	match.c match.h os.h xctype.h xstdlib.h xstring.h

reallyclean realclean:	distclean
	-$(RM) TAGS

# Build a test program for romtol() and compare its results with
# correct ones
romtol:	romtol.c
	-$(RM) romtol.o
	$(CC) $(CFLAGS) -DTEST -o romtol romtol.c
	-$(RM) romtol.o
	./romtol <romtol.dat >romtol.lst
	@echo "There should be no differences found:"
	diff romtol.lok romtol.lst
	@if cmp romtol.lok romtol.lst 2>/dev/null ; then $(RM) romtol.lst ; fi

romtol.o:	romtol.c os.h xctype.h xstdlib.h xstring.h

strtol.o:	strtol.c os.h xctype.h xstdlib.h xstring.h

TAGS:	Makefile $(TAGS-FILES)
	etags $(TAGS-FILES)

test check:	test-bibtex test-scribe

# Test bibclean on Part 1 of the Reduce bibliography, testbib2.org.  The
# output file, testbib2.bib, is compared against a correct output file,
# testbib2.bok, from the author's site, and then the bibliography is
# additionally tested by LaTeX and BibTeX.

test-bibtex:	bibclean test-bibtex-1 test-bibtex-2 test-bibtex-3 \
		test-bibtex-4 test-bibtex-5

test-bibtex-1:	bibclean testbib1.org
	@echo
	@echo "==================== begin BibTeX test 1 ====================="
	@echo
	-@$(RM) testbib1.err testbib1.bib
	@echo
	-$(BIBCLEAN) testbib1.org >testbib1.bib 2>testbib1.err
	@echo
	@echo "There should be no differences found:"
	@echo "diff testbib1.bok testbib1.bib"
	-@if diff testbib1.bok testbib1.bib ; then $(RM) testbib1.bib ; fi
	@echo
	@echo "There should be no differences found:"
	@echo "diff testbib1.eok testbib1.err"
	-@if diff testbib1.eok testbib1.err ; then $(RM) testbib1.err ; fi
	@echo
	@echo "===================== end BibTeX test 1 ======================"
	@echo

test-bibtex-2:	bibclean testbib2.org
	@echo
	@echo "==================== begin BibTeX test 2 ====================="
	@echo
	@-$(RM) testbib2.aux testbib2.bbl testbib2.bib testbib2.blg \
		testbib2.dvi testbib2.log
	@echo
	-$(BIBCLEAN) -no-check-values testbib2.org >testbib2.bib 2>testbib2.err
	@echo
	@echo "There should be no differences found:"
	-diff testbib2.bok testbib2.bib
	@echo
	@echo "There should be no differences found:"
	@echo "diff testbib2.eok testbib2.err"
	-@if diff testbib2.eok testbib2.err ; then $(RM) testbib2.err ; fi
	@echo
	$(LATEX) testbib2.ltx >/dev/null
	@echo
	@echo "Expect 6 BibTeX warnings:"
	-$(BIBTEX) testbib2
	@if cmp testbib2.bok testbib2.bib 2>/dev/null ; \
		then $(RM) testbib2.bib ; fi
	@echo
	$(LATEX) testbib2.ltx >/dev/null
	@echo
	$(LATEX) testbib2.ltx
	@echo
	@echo "===================== end BibTeX test 2 ======================"
	@echo

test-bibtex-3:	bibclean testbib3.org
	@echo
	@echo "==================== begin BibTeX test 3 ====================="
	@echo
	@-$(RM) testbib3.bib testbib3.err
	@echo
	-$(BIBCLEAN) -fix-font-change testbib3.org >testbib3.bib 2>testbib3.err
	@echo
	@echo "There should be no differences found:"
	-@if diff testbib3.bok testbib3.bib ; then $(RM) testbib3.bib ; fi
	@echo
	@echo "There should be no differences found:"
	@echo "diff testbib3.eok testbib3.err"
	-@if diff testbib3.eok testbib3.err ; then $(RM) testbib3.err ; fi
	@echo
	@echo "===================== end BibTeX test 3 ======================"
	@echo

test-bibtex-4:	bibclean testbib4.org
	@echo
	@echo "==================== begin BibTeX test 4 ====================="
	@echo
	@-$(RM) testbib4.bib testbib4.err
	@echo
	-$(BIBCLEAN) -fix-font-change testbib4.org >testbib4.bib 2>testbib4.err
	@echo
	@echo "There should be no differences found:"
	-@if diff testbib4.bok testbib4.bib ; then $(RM) testbib4.bib ; fi
	@echo
	@echo "There should be no differences found:"
	@echo "diff testbib4.eok testbib4.err"
	-@if diff testbib4.eok testbib4.err ; then $(RM) testbib4.err ; fi
	@echo
	@echo "===================== end BibTeX test 4 ======================"
	@echo

# Test bibclean verification of ISBN and ISSN values.  The test file,
# testisxn.org, contains several hundred correct values, and also
# several hundred erroneous values.  We therefore discard error and
# warning messages, we ignore the return code, and we don't try to use
# the output with LaTeX or BibTeX.
test-bibtex-5:	bibclean testisxn.org
	@echo
	@echo "==================== begin BibTeX test 5 ====================="
	@echo
	-$(BIBCLEAN) testisxn.org >testisxn.bib 2>testisxn.err
	@echo
	@echo "There should be no differences found:"
	@echo "diff testisxn.bok testisxn.bib"
	-@if diff testisxn.bok testisxn.bib ; then $(RM) testisxn.bib ; fi
	@echo
	@echo "There should be no differences found:"
	@echo "diff testisxn.eok testisxn.err"
	-@if diff testisxn.eok testisxn.err ; then $(RM) testisxn.err ; fi
	@echo
	@echo "===================== end BibTeX test 5 ======================"
	@echo

# Test bibclean on a collection of Scribe bibliographies containing
# test cases to exhibit variations in Scribe bibliography syntax.

test-scribe:	bibclean test-scribe-1 test-scribe-2 test-scribe-3

# The peculiar step using tr to prepare the .aux files is needed to
# overcome inconsistencies in the handling of backslashes by the IBM
# RS/6000 shell.  The documented behavior in the SunOS 4.1.1 manual
# pages is (emphasis mine):
#     All characters enclosed between a pair of single quote marks
#     (''), except a single quote, are quoted by the shell.  BACKSLASH
#     HAS NO SPECIAL MEANING INSIDE A PAIR OF SINGLE QUOTES.  A single
#     quote may be quoted inside a pair of double quote marks (for
#     example, "'").
# On SunOS, HP UX, IBM 3090 AIX, NeXT Mach, and SGI IRIX, the shells
# csh, sh, bash, and ksh agree with this.  However, on IBM RS/6000
# AIX 3.2, backslashes in single quotes are untouched by csh, but
# expanded by sh and ksh.  This is clearly a bug, because the INFO
# hypertext node on bsh/rsh says:
#     All characters, except the enclosing single quotation marks, are
#     taken literally, with any special meaning removed.
#
test-scribe-1:	bibclean $(SCRIBE-TESTS-1)
	@echo
	@echo "==================== begin Scribe test 1 ====================="
	@echo
	-@for f in $(SCRIBE-TESTS-1) ; \
	do \
		BASENAME=`basename $$f .org` ; \
		echo ; \
		echo "----------------------------------------------------" ; \
		echo ; \
		echo "$(BIBCLEAN) -scribe -no-check $$f >$$BASENAME.bib" ; \
		$(BIBCLEAN) -scribe -no-check $$f >$$BASENAME.bib \
			2>$$BASENAME.err; \
		echo ; \
		echo "There should be no differences found:" ; \
		echo "diff $$BASENAME.bok $$BASENAME.bib" ; \
		diff $$BASENAME.bok $$BASENAME.bib ; \
		echo ; \
		echo "There should be no differences found:" ; \
		echo "diff $$BASENAME.eok $$BASENAME.err" ; \
		if diff $$BASENAME.eok $$BASENAME.err ; \
			then $(RM) $$BASENAME.err ; fi ; \
		echo ; \
		echo 'Bbibstyle{plain}NBcitation{*}NBbibdata{'$$BASENAME'}' | \
			tr BN '\134\012' >$$BASENAME.aux ; \
		if [ "$$BASENAME" = "testscr1" ] ; \
			then echo "Expect 5 BibTeX warnings" ; fi ; \
		if [ "$$BASENAME" = "testscr2" ] ; \
			then echo "There should be no BibTeX warnings:" ; fi ; \
		echo "$(BIBTEX) $$BASENAME" ; \
		$(BIBTEX) $$BASENAME; \
		if cmp $$BASENAME.bok $$BASENAME.bib 2>/dev/null ; \
			then $(RM) $$BASENAME.bib ; fi ; \
	done
	@echo "===================== end Scribe test 1 ======================"
	@echo

test-scribe-2:	bibclean testscr2.org
	@echo
	@echo "==================== begin Scribe test 2 ====================="
	@echo
	-$(BIBCLEAN) -scribe -file -no-check -no-par testscr2.org \
		>testscr2.bi2 2>testscr2.er2
	@echo
	@echo "There should be no differences found:"
	@echo "diff testscr2.bo2 testscr2.bi2"
	-@if diff testscr2.bo2 testscr2.bi2 ; then $(RM) testscr2.bi2 ; fi
	@echo
	@echo "There should be no differences found:"
	@echo "diff testscr2.eo2 testscr2.er2"
	-@if diff testscr2.eo2 testscr2.er2 ; then $(RM) testscr2.er2 ; fi
	@echo
	@echo "===================== end Scribe test 2 ======================"
	@echo

test-scribe-3:	bibclean testscr3.org
	@echo
	@echo "==================== begin Scribe test 3 ====================="
	@echo
	-$(BIBCLEAN) -scribe -no-check testscr3.org >testscr3.bib 2>testscr3.err
	@echo
	@echo "There should be no differences found:"
	@echo "diff testscr3.bok testscr3.bib"
	-@if diff testscr3.bok testscr3.bib ; then $(RM) testscr3.bib ; fi
	@echo
	@echo "There should be no differences found:"
	@echo "diff testscr3.eok testscr3.err"
	-@if diff testscr3.eok testscr3.err ; then $(RM) testscr3.err ; fi
	@echo
	@echo "===================== end Scribe test 3 ======================"
	@echo

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

uninstall:
	-$(RM) $(BINDIR)/bibclean $(BINDIR)/.bibcleanrc \
		$(MANDIR)/bibclean.$(MANEXT) \
		$(MANDIR)/../cat$(MANEXT)/bibclean.$(MANEXT)
	-$(RM) install.time

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

vms/alpha/bibclean.uue:	vms/alpha/bibclean.exe
	uuencode vms/alpha/bibclean.exe bibclean.exe >vms/alpha/bibclean.uue

vms/vax/bibclean.uue:	vms/vax/bibclean.exe
	uuencode vms/vax/bibclean.exe bibclean.exe >vms/vax/bibclean.uue

#=======================================================================
# Private targets for developer use only; these make customized
# Makefiles in subdirectories for different architectures.

Makefiles: next/Makefile sgi/Makefile stardent/Makefile ultrix/Makefile

next/Makefile:	Makefile
	$(CP) Makefile next/Makefile
	echo 'CC    = cc $$(GCCFLAGS)' >>next/Makefile

sgi/Makefile:	Makefile
	$(CP) Makefile sgi/Makefile
	echo 'CC    = cc -ansiposix -fullwarn \
		-woff 22,24,183,205,262,269,302,303' >>sgi/Makefile

stardent/Makefile:	Makefile
	$(CP) Makefile stardent/Makefile
	echo 'CC    = cc' >>stardent/Makefile
	echo 'OPT   = '   >>stardent/Makefile

ultrix/Makefile:	Makefile
	$(CP) Makefile ultrix/Makefile
	echo 'CC    = lcc -A -A -n' >>ultrix/Makefile

#=======================================================================
# Public convenience targets.   You can supply a TARGET=target setting
# when you invoke make to select a particular target; if you do not,
# then the default target, all, will be made.

generic:
	$(MAKE) CC=cc $(TARGET)

cdc-mips-epix-cc:
	$(MAKE) CC='cc -systype bsd43 -D__CC__' $(TARGET)

dec-alpha-osf1-c++:
	$(MAKE) CC=cxx $(TARGET)

dec-alpha-osf1-cc:
	$(MAKE) CC=c89 $(TARGET)

dec-alpha-osf1-g++:
	$(MAKE) CC='g++ $(GCCFLAGS)' $(TARGET)

dec-alpha-osf1-gcc:
	$(MAKE) CC='gcc $(GCCFLAGS)' $(TARGET)

dec-mips-ultrix-cc:
	$(MAKE) CC=cc $(TARGET)

dec-mips-ultrix-g++:
	$(MAKE) CC='g++ $(GCCFLAGS)' $(TARGET)

dec-mips-ultrix-gcc:
	$(MAKE) CC='gcc $(GCCFLAGS)' $(TARGET)

dec-mips-ultrix-lcc:
	$(MAKE) CC='lcc -A -A -n' $(TARGET)

hp-370-bsd43-c++:
	$(MAKE) CC=CC $(TARGET)

hp-370-bsd43-cc:
	$(MAKE) CC=CC $(TARGET)

hp-9000-hpux-c++:
	$(MAKE) CC='CC -D_HPUX_SOURCE' $(TARGET)

hp-9000-hpux-cc:
	$(MAKE) CC='c89 -D_HPUX_SOURCE' $(TARGET)

IBM370CC = 'CC +a1 +p +w -D_POSIX_SOURCE -Hansi -D__STDC__ -D_BSD -D_AIX \
	-D_AIX370'
ibm-370-aix-c++:
	$(MAKE) CC=$(IBMPS2CC) $(TARGET)

ibm-370-aix-cc:
	$(MAKE) CC=cc $(TARGET)

IBMPS2CC = 'CC +a1 +p +w -D_POSIX_SOURCE -Hansi -D__STDC__ -D_BSD -D_AIX \
	-Dps2 -DHAVE_TERMIO_H'
ibm-ps2-aix-c++:
	$(MAKE) CC=$(IBMPS2CC) $(TARGET)

ibm-ps2-aix-cc:
	$(MAKE) CC=cc $(TARGET)

ibm-rs6000-aix-cc:
	$(MAKE) CC='c89 -D_POSIX_SOURCE -D_ALL_SOURCE' $(TARGET)

ibm-rs6000-aix-c++:
	$(MAKE) CC='xlC' $(TARGET)

ibm-rs6000-aix-g++:
	$(MAKE) CC='g++ $(GCCFLAGS)' $(TARGET)

ibm-rs6000-aix-gcc:
	$(MAKE) CC='gcc $(GCCFLAGS)' $(TARGET)

mips-mips-riscos-cc:
	$(MAKE) CC='cc -systype bsd43 -D__CC__' $(TARGET)

next-motorola-mach-cc:
	$(MAKE) CC='cc $(GCCFLAGS)' EXTRA-OBJS= $(TARGET)

next-motorola-mach-g++:
	$(MAKE) CC='g++ $(GCCFLAGS)' EXTRA-OBJS= $(TARGET)

next-motorola-mach-gcc:
	$(MAKE) CC='gcc $(GCCFLAGS)' EXTRA-OBJS= $(TARGET)

next-motorola-mach-lcc:
	$(MAKE) CC='lcc -A -A -n' EXTRA-OBJS= $(TARGET)

sgi-mips-irix-c++:
	$(MAKE) CC='CC +a1 -xansi +w' $(TARGET)

SGICC	= 'cc -ansiposix -fullwarn -woff 22,24,183,205,262,269,302,303'
sgi-mips-irix-cc:
	$(MAKE) CC=$(SGICC) $(TARGET)

sgi-mips-irix-g++:
	$(MAKE) CC='g++ $(GCCFLAGS)' $(TARGET)

sgi-mips-irix-gcc:
	$(MAKE) CC='gcc $(GCCFLAGS)' $(TARGET)

sgi-mips-irix-lcc:
	$(MAKE) CC='lcc -A -A -n' $(TARGET)

stardent-mips-os2-cc:
	$(MAKE) CC='cc' OPT= $(TARGET)

SUNAPCC	= 'apcc -Xc=ansi -D__ACC__ -D__solaris -DHAVE_TERMIOS_H'
sun-sparc-solaris2-apcc sun-sparc-sunos5-apcc:
	$(MAKE) CC=$(SUNAPCC) $(TARGET)

sun-sparc-solaris2-g++ sun-sparc-sunos5-g++:
	$(MAKE) CC='g++ $(GCCFLAGS) -D__solaris -DHAVE_TERMIOS_H' $(TARGET)

sun-sparc-solaris2-gcc sun-sparc-sunos5-gcc:
	$(MAKE) CC='gcc $(GCCFLAGS) -D__solaris -DHAVE_TERMIOS_H' $(TARGET)

sun-sparc-solaris2-c++ sun-sparc-sunos5-c++:
	$(MAKE) CC='CC -D__solaris -DHAVE_TERMIOS_H' $(TARGET)

sun-sparc-solaris2-cc sun-sparc-sunos5-cc:
	$(MAKE) CC='cc -Xc -D__ACC__ -D__solaris -DHAVE_TERMIOS_H' $(TARGET)

SUNACC	= 'acc -Xc -vc -strconst -D__ACC__ -D_POSIX_SOURCE -DHAVE_TERMIOS_H'
sun-sparc-solaris1-acc sun-sparc-sunos4-acc:
	$(MAKE) CC=$(SUNACC) $(TARGET)

sun-sparc-solaris1-c++ sun-sparc-sunos4-c++:
	$(MAKE) CC='/usr/CC/sun4/CC -I/usr/CC/incl -D__SUNCC__' $(TARGET)

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