# Top level make of the WAIS system
#   brewster 2/91
#   jonathan 6/91

# common customizations:
# see the CFLAGS variable for pointers.
#
# to do:
# create the scripts, install the pointer to this version if it is the
# newest.

RM = rm -f
AR = ar

#ifdef vax
OCC = gcc
#else
OCC = cc
#endif
CC= cc

# set this for your site.  This syntax only works in SunOS
# for other UNIX-like OS's set this to this directory.
TOP=/mit/wais/build/@sys/wais-8-b2

SUPDIR = $(TOP)/ir

# for old BSD add -DBSD
# for System V add -DSYSV 
# for XENIX add -M3e -Zi
# 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
# USG for Unix Dirent in lib
CFLAGS = -O -I$(SUPDIR) -DSECURE_SERVER -DRELEVANCE_FEEDBACK ${MACHFL}

#if defined(vax) || defined(ibm032)
MACHFL=-DBSD
#else
/* the following is for sun4, decmips */
MACHFL=-DUSG
#endif

#if defined(_IBMR2) 
/* The -DBSD is for the socket header garbage */
MACHFL=-DBSD -DUSG
#endif

# this is a pretty good guess at the MAKE command.  -e seems to be
# SunOS specific too, so remove it for ULTRIX.

MAKE = make -e -k CC=$(CC) "CFLAGS=$(CFLAGS)" TOP=$(TOP)

all:: default

default: lib ir ui x bin doc
	@echo "Welcome to WAIS"

lib::
	cd lib; $(MAKE) 

ir::
	cd ir; $(MAKE) 

ui::
	cd ui; $(MAKE)

# ULTRIX doesn't have an env command, so this doesn't work.
# try going to the x directory and just doing a make -k
# you may have to edit the CFLAGS in the Makefile yourself.

#if defined(vax) || defined(ibm032)
x::
	cd x; TOP=$(TOP) CC=$(OCC) CFLAGS="$(CFLAGS)" ./makex.sh
#else
x::
	cd x; (env TOP=$(TOP) CC=$(CC) "CFLAGS=$(CFLAGS) -I/usr/athena/include" ./makex.sh LFLAGS=-L/usr/athena/lib)
#endif

bin::
	cd bin; $(MAKE)

doc::
	cd doc; $(MAKE)

test::
	@echo $(MAKE)

# to make the emacs tags table for meta-.:
tags: 	
	etags -f TAGS ir/?*?.[ch]
	etags -af TAGS ui/?*.[ch]
	etags -af TAGS x/?*.[ch]

# Remove objects and library.
clean::
	$(RM) *~
	$(RM) \#*\#
	$(RM) core
	$(RM) TAGS
	$(RM) -r SearchLog
	$(RM) wais-sources/wais-docs*
	cd lib; make $@
	cd ir; make $@
	cd ui; make  $@
	cd bin; make  $@
	cd doc; make  $@ RM="$(RM)"
	cd x; make $@ RM="$(RM)"

RELEASE = wais-8-b2

release:
	mkdir ../${RELEASE}
	tar cvf - . | (cd ../${RELEASE}; tar xf -)
	find ../${RELEASE} -name RCS -exec rm -rf {} ";"
	(cd ../${RELEASE}; make -k clean; rm -rf seeker)
	(cd ..; tar cvf ${RELEASE}.tar ${RELEASE})
	(cd ..; compress -f ${RELEASE}.tar)

# when making a new release, change ir/version.h to say so.
distrib:
	mkdir ${TOP}-dist
	tar cvf - . | (cd ${TOP}-dist; tar xf -)
	find ${TOP}-dist -name RCS -exec rm -rf {} ";"
	(cd ${TOP}-dist; make -k clean)
	(cd ..; tar cvf ${TOP}-dist.tar `basename ${TOP}-dist`)
	compress -f ${TOP}-dist.tar
	rm -rf ${TOP}-dist

expt:
	mkdir ${TOP}-expt
	tar cvf - . | (cd ${TOP}-expt; tar xf -)
	find ${TOP}-expt -name RCS -exec rm -rf {} ";"
	(cd ${TOP}-expt; make -k clean)
	(cd ..; tar cvf ${TOP}-expt.tar `basename ${TOP}-expt`)
	compress -f ${TOP}-expt.tar
	rm -rf ${TOP}-expt
