# $Id: Makefile,v 1.6 2002/09/30 11:46:20 arto Exp $ 
# (c) 2000-2001 IC&S, The Netherlands

#! /bin/sh

DBASETYPE = mysql
DBASE_AUTHTYPE = mysql

AUTHOBJECT = $(DBASETYPE)/dbauth$(DBASE_AUTHTYPE).o
MSGBUFOBJECT = $(DBASETYPE)/dbmsgbuf$(DBASETYPE).o
SEARCHOBJECT = $(DBASETYPE)/dbsearch$(DBASETYPE).o
DBOBJECT = $(DBASETYPE)/db$(DBASETYPE).o

# Several weighting and scoring methods used in bow are compiled as
# separate objects which are not included in the main library.
BOWLIBDIR=/home/arto/devel/bow
BOW_METHOD_OBJECTS = $(BOWLIBDIR)/tfidf.o

# Sorry, now all these require bow and a bunch of extra objects
# (including organize-helpers.o) because they are used in database
# routines. It makes all binaries huge, should separate the extra
# database stuff in another file.
ORGANIZE_HELPER_OBJECTS = organize-helpers.o rfcmsg.o $(MSGBUFOBJECT)

SMTP_OBJECTS = list.o debug.o pipe.o mime.o $(DBOBJECT) dbmd5.o md5.o bounce.o forward.o memblock.o \
$(AUTHOBJECT) $(ORGANIZE_HELPER_OBJECTS)
INJECTOR_OBJECTS = list.o debug.o $(DBOBJECT) dbmd5.o md5.o $(AUTHOBJECT) mime.o $(ORGANIZE_HELPER_OBJECTS) memblock.o
UNIONE_OBJECTS = list.o debug.o $(DBOBJECT) dbmd5.o md5.o $(AUTHOBJECT) mime.o memblock.o $(ORGANIZE_HELPER_OBJECTS)
MINI_OBJECTS = debug.o $(DBOBJECT) list.o dbmd5.o md5.o $(AUTHOBJECT) mime.o $(ORGANIZE_HELPER_OBJECTS) memblock.o
POP_OBJECTS = pop3.o list.o debug.o $(DBOBJECT) dbmd5.o md5.o mime.o misc.o memblock.o $(AUTHOBJECT) $(ORGANIZE_HELPER_OBJECTS)
IMAP_OBJECTS = organize-helpers.o imap4.o debug.o $(DBOBJECT) serverservice.o list.o dbmd5.o md5.o imaputil.o imapcommands.o mime.o misc.o memblock.o rfcmsg.o $(MSGBUFOBJECT) $(SEARCHOBJECT) $(AUTHOBJECT) $(BOW_METHOD_OBJECTS) 
MAINTENANCE_OBJECTS = debug.o list.o dbmd5.o md5.o $(DBOBJECT) mime.o memblock.o $(AUTHOBJECT) $(ORGANIZE_HELPER_OBJECTS)
CONFIG_OBJECTS = $(DBOBJECT) list.o md5.o debug.o dbmd5.o mime.o memblock.o $(AUTHOBJECT) $(ORGANIZE_HELPER_OBJECTS)
USER_OBJECTS = debug.o list.o dbmd5.o md5.o $(DBOBJECT) mime.o memblock.o $(AUTHOBJECT) $(ORGANIZE_HELPER_OBJECTS)
VUTCONV_OBJECTS = debug.o list.o dbmd5.o md5.o mime.o $(DBOBJECT) $(AUTHOBJECT) $(ORGANIZE_HELPER_OBJECTS) memblock.o
DBTEST_OBJECTS = debug.o list.o dbmd5.o md5.o mime.o $(DBOBJECT) $(AUTHOBJECT) $(ORGANIZE_HELPER_OBJECTS) memblock.o
REALSMTP_OBJECTS = smtp.o debug.o dbmd5.o md5.o list.o mime.o serverservice.o misc.o \
smtpcommands.o memblock.o $(DBOBJECT) $(AUTHOBJECT) $(ORGANIZE_HELPER_OBJECTS)
ORGANIZE_OBJECTS = organize-helpers.o debug.o dbmd5.o md5.o list.o memblock.o rfcmsg.o $(MSGBUFOBJECT) $(DBOBJECT) mime.o $(AUTHOBJECT) $(BOW_METHOD_OBJECTS)
CC = cc

# PGSQLLIBDIR=/usr/local/pgsql/lib
MYSQLLIBDIR=/usr/lib

# LIBS = -L$(PGSQLLIBDIR)
# LIB = -pq -lcrypt
LIBS = -L$(MYSQLLIBDIR) -L$(BOWLIBDIR)
LIB = -lcrypt -lmysqlclient
EXTRA_INCLUDES = -I$(BOWLIBDIR)

# Added the -D_BSD_SOURCE option to suppress warnings
# from compiler about vsyslog function 
# Added the -D_SVID_SOURCE option because ipc.h asked me to.

CFLAGS = -Wall  -D_BSD_SOURCE -D_SVID_SOURCE -g $(EXTRA_INCLUDES)

.PHONY: clean install

all: smtp pop3d maintenance config imapd user readvut mbox2dbmail injector miniinjector unione raw organize

smtp: config.h main.h $(SMTP_OBJECTS) main.c
		$(CC)	$(CFLAGS) main.c -o dbmail-smtp $(SMTP_OBJECTS) $(LIBS) $(LIB) -lbow

pop3d: pop3.h $(POP_OBJECTS) pop3d.c
		$(CC) $(CFLAGS) pop3d.c -o dbmail-pop3d $(POP_OBJECTS) $(LIBS) $(LIB) -lbow

imapd: imap4.h $(IMAP_OBJECTS) imapd.c
	$(CC) $(CFLAGS) imapd.c -o dbmail-imapd $(IMAP_OBJECTS) $(LIBS) $(LIB) -lbow

maintenance: maintenance.h $(MAINTENANCE_OBJECTS) maintenance.c
	$(CC) $(CFLAGS) maintenance.c -o dbmail-maintenance $(MAINTENANCE_OBJECTS) $(LIBS) $(LIB) -lbow

organize: organize.h $(ORGANIZE_OBJECTS) organize.c
	$(CC) $(CFLAGS) organize.c -o dbmail-organize $(ORGANIZE_OBJECTS) $(LIBS) $(LIB) -lbow

config: $(CONFIG_OBJECTS) settings.c
	$(CC) $(CFLAGS) settings.c -o dbmail-config $(CONFIG_OBJECTS) $(LIBS) $(LIB) -lbow

user: user.h $(USER_OBJECTS) user.c
	$(CC) $(CFLAGS) user.c -o dbmail-adduser $(USER_OBJECTS) $(LIBS) $(LIB) -lbow

readvut: db.h auth.h vut2dbmail.c $(VUTCONV_OBJECTS)
	$(CC) $(CFLAGS) vut2dbmail.c -o dbmail-readvut $(VUTCONV_OBJECTS) $(LIBS) $(LIB) -lbow

realsmtp: db.h smtp.h $(REALSMTP_OBJECTS) smtpd.c
	$(CC) $(CFLAGS) smtpd.c -o dbmail-realsmtp $(REALSMTP_OBJECTS) $(LIBS) $(LIB) -lbow

injector: db.h auth.h $(INJECTOR_OBJECTS) injector.c
	$(CC) $(CFLAGS) injector.c -o dbmail-smtp-injector $(INJECTOR_OBJECTS) $(LIBS) $(LIB) -lbow

unione: db.h auth.h $(INJECTOR_OBJECTS) uni-one-convert-ajt.c
	$(CC) $(CFLAGS) uni-one-convert-ajt.c -o uni-one-convertor $(UNIONE_OBJECTS) $(LIBS) $(LIB) -lbow

raw: db.h auth.h $(INJECTOR_OBJECTS) raw-convert.c
	$(CC) $(CFLAGS) raw-convert.c -o raw-convertor $(UNIONE_OBJECTS) $(LIBS) $(LIB) -lbow

miniinjector: db.h $(MINI_OBJECTS) mini-injector.c
	$(CC) $(CFLAGS) mini-injector.c -o dbmail-mini-injector $(MINI_OBJECTS) $(LIBS) $(LIB) -lbow

mbox2dbmail:	

dbtest: $(DBTEST_OBJECTS) dbtest.c db.h
	$(CC) $(CFLAGS) dbtest.c -o dbtest $(DBTEST_OBJECTS) $(LIBS) $(LIB) -lbow

list.o: list.h debug.h
debug.o: debug.h
pipe.o: pipe.h config.h debug.h
forward.o: forward.h config.h debug.h
mime.o: mime.h config.h debug.h
misc.o:misc.h config.h debug.h
pop3.o:pop3.h config.h debug.h dbmailtypes.h
dbmd5.o:dbmd5.h md5.h debug.h
bounce.o:bounce.h list.h debug.h
imap4.o: imap4.h db.h debug.h serverservice.h imaputil.h imapcommands.h
imaputil.o: imaputil.h db.h memblock.h debug.h dbmailtypes.h
imapcommands.o: imapcommands.h imaputil.h imap4.h db.h memblock.h debug.h dbmailtypes.h
serverservice.o: serverservice.h debug.h
smtp.o: smtp.h db.h debug.h serverservice.h smtpcommands.h memblock.h
smtpcommands.o: smtpcommands.h db.h debug.h dbmailtypes.h memblock.h
maintenance.o: maintenance.h debug.h
organize.o: organize.h organize-helpers.h debug.h
organize-helpers.o: organize-helpers.h debug.h
settings.o: settings.h debug.h
user.o: user.h debug.h
memblock.o: memblock.h debug.h
rfcmsg.o: rfcmsg.h dbmailtypes.h
vut2dbmail.o: db.h auth.h
$(DBOBJECT):db.h dbmd5.h config.h mime.h list.h memblock.h debug.h dbmailtypes.h auth.h
$(MSGBUFOBJECT): dbmsgbuf.h db.h
$(SEARCHOBJECT): dbsearch.h db.h
$(AUTHOBJECT): auth.h db.h

distclean: clean
	rm -rf dbmail-smtp dbmail-pop3d dbmail-maintenance dbmail-imapd dbmail-config dbmail-adduser dbmail-readvut mbox2dbmail dbmail-realsmtp

clean:
	rm -f *.o core $(DBASETYPE)/*.o
