#
# Compiling and Installing Isearch
#
# 1)  Type `make'
#
# 2)  Type `make install' (as root), to copy executables to /usr/local/bin/.
#       or `make install INSTALL=~/bin' to copy them to ~/bin/.
#       etc.
#
# 3)  Typing `make clean' will clean up .o files.
#
# The executables are
#
#	Iindex	- command line indexing utility
#	Isearch	- command line searching utility
#	Iutil - command line utilities for Isearch databases
#
SHELL=/bin/sh

#
# Compiler
#
CC=g++

DTCC=g++
#CC=/sw/CenterLine/bin/CC

#
# Compiler flags?
#
# Select your platform and comment/uncomment the appropriate CFLAGS
# 
# -DVERBOSE makes Iindex tell you when it's parsing docs and fields
# -DMULTI compiles code to handle documents consisting of multiple files
#         in a single subdirectory
#
# for Solaris, SunOS, Ultrix, OSF
#
#CFLAGS=-O2 -DUNIX -DMULTI
CFLAGS=-O2 -DUNIX

#
# for Linux
#
#CFLAGS=-O2 -m486 -DUNIX

#
# for HP
# - for some odd reason, compiling with optimization (-O2) implants
#   a bug in INDEX::TermSearch, so don't optimize.
#
#CFLAGS=-DUNIX -D_HP_ -DNO_MMAP

# 
# for AIX
#
#CFLAGS=-O2 -DUNIX -DNOCACHE -D_BSD

#
# for DG
# - same comment as for HP
#CFLAGS=-DUNIX

#
# for SGI C++
#
#CC=CC
#CFLAGS=-O2 -DUNIX -DSGI_CC -woff 3262 -32

#
# Install Directory
#
# Where should I install executables (make install)?
#
INSTALL=/usr/local/bin
CGI_INSTALL=/usr/local/etc/httpd/cgi-bin

#
# Executables Directory
#
# Where should I place executables?
#
BIN_DIR=bin

#
# Document Type Directory
#
# Where are document type sources located?
#
DOCTYPE_DIR=doctype

#
# Doctype dependent libraries (-lgdbm, etc)
DOCLIB=

#
# Source Directory
#
# Where are search engine sources located?
#
SRC_DIR=src

#
# Isearch-cgi Directory
#
# Where is the CGI gateway code?
#
CGI_DIR=Isearch-cgi

# 
# That should be all you need to configure
#

RM = rm -f
LDFLAGS=
VER=1.20
DIST=Isearch-$(VER)
BINDIST=$(DIST)-bin
freezename=`echo $(VER) | sed 's/\./-/g'`
OSNAME=`uname -s`
OSVER=`uname -r`
OS=$(OSNAME)_$(OSVER)

all: isearch isearch-cgi done

isearch::
	`if [ -f src/conf.h ] ; \
		then true ; \
		else echo ./configure ; \
	fi`
	cd $(DOCTYPE_DIR); make "CC=$(CC)" \
		CFLAGS="$(CFLAGS) -DVERS=\\\"$(VER)\\\" "
	cd $(SRC_DIR); make "BIN_DIR=../$(BIN_DIR)" \
			"DOCTYPE_DIR=../$(DOCTYPE_DIR)" \
			CFLAGS="$(CFLAGS) -DVERS=\\\"$(VER)\\\" " \
			"CC=$(CC)" "DOCLIB=$(DOCLIB)" "LDFLAGS=$(LDFLAGS)"

isearch-cgi::
	cd $(CGI_DIR); make "BIN_DIR=../$(BIN_DIR)" \
			"LIB_DIR=../$(BIN_DIR)" "ISEARCH_DIR=.." \
			CFLAGS="$(CFLAGS) -DVERS=\\\"$(VER)\\\"" \
			"CC=$(CC)" "DOCLIB=$(DOCLIB)" "LDFLAGS=$(LDFLAGS)"

done:
	@echo ""
	@echo "Welcome to CNIDR Isearch version $(VER)!"
	@echo ""
	@echo "Read the README file for configuration and installation instructions"
	@echo ""

clean:
	$(RM) *~ $(BIN_DIR)/Iindex $(BIN_DIR)/Isearch $(BIN_DIR)/Iutil \
		$(BIN_DIR)/libIsearch.a $(BIN_DIR)/core
	cd $(SRC_DIR); make -i clean
	cd $(DOCTYPE_DIR); make -i clean
	cd $(CGI_DIR); make -i clean

realclean:
	$(RM) *~ $(BIN_DIR)/Iindex $(BIN_DIR)/Isearch $(BIN_DIR)/Iutil \
		$(BIN_DIR)/libIsearch.a $(BIN_DIR)/core config.* \
		Makefile.all
	cd $(SRC_DIR); make -i realclean
	cd $(DOCTYPE_DIR); make -i clean
	cd $(CGI_DIR); make -i clean

distclean:
	$(RM) *~ $(BIN_DIR)/Iindex $(BIN_DIR)/Isearch $(BIN_DIR)/Iutil \
		$(BIN_DIR)/libIsearch.a $(BIN_DIR)/core config.* \
		Makefile.all
	cd $(SRC_DIR); make -i distclean
	cd $(DOCTYPE_DIR); make -i clean
	cd $(CGI_DIR); make -i clean

binclean:
	$(RM) *~ $(BIN_DIR)/Iindex $(BIN_DIR)/Isearch $(BIN_DIR)/Iutil \
		$(BIN_DIR)/libIsearch.a $(BIN_DIR)/core
	cd $(CGI_DIR);$(RM) isrch_fetch isrch_srch search_form

build:
	`if [ -e src/conf.h ] ; \
		then make -i realclean; \
		else true; \
	fi`
	make all

install:
	@echo "*** Copying Isearch executables to $(INSTALL) ***"
	cp $(BIN_DIR)/Iindex $(INSTALL)
	cp $(BIN_DIR)/Isearch $(INSTALL)
	cp $(BIN_DIR)/Iutil $(INSTALL)
	@echo "*** Copying Isearch-cgi executables to $(INSTALL) ***"
	cp $(CGI_DIR)/isrch_srch $(INSTALL)
	cp $(CGI_DIR)/isrch_fetch $(INSTALL)
	cp $(CGI_DIR)/isrch_html $(INSTALL)
	cp $(CGI_DIR)/search_form $(INSTALL)


dist:
	make -i distclean
	rm -f *~ $(SRC_DIR)/*~ $(DOCTYPE_DIR)/*~ \
		*.bak $(SRC_DIR)/*.bak $(DOCTYPE_DIR)/*.bak \
		$(SRC_DIR)/ISEARCH.*
	ls -F $(SRC_DIR)
	rm -fr ../$(DIST)
	mkdir ../$(DIST)
#	cd $(SRC_DIR); rcsfreeze $(freezename); co -r$(freezename) RCS/*,v
	find . -name \* -print | grep -v '^RCS/' > .tmpdist-$(VER)
	tar cf - `cat .tmpdist-$(VER)` | (cd ../$(DIST); tar xf -)
	cd ..; tar cf $(DIST).tar $(DIST)
	rm -f ../$(DIST).tar.gz
	cd ..; gzip $(DIST).tar
	cp ./CHANGES ../.

srcdist:
	make -i distclean;cd ..;tar cvf $(DIST)-$(VER).tar $(DIST);gzip $(DIST)-$(VER).tar

bindist:
	cd ..; \
	strip $(DIST)/bin/Iindex; \
	strip $(DIST)/bin/Isearch; \
	strip $(DIST)/bin/Iutil; \
	strip $(DIST)/Isearch-cgi/Configure; \
	strip $(DIST)/Isearch-cgi/isrch_fetch; \
	strip $(DIST)/Isearch-cgi/isrch_srch; \
	strip $(DIST)/Isearch-cgi/search_form; \
	tar cvf $(DIST)_$(OS).tar \
		$(DIST)/bin/Iindex \
		$(DIST)/bin/Isearch \
		$(DIST)/bin/Iutil \
		$(DIST)/Isearch-cgi/Configure \
		$(DIST)/Isearch-cgi/README \
		$(DIST)/Isearch-cgi/isrch_fetch \
		$(DIST)/Isearch-cgi/isrch_srch \
		$(DIST)/Isearch-cgi/search_form \
		$(DIST)/doc \
		$(DIST)/README \
		$(DIST)/RELEASE \
		$(DIST)/html  \
		$(DIST)/COPYRIGHT; \
		gzip $(DIST)_$(OS).tar
