############################ -*- Mode: Makefile -*- ###########################
## Imakefile -- 
## ITIID           : $ITI$ $Header $__Header$
## Author          : Ulrich Pfeifer
## Created On      : Tue Mar  8 13:39:44 1994
## Last Modified By: Huynh Quoc T. Tung
## Last Modified On: Mon May 16 12:35:15 1994
## Update Count    : 84
## Status          : Unknown, Use with caution!
###############################################################################


#include "../Install.tmpl"

            LEX.l = $(LEX) $(LFLAGS) -t
#ifdef ISO
   EXTRA_INCLUDES = -I../ctype
          ISOOBJS = ../ctype/ctype.o
              LEX = flex
           LFLAGS = -8 -s
#endif
           YFLAGS = -d
           YACC.y = $(YACC) $(YFLAGS)

     PROTOCOL_SRCS = \
                    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   


     PROTOCOL_OBJS = $(ISOOBJS) \
                    cutil.o \
                    syslog.o \
                    futil.o \
                    ircfiles.o \
                    irfileio.o \
                    irfiles.o \
                    irtfiles.o \
                    irkeywords.o \
                    stemmer.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   

           IR_SRCS = \
                    ir.c \
                    irretrvl.c \
                    stoplist.c \
                    irsearch.c \
                    stemmer.c \
                    synonym.c \
                    trie.c \
                    soundex.c \
                    field_index.c \
                    field_search.c 

          IR_OBJS = \
                    ir.o \
                    irretrvl.o \
                    stoplist.o \
                    irsearch.o \
                    stemmer.o \
                    synonym.o \
                    trie.o \
                    soundex.o \
                    field_index.o \
                    field_search.o 


      CLIENT_SRCS = \
                    ui.c

      CLIENT_OBSS = \
                    ui.o

CLIENT_LOCAL_SRCS = \
                    ui-local.c

CLIENT_LOCAL_OBJS = \
                    ui-local.o

         INV_SRCS = $(IR_SRCS) \
                    $(CLIENT_LOCAL_SRCS) \
                    sersrch.c \
                    irhash.c \
                    hash.c \
                    irinv.c \
		    weight.c \
                    boolean_op.c 

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

         SIG_SRCS = \
                    sighash.c \
                    hash.c

         SIG_OBJS = \
                    sighash.o \
                    hash.o

       INDEX_SRCS = waisindex.c \
                    field_l.c \
                    field_y.c 

       INDEX_OBJS = waisindex.o \
                    field_l.o \
                    field_y.o 

      SERVER_SRCS = $(INV_SRCS) \
                    query_y.c \
                    query_l.c \
                    waisserver.c \
                    server-single.c

      SERVER_OBJS = $(INV_OBJS) \
                    query_y.o \
                    query_l.o \
                    waisserver.o

     SERVER1_OBJS = $(INV_OBJS) \
                    query_y.o \
                    query_l.o \
                    server-single.o

       LOCAL_OBJS = \
                    query_y.o \
                    query_l.o \
                    field_index.o \
                    irtfiles.o 

/* all sources for make depend */
             SRCS = $(PROTOCOL_SRCS) $(SIG_SRCS) $(INDEX_SRCS) $(SERVER_SRCS) 

/* make the libraries */
NormalLibraryTarget(wais,$(PROTOCOL_OBJS))
NormalLibraryTarget(inv,$(INV_OBJS))
NormalLibraryTarget(sig,$(SIG_OBJS))
#ifdef LOCAL_SEARCH    
NormalLibraryTarget(local,$(LOCAL_OBJS))
#endif
/* make the programs */

all:: waisindex waisserver waisserver1

#ifdef SYSVREGEXP
        REGEXPLIB = ../regexp/libregexp.a

$(REGEXPLIB):
	cd ../regexp; $(MAKE) libregexp.a
#endif
  LOCAL_LIBRARIES = libwais.a libinv.a ../lib/libftw.a $(REGEXPLIB) 

NormalProgramTarget(waisindex,$(INDEX_OBJS),$(LOCAL_LIBRARIES),$(LOCAL_LIBRARIES) libwais.a ,-lm)
InstallProgram(waisindex,$(BINDIR))

NormalProgramTarget(waisserver,$(SERVER_OBJS),$(LOCAL_LIBRARIES),$(LOCAL_LIBRARIES),-lm)
InstallProgram(waisserver,$(BINDIR))

NormalProgramTarget(waisserver1,$(SERVER1_OBJS),$(LOCAL_LIBRARIES),$(LOCAL_LIBRARIES),-lm)
InstallProgram(waisserver1,$(BINDIR))
test_query: query_l.o query_y.c
	$(CC) -DTEST_QUERY  $(CFLAGS) -o $@ query_y.c query_l.o

clean::
	$(RM) test_query

veryclean:: clean
	$(RM) libwais.a libsig.a libinv.a

/*
  Lex and Yacc rules
*/

#define CopyRule(src,target) \
	   @if { cmp src target ; } then \				@@\
		   echo "src not changed";\				@@\
	   else \							@@\
		   echo "src changed";\					@@\
		   cp src target;\					@@\
	   fi;

#define LexRule(src)  \
Concat(src,.c): Concat(src,.l)						@@\
	$(RM) Concat(src,.c)						@@\
	$(LEX.l) Concat(src,.l) > Concat(src,.c)			@@\
									@@\
veryclean::                                                             @@\
	$(RM) Concat(src,.c)						@@\
									@@\
includes:: Concat(src,.c)						@@\


#define YaccRule(src,token) \
Concat(token,.h) Concat(src,.c): Concat(src,.y)				@@\
	$(YACC.y)  Concat(src,.y)					@@\
	CopyRule(y.tab.h,Concat(token,.h))				@@\
	mv y.tab.c Concat(src,.c)					@@\
									@@\
veryclean::                                                             @@\
	$(RM) Concat(src,.c) y.tab.h Concat(token,.h)			@@\
									@@\
includes:: Concat(src,.c)  Concat(token,.h)				@@\


YaccRule(query_y,query_token)
YaccRule(field_y,field_token)
LexRule(query_l)
LexRule(field_l)

DependTarget()

../lib/libftw.a:
	cd ../lib; $(MAKE) libftw.a

#ifdef ISO
$(ISOOBJS):
	cd ../ctype; $(MAKE)
#endif
