#
#  Makefile for the Harvest Broker
#
#  William G. Camargo & Darren Hardy, July 1994
#
#  Makefile.in,v 1.89 1995/11/16 19:26:26 duane Exp
#
prefix = @prefix@
INSTALL_BINDIR	= $(prefix)/bin
INSTALL_LIBDIR	= $(prefix)/lib
INSTALL_UTILDIR	= $(INSTALL_LIBDIR)/broker
INSTALL_MANDIR 	= $(prefix)/man

CC		= @CC@
INSTALL		= @INSTALL@
INSTALL_BIN 	= @INSTALL_PROGRAM@
INSTALL_FILE 	= @INSTALL_DATA@
RANLIB		= @RANLIB@
YACC		= @YACC@
LEX		= @LEX@
LEXLIB		= @LEXLIB@
XTRA_LIBS	= @XTRA_LIBS@
DEBUG_TOP	= @DEBUG_TOP@

DEBUG		= $(DEBUG_TOP) #-O #-g #-DDEBUG
DEBUG_LIBS	= 
LFLAGS		= 
YFLAGS  	= -d #-t #-v

INDEX_OBJS	= Glimpse/index.o Wais/index.o
# 		  Netfind/index.o
#		  Grass/index.o
#		  PLWeb/index.o

INDEX_SUPPORT	= -DUSE_GLIMPSE -DUSE_WAIS
#		  -DUSE_NEBULA
#		  -DUSE_VERITY
#		  -DUSE_PLWEB

CFLAGS		= $(DEBUG) -I../common/include -I.
LDFLAGS		= -L../common/lib
LIBS		= -ltemplate -lutil $(DEBUG_LIBS) $(LEXLIB) $(XTRA_LIBS)

PROGS		= broker gather CreateBroker
UTILS		= dumpregistry brkclient mkbrokerstats.pl info-to-html.pl
OBJS		= lex.yy.o y.tab.o \
		  admin.o brkutil.o collector.o event.o gid.o \
		  log.o parser.o query_man.o registry.o \
		  select_loop.o stor_reg.o stor_man.o main.o \
		  $(INDEX_OBJS)

#
#  Uncomment to use Nebula as an indexer
#
#  NEBDIR	= indexing/Nebula/unp
#  CFLAGS	= $(DEBUG) -I../common/include -I. -I$(NEBDIR)
#  LDFLAGS	= -L../common/lib -L$(NEBDIR)
#  LIBS		= -ltemplate -lutil $(DEBUG_LIBS) -lunpi $(LEXLIB) $(XTRA_LIBS)
#


all:	broker gather CreateBroker $(UTILS)

broker:	$(OBJS)
	$(CC) -o $@ $(OBJS) $(LDFLAGS) $(LIBS)

main.o: main.c
	$(CC) -c -o $@ $(INDEX_SUPPORT) $(CFLAGS) main.c

Wais/index.o:	Wais/index.c
	$(CC) $(CFLAGS) -c -o $@ Wais/index.c

# ptr to the WAIS, Inc.'s client-toolkit directory
WAIS_CLTDIR = /usr/local/wais/current/client-toolkit
Wais/waisquery.o:	Wais/waisquery.c
	$(CC) -I$(WAIS_CLTDIR)/include $(CFLAGS) -c -o $@ Wais/waisquery.c

broker.inline-wais:	$(OBJS) Wais/waisquery.o
	$(CC) $(CFLAGS) -DUSE_WAIS_INLINE -c -o $@ Wais/index.c
	$(CC) -o $@ $(OBJS) Wais/waisquery.o $(LDFLAGS) $(LIBS) -L$(WAIS_CLTDIR)/lib -lCli -lCliZ1988 -lCliZV2 -lm

Glimpse/index.o:	Glimpse/index.c
	$(CC) $(CFLAGS) -c -o $@ Glimpse/index.c

Grass/index.o:	Grass/index.c
	$(CC) $(CFLAGS) -c -o $@ Grass/index.c

dumpregistry:	stor_reg.o dumpregistry.o brkutil.o gid.o
	$(CC) -o $@ stor_reg.o dumpregistry.o brkutil.o gid.o $(LDFLAGS) $(LIBS)

y.tab.c y.tab.h:	query.y 
	$(YACC) $(YFLAGS) query.y

lex.yy.c:	query.l y.tab.h
	$(LEX) $(LFLAGS) query.l

clean:
	-rm core *.o broker gather dumpregistry brkclient y.tab.c y.tab.h lex.yy.c tags $(INDEX_OBJS)

realclean:	clean
	-rm -f Makefile

install: all
	@for f in $(UTILS); do \
		echo $(INSTALL_BIN) $$f $(INSTALL_UTILDIR)/$$f; \
		$(INSTALL_BIN) $$f $(INSTALL_UTILDIR)/$$f; \
	done
	@for f in $(PROGS); do \
		echo $(INSTALL_BIN) $$f $(INSTALL_BINDIR)/$$f; \
		$(INSTALL_BIN) $$f $(INSTALL_BINDIR)/$$f; \
	done
	@for f in ctime.pl; do \
		echo $(INSTALL_FILE) $$f $(INSTALL_LIBDIR)/$$f; \
		$(INSTALL_FILE) $$f $(INSTALL_LIBDIR)/$$f; \
	done
	-find example/brokers -type d -print | xargs chmod go+x
	-find example/brokers -type f -print | xargs chmod go+r
	cd example; find brokers -depth -print | cpio -pdvu $(prefix)/

#
#  The Broker needs to have the Gatherer's "gather" program installed
#  so that it can do collections.  Here's a hack so that you don't have
#  to compile and install the Gatherer to get this program.  The broker 
#  will build and install the gather program itself.
#
gather:	gather.o
	$(CC) -o $@ $@.o $(LDFLAGS) $(XTRA_LIBS)

brkclient:	brkclient.o
	$(CC) -o $@ $@.o $(LDFLAGS) $(XTRA_LIBS)
