# Makefile for LQ-Text, a full text retrieval package by Liam R. Quin
#
# $Id: Makefile,v 1.14 92/08/24 00:27:29 lee Exp $
#

# Do this first for sanity...:
SHELL=/bin/sh

### Some global configuration options.

# You should also look at h/globals.h for more things to change.
#
# DEFS are included in CFLAGS, passed to the C compiler:
# If ASCIITRACE is defined, you can get extra debugging output using -t99
# (or some other number), but there is a slight performance penalty for
# including this, and you'd need to understand the code.

# DEFS:
# Use either -UBSD -DSYSV or -USYSV -DBSD as appropriate...
# This affects
# * the choice of default pager ($PAGER) in globals.h
# * whether some extra declarations are used to make lint and gcc -Wall
#   happy about SysV stdio.h
# It isn't very important... if you have System V stdio and curses, you
# might as well use -DSYSV -UBSD even on BSD.  Ultrix diffs are included
# inside #ifdef ultrix; use BSD on Ultrix.
# Lqtext doesn't do explicit locking or signal handling at the moment.
# If you are using sdbm and get messages about L_SET or L_SEEK being
# undefined, add -DSVID (there are other changes, but
# this is a useful symptom...)
#
# -DMALLCTRACE makes malloc.c produce masses of output...
#
# -DCURSESX, if present, says that we have the System V.3.1 or later
# curses that has A_STANDOUT and in which box(win, 0, 0) draws a neat box
# with vt100 characters.  If you're not sure, if the string ACS appears
# in /usr/include/curses.h you should probably use -DCURSESX.
#
# -DNEWSYM gives a new, improved but not quite so tested symbol table in
# lqaddfile, that saves scads of memory...  Please don't try and use the old
# one, as I haven't included it!  This option will go away soon.
#
# -DWIDINBLOCK is really for serious debugging -- it uses up 4 out of every
# BLOCKSIZE (32 or 64) data bytes to record the word number for checking...
#
# DEFS= -DASCIITRACE -UBSD -DSYSV -DMALLOCTRACE -DCURSESX ### for BIG testing
DEFS= -UWIDINBLOCK -DASCIITRACE -DBSD -USYSV -UCURSESX  ### Try this on BSD
# DEFS= -I/usr/5include -L/usr/5lib -DASCIITRACE -UBSD -DSYSV -DCURSESX -DSVID ### ...and this on Sys V

# where do the installed binaries go?
BINDIR=/usr/local/bin
LIBDIR=/usr/local/lib/lqtext
# and the file mode for executables?
MODE=751

# NewsFilter and MailFilter are programs which read news/mail files and
# turn unwanted words (e.g. Received-By lines inside mail headers) into
# "qxxxxx", with the right number of x's so that the total byte count is
# unchanged....
# Lqshow is the document browser.
MAILFILTER=$(LIBDIR)/MailFilter
NEWSFILTER=$(LIBDIR)/NewsFilter
DEFAULTFILTER=$(LIBDIR)/DefaultFilter
LQSHOW=$(BINDIR)/lqshow
LQFILE=$(BINDIR)/lqfile

# If you have -lmalloc, use it...
# MALLOC=-lmalloc # faster version of malloc
MALLOC= # BSD Unix doesn't have malloc(3X), only malloc(3)

# Choose between bsdhash, ndbm, sdbm, bsdhash, gdbm or dbm -- if you only have
# dbm, you may have some work to do -- see PORTING for gdbm or dbm.
# The necessary changes are in h/smalldb.h and h/Liamdbm.h if you need them.
#
# If you use bsdhash or sdbm you must use the fixed versions -- sdbm was
# posted to netnews in 1991, and bsdhash is included with this distribution.
#
# Note that the older ozmahash should not be used.  Bsdhash replaces it.
#
# The 4.4 BSD db package could be used instead if you have it, but I advise
# setting ffactor to 256 or higher in the call to hash_open (or in ndbm.c).

#WHICHDBM=ndbm
#DBMLIBS=-lndbm
# MKDBM= # this is the target if we have to build ndbm...
WHICHDBM=bsdhash
DBMLIBS=../lib/libhash.a
MKDBM=mkbsdhash # this is the target if we have to build bsdhash...

# On BSD systems you need -ltermcap as well as libcurses for "lqshow".
# TERMCAP=-lcursesX -ltermcap # ultrix -- cursesx
TERMCAP=-lcurses -ltermcap
# TERMCAP=-L/usr/5lib -lcurses

# on SYSV ranlib is usually "echo"
# RANLIB=echo
RANLIB=ranlib

# Choose a C compiler -- GNU's gcc if you have it, or the standard cc.
# GNU cc won't compile lqaddfile.c on some machines, but I don't know why.
## for gcc:
# CC=gcc
# GCCF= -Fwriteable-strings -I/usr/include
# GCCF= -Wall -I/usr/include -I../bsdhash
##
# CC=/usr/5bin/cc
# GCCF= -I/usr/5include -L/usr/5lib
## for anything else:
CC=/usr/5bin/cc
GCCF=-I../bsdhash
#
# Use -O or -O -g for the optimiser.  Or -ql or -p for profiling (sysV)
# -O4 is for SunOS - it works fine under 4.0.3 and 4.1.1 at least.
# With gcc or recent System V compilers, you can use OPT=-O -g
# NOTE to profilers: do not mix -g with -p -- this is often broken!
# Also, if you change OPT to -p, do a make clean first, as otherwise you're
# likely to get core dumps, you can't link -g and -p objects together.
# OPT=-g
OPT=-O4 -Qoption iropt -l4

CFLAGS= $(OPT) $(DEFS) $(GCCF) -D$(WHICHDBM) $$(EXTRA)

# Lint flags vary wildly between systems.
# LINTFLAGS=-xv
LINTFLAGS=-a -b -c -h -x 

### End of configuration section.  See also PORTING in this directory.

# Note that liblqerror must be made first so that error.h is installed!
DIRS=mkliblqerror mkliblqtext mkliblqutil mklqtext mkfilters mkmenu mktest
MKTARGETS=mklib mkbin $(MKDBM) $(DIRS)

# Make all does a local install (in src/bin src/lib src/testbin) too...
all: local

.SUFFIXES: .c .o .src .obj

.c.src:
	#load $(CFLAGS) $<

.o.obj:
	#load $(CFLAGS) $<

saber_src:
	$(MAKE) -$(MAKEFLAGS) MAKEWHAT=saber_src $(MKTARGETS)

saber_obj:
	$(MAKE) -$(MAKEFLAGS) MAKEWHAT=saber_obj $(MKTARGETS)

lqaddfile.src:
	#cd lqtext
	$(MAKE) -$(MAKEFLAGS) MALLOC='$(MALLOC)' CFLAGS='$(CFLAGS)' CC='$(CC)' WHICHDBM='$(WHICHDBM)' TERMCAP='$(TERMCAP)' RANLIB='$(RANLIB)' DBMLIBS="${DBMLIBS}" LINTFLAGS='$(LINTFLAGS)' lqaddfile.src
	#cd ..

tidy:
	$(MAKE) -i$(MAKEFLAGS) MAKEWHAT=tidy $(MKTARGETS)

clean:
	$(MAKE) -$(MAKEFLAGS) MAKEWHAT=clean $(MKTARGETS)
	rm -f lib/* bin/* testbin/* core *.o m.log tags

depend:
	$(MAKE) -$(MAKEFLAGS) MAKEWHAT=depend $(MKTARGETS)

local: mklib mkbin # libs
	$(MAKE) -$(MAKEFLAGS) MAKEWHAT=install $(MKTARGETS)

install: libs
	$(MAKE) -$(MAKEFLAGS) MAKEWHAT=install $(MKTARGETS)
	( cd bin ; for i in *; do \
	    test -f ${BINDIR}/$$i && /bin/mv ${BINDIR}/$$i ${BINDIR}/$$i.old; \
	    /bin/cp $$i ${BINDIR}; \
	    chmod 711 ${BINDIR}/$$i; \
	  done; \
	)
	( cd lib ; for i in `ls | grep -v '\.a$'`; do \
	    test -f ${LIBDIR}/$$i && /bin/mv ${LIBDIR}/$$i ${LIBDIR}/$$i.old; \
	    /bin/cp $$i ${LIBDIR}; \
	    chmod 711 ${LIBDIR}/$$i; \
	  done; \
	)
	@-echo Binary Installation complete
	@-echo Now install manual pages from ../doc if appropriate.

lint:
	$(MAKE) -$(MAKEFLAGS) MAKEWHAT=lint $(MKTARGETS)

libs:
	-/bin/test -d ${LIBDIR} || mkdir ${LIBDIR}
	$(MAKE) -$(MAKEFLAGS) MAKEWHAT=install $(MKDBM) mkliblqtext
	$(MAKE) -$(MAKEFLAGS) MAKEWHAT=install $(MKDBM) mkliblqutil
	$(MAKE) -$(MAKEFLAGS) MAKEWHAT=install $(MKDBM) mkliblqerror
	-@echo libraries up to date

# Note to mklib and mkbin:
# If the mkdir -p bombs out, there is a shell-script mkdir you can use
# in the utils directory.  The -p means to create parent directores as needed.

mklib: # see note above about mkdir
	-@test -d lib || mkdir lib
	-@test -d $(LIBDIR) || mkdir -p $(LIBDIR)

mkbin:  # see note above about mkdir
	-@test -d bin || mkdir bin
	-@test -d $(BINDIR) || mkdir -p $(BINDIR)

mkfilters:
	cd filters; \
	$(MAKE) -$(MAKEFLAGS) MALLOC='$(MALLOC)' \
	CFLAGS='$(CFLAGS) -DMAILFILTER=\"$(MAILFILTER)\" \
	-DDEFAULTFILTER=\"$(DEFAULTFILTER)\" \
	-DNEWSFILTER=\"$(NEWSFILTER)\" ' CC='$(CC)' \
	WHICHDBM='$(WHICHDBM)' TERMCAP='$(TERMCAP)' RANLIB='$(RANLIB)' \
	DBMLIBS="${DBMLIBS}" LINTFLAGS='$(LINTFLAGS)' $(MAKEWHAT) 

mkliblqtext:
	cd liblqtext; \
	$(MAKE) -$(MAKEFLAGS) MALLOC='$(MALLOC)' \
	CFLAGS='$(CFLAGS) -DMAILFILTER=\"$(MAILFILTER)\" \
	-DDEFAULTFILTER=\"$(DEFAULTFILTER)\" \
	-DNEWSFILTER=\"$(NEWSFILTER)\" ' CC='$(CC)' \
	WHICHDBM='$(WHICHDBM)' TERMCAP='$(TERMCAP)' RANLIB='$(RANLIB)' \
	DBMLIBS="${DBMLIBS}" LINTFLAGS='$(LINTFLAGS)' $(MAKEWHAT)


mkliblqutil:
	cd liblqutil; \
	$(MAKE) -$(MAKEFLAGS) MALLOC='$(MALLOC)' \
	CFLAGS='$(CFLAGS) -DMAILFILTER=\"$(MAILFILTER)\" \
	-DDEFAULTFILTER=\"$(DEFAULTFILTER)\" \
	-DNEWSFILTER=\"$(NEWSFILTER)\" ' CC='$(CC)' \
	WHICHDBM='$(WHICHDBM)' TERMCAP='$(TERMCAP)' RANLIB='$(RANLIB)' \
	DBMLIBS="${DBMLIBS}" LINTFLAGS='$(LINTFLAGS)' $(MAKEWHAT)


mkliblqerror:
	cd liblqerror; \
	$(MAKE) -$(MAKEFLAGS) MALLOC='$(MALLOC)' \
	CFLAGS='$(CFLAGS) -DMAILFILTER=\"$(MAILFILTER)\" \
	-DDEFAULTFILTER=\"$(DEFAULTFILTER)\" \
	-DNEWSFILTER=\"$(NEWSFILTER)\" ' CC='$(CC)' \
	WHICHDBM='$(WHICHDBM)' TERMCAP='$(TERMCAP)' RANLIB='$(RANLIB)' \
	DBMLIBS="${DBMLIBS}" LINTFLAGS='$(LINTFLAGS)' $(MAKEWHAT)

mklqtext:
	cd lqtext; \
	$(MAKE) -$(MAKEFLAGS) MALLOC='$(MALLOC)' \
	CFLAGS='$(CFLAGS) -DMAILFILTER=\"$(MAILFILTER)\" \
	-DDEFAULTFILTER=\"$(DEFAULTFILTER)\" \
	-DNEWSFILTER=\"$(NEWSFILTER)\" ' CC='$(CC)' \
	WHICHDBM='$(WHICHDBM)' TERMCAP='$(TERMCAP)' RANLIB='$(RANLIB)' \
	DBMLIBS="${DBMLIBS}" LINTFLAGS='$(LINTFLAGS)' $(MAKEWHAT)

mksdbm:
	cd sdbm; \
	$(MAKE) -$(MAKEFLAGS) MALLOC='$(MALLOC)' CFLAGS='$(CFLAGS)' \
	CC='$(CC)' WHICHDBM='$(WHICHDBM)' TERMCAP='$(TERMCAP)' \
	RANLIB='$(RANLIB)' \
	DBMLIBS="${DBMLIBS}" LINTFLAGS='$(LINTFLAGS)' $(MAKEWHAT)

mkbsdhash:
	cd bsdhash; \
	$(MAKE) -$(MAKEFLAGS) MALLOC='$(MALLOC)' CFLAGS='-I. $(CFLAGS)' \
	CC='$(CC)' WHICHDBM='$(WHICHDBM)' TERMCAP='$(TERMCAP)' \
	RANLIB='$(RANLIB)' \
	DBMLIBS="${DBMLIBS}" LINTFLAGS='$(LINTFLAGS)' $(MAKEWHAT)

mktest:
	cd test; \
	$(MAKE) -$(MAKEFLAGS) MALLOC='$(MALLOC)' CFLAGS='$(CFLAGS)' \
	CC='$(CC)' WHICHDBM='$(WHICHDBM)' TERMCAP='$(TERMCAP)' \
	OWNER='$(OWNER)' RANLIB='$(RANLIB)' \
	DBMLIBS="${DBMLIBS}" LINTFLAGS='$(LINTFLAGS)' $(MAKEWHAT)

mkmenu:
	cd menu; \
	$(MAKE) -$(MAKEFLAGS) MALLOC='$(MALLOC)' CFLAGS='$(CFLAGS)' \
	MALLOC='$(MALLOC)' RANLIB='$(RANLIB)' \
	CFLAGS='$(CFLAGS) -DLQSHOW=\"$(LQSHOW)\" -DLQFILE=\"$(LQFILE)\" ' \
	CC='$(CC)' WHICHDBM='$(WHICHDBM)' TERMCAP='$(TERMCAP)' \
	DBMLIBS="${DBMLIBS}" LINTFLAGS='$(LINTFLAGS)' $(MAKEWHAT)


# shorthand:

ctags:
	ctags $(WHICHDBM)/*.[hc] h/*.h `echo $(DIRS) | tr ' ' '\012' | sed -e 's/^mk//' -e 's;$$;/*.[ch];'`

lq:
	$(MAKE) -$(MAKEFLAGS)  mklqtext MAKEWHAT=lq

lqaddfile:
	$(MAKE) -$(MAKEFLAGS)  mklqtext MAKEWHAT=lqaddfile

lqfile:
	$(MAKE) -$(MAKEFLAGS)  mklqtext MAKEWHAT=lqfile

lqkwik:
	$(MAKE) -$(MAKEFLAGS)  mklqtext MAKEWHAT=lqkwik

lqphrase:
	$(MAKE) -$(MAKEFLAGS)  mklqtext MAKEWHAT=lqphrase

lqshow:
	$(MAKE) -$(MAKEFLAGS)  mklqtext MAKEWHAT=lqshow

lqtext:
	$(MAKE) -$(MAKEFLAGS)  mklqtext MAKEWHAT=lqtext

lqword:
	$(MAKE) -$(MAKEFLAGS)  mklqtext MAKEWHAT=lqword

mkwidtable:
	$(MAKE) -$(MAKEFLAGS)  mklqtext MAKEWHAT=mkwidtable

