#/* Copyright (c) CNIDR (Work in progress) */
#
# Moved the main programs (waisindex, waisserver) to their own
# subdirectories as part of directory tree restructuring
#  - warnock@clark.net 9/94
#
# Renamed a bunch of files to make sense:
#         irbuild.c is now waisindex.c
#         server.c is now waisserver.c
# Can now invoke make to build individual binaries:
#         make waisindex   - just makes waisindex
#         make waisserver  - just makes waisserver
#         make libs        - makes wais.a, client.a, inv.a, sig.a
#  - warnock@hypatia.gsfc.nasa.gov  7/93
#
# 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
#
# $Log: Makefile,v $
# Revision 1.1  1993/02/16  15:05:35  freewais
# Initial revision
#
# Revision 1.8  92/05/10  14:42:26  jonathan
# Changed CLIENT_LOCAL_SRC to ui-local.c.  Added link to ui.c
# 
# Revision 1.7  92/04/30  12:30:22  jonathan
# Changed CC = to use cc instead.  It's the right thing to do...
# 
# Revision 1.6  92/04/28  17:09:05  jonathan
# Added lock.[co] to lists.
# 
# Revision 1.5  92/02/27  09:15:28  jonathan
# fixed compile line for ui-local.o
# 
# Revision 1.4  92/02/24  10:06:59  jonathan
# Removed -DBOOL from CFLAGS
# 
# Revision 1.3  92/02/13  13:02:44  jonathan
# Added CLIENT_LIB to default, and fixed rule.
# 
# Revision 1.2  92/02/13  12:28:26  jonathan
# Removed object and boolean sources from definitions.
# 
# Revision 1.1  92/02/13  11:55:08  jonathan
# Initial revision
# 
#

# 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
#
# see the CFLAGS variable for pointers.
#
# SGIs want this uncommented
# SHELL=/bin/sh

RELEASE = freeWAIS-0.5

# For HP-UX build shared library
SHARED =
#SHARED = shared

# Where to install include files
INCDEST = /usr/local/include/wais

# Where to install libraries
LIBDEST = /usr/local/lib/wais

# Libraries to install
LIBINST = client.a client.sl inv.a inv.sl libftw.a libftw.sl sig.a sig.sl \
	wais.a wais.sl

#
# Some default programs
# CC = cc
AR	= ar
CC	= gcc
RM	= /bin/rm
MV	= mv
MAKE	= make
# on AU/X and SGIs set this to true
# RANLIB = true
RANLIB 	= ranlib

#
# Directory definitions
#
# set this for your site.  This syntax only works in SunOS
# for other UNIX-like OS's set this to this directory.
#TOP:sh = pwd
# or fill in the blank for other OS's
#comment-me:
#       @echo You must set "\$$(TOP)" to point to the freeWAIS src directory

INCLUDE = $(TOP)/include
LIBDIR  = $(TOP)/bin
BINDIR  = $(TOP)/bin
SRCDIR  = $(TOP)/src
UIDIR   = $(SRCDIR)/client/ui

# compiler specific stuff
#
# for old BSD add -DBSD
# for newer BSD that needs to use <sys/dir.h>, add -DBSD43
# for System V add -DSYSV 
# for XENIX add -M3e -Zi
# USG for Unix Dirent in lib
# for SGIs running IRIX 4.0.1, add -cckr
# for NeXTSTEP add -DNeXT and -posix
# for Linux add -DLINUX
# for A/UX add -DA_UX
#
# For a little better security in the server, add -DSECURE_SERVER
# this sets the server user id to -u argument after startup.
# for relevance feedaback in the search engine, add -DRELEVANCE_FEEDBACK
#
#   dgg additions
# LITERAL == waisserver, search for "literal strings"
# BOOLEANS == waisserver, search with boolean AND, NOT operators
# PARTIALWORD == waisserver, search for partial words, hum* matches human, 
#   hummingbird, ...
# BIO == waisindex, waisserver changes including symbol indexing & search 
#   & bio data formats
#
# -DTELL_USER lets the server know who you are at connect time
# -DUSE_SYSLOG if you want logging to be done with syslog rather than
#   fprintf
# -DNEED_VSYSLOG if your C library does not have a vsyslog() function
#   in it (and you defined USE_SYSLOG)
# -DDUMPCORE will force the waisserver to dump the core when aborting
#   otherwise the core will not be dumped
# -DEND_MERGE if you want to merge the index files at the end of an
#   index process otherwise they are merged as we go along
# -DSTEM_WORDS to stem words during indexing and queries
#
# Note - the default Porter Stemmer removes trailing e's from words -
# variable becomes variabl  - this can impact the use of literals in
# searches!!!!!!!!!!
#
# -DLIST_STEMS to show stemmed words in server log and indexer output
# -DSOLARIS for SunOS 5.2 (Solaris 2.2) machines.
#
# Use this version of CFLAGS for HPUX 9.01 with cc
#CFLAGS = +O1 +z -I$(SUPDIR) -DTELL_USER -DSECURE_SERVER -DRELEVANCE_FEEDBACK -DUSG -DBOOLEANS -DPARTIALWORD -DLITERAL -DSOUND -DBIBDB
#CFLAGS = +O3 +z -I$(SUPDIR) -DNDEBUG -DBIO -DTELL_USER -DSECURE_SERVER -DRELEVANCE_FEEDBACK -DUSG -DBOOLEANS -DPARTIALWORD -DLITERAL -DSOUND -DBIBDB
#
# Use this version of CFLAGS for SGIs with gcc
# CFLAGS = -I$(SUPDIR) -DTELL_USER -DSECURE_SERVER -DRELEVANCE_FEEDBACK -DUSG -DBOOLEANS -DPARTIALWORD -DLITERAL -DSOUND -DBIBDB
#
# Use this version of CFLAGS for DECstation with gcc
# CFLAGS = -ansi -I$(SUPDIR) -DTELL_USER -DUSG -DSECURE_SERVER -DRELEVANCE_FEEDBACK -DBOOLEANS -DPARTIALWORD -DLITERAL -DSOUND -DBIBDB -DULTRIX
#
# Use this version of CFLAGS for DECstation with cc
# CFLAGS = -I$(SUPDIR) -DTELL_USER -DUSG -DSECURE_SERVER -DRELEVANCE_FEEDBACK -DBOOLEANS -DPARTIALWORD -DLITERAL -DSOUND -DBIBDB -DULTRIX
#
# Use this version of CFLAGS for DEC Alpha with gcc
# CFLAGS = -ansi -I$(SUPDIR) -DTELL_USER -DUSG -DSECURE_SERVER -DRELEVANCE_FEEDBACK -DBOOLEANS -DPARTIALWORD -DLITERAL -DSOUND -DBIBDB
#
# Use this version of CFLAGS on Sun with gcc (not Solaris)
# CFLAGS = -ansi -I$(SUPDIR) -DTELL_USER -DUSG -DSECURE_SERVER -DRELEVANCE_FEEDBACK -DBOOLEANS -DPARTIALWORD -DLITERAL -DSOUND -DBIBDB
#
# Use this version of CFLAGS for Linux with gcc
# CFLAGS = -O2 -ansi -m486 -fwritable-strings -I$(SUPDIR) -DTELL_USER -DUSG -DSECURE_SERVER -DRELEVANCE_FEEDBACK -DBOOLEANS -DPARTIALWORD -DLITERAL -DSOUND -DBIBDB -DLINUX
#
# Use this version of CFLAGS for A/UX with cc
# CFLAGS = -g -I$(SUPDIR) -DA_UX -DTELL_USER -DUSG -DSECURE_SERVER -DRELEVANCE_FEEDBACK -DBOOLEANS -DPARTIALWORD -DLITERAL -DSOUND -DBIBDB
#
# Flag definitions
CFLAGS	= -ansi -DUSG -DTELL_USER -DUSG -DSECURE_SERVER -DRELEVANCE_FEEDBACK -DBOOLEANS -DPARTIALWORD -DLITERAL -DSOUND -DBIBDB
LFLAGS	=
RMFLAGS	= -f
MFLAGS	= -k
# For HP/UX use ARFLAGS = cr
ARFLAGS =

#
# Targets to build

PROTOCOL_LIB  = $(TOP)/bin/wais.a      # file name of the protocol library
CLIENT_LIB    = $(TOP)/bin/client.a    # file name of the client library
INV_LIB       = $(TOP)/bin/inv.a       # file name of the inverted file library
SIG_LIB       = $(TOP)/bin/sig.a       # file name of the signature file library
LIBFTW        = $(TOP)/bin/libftw.a    # support library

# List of source files for saber.

PROTOCOL_SRC = \
	cutil.c \
	syslog.c \
	futil.c \
	ircfiles.c \
	irfileio.c \
	irfiles.c \
	irtfiles.c \
	irkeywords.c \
	stemmer.c \
	panic.c \
	sockets.c \
	transprt.c \
	ustubs.c \
	wmessage.c \
	wprot.c \
	wutil.c \
	zprot.c \
	zutil.c \
	ztype1.c \
	docid.c \
	list.c \
	lock.c \
	gopher.c 

IR_SRC = \
	ir.c \
	irretrvl.c \
	stoplist.c \
	irsearch.c \
	stemmer.c \
	synonym.c \
	trie.c \
	soundex.c \
	manipulstr.c

CLIENT_SRC = \
	ui.c

CLIENT_LOCAL_SRC = \
	ui-local.c

INV_SRC  =    $(SOURCES) \
	sersrch.c \
	irhash.c \
	hash.c \
	irinv.c \
	boolean_op.c

SIG_SRC  =    $(SOURCES) \
	sighash.c \
	hash.c

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

PROTOCOL_OBJ =    \
	cutil.o \
	syslog.o \
	futil.o \
	ircfiles.o \
	irfileio.o \
	irkeywords.o\
	irfiles.o \
	panic.o \
	sockets.o \
	transprt.o \
	ustubs.o \
	wmessage.o \
	wprot.o \
	wutil.o \
	zprot.o \
	zutil.o \
	ztype1.o \
	docid.o \
	list.o \
	lock.o \
	gopher.o 

IR_OBJS = \
	ir.o \
	irretrvl.o \
	irsearch.o \
	irtfiles.o \
	stemmer.o \
	synonym.o \
	stoplist.o \
	trie.o \
	soundex.o \
	manipulstr.o

CLIENT_OBJS = \
	ui.o

CLIENT_LOCAL_OBJS = \
	ui-local.o

INV_OBJ  =    $(IR_OBJS) \
	$(CLIENT_LOCAL_OBJS) \
	sersrch.o \
	irhash.o \
	hash.o \
	irinv.o \
	boolean_op.o

SIG_OBJ  =    $(IR_OBJS) \
	$(CLIENT_LOCAL_OBJS) \
	sighash.o \
	hash.o

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

default:	$(PROTOCOL_LIB) \
	$(INV_LIB) \
	$(SIG_LIB) \
	$(CLIENT_LIB) \
	$(SHARED)

libs:	$(PROTOCOL_LIB) \
	$(INV_LIB) \
	$(SIG_LIB) \
	$(CLIENT_LIB) \
	$(SHARED)

$(CLIENT_LOCAL_OBJS): $(CLIENT_LOCAL_SRC)
	$(CC) $(CFLAGS) -I$(INCLUDE) -DLOCAL_SEARCH -c $(CLIENT_LOCAL_SRC)

# construct ../lib/wais.a
$(PROTOCOL_LIB): $(PROTOCOL_OBJ)
	$(AR) $(ARFLAGS) $@ $(PROTOCOL_OBJ)
	$(RANLIB) $@

# construct ../lib/client.a
$(CLIENT_LIB): $(CLIENT_OBJS)
	$(AR) $(ARFLAGS) $@ $(CLIENT_OBJS)
	$(RANLIB) $@

# construct ../lib/inv.a
$(INV_LIB):       $(INV_OBJ)
	$(AR) $(ARFLAGS) $@ $(INV_OBJ)
	$(RANLIB) $@

# construct ../lib/sig.a
$(SIG_LIB):       $(SIG_OBJ)
	$(AR) $(ARFLAGS) $@ $(SIG_OBJ)
	$(RANLIB) $@

# HP-UX shared library
#Build them after all the archived ones have been created
shared:	$(PROTOCOL_LIB) $(CLIENT_LIB) $(INV_LIB) $(SIG_LIB)
	ld -s -b -o $(LIBDIR)/wais.sl $(PROTOCOL_OBJ)
	ld -s -b -o $(LIBDIR)/client.sl $(CLIENT_OBJS)
	ld -s -b -o $(LIBDIR)/inv.sl $(INV_OBJ)
	ld -s -b -o $(LIBDIR)/sig.sl $(SIG_OBJ)

#
# Saber loading.  Tuned for Saber 3.0
#

# Load source code into saber.

CSFLAGS = -D_ansi_prototypes -Dsparc -I/usr/include/cs/6.0.2 -I/usr/include 

screen_ui_src:    $(INV_SRC) ../ui/screen-ui.c
          #suppress 35
          #suppress 53
          #suppress 57
          #suppress 530
          #suppress 529
          #suppress 558
          #suppress 590
          #suppress 592
          #suppress 701 on strspn
          #suppress 701 on strlen
          #suppress 701 on strcspn
          #suppress 594 on waislog
          #load $(CFLAGS) -I./ $(INV_SRC) ../ui/screen-ui.c
          #load /usr/lib/libm.a

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

pump_question_src:    $(INV_SRC) pump_question.c
          #suppress 35
          #suppress 53
          #suppress 57
          #suppress 530
          #suppress 529
          #suppress 558
          #suppress 590
          #suppress 592
          #suppress 701 on strspn
          #suppress 701 on strlen
          #suppress 701 on strcspn
          #suppress 594 on waislog
          #load $(CFLAGS) -I./ $(INV_SRC) pump_question.c
          #load /usr/lib/libm.a

# Remove objects and library.
clean:
	$(RM) $(RMFLAGS) *%
	$(RM) $(RMFLAGS) *.o
	$(RM) $(RMFLAGS) *~
	$(RM) $(RMFLAGS) \#*\#
	$(RM) $(RMFLAGS) .nfs*  # NFS lossage
	$(RM) $(RMFLAGS) *.elc
	$(RM) $(RMFLAGS) $(PROTOCOL_LIB)
	$(RM) $(RMFLAGS) $(CLIENT_LIB) $(INV_LIB) $(SIG_LIB)
	$(RM) $(RMFLAGS) SearchLog
	$(RM) $(RMFLAGS) core

#
# Suffix rules for making the object files
.c.o :
	$(CC) $(CFLAGS) -I$(INCLUDE) -c $<

