#
#  Makefile for Glimpse 2.0
#
#  Makefile.in,v 1.30 1995/11/16 21:47:08 duane Exp
#  Copyright (c) 1994 Sun Wu, Udi Manber, Burra Gopal.  All Rights Reserved.

prefix = @prefix@
INSTALL_BINDIR	= $(prefix)/bin
INSTALL_LIBDIR	= $(prefix)/lib
INSTALL_MANDIR 	= $(prefix)/man
INSTALL_UTILDIR	= $(INSTALL_LIBDIR)/broker

CC		= @CC@
INSTALL		= @INSTALL@
INSTALL_BIN 	= @INSTALL_PROGRAM@
INSTALL_FILE 	= @INSTALL_DATA@
RANLIB		= @RANLIB@
XTRA_LIBS	= @XTRA_LIBS@


# YOU DON'T HAVE TO CHANGE ANYTHING BELOW THIS LINE

# The binaries will be made in ./bin/. and the libraries are assumed to
# be in ./lib . You normally don't have to change them.
# NOTE: GLIMPSEDIR can be relative or absolute.
GLIMPSEDIR	= ..
BINDIR		= bin
AGREPDIR	= agrep
INDEXDIR	= index
COMPRESSDIR	= compress
TEMPLATEDIR	= ../../../../src/common
LIBDIR		= lib
LIBTEMPLATEDIR	= $(TEMPLATEDIR)/lib
LIBAGREP	= agrep
LIBCOMPRESS	= cast
LIBTEMPLATE	= template
LIBUTIL		= util
STRUCTURED_QUERIES = 1

PROG		= glimpse
PROGSERVER	= glimpseserver
NOTSPROG	= nots$(PROG)
NOTSPROGSERVER	= nots$(PROGSERVER)
PROGINDEX	= index/glimpseindex
PROGAGREP	= agrep/agrep

CFLAGS		= -DISO_CHAR_SET $(DEBUG_TOP) -c -I$(INDEXDIR) -I$(AGREPDIR) -I$(TEMPLATEDIR)/include -w
LINKFLAGS	= -I$(INDEXDIR) -I$(AGREPDIR) -I$(TEMPLATEDIR)/include 

OBJS		= get_filename.o \
		get_index.o \
		split.o \
		$(INDEXDIR)/region.o \
		$(INDEXDIR)/getword.o \
		$(INDEXDIR)/filetype.o \
		$(INDEXDIR)/simpletest.o \
		$(INDEXDIR)/memlook.o \
		$(INDEXDIR)/io.o

HDRS		= $(INDEXDIR)/glimpse.h $(AGREPDIR)/agrep.h $(AGREPDIR)/checkfile.h $(AGREPDIR)/re.h $(INDEXDIR)/region.h

HARVEST_LIBS	= $(LIBDIR)/lib$(LIBAGREP).a \
		  $(LIBTEMPLATEDIR)/lib$(LIBTEMPLATE).a \
		  $(LIBTEMPLATEDIR)/lib$(LIBUTIL).a

SRC		= main.c \
		get_filename.c \
		get_index.c \
		split.c \
		$(INDEXDIR)/region.c \
		$(INDEXDIR)/getword.c \
		$(INDEXDIR)/filetype.c \
		$(INDEXDIR)/simpletest.c \
		$(INDEXDIR)/memlook.c \
		$(INDEXDIR)/io.c

all:		mkdir-bin-lib HarvestSall

mkdir-bin-lib:
	@if [ ! -d $(BINDIR) ]; then \
		mkdir $(BINDIR); \
	fi
	@if [ ! -d $(LIBDIR) ]; then \
		mkdir $(LIBDIR); \
	fi

#
#  For Harvest, we only need glimpse, glimpseserver, and glimpseindex
#
HarvestSall:	$(PROG) $(PROGSERVER) $(PROGINDEX)

Sall:		$(PROGINDEX) $(PROGAGREP) $(PROG) $(PROGSERVER)

NOTSall:	$(PROGINDEX) $(PROGAGREP) $(NOTSPROG) $(NOTSPROGSERVER)

$(PROG):	$(HARVEST_LIBS) main.o $(OBJS) $(SRC) $(HDRS) 
	$(CC) $(LINKFLAGS) -L$(LIBDIR) -L$(LIBTEMPLATEDIR) -o $(PROG) main.o $(OBJS) -l$(LIBAGREP) -l$(LIBTEMPLATE) -l$(LIBUTIL) $(XTRA_LIBS)
	$(INSTALL_BIN) $(PROG) $(BINDIR)

$(PROGSERVER):	$(HARVEST_LIBS) main_server.o $(OBJS) $(SRC) $(HDRS) 
	$(CC) $(LINKFLAGS) -L$(LIBDIR) -L$(LIBTEMPLATEDIR) -o $(PROGSERVER) main_server.o $(OBJS) -l$(LIBAGREP) -l$(LIBTEMPLATE) -l$(LIBUTIL) $(XTRA_LIBS)
	$(INSTALL_BIN) $(PROGSERVER) $(BINDIR)

$(PROGINDEX):	$(HARVEST_LIBS)
	@echo "Making all in $(INDEXDIR)"
	@(cd $(INDEXDIR); $(MAKE) $(MFLAGS) DEBUG_TOP="$(DEBUG_TOP)" all)

# to build libagrep.a you need to build the compress dir first
$(LIBDIR)/lib$(LIBAGREP).a:
	@echo "Making all in $(COMPRESSDIR)"
	@(cd $(COMPRESSDIR); $(MAKE) $(MFLAGS) DEBUG_TOP="$(DEBUG_TOP)" all)
	@echo "Making all in $(AGREPDIR)"
	@(cd $(AGREPDIR); $(MAKE) $(MFLAGS) DEBUG_TOP="$(DEBUG_TOP)" all)

main_server.o: main.c defs.h $(AGREPDIR)/agrep.h $(AGREPDIR)/checkfile.h $(INDEXDIR)/glimpse.h
	 $(CC) $(CFLAGS) -DISSERVER=1 -o $@ main.c

main.o:	main.c defs.h $(AGREPDIR)/agrep.h $(AGREPDIR)/checkfile.h $(INDEXDIR)/glimpse.h
	 $(CC) $(CFLAGS) -DISSERVER=0 -o $@ main.c


install:	all
	@for f in glimpse glimpseserver glimpseindex; do \
		echo Installing $$f in $(INSTALL_UTILDIR); \
		$(INSTALL_BIN) ./bin/$$f $(INSTALL_UTILDIR); \
	done

clean:
	-rm -f main_server.o main.o $(OBJS) core a.out $(LIBDIR)/lib$(LIBAGREP).a $(PROG) $(PROGSERVER)
	-(cd $(AGREPDIR); $(MAKE) $@)
	-(cd $(INDEXDIR); $(MAKE) $@)
	-(cd $(COMPRESSDIR); $(MAKE) $@)

realclean:	clean
	-rm -f bin/* lib/* Makefile
	-(cd $(AGREPDIR); $(MAKE) $@)
	-(cd $(INDEXDIR); $(MAKE) $@)
	-(cd $(COMPRESSDIR); $(MAKE) $@)


$(PROGAGREP):	$(LIBDIR)/lib$(LIBCOMPRESS).a
	(cd $(AGREPDIR) ; $(MAKE) $(MFLAGS) DEBUG_TOP="$(DEBUG_TOP)")

$(LIBDIR)/lib$(LIBCOMPRESS).a:
	(cd $(COMPRESSDIR) ; $(MAKE) $(MFLAGS) DEBUG_TOP="$(DEBUG_TOP)")


$(NOTSPROG):	main.o $(OBJS) $(SRC) $(HDRS) $(LIBDIR)/lib$(LIBAGREP).a
	$(CC) $(LINKFLAGS) -L$(LIBDIR) -o $(PROG) main.o $(OBJS) -l$(LIBAGREP)
	cp $(PROG) $(BINDIR)

$(NOTSPROGSERVER):	main_server.o $(OBJS) $(SRC) $(HDRS) $(LIBDIR)/lib$(LIBAGREP).a
	$(CC) $(LINKFLAGS) -L$(LIBDIR) -o $(PROGSERVER) main_server.o $(OBJS) -l$(LIBAGREP)
	cp $(PROGSERVER) $(BINDIR)

$(LIBTEMPLATEDIR)/lib$(LIBTEMPLATE).a:
	(cd $(TEMPLATEDIR) ; $(MAKE) $(MFLAGS) DEBUG_TOP="$(DEBUG_TOP)")

$(LIBTEMPLATEDIR)/lib$(LIBUTIL).a:
	(cd $(TEMPLATEDIR) ; $(MAKE) $(MFLAGS) DEBUG_TOP="$(DEBUG_TOP)")


get_filename.o:	get_filename.c $(AGREPDIR)/agrep.h $(AGREPDIR)/checkfile.h $(INDEXDIR)/glimpse.h
	 $(CC) $(CFLAGS) -o $@ get_filename.c

get_index.o: get_index.c $(AGREPDIR)/agrep.h $(AGREPDIR)/checkfile.h $(INDEXDIR)/glimpse.h
	 $(CC) $(CFLAGS) -o $@ get_index.c

split.o: split.c $(AGREPDIR)/agrep.h $(AGREPDIR)/checkfile.h $(INDEXDIR)/glimpse.h
	 $(CC) $(CFLAGS) -o $@ split.c

$(INDEXDIR)/io.o:	$(INDEXDIR)/io.c $(INDEXDIR)/glimpse.h
	 $(CC) $(CFLAGS) -o $@ $(INDEXDIR)/io.c

$(INDEXDIR)/region.o: $(INDEXDIR)/region.c $(INDEXDIR)/glimpse.h $(INDEXDIR)/region.h
	 $(CC) $(CFLAGS) -DSTRUCTURED_QUERIES=$(STRUCTURED_QUERIES) -o $@ $(INDEXDIR)/region.c

$(INDEXDIR)/getword.o: $(INDEXDIR)/getword.c $(INDEXDIR)/glimpse.h
	 $(CC) $(CFLAGS) -o $@ $(INDEXDIR)/getword.c

$(INDEXDIR)/filetype.o: $(INDEXDIR)/filetype.c $(INDEXDIR)/glimpse.h
	 $(CC) $(CFLAGS) -o $@ $(INDEXDIR)/filetype.c

$(INDEXDIR)/simpletest.o: $(INDEXDIR)/simpletest.c $(INDEXDIR)/glimpse.h
	 $(CC) $(CFLAGS) -o $@ $(INDEXDIR)/simpletest.c

$(INDEXDIR)/memlook.o: $(INDEXDIR)/memlook.c $(INDEXDIR)/glimpse.h
	 $(CC) $(CFLAGS) -o $@ $(INDEXDIR)/memlook.c
