PROGRAM=	smtpserver
#
# ZMailer SMTP server 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@
SMTPSERVER_INCL= @GENINCL@ @INCLRESOLV@ @INCLWRAP@ @INCLWHOSON@ @OPENSSLINCL@
SMTPSERVER_LIB=	 @GENLIB@ @GETPWLIB@ @LIBLOCALDBMS@ @LIBWRAP@ @LIBWHOSON@ @LIBRESOLV@ @OPENSSLLIB@ @AUTHLIB@ @LIBSOCKET@
#  old vestiges: @LIBLOADAVER@
#
#   Above the  LIBSOCKET (for SysVR4) must be last
#
INCL=		-I$(srcdir)/$(TOPDIR)/include -I$(TOPDIR)/include -I$(TOPDIR)
CFLAGS=		$(COPTS) $(CPPFLAGS) $(DEFS) $(INCL) $(SMTPSERVER_INCL) 
LIBMALLOC=	@LIBMALLOC@
LIBMALLOCDEB=	$(TOPDIR)/libmalloc/libmalloc_d.a-a
LIB=		-L$(TOPDIR)/libs -lzm -lzc -lident -lta $(LIBMALLOC)
LIBDEB=		$(TOPDIR)/libs/libtag $(TOPDIR)/libs/libta.a \
		$(TOPDIR)/libs/libzm.a $(TOPDIR)/libs/libzc.a \
		$(TOPDIR)/libs/libident.a $(TOPDIR)/include/sfio.h
LINTLIB=	$(TOPDIR)/lib/llib-llibz.ln $(TOPDIR)/libc/llib-llibzc.ln $(TOPDIR)/libident/llib-llibident.ln
OBJS=		$(PROGRAM).o rfc821scn.o debugreport.o fdstatfs.o \
		policytest.o cfgread.o smtpdata.o smtpcmds.o smtphelp.o \
		smtprouter.o smtpchild.o mxverify.o contentpolicy.o     \
		smtpauth.o zpwmatch.o smtptls.o zpwmatch-pipe.o smtpetrn.o \
		wantconn.o
# loadaver.o

SOURCE=		$(PROGRAM).c rfc821scn.c debugreport.c fdstatfs.c \
		policytest.c  cfgread.c smtpdata.c smtpcmds.c smtphelp.c \
		smtprouter.c smtpchild.c mxverify.c contentpolicy.c	 \
		smtpauth.c zpwmatch.c smtptls.c zpwmatch-pipe.c smtpetrn.c \
		wantconn.c
# loadaver.c

# Compile & install time: 'make privateauth="private/"'
privateauth=	@PRIVATEAUTH@


all: $(PROGRAM)

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

smtpserver.o: $(srcdir)/smtpserver.c $(srcdir)/smtpserver.h	\
		$(srcdir)/policytest.h
cfgread.o:    $(srcdir)/cfgread.c $(srcdir)/smtpserver.h
smtpcmds.o:   $(srcdir)/smtpcmds.c $(srcdir)/smtpserver.h	\
		$(srcdir)/policytest.h
smtpauth.o:   $(srcdir)/smtpauth.c $(srcdir)/smtpserver.h
smtpdata.o:   $(srcdir)/smtpdata.c $(srcdir)/smtpserver.h
smtpetrn.o:   $(srcdir)/smtpetrn.c $(srcdir)/smtpserver.h
smtphelp.o:   $(srcdir)/smtphelp.c $(srcdir)/smtpserver.h
smtprouter.o: $(srcdir)/smtprouter.c $(srcdir)/smtpserver.h
policytest.o:  $(srcdir)/policytest.c $(srcdir)/policytest.h # ignored: $(srcdir)/smtpserver.h
contentpolicy.o: $(srcdir)/contentpolicy.c $(srcdir)/policytest.h # ignored: $(srcdir)/smtpserver.h

zpwmatch.o:	$(srcdir)/$(privateauth)zpwmatch.c
	$(CC) $(CFLAGS) -c $(srcdir)/$(privateauth)zpwmatch.c

$(PROGRAM):	$(LIBDEB) $(OBJS)
	$(MAKE) $(MFLAGS) version.o
	$(CC) $(CFLAGS) -o $@ $(OBJS) version.o $(LIB) $(SMTPSERVER_LIB)

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


install:	$(PROGRAM)
	$(INSTALL) -m 0755 $(PROGRAM) $(MAILBIN)/$(PROGRAM).x
	mv $(MAILBIN)/$(PROGRAM).x $(MAILBIN)/$(PROGRAM)

clean:
	-rm -f $(PROGRAM) make.log *.o *.out *~ fdstatfs-test

distclean: clean
	-rm -f Makefile

fdstatfs-test: fdstatfs-test.o fdstatfs.o
	$(CC) $(CFLAGS) -o $@ fdstatfs-test.o fdstatfs.o

lint:	$(LINTLIB)
	lint $(DEFS) $(INCL) $(LINTLIB) $(PROGRAM).c

depend:	$(SOURCE)
	CPPDEP="${CPPDEP}" $(TOPDIR)/bin/mkdep -f Makefile $(CFLAGS) $(SOURCE)

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

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

$(TOPDIR)/libc/llib-llibzc.ln:
	cd $(TOPDIR)/libc ; $(MAKE) $(MFLAGS) lintlib

$(TOPDIR)/lib/llib-llibz.ln:
	cd $(TOPDIR)/lib ; $(MAKE) $(MFLAGS) lintlib

$(TOPDIR)/libident/llib-llibident.ln:
	cd $(TOPDIR)/libident ; $(MAKE) $(MFLAGS) lintlib

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