#
# This is a sample server, Z39.50 library, and a user interface stub
#  The Z39.50 library was primariy written by Harry Morris and the search
#  engine was primarily written by Brewster Kahle.
#  -brewster 4/90

# Compile it all out of place for common source and separate
# object files for each architecure TBL 910925
# This directory has only machine-specific files. The following macros
# specify where to find the common sources

WAIS = ../../../../../WAIS
IR = $(WAIS)/ir
COMPILE = $(CC) -c $(CFLAGS) $(IR)/$*.c


# Common customizations:
#  If a namespace resolver is not used (gethostbyname),
#   set RESOLVER to nothing, otherwise -lresolv
#  gcc vs cc:  This library was written on a bunch of ANSI routines.
#   the ones that did not exist in gcc or for non-ANSI cc are in ustubs.c
# for old BSD cc or System V, see cflags below

SERVER_CMD = ../bin/waisserver	# command name for the wais server
INDEX_CMD  = ../bin/waisindex 	# command name for indexing files
SIG_INDEX_CMD  = ../bin/waisindex-sig 	# command name for indexing files
#				# with signiture system. 
UI_LIB =     ../bin/ui.a	# file name of the ui library
UI_SIG_LIB = ../bin/ui-sig.a	# file name of the ui library

IPC_UI_CMD = ../bin/waissearch-ipc # command name for a IPC 1990 interface (for apple)


SHELL_UI_SRC = $(WAIS)/ui/shell-ui.c

RM = rm -f
AR = ar 
ARFLAGS = r
#
# Files.
#

# List of source files for saber.

SOURCES =	\
		$(IR)/cutil.c \
		$(IR)/futil.c \
		$(IR)/ir.c \
		$(IR)/ircfiles.c \
		$(IR)/irfileio.c \
		$(IR)/irfiles.c \
		$(IR)/irretrvl.c \
		$(IR)/irtfiles.c \
		$(IR)/panic.c \
		$(IR)/sockets.c \
		$(IR)/stoplist.c \
		$(IR)/transprt.c \
		$(IR)/ui.c \
		$(IR)/ustubs.c \
		$(IR)/wmessage.c \
		$(IR)/wprot.c \
		$(IR)/wutil.c \
		$(IR)/zprot.c \
		$(IR)/zutil.c \
 		$(IR)/irsearch.c \
 		$(IR)/ztype1.c \
		$(IR)/docid.c

INV_SRC  =	$(SOURCES) \
		$(IR)/sersrch.c \
		$(IR)/irhash.c \
		$(IR)/irinv.c		

SIG_SRC  = 	$(SOURCES) \
		$(IR)/sigsrch.c \
		$(IR)/sighash.c \
		$(IR)/sigindex.c

INDEX_SRC=	$(IR)/irbuild.c

SERVER_SRC=	$(INV_SRC) \
		$(IR)/server.c

# List of object files for saber and regular compilation.
# Should correspond to source files.

OBJECTS =	\
		cutil.o \
		futil.o \
		ir.o \
		ircfiles.o \
		irfileio.o \
		irfiles.o \
		irretrvl.o \
		irtfiles.o \
		panic.o \
		sockets.o \
		stoplist.o \
		transprt.o \
		ui.o \
		ustubs.o \
		wmessage.o \
		wprot.o \
		wutil.o \
		zprot.o \
		zutil.o \
 		irsearch.o \
 		ztype1.o \
		docid.o

INV_OBJ  =	$(OBJECTS) \
		sersrch.o \
		irhash.o \
		irinv.o		

SIG_OBJ  = 	$(OBJECTS) \
		sigsrch.o \
		sighash.o \
		sigindex.o

INDEX_OBJ=	irbuild.o

SERVER_OBJ=	$(INV_OBJ) \
		server.o \
		../bin/libftw.a

#
# Compilation.
#

# C Compiler.  Use either cc or gcc.
#CC = gcc

# Compiler & linker flags.
# Compiler debug flag.  Use -g for debugging, -O for optimization.
# for antique bsd add -DBSD 
# for System V add -DSYSV 
# for XENIX add -M3e -Zi
# -DSECURE_SERVER for waisserver to setuid to uucp after startup.
CFLAGS = -g -DSECURE_SERVER -DRELEVANCE_FEEDBACK -I$(IR)

# dealing with taking an intenet name and resolving it.  
# set to -lresolv or nothing
RESOLVER=	#-lresolv 

default:	$(UI_LIB)

# default:	$(INDEX_CMD) $(SIG_INDEX_CMD) $(SERVER_CMD) $(UI_LIB) $(UI_SIG_LIB)

$(SIG_INDEX_CMD): $(SIG_OBJ) $(INDEX_OBJ)
		$(CC) $(CFLAGS) -o $(SIG_INDEX_CMD) $(SIG_OBJ) $(INDEX_OBJ) -lm;

$(INDEX_CMD):	$(INV_OBJ) $(INDEX_OBJ) 
		$(CC) $(CFLAGS) -o $(INDEX_CMD) $(INV_OBJ) $(INDEX_OBJ) -lm;

$(SERVER_CMD):	$(SERVER_OBJ)
		$(CC) $(CFLAGS) -o $(SERVER_CMD) $(SERVER_OBJ) -lm;

$(UI_LIB):	$(INV_OBJ)
		$(AR) $(ARFLAGS) $(UI_LIB) $(INV_OBJ)
		ranlib $(UI_LIB)

$(UI_SIG_LIB):	$(SIG_OBJ)
		$(AR) $(ARFLAGS) $(UI_SIG_LIB) $(SIG_OBJ)
		ranlib $(UI_SIG_LIB)

#	Where to find the source files (TBL). Dependencies not complete!

cutil.o : $(IR)/cutil.c
	$(COMPILE)
futil.o : $(IR)/futil.c
	$(COMPILE)
ir.o : $(IR)/ir.c
	$(COMPILE)
ircfiles.o : $(IR)/ircfiles.c
	$(COMPILE)
irfileio.o : $(IR)/irfileio.c
	$(COMPILE)
irfiles.o : $(IR)/irfiles.c
	$(COMPILE)
irretrvl.o : $(IR)/irretrvl.c
	$(COMPILE)
irtfiles.o : $(IR)/irtfiles.c
	$(COMPILE)
panic.o : $(IR)/panic.c
	$(COMPILE)
sockets.o : $(IR)/sockets.c
	$(COMPILE)
stoplist.o : $(IR)/stoplist.c
	$(COMPILE)
transprt.o : $(IR)/transprt.c
	$(COMPILE)
ui.o : $(IR)/ui.c
	$(COMPILE)
ustubs.o : $(IR)/ustubs.c
	$(COMPILE)
wmessage.o : $(IR)/wmessage.c
	$(COMPILE)
wprot.o : $(IR)/wprot.c
	$(COMPILE)
wutil.o : $(IR)/wutil.c
	$(COMPILE)
zprot.o : $(IR)/zprot.c
	$(COMPILE)
zutil.o : $(IR)/zutil.c
	$(COMPILE)
irsearch.o : $(IR)/irsearch.c
	$(COMPILE)
ztype1.o : $(IR)/ztype1.c
	$(COMPILE)
docid.o : $(IR)/docid.c
	$(COMPILE)
sersrch.o : $(IR)/sersrch.c
	$(COMPILE)
irhash.o : $(IR)/irhash.c
	$(COMPILE)
irinv.o	: $(IR)/irinv.c	
	$(COMPILE)
sigsrch.o : $(IR)/sigsrch.c
	$(COMPILE)
sighash.o : $(IR)/sighash.c
	$(COMPILE)
sigindex.o : $(IR)/sigindex.c
	$(COMPILE)
irbuild.o  : $(IR)/irbuild.c
	$(COMPILE)
server.o : $(IR)/server.c
	$(COMPILE)

#
# Saber loading.  Tuned for Saber 3.0
#

# Load source code into saber.
index_src:	$(INV_SRC) $(INDEX_SRC)
		#suppress 53
		#suppress 529
		#suppress 530
		#suppress 558
		#suppress 590
		#suppress 701 on strspn 
		#suppress 701 on strlen 
		#suppress 701 on strcspn 
		#load $(CFLAGS) $(INV_SRC) $(INDEX_SRC)

index_sig__src:	$(SIG_SRC) $(INDEX_SRC)
		#suppress 53
		#suppress 529
		#suppress 530
		#suppress 558
		#suppress 590
		#suppress 701 on strspn 
		#suppress 701 on strlen 
		#suppress 701 on strcspn 
		#load $(CFLAGS) $(SIG_SRC) $(INDEX_SRC)

server_src:	$(INV_SRC) $(SERVER_SRC)
		#suppress 53
		#suppress 529
		#suppress 530
		#suppress 558
		#suppress 590
		#suppress 701 on strspn 
		#suppress 701 on strlen 
		#suppress 701 on strcspn 
		#suppress 65 on cprintf
		#load $(CFLAGS) $(INV_SRC) $(SERVER_SRC)
		#load /usr/lib/libm.a

ui_src:		$(INV_SRC) $(SHELL_UI_SRC)
		#suppress 35
		#suppress 53
		#suppress 57
		#suppress 530
		#suppress 529
		#suppress 558
		#suppress 590
		#suppress 701 on strspn 
		#suppress 701 on strlen 
		#suppress 701 on strcspn 
		#load $(CFLAGS) $(INV_SRC) $(SHELL_UI_SRC)
		#load /usr/lib/libm.a

# Remove objects and library.
clean:
	$(RM) *.o
	$(RM) *~
	$(RM) /$*.c#*\#
	$(RM) .nfs*  # NFS lossage
	$(RM) *.elc
	$(RM) $(SERVER_CMD)
	$(RM) $(INDEX_CMD)
	$(RM) $(SIG_INDEX_CMD)
	$(RM) $(IPC_UI_CMD)
	$(RM) SearchLog
	$(RM)  core

