###############################################################################
#
# File:         Makefile
# RCS:          $Header: Makefile,v 1.5 89/09/14 21:16:09 chip Rel $
# Description:  Makefile for Bible Retrieval System
# Author:       Chip Chapin, Hewlett Packard Company
# Created:      Thu Aug 24 17:26:25 1989
# Modified:     Thu Sep 14 21:19:54 1989 (Chip Chapin) chip@hpcllcc
# Language:     make
# Package:      Bible Retrieval System
# Status:       Experimental (Do Not Distribute)
#
# $Log:	Makefile,v $
# Revision 1.5  89/09/14  21:16:09  21:16:09  chip (Chip Chapin)
# Release 1-2.  Supports -f and -l options for formatting the output.
# Updates primarily brl.c, bible.c, and bible.1.
# Makefile updates include automatic release.
# 
# Revision 1.4  89/09/08  13:23:38  13:23:38  chip (Chip Chapin)
# Better error checking on verse syntax; automatic test suite.
# 
# Revision 1.3  89/09/07  09:55:39  09:55:39  chip (Chip Chapin)
# Bug fixes: "make install" now creates non-existent directories instead
# of barfing.  Added man file to "make uninstall".
# 
# Revision 1.2  89/09/05  20:23:53  20:23:53  chip (Chip Chapin)
# Fix install bug.
# 
# Revision 1.1  89/09/05  17:49:57  17:49:57  chip (Chip Chapin)
# Initial revision
#
###############################################################################

XeF    	      =

#CFLAGS	      = -g
#CFLAGS	      = -O
PFLAGS	      =
FFLAGS	      = 

DIRS	      =

# where to install this stuff
DEST	      = /usr/local
#DEST	      = $(HOME)/local
DESTBIN	      = $(DEST)/bin
DESTLIB       = $(DEST)/lib
DESTMAN	      = $(DEST)/man
DESTMAN1      = $(DESTMAN)/man1.Z

# release directory.  Nobody should care about this but me
RELEASEDIR    = /extra/users/ftp/pub/bible

EXTHDRS	      = /usr/include/ctype.h \
		/usr/include/machine/frame.h \
		/usr/include/machine/frame.h \
		/usr/include/machine/save_state.h \
		/usr/include/machine/save_state.h \
		/usr/include/signal.h \
		/usr/include/stdio.h \
		/usr/include/sys/signal.h \
		/usr/include/sys/stat.h \
		/usr/include/sys/syscall.h \
		/usr/include/sys/types.h

HDRS	      = brl.h \
		tsl.h

INSTALL	      = install

LD	      = cc

LDFLAGS	      =

LIBS	      =

MAKEFILE      = Makefile

OBJS	      = brl-index.o \
		brl.o \
		tsl-index.o \
		tsl.o \
		compresslib.o

PROGOBJS      = bible.o \
		buildcmp.o \
		makeindex.o \
		squish.o

PRINT	      = pr

PROGRAMS      = buildcmp squish makeindex bible

# user programs -- these get installed
UPROGRAMS     = bible

# man pages
MAN	      = bible.1

# Derived data file.  Comes from processing raw data file.
DATA	      = bible.data

SHELL	      = /bin/sh

SRCS	      = bible.c \
		brl-index.c \
		brl.c \
		tsl.c \
		buildcmp.c \
		compresslib.c \
		makeindex.c \
		squish.c

# List of all files that go into a distribution
MOSTFILES     = README $(MAN) $(SRCS) $(HDRS) $(MAKEFILE) testall
DISTFILES     =  $(MOSTFILES) test.stdresults bible.rawtext


all:		$(PROGRAMS) $(DATA)

bible:		bible.o $(OBJS) $(LIBS)
		@echo "Linking $@ ..."
		@$(LD) $(LDFLAGS) $@.o $(OBJS) $(LIBS) -o $@
		@echo "done"
		
buildcmp:	buildcmp.o compresslib.o
		@echo "Linking $@ ..."
		@$(LD) $(LDFLAGS) $@.o compresslib.o -o $@
		@echo "done"
		
squish:		squish.o
		@echo "Linking $@ ..."
		@$(LD) $(LDFLAGS) $@.o $(LIBS) -o $@
		@echo "done"
		
makeindex:	makeindex.o
		@echo "Linking $@ ..."
		@$(LD) $(LDFLAGS) $@.o $(LIBS) -o $@
		@echo "done"
		
$(DATA):	squish.stats squish.data
		./buildcmp
		mv squish.output $(DATA)

squish.stats squish.data:	squish bible.rawtext
		./squish -w 65536 -v <bible.rawtext >squish.data

tsl-index.c:	bible.rawtext
		./makeindex bible.rawtext > $@

clean:;		@rm -f $(OBJS) $(PROGOBJS) squish.stats squish.data core

clobber:;	@rm -f $(OBJS) $(PROGOBJS) $(PROGRAMS) $(DATA) \
			tsl-index.c squish.stats squish.data core tags

depend:;	@mkmf -f $(MAKEFILE) ROOT=$(ROOT)

echo:;		@echo $(HDRS) $(SRCS)

index:;		@ctags -wx $(HDRS) $(SRCS)

install:	$(UPROGRAMS) $(DATA) $(MAN)
		@if [ ! -r $(DEST) ]; then mkdir $(DEST); fi
		@echo Installing $(UPROGRAMS) in $(DESTBIN)
		@-strip $(UPROGRAMS)
		@if [ ! -r $(DESTBIN) ]; then mkdir $(DESTBIN); fi
		@if [ $(DESTBIN) != . ]; then \
		((cd $(DESTBIN);rm -f $(UPROGRAMS)); \
		mv $(UPROGRAMS) $(DESTBIN)); fi
		@echo Installing $(DATA) in $(DESTLIB)
		@if [ ! -r $(DESTLIB) ]; then mkdir $(DESTLIB); fi
		@if [ $(DESTLIB) != . ]; then \
		mv $(DATA) $(DESTLIB); fi
		@if [ ! -r $(DESTMAN) ]; then mkdir $(DESTMAN); fi
		@echo Installing $(MAN) in $(DESTMAN1)
		@if [ ! -r $(DESTMAN1) ]; then mkdir $(DESTMAN1); fi
		@if [ $(DESTMAN1) != . ]; then \
		compress < $(MAN) > $(DESTMAN1)/$(MAN); fi

uninstall:;	@echo Un-installing $(UPROGRAMS), $(DATA) and $(MAN)
		rm -f $(DESTBIN)/$(UPROGRAMS)
		rm -f $(DESTLIB)/$(DATA)
		rm -f $(DESTMAN1)/$(MAN)

print:;		@$(PRINT) $(HDRS) $(SRCS)

tags:           $(HDRS) $(SRCS); @ctags $(HDRS) $(SRCS)

# update:		$(DESTBIN)/$(PROGRAM) $(DESTLIB)/$(DATA)

shar:;		shar -Zcstem $(DISTFILES) > bible.shar

tar:		$(DISTFILES)
		tar cvf bible.tar $(DISTFILES)
		compress <bible.tar >bible.tar.Z
		touch tar

stdresults:	test.results
		@echo "Storing Standard test results in test.stdresults...\c"
		@cp test.results test.stdresults
		@touch stdresults
		@echo " done."

test.results:	testall bible
		@echo "Running Test Suite (results in test.results)...\c"
		@./testall > test.results 2>&1
		@echo " test suite completed"

test:		test.results test.stdresults
		@echo "Comparing results to standard results"
		@if diff -c test.results test.stdresults; \
		then echo "  results OK."; \
		else echo "  results differ.  Possible error."; fi

checkin:	$(MOSTFILES)
		ci -l $?
		touch checkin

relcheckin:	$(MOSTFILES)
		@if [ "$(RELNAME)" = "" ]; \
		then echo "*** No RELNAME value specified ***"; \
		echo "*** Set RELNAME to release name and export it ***"; \
		exit 1; fi
		@if [ "$(CFLAGS)" != "-O" ]; \
		then echo "*** CFLAGS not set to -O for release ***"; \
		echo "*** Set CFLAGS to -O and export it ***"; \
		exit 1; fi
		ci -l -n"$(RELNAME)" -sRel $?
		echo "$(RELNAME)" > relcheckin

$(MOSTFILES):;	co $@

# The nested makes are here because the timestamps don't get updated
# correctly from the ci -l otherwise.
release:	relcheckin
		make all
		strip bible
		make stdresults
		make tar
		if hp9000s800; then cp bible $(RELEASEDIR)/bible.s800; fi
		cp $(DATA) $(RELEASEDIR)/$(DATA)
		cp bible.tar.Z $(RELEASEDIR)
		compress < $(MAN) > $(RELEASEDIR)/$(MAN).Z
		cp README $(RELEASEDIR)/README.bible
		touch release


# $(DESTBIN)/$(PROGRAM): $(SRCS) $(LIBS) $(HDRS) $(EXTHDRS)
#		@$(MAKE) -f $(MAKEFILE) ROOT=$(ROOT) DEST=$(DEST) install
###
bible.o: /usr/include/stdio.h brl.h
brl.o: /usr/include/stdio.h /usr/include/ctype.h brl.h
tsl.o: /usr/include/stdio.h brl.h tsl.h
buildcmp.o: /usr/include/stdio.h tsl.h
