# Makefile for cyrus imap server and associated programs
# $Id: Makefile.in,v 1.136 2001/04/27 05:58:35 wcw Exp $
# 
# @configure_input@
#
# 
# Copyright (c) 1998-2000 Carnegie Mellon University.  All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer. 
#
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in
#    the documentation and/or other materials provided with the
#    distribution.
#
# 3. The name "Carnegie Mellon University" must not be used to
#    endorse or promote products derived from this software without
#    prior written permission. For permission or any other legal
#    details, please contact  
#      Office of Technology Transfer
#      Carnegie Mellon University
#      5000 Forbes Avenue
#      Pittsburgh, PA  15213-3890
#      (412) 268-4387, fax: (412) 268-7395
#      tech-transfer@andrew.cmu.edu
#
# 4. Redistributions of any form whatsoever must retain the following
#    acknowledgment:
#    "This product includes software developed by Computing Services
#     at Carnegie Mellon University (http://www.cmu.edu/computing/)."
#
# CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO
# THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
# AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE
# FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
# AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
# OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
# 
DEFINES=-DSETPROCTITLE

# \Seen state database.  Either 'db' (berkeley db) or 
# 'local' (legacy flat file).
SEEN=seen_db.o

# New mail notification mechanism
NOTIFY=notify_@WITH_NOTIFY@.o

# IMAP IDLE mechanism
IDLE=idle_@WITH_IDLE@.o

srcdir = @srcdir@
VPATH = @srcdir@

CC = @CC@
INSTALL = @INSTALL@
RANLIB = @RANLIB@

CYRUS_USER=@cyrus_user@
CYRUS_GROUP=@cyrus_group@

DEFS = @DEFS@ @LOCALDEFS@
CPPFLAGS = -I. -I.. -I../sieve -I$(srcdir) -I$(srcdir)/../lib -I$(srcdir)/../acap -I../acap @COM_ERR_CPPFLAGS@ @SIEVE_CPPFLAGS@ @CPPFLAGS@ @ZEPHYR_CPPFLAGS@ @SASLFLAGS@
IMAP_LIBS = @IMAP_LIBS@
SIEVE_LIBS = @SIEVE_LIBS@
IMAP_COM_ERR_LIBS = @IMAP_COM_ERR_LIBS@
LIB_WRAP = @LIB_WRAP@
LIBS = $(IMAP_LIBS) @ZEPHYR_LIBS@ $(IMAP_COM_ERR_LIBS)
DEPLIBS = ../acap/libacap.a ../lib/libcyrus.a @DEPLIBS@

CFLAGS = @CFLAGS@
LDFLAGS = @LDFLAGS@ @CFLAGS@ @COM_ERR_LDFLAGS@ 

SHELL = /bin/sh
MAKEDEPEND = @MAKEDEPEND@

COMPILE_ET=@COMPILE_ET@

#
# Some notes on purify --
#     you probably want to run the make as the cyrus user as 
#     purify sets the cache directory based on the user. So,
#     if you don't, purify can't find the instrumented libraries
#     and so you don't get any useful information.
#     It may also help to run purify by hand to instrument any of
#     the dynamic libraries that may crop up during run time.
# 
PURIFY=/usr/local/bin/purify
PUREOPT= -best-effort -logfile=/tmp/pure/%v.%p.log -always_use_cache_dir
QUANTIFY=/usr/local/bin/quantify
QUANTOPT=-windows=no -filename-prefix=/tmp/quant/%v.%p -write-summary-file= -logfile=/tmp/quant/%v.%p.log

prefix = @prefix@
exec_prefix = @exec_prefix@
cyrus_prefix = @cyrus_prefix@

LOBJS= append.o mailbox.o mboxlist.o mboxname.o message.o \
	config.o imap_err.o proc.o setproctitle.o convert_code.o \
	duplicate.o saslclient.o acapmbox.o signals.o \
	base64.o imapparse.o telemetry.o $(SEEN) $(NOTIFY) $(IDLE)

IMAPDOBJS=pushstats.o imapd.o index.o tls.o

SERVICE=../master/service.o
SERVICETHREAD=../master/service-thread.o

PROGS = imapd lmtpd pop3d \
	fud reconstruct quota \
	mbpath ipurge cyrdump deliver \
	ctl_mboxlist ctl_deliver @IMAP_PROGS@

BUILTSOURCES = imap_err.h pushstats.h lmtpstats.h

all: $(BUILTSOURCES) $(PROGS) $(SUIDPROGS)

install:
	$(srcdir)/../install-sh -d ${DESTDIR}$(cyrus_prefix)/bin
	for file in $(PROGS); \
	do \
		$(INSTALL) -m 755 $$file $(DESTDIR)$(cyrus_prefix)/bin || exit 1; \
	done
	$(INSTALL) -m 755 feedcyrus $(DESTDIR)$(cyrus_prefix)/bin

.c.o:
	$(CC) -c $(CPPFLAGS) $(DEFS) $(CFLAGS) \
	$<

idled: idled.o libimap.a $(DEPLIBS)
	$(CC) $(LDFLAGS) -o idled \
	 idled.o libimap.a $(DEPLIBS) $(LIBS)

acappush: acappush.o libimap.a $(DEPLIBS)
	$(CC) $(LDFLAGS) -o acappush \
	 acappush.o libimap.a $(DEPLIBS) $(LIBS)

pushstats.c pushstats.h: pushstats.snmp $(srcdir)/../snmp/snmpgen
	$(srcdir)/../snmp/snmpgen $(srcdir)/pushstats.snmp

lmtpstats.c lmtpstats.h: lmtpstats.snmp $(srcdir)/../snmp/snmpgen
	$(srcdir)/../snmp/snmpgen $(srcdir)/lmtpstats.snmp

collectnews: collectnews.o libimap.a $(DEPLIBS)
	$(CC) $(LDFLAGS) -o collectnews collectnews.o libimap.a $(DEPLIBS) \
	 $(LIBS)

deliver: deliver.o lmtpstats.o lmtpengine.o libimap.a $(DEPLIBS)
	$(CC) $(LDFLAGS) -o deliver deliver.o lmtpengine.o lmtpstats.o \
	libimap.a $(DEPLIBS) $(LIBS)

lmtpd: lmtpstats.o lmtpd.o lmtpengine.o \
	libimap.a $(SIEVE_LIBS) $(DEPLIBS) $(SERVICE)
	$(CC) $(LDFLAGS) -o lmtpd \
	 $(SERVICE) lmtpd.o lmtpengine.o lmtpstats.o \
	 libimap.a $(SIEVE_LIBS) $(DEPLIBS) $(LIBS) $(LIB_WRAP)

lmtpd.pure: lmtpstats.o lmtpd.o lmtpengine.o \
	libimap.a $(SIEVE_LIBS) $(DEPLIBS) $(SERVICE)
	$(PURIFY) $(PUREOPT) $(CC) $(LDFLAGS) -o lmtpd.pure \
	 $(SERVICE) lmtpd.o lmtpengine.o lmtpstats.o \
	 libimap.a $(SIEVE_LIBS) $(DEPLIBS) $(LIBS) $(LIB_WRAP)

lmtpproxyd: lmtpstats.o lmtpproxyd.o lmtpengine.o \
	libimap.a $(SIEVE_LIBS) $(DEPLIBS) $(SERVICE)
	$(CC) $(LDFLAGS) -o lmtpproxyd \
	 $(SERVICE) lmtpproxyd.o lmtpengine.o lmtpstats.o \
	 libimap.a $(SIEVE_LIBS) $(DEPLIBS) $(LIBS) $(LIB_WRAP)

ctl_deliver: ctl_deliver.o libimap.a $(DEPLIBS)
	$(CC) $(LDFLAGS) -o \
	 $@ ctl_deliver.o libimap.a $(DEPLIBS) $(LIBS)

ctl_mboxlist: ctl_mboxlist.o libimap.a $(DEPLIBS)
	$(CC) $(LDFLAGS) -o \
	 $@ ctl_mboxlist.o libimap.a $(DEPLIBS) $(LIBS)

imapd: $(IMAPDOBJS) libimap.a $(DEPLIBS) $(SERVICE)
	$(CC) $(LDFLAGS) -o imapd \
	 $(SERVICE) $(IMAPDOBJS) libimap.a $(DEPLIBS) $(LIBS) $(LIB_WRAP)

imapd.pure: $(IMAPDOBJS) libimap.a $(DEPLIBS) $(SERVICE)
	$(PURIFY) $(PUREOPT) $(CC) $(LDFLAGS) -o imapd.pure \
	 $(SERVICE) $(IMAPDOBJS) libimap.a $(DEPLIBS) $(LIBS) $(LIB_WRAP)

imapd.quant: $(IMAPDOBJS) libimap.a $(DEPLIBS) $(SERVICE)
	$(QUANTIFY) $(QUANTOPT) $(CC) $(LDFLAGS) -o imapd.quant \
	 $(SERVICE) $(IMAPDOBJS) libimap.a $(DEPLIBS) $(LIBS) $(LIB_WRAP)

proxyd: pushstats.o proxyd.o tls.o libimap.a $(DEPLIBS) $(SERVICE)
	$(CC) $(LDFLAGS) -o proxyd \
	 $(SERVICE) pushstats.o proxyd.o tls.o libimap.a $(DEPLIBS) $(LIBS) $(LIB_WRAP)

target-acap: target-acap.o libimap.a $(DEPLIBS)
	$(CC) $(LDFLAGS) -o target-acap \
	 target-acap.o libimap.a $(DEPLIBS) $(LIBS)

sendmail-map: sendmail-map.o libimap.a $(DEPLIBS)
	$(CC) $(LDFLAGS) -o sendmail-map \
	 sendmail-map.o libimap.a $(DEPLIBS) $(LIBS)

mupdate: mupdate.o libimap.a $(DEPLIBS)
	$(CC) $(LDFLAGS) -o mupdate \
	 $(SERVICETHREAD) mupdate.o libimap.a $(DEPLIBS) $(LIBS) $(LIB_WRAP) -lpthread

pop3d: pop3d.o tls.o libimap.a $(DEPLIBS) $(SERVICE)
	$(CC) $(LDFLAGS) -o pop3d pop3d.o tls.o $(SERVICE) \
	 libimap.a $(DEPLIBS) $(LIBS) $(LIB_WRAP)

pop3proxyd: pop3proxyd.o tls.o libimap.a $(DEPLIBS) $(SERVICE)
	$(CC) $(LDFLAGS) -o pop3proxyd pop3proxyd.o tls.o $(SERVICE) \
	 libimap.a $(DEPLIBS) $(LIBS) $(LIB_WRAP)

arbitron: arbitron.o libimap.a $(DEPLIBS)
	$(CC) $(LDFLAGS) -o arbitron arbitron.o libimap.a $(DEPLIBS) $(LIBS)

populateacap: populateacap.o libimap.a $(DEPLIBS)
	$(CC) $(LDFLAGS) -o populateacap populateacap.o libimap.a $(DEPLIBS) $(LIBS)

fud: fud.o libimap.a $(DEPLIBS)
	$(CC) $(LDFLAGS) -o fud fud.o libimap.a $(DEPLIBS) $(LIBS)

mbpath: mbpath.o libimap.a $(DEPLIBS)
	$(CC) $(LDFLAGS) -o mbpath mbpath.o libimap.a $(DEPLIBS) $(LIBS)

ipurge: ipurge.o libimap.a $(DEPLIBS)
	$(CC) $(LDFLAGS) -o ipurge ipurge.o libimap.a $(DEPLIBS) $(LIBS)

cyrdump: cyrdump.o index.o libimap.a $(DEPLIBS)
	$(CC) $(LDFLAGS) -o cyrdump cyrdump.o index.o libimap.a $(DEPLIBS) $(LIBS)

reconstruct: reconstruct.o libimap.a $(DEPLIBS)
	$(CC) $(LDFLAGS) -o \
	 reconstruct reconstruct.o libimap.a $(DEPLIBS) $(LIBS)

quota: quota.o libimap.a $(DEPLIBS)
	$(CC) $(LDFLAGS) -o quota quota.o libimap.a $(DEPLIBS) $(LIBS)

krbck: krbck.o libimap.a $(DEPLIBS)
	$(CC) $(LDFLAGS) -o krbck krbck.o $(DEPLIBS) $(LIBS)

libimap.a: $(LOBJS)
	rm -f libimap.a
	ar cr libimap.a $(LOBJS)
	$(RANLIB) libimap.a

imap_err.h imap_err.c: imap_err.et
	$(COMPILE_ET) $(srcdir)/imap_err.et

clean:
	rm -f *.o *.a Makefile.bak imap_err.c imap_err.h makedepend.log \
	$(PROGS) $(SUIDPROGS) pushstats.[ch]

# feedcyrus can't be in the config line because it's generated by configure,
# and we can't make it without running configure again.
distclean: clean
	rm -f Makefile feedcyrus

depend: imap_err.h
	${MAKEDEPEND} $(CPPFLAGS) $(DEFS) $(CFLAGS) *.c $(srcdir)/*.c 1>makedepend.log 2>&1

# DO NOT DELETE THIS LINE -- make depend depends on it.
