#
#  This & that...  Trickle3
#
#  Copyright 1990-1993   Matti.Aarnio @ FUNET.FI
#  This software is free under similar rules as BSD copyrights.
#  (Definitely this is NOT Public Domain.  "Just" FREELY AVAILABLE.
#   Don't clain you did this..)
#  You can use this, but you shall not held us liable for anything.
#  You must not use our name in marketing, in case you decide to
#  use this.  We do appreciate bug-reports  -> mailserver-owner@nic.funet.fi
#  for improving this piece of software.
#
SHELL=/bin/sh
CC=	gcc -g -O
CFLAGS=	$(CONFIGS) -g #-Bstatic #-O?

#    define where the mailserver itself is located at:
CONFIGS= -DTRICKLE_HOME='"/l/lib/mailserver"'

#CFLAGS= $(CONFIGS) -DUSG -DSYSV -I. -g
#LIBS=	../Sigtest/malloc/RCS/libmalloc.a -lgdbm -lPW
#LIBS=	-lgdbm -lPW
LIBS=	#-lresolv -lgdbm
#GDBM=	/usr/lib/libgdbm.a /lib/libPW.a
#GDBM=	-lgdbm #-lPW
#   PRODDIR Tells the beasts name.. (src directory name that is)
PRODDIR=mailserver
SRC=	tr-files.c dbcommon.c inits.c trickle3.c hosts.c cache.c queues.c \
	qsort.c xxencode.c xxdecode.c
OBJ=	tr-files.o dbcommon.o inits.o trickle3.o hosts.o cache.o queues.o \
	qsort.o
HFIL=	tr-dbase.h defaults.h
CHSRC=	ch-protocol.c ch-protocio.c ch-ftp.c ch-main.c
CHOBJ=	ch-protocol.o ch-protocio.o ch-ftp.o ch-main.o
CMDsrc= input.c cmds1.c maillists.c filecmds.c	\
	suspectaddr.c rfc822.c llist.c input.h \
	rootcmdpopen.c glob.c mailutil.c fastcd.c filestats.c \
	filestats.h cmds.h proto.h config.h qsort.c rfc821scn.c \
	archie.c accesslogging.c  # getdate.y 
CMDobj= input.o cmds1.o maillists.o filecmds.o suspectaddr.o	\
	rfc822.o llist.o rootcmdpopen.o glob.o mailutil.o	\
	fastcd.o filestats.o qsort.o rfc821scn.o archie.o	\
	accesslogging.o
LSVSRC= lsvinput.c rfc822.c llist.c llist.h
LSVOBJ= lsvinput.o rfc822.o llist.o
LIBSRC=	cmdlib.c
LIBRARY= libcmd.a
LIBFUNCS=	_strerror	_strsignal	_xsalloc	_xrealloc    \
		_xcalloc	_upperstr	_rdomaincmp	_pick_narg \
		_lowerstr	_strcasecmp	_strncasecmp	_basename

MAILSERVSRC= Makefile mailserver.doc $(MAILSRVAUX)  $(CMDsrc) $(LSVSRC) $(LIBSRC) fastcdmaker.c
MAILSRVAUX= help maillists/LISTINDEX maillists/test maillists/test.header .gdbinit makelist.sh xxdecode.c xxencode.c
#	    ^^^^ that "help" is a DIRECTORY full of documents..

all:	lsvinput input-program #fastcdmaker
oldall:	trickle3 ftp-channel lsvinput input-program

test: lsvinput input-program
	lsvinput -H -S req.test4

ttt:
	lsvinput -H -S req.test4

tt:	trickle3
	trickle3

try:	try1 try2

try1:	try1.o
	$(CC) $(CFLAGS) -o try1 try1.o

try2:	try2.o
	$(CC) $(CFLAGS) -o try2 try2.o

trickle3:	$(OBJ) #$(GDBM)
	$(CC) -o trickle3 $(OBJ) $(GDBM) $(LIBS)

ftp-channel:	$(CHOBJ)
	$(CC) $(CFLAGS) -o ftp-channel $(CHOBJ) $(LIBS)

lsvinput:	$(LSVOBJ) $(LIBRARY)
	$(CC) $(CFLAGS) -o $@.x $(LSVOBJ) $(LIBRARY) $(LIBS)
	mv $@.x $@

fastcdmaker:	fastcdmaker.o fastcd.o $(LIBRARY)
	$(CC) $(CFLAGS) -o fastcdmaker fastcdmaker.o fastcd.o $(LIBRARY) $(LIBS)

input-program:	$(CMDobj) $(LIBRARY)
	$(CC) $(CFLAGS) -o $@.x $(CMDobj) $(LIBRARY) $(LIBS)
	mv $@.x $@

pdlistx:	pdlistx.c
	$(CC) $(CFLAGS) -o pdlistx pdlistx.c

pdlistx2:	pdlistx2.c
	$(CC) $(CFLAGS) -o pdlistx2 pdlistx2.c

test1:	pdlistx
	pdlistx tucos.rawdir tucos.files tucos.dir 1989

test2:	pdlistx2
	pdlistx2 sauna.rawlist sauna.files sauna.dir 1989
test3:	pdlistx2
	pdlistx2 vega.rawlist vega.files vega.dir 1989

#.c.o:
	if [ "$(CC)" = "cc" ]	; \
	then			; \
		ansi2knr $*.c _temp_.c	; \
		$(CC) $(CFLAGS) -Dconst $(CCDEBUG) -c _temp_.c ; \
		mv _temp_.o $*.o	; \
		rm _temp_.c		; \
	else			; \
		$(CC) $(CFLAGS) $(CCDEBUG) -c $*.c	; \
	fi

getdate.o: getdate.y
	yacc getdate.y
	mv y.tab.c getdate.c
	$(CC) $(CFLAGS) -c getdate.c
	rm getdate.c

input.o:	input.c input.h cmds.h
cmds1.o:	cmds1.c input.h
lsvinput.o:	lsvinput.c input.h
maillists.o:	maillists.c input.h
utils.o:	utils.c input.h

dist:	/pub/local/src/$(PRODDIR).tar.gz

/pub/local/src/$(PRODDIR).tar.gz: $(MAILSERVSRC) help/*
	files=`for x in $(MAILSERVSRC);do echo $(PRODDIR)/$$x;done`;cd ..;gtar czf  /pub/local/src/$(PRODDIR).tar.gz $$files

$(LIBRARY):	$(LIBSRC)
	rm -f $(LIBRARY) tmplib;	\
	for name in $(LIBFUNCS);	\
	do				\
		echo $${name};		\
		rm -f $${name}.c;	\
		$(CC) $(CFLAGS) $(CCDEBUG) -c -DL$${name} cmdlib.c;	\
		mv cmdlib.o $${name}.o;		\
		ar qc tmplib $${name}.o;	\
		rm -f $${name}.[co];	\
	done
	-if [ -f /usr/bin/ranlib -o -f /bin/ranlib ] ;then ranlib tmplib; else true; fi
	mv tmplib $(LIBRARY)

glob.o:	glob.c
	cc $(CFLAGS) -c $<

fastcd.o: fastcd.c
	cc $(CFLAGS) -c $<

fastcdmaker.o: fastcdmaker.c
	cc $(CFLAGS) -c $<

filestats.o:	filestats.c filestats.h input.h
	cc $(CFLAGS) -c $<

cmdlib.o: input.h
cmds1.o: input.h
filecmds.o: input.h config.h filestats.h
filestats.o: input.h config.h filestats.h
input.o: input.h
llist.o: llist.h
lsvinput.o: input.h
maillists.o: input.h
mailutil.o: input.h
rfc822.o: llist.h
