# Copyright (c) 1994 Sun Wu, Udi Manber, Burra Gopal.  All Rights Reserved.

# YOU DON'T HAVE TO CHANGE ANYTHING BELOW THIS LINE
 
srcdir = @srcdir@
VPATH  = @srcdir@
SHELL  = /bin/sh
CC     = @CC@
LIBS   = @LIBS@
INSTALL		= @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_DATA	= @INSTALL_DATA@
DEFS		= @DEFS@

prefix = @prefix@
exec_prefix = $(prefix)
binprefix =
manprefix =

bindir = $(exec_prefix)/bin
libdir = $(exec_prefix)/lib
mandir = $(prefix)/man/man1
manext = 1

AGREPDIR        = agrep
AGREPSRC        = $(srcdir)/$(AGREPDIR)
INDEXDIR        = index
INDEXSRC        = $(srcdir)/$(INDEXDIR)
TEMPLATEDIR     = libtemplate
TEMPLATESRC     = $(srcdir)/$(TEMPLATEDIR)
COMPRESSDIR	= compress
COMPRESSSRC	= $(srcdir)/$(COMPRESSDIR)

CFLAGS		= -O -DSTRUCTURED_QUERIES=1
ALL_CFLAGS      = $(CFLAGS) $(DEFS) -I$(INDEXSRC) -I$(AGREPSRC) -I$(TEMPLATESRC)/include

.c.o:
		$(CC) -c $(ALL_CFLAGS) $<

PROG		= glimpse
PROGSERVER	= glimpseserver
PROGINDEX	= index/glimpseindex
PROGAGREP	= agrep/agrep
LIBAGREP	= agrep
LIBCOMPRESS	= cast
LIBTEMPLATE	= template
LIBUTIL		= util

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

HDRS		= $(INDEXSRC)/glimpse.h $(AGREPSRC)/agrep.h $(AGREPSRC)/checkfile.h $(AGREPSRC)/re.h $(INDEXSRC)/region.h

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

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

install:	all installdirs
		$(INSTALL_PROGRAM) $(PROGINDEX) $(bindir)/$(binprefix)glimpseindex
		$(INSTALL_PROGRAM) $(PROGAGREP) $(bindir)/$(binprefix)agrep
		$(INSTALL_PROGRAM) $(PROGSERVER) $(bindir)/$(binprefix)glimpseserver
		$(INSTALL_PROGRAM) $(PROG) $(bindir)/$(binprefix)glimpse
		$(INSTALL_DATA) $(srcdir)/glimpse.1 $(mandir)/$(manprefix)glimpse.$(manext)
		$(INSTALL_DATA) $(srcdir)/glimpseindex.1 $(mandir)/$(manprefix)glimpseindex.$(manext)
		$(INSTALL_DATA) $(srcdir)/glimpseserver.1 $(mandir)/$(manprefix)glimpseserver.$(manext)
		$(INSTALL_DATA) $(srcdir)/agrep/agrep.1 $(mandir)/$(manprefix)agrep.$(manext)

installdirs:	mkinstalldirs
		$(srcdir)/mkinstalldirs $(bindir) $(mandir)

$(PROGINDEX):	$(PROGAGREP) $(AGREPDIR)/lib$(LIBAGREP).a $(TEMPLATEDIR)/$(LIBTEMPLATE)/lib$(LIBTEMPLATE).a $(TEMPLATEDIR)/$(LIBUTIL)/lib$(LIBUTIL).a $(COMPRESSDIR)/lib$(LIBCOMPRESS).a
	cd $(INDEXDIR) ; $(MAKE)

$(PROGAGREP):	$(COMPRESSDIR)/lib$(LIBCOMPRESS).a
	cd $(AGREPDIR) ; $(MAKE)

$(COMPRESSDIR)/lib$(LIBCOMPRESS).a:
	cd $(COMPRESSDIR); $(MAKE)

$(PROG):	main.o $(OBJS) $(SRC) $(HDRS) $(AGREPDIR)/lib$(LIBAGREP).a $(TEMPLATEDIR)/$(LIBTEMPLATE)/lib$(LIBTEMPLATE).a $(TEMPLATEDIR)/$(LIBUTIL)/lib$(LIBUTIL).a $(COMPRESSDIR)/lib$(LIBCOMPRESS).a
	 $(CC) $(LINKFLAGS) -L$(AGREPDIR) -L$(COMPRESSDIR) -L$(TEMPLATEDIR)/$(LIBTEMPLATE) -L$(TEMPLATEDIR)/$(LIBUTIL) -o $(PROG) main.o $(OBJS) -l$(LIBAGREP) -l$(LIBTEMPLATE) -l$(LIBUTIL) $(LIBS)

$(PROGSERVER):	main_server.o $(OBJS) $(SRC) $(HDRS) $(AGREPDIR)/lib$(LIBAGREP).a $(TEMPLATEDIR)/$(LIBTEMPLATE)/lib$(LIBTEMPLATE).a $(TEMPLATEDIR)/$(LIBUTIL)/lib$(LIBUTIL).a $(COMPRESSDIR)/lib$(LIBCOMPRESS).a
	 $(CC) $(LINKFLAGS) -L$(COMPRESSDIR) -L$(AGREPDIR) -L$(TEMPLATEDIR)/$(LIBTEMPLATE) -L$(TEMPLATEDIR)/$(LIBUTIL) -o $(PROGSERVER) main_server.o $(OBJS) -l$(LIBAGREP) -l$(LIBTEMPLATE) -l$(LIBUTIL) $(LIBS)

$(TEMPLATEDIR)/$(LIBTEMPLATE)/lib$(LIBTEMPLATE).a:
	cd $(TEMPLATEDIR) ; $(MAKE)

$(TEMPLATEDIR)/$(LIBUTIL)/lib$(LIBUTIL).a:
	cd $(TEMPLATEDIR) ; $(MAKE)

$(AGREPDIR)/lib$(LIBAGREP).a:
	cd $(AGREPDIR); $(MAKE)

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

main_server.o: $(srcdir)/main.c $(srcdir)/defs.h $(AGREPSRC)/agrep.h $(AGREPSRC)/checkfile.h $(INDEXSRC)/glimpse.h
	cp $(srcdir)/main.c main_server.c
	$(CC) -c $(ALL_CFLAGS) -DISSERVER=1 -o $@ main_server.c

main.o:	$(srcdir)/main.c $(srcdir)/defs.h $(AGREPSRC)/agrep.h $(AGREPSRC)/checkfile.h $(INDEXSRC)/glimpse.h
	$(CC) -c $(ALL_CFLAGS) -DISSERVER=0 -o $@ $(srcdir)/main.c

get_filename.o:	get_filename.c $(AGREPSRC)/agrep.h $(AGREPSRC)/checkfile.h $(INDEXSRC)/glimpse.h

get_index.o: get_index.c $(AGREPSRC)/agrep.h $(AGREPSRC)/checkfile.h $(INDEXSRC)/glimpse.h

split.o: split.c $(AGREPSRC)/agrep.h $(AGREPSRC)/checkfile.h $(INDEXSRC)/glimpse.h

$(INDEXDIR)/lib.o:	$(INDEXSRC)/lib.c $(INDEXSRC)/glimpse.h

$(INDEXDIR)/io.o:	$(INDEXSRC)/io.c $(INDEXSRC)/glimpse.h

$(INDEXDIR)/region.o: $(INDEXSRC)/region.c $(INDEXSRC)/glimpse.h $(INDEXSRC)/region.h

$(INDEXDIR)/getword.o: $(INDEXSRC)/getword.c $(INDEXSRC)/glimpse.h

$(INDEXDIR)/build_in.o: $(INDEXSRC)/build_in.c $(INDEXSRC)/glimpse.h

$(INDEXDIR)/filetype.o: $(INDEXSRC)/filetype.c $(INDEXSRC)/glimpse.h

$(INDEXDIR)/simpletest.o: $(INDEXSRC)/simpletest.c $(INDEXSRC)/glimpse.h

$(INDEXDIR)/memlook.o: $(INDEXSRC)/memlook.c $(INDEXSRC)/glimpse.h

