PROGRAM=	mailbox
#
# ZMailer local delivery Transport Agent makefile
#
srcdir = @srcdir@
VPATH = @srcdir@
@SET_MAKE@

SHELL=		/bin/sh
CC=		@CC@
COPTS=		@CFLAGS@
CPPFLAGS=	@CPPFLAGS@
CPPDEP=		@CPPDEP@
TOPDIR=		../..
MAILBIN=	$(prefix)@MAILBIN@
DEFS=		@DEFS@
INSTALL=	@INSTALL@
MAILBOX_INCL=	@GENINCL@
MAILBOX_LIB=	@GENLIB@ @GETPWLIB@ @LIBMAIL@ @LIBRESOLV@ @LIBSOCKET@ $(LIBMALLOC)

# Compile & install time: 'make privatembox="private/"'
privatembox=	@PRIVATEMBOX@

#
SOURCE=		mailbox.c
INCL=		-I$(srcdir)/$(TOPDIR)/include -I$(TOPDIR)/include -I$(TOPDIR)
CFLAGS=		$(COPTS) $(CPPFLAGS) $(DEFS) $(INCL) $(MAILBOX_INCL)
LIBMALLOC=	@LIBMALLOC@
LIBMALLOCDEB=	$(TOPDIR)/libs/libmalloc_d.a
LIB=		-L$(TOPDIR)/libs -lta -lzm -lzc -lsfio
LIBDEB=		$(TOPDIR)/libs/libtag
LINTLIB=	../libta/llib-llibta.ln

# defines related to 'mailbox' and 'lock':
# -DBIFF         - tell biff about mail
# -DRBIFF        - tell remote comsats about mail
# -DRBIFF_ALWAYS - tell even if user has no  "~/.rbiff" file
# -DUSE_NFSMBOX  - do remote locking of mail spool files mounted via NFS
#	see ../../support/{nfslock,rlockd} for more about this
MAILBOXDEFS=	-DBIFF -DRBIFF -DRBIFF_ALWAYS # -DUSE_NFSMBOX

HDRS=		$(srcdir)/$(TOPDIR)/include/sieve.h

all:	mailbox-a mboxpath-a # in.rlockd

mailbox-a:	$(LIBDEB) mailbox
mboxpath-a:	$(LIBDEB) mboxpath

mailbox:	mailbox.o version.o lock.o sieve.o fmtmbox.o $(LIBDEB)
	$(CC) $(CFLAGS) -o $@ mailbox.o version.o lock.o sieve.o fmtmbox.o $(LIB) $(MAILBOX_LIB)

mboxpath:	mboxpath.o version.o fmtmbox.o $(LIBDEB)
	$(CC) $(CFLAGS) -o $@ mboxpath.o version.o fmtmbox.o $(LIB) $(MAILBOX_LIB)

mailbox.o: $(srcdir)/mailbox.c $(HDRS)
	$(CC) $(CFLAGS) $(MAILBOXDEFS) -c $(srcdir)/mailbox.c

sieve.o:	$(srcdir)/$(privatembox)sieve.c $(HDRS)
	$(CC) $(CFLAGS) $(MAILBOXDEFS) -c $(srcdir)/$(privatembox)sieve.c

fmtmbox.o:	$(srcdir)/fmtmbox.c $(HDRS)
	$(CC) $(CFLAGS) $(MAILBOXDEFS) -c $(srcdir)/fmtmbox.c

mboxpath.o:	$(srcdir)/mboxpath.c
	$(CC) $(CFLAGS) $(MAILBOXDEFS) -c $(srcdir)/mboxpath.c

version.c:	mailbox.o $(TOPDIR)/Makefile
	@$(MAKE) $(MFLAGS) -f $(TOPDIR)/Makefile $@

lock.o: $(srcdir)/lock.c
	$(CC) $(CFLAGS) $(MAILBOXDEFS) -c $(srcdir)/lock.c

install:	mailbox mboxpath
	$(INSTALL) -m 0755 mailbox $(MAILBIN)/ta/mailbox.x
	mv $(MAILBIN)/ta/mailbox.x $(MAILBIN)/ta/mailbox
	$(INSTALL) -m 0755 mboxpath $(MAILBIN)/mboxpath.x
	mv $(MAILBIN)/mboxpath.x $(MAILBIN)/mboxpath

clean:
	-rm -f mailbox in.rlockd *.o *.out make.log *~ mboxpath
distclean: clean
	-rm -f Makefile

lint:	$(LINTLIB)
	lint $(DEFS) $(MAILBOXDEFS) $(INCL) $(LINTLIB) mailbox.c lock.c

../libta/llib-llibta.ln:
	cd ../libta ; $(MAKE) $(MFLAGS) lintlib

$(TOPDIR)/libs/libtag:
	cd $(TOPDIR)/libs ; $(MAKE) $(MFLAGS) libtag

../libta/libta.a-a:
	cd ../libta ; $(MAKE) $(MFLAGS)
$(TOPDIR)/libs/libta.a:
	cd $(TOPDIR)/libs ; $(MAKE) $(MFLAGS)

$(TOPDIR)/lib/libzm.a-a:
	cd $(TOPDIR)/lib ; $(MAKE) $(MFLAGS)
$(TOPDIR)/libs/libzm.a:
	cd $(TOPDIR)/libs ; $(MAKE) $(MFLAGS)

$(TOPDIR)/libc/libzc.a-a:
	cd $(TOPDIR)/libc ; $(MAKE) $(MFLAGS)
$(TOPDIR)/libs/libzc.a:
	cd $(TOPDIR)/libs ; $(MAKE) $(MFLAGS)

$(TOPDIR)/libs/libmalloc_d.a:
	cd $(TOPDIR)/libmalloc ; $(MAKE) $(MFLAGS)

depend:
	$(TOPDIR)/bin/mklibdep $(CFLAGS) $(SOURCE)

# DO NOT DELETE THIS LINE -- mkdep uses it.
# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY.

# IF YOU PUT ANYTHING HERE IT WILL GO AWAY
