#=======================================================================
# Makefile for bibindex and biblook.
#
# These programs are written in ISO/ANSI Standard C.  They must be
# compiled with a Standard C compiler, or with a C++ compiler.
#
# Current target list:
#	all 			make bibindex and biblook
#	bibindex.txt 		ascii text file from UNIX man pages
#	bibindex 		make indexing program
#	bibindex.tar		UNIX tar archive file for bibindex
#				distribution
#	bibindex.tar.z		compressed UNIX tar archive file for bibindex
#	bibindex.uue		uuencoded bibindex.tar.z archive
#	bibindex.zip		InfoZip archive file for bibindex
#				distribution
#	bibindex.zoo		zoo archive file for bibindex distribution
#	bibindex.tar-lst	listing of UNIX tar archive file
#	bibindex.zip-lst	listing of InfoZip archive file
#	bibindex.zoo-lst	listing of zoo archive file
#	biblook.txt 		ascii text file from UNIX man pages
#	biblook 		make lookup program
#	clean 			remove all recreatable files, except
#				executables
#	clobber 		remove all recreatable files
#	install 		install executables and manual pages
#	uninstall 		uninstall executables and manual pages
#
# [01-Jun-1993]
#=======================================================================

DEST		= /usr/local

BINDIR		= $(DEST)/bin

CATDIR		= $(DEST)/man/cat1

# Compilation with a C++ compiler is preferable.  SunOS 4.1 CC cannot be
# used, however, because of its erroneous function prototypes in stdlib.h
# which use char* instead of void* in many places.  There is no such
# problem with Sun Solaris 2.1 CC, which works fine.
CC		= CC			## some UNIX C++ compilers
CC		= CC -I/usr/CC/incl	## C++ on SunOS 4.1.1
CC		= acc -Dsun		## SunOS Standard C compiler
CC		= c89 -D_POSIX_SOURCE	## HP 9000/850 HP-UX A.08.00 D
CC		= c89 -D_POSIX_SOURCE	## IBM RS/6000 Standard C
CC		= xlC			## IBM RS/6000 C++
CC		= cc			## many UNIX systems
CC		= cc $(GCCFLAGS)	## NeXT
CC		= lcc -A -A -n		## Princeton/AT&T Standard C compiler
CC		= g++ $(GCCFLAGS)	## UNIX systems with GNU C++
CC              = gcc $(GCCFLAGS)	## GNU C
CC		= g++ $(GCCFLAGS)	## UNIX systems with GNU C++
CC		= g++ $(GCCFLAGS) -Dtemplate=Template ## NeXT systems with GNU C++
CC		= cc -ObjC		## NeXT systems with Objective C
CC              = gcc $(GCCFLAGS)	## GNU C

CFLAGS		= $(OPT)		## most cases

GCCFLAGS	= -Wall -Wshadow -Wcast-qual -Wpointer-arith \
		  -Wwrite-strings

COL		= col -b

COMPRESS	= compress

CP		= /bin/cp

FTPDIR		= /usr/spool/ftp/pub/tex/bib

LDFLAGS		=

# Use /usr/lib/debug/malloc.o on Sun systems for malloc debugging
# with acc, gcc, or CC
LIBS		= /usr/lib/debug/malloc.o
LIBS		=

MANDIR		= $(DEST)/man/man1

MANEXT		= 1

NROFF		= nroff -man

# Define DEBUG_MALLOC on Sun systems for debugging memory allocation
OPT		= -g -DDEBUG_MALLOC
OPT		= -g

RM		= /bin/rm -f

SHELL		= /bin/sh

TAR		= tar

TARFILES	= README Makefile bibindex.c bibindex.man bibindex.txt \
		biblook.c biblook.h biblook.man biblook.txt

UNZIP		= unzip

UUENCODE	= uuencode

ZIP		= zip

ZOO		= zoo

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

all:	bibindex biblook bibindex.txt biblook.txt

bibindex:	bibindex.o
	$(CC) $(CFLAGS) -o bibindex bibindex.o $(LDFLAGS) $(LIBS)

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

bibindex.tar:	$(TARFILES)
	$(TAR) cf $@ $(TARFILES)

bibindex.tar-lst:	bibindex.tar
	$(TAR) tvf $? >$@

bibindex.tar.z:	bibindex.tar
	$(COMPRESS) <$? >$@

bibindex.uue:	bibindex.tar.z
	$(UUENCODE) $? $? >$@

bibindex.zip:	$(TARFILES)
	-$(RM) $@
	$(ZIP) $@ $(TARFILES)

bibindex.zip-lst:	bibindex.zip
	$(UNZIP) -v $? >$@

bibindex.zoo:	$(TARFILES)
	-$(RM) $@
	$(ZOO) a $@ $(TARFILES)

bibindex.zoo-lst:	bibindex.zoo
	$(ZOO) v $? >$@

biblook:	biblook.o
	$(CC) $(CFLAGS) -o biblook biblook.o $(LDFLAGS) $(LIBS)

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

bibindex.o biblook.o: biblook.h

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

clobber distclean realclean reallyclean:	clean
	-$(RM) biblook bibindex
	-$(RM) biblook.txt bibindex.txt

install:	bibindex biblook
	-$(CP) bibindex $(BINDIR)
	-chmod 775 $(BINDIR)/bibindex
	-$(CP) biblook $(BINDIR)
	-chmod 775 $(BINDIR)/biblook
	-$(CP) bibindex.man $(MANDIR)/bibindex.$(MANEXT)
	-chmod 774 $(MANDIR)/bibindex.$(MANEXT)
	-$(CP) biblook.man $(MANDIR)/biblook.$(MANEXT)
	-chmod 774 $(MANDIR)/biblook.$(MANEXT)

install-ftp:	bibindex.tar.z bibindex.zip bibindex.zoo \
		bibindex.tar-lst bibindex.zip-lst bibindex.zoo-lst
	-for f in $? ; \
	do \
		$(CP) $$f $(FTPDIR) ; \
		chmod 774 $(FTPDIR)/$$f ; \
	done

uninstall:
	-$(RM) $(BINDIR)/bibindex
	-$(RM) $(BINDIR)/biblook
	-$(RM) $(MANDIR)/bibindex.$(MANEXT)
	-$(RM) $(MANDIR)/biblook.$(MANEXT)
	-$(RM) $(CATDIR)/bibindex.$(MANEXT)
	-$(RM) $(CATDIR)/biblook.$(MANEXT)

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