#
# ZMailer compatible programs that replace standard UNIX distribution programs
#
srcdir = @srcdir@
VPATH = @srcdir@
@SET_MAKE@
SHELL=		/bin/sh
CC=		@CC@
COPTS=		@CFLAGS@
CPPFLAGS=	@CPPFLAGS@
DEFS=		@DEFS@
SENDMAIL_INCL=	@GENINCL@
SENDMAIL_LIB=	@LIBRESOLV@ @LIBSOCKET@
TOPDIR=		../..
MAILBIN=	@MAILBIN@
INSTALL=	@INSTALL@
LN_S=		"@LN_S@"
MKDIR=		@MKDIR@
#
INCL=           -I$(srcdir)/$(TOPDIR)/include -I$(TOPDIR)/include -I$(TOPDIR)
LIB=            -L$(TOPDIR)/libs -lzm -lzc
LIBDEB=         $(TOPDIR)/libs/libtag
CFLAGS=         $(COPTS) $(CPPFLAGS) $(DEFS) $(INCL) $(SENDMAIL_INCL)
SENDMAILPATH=	$(prefix)@SENDMAILPATH@

SOURCE=		sendmail.c

sendmail-a:	$(LIBDEB) sendmail

sendmail:	sendmail.o version.o $(LIBDEB)
	$(CC) $(CFLAGS) -o $@ sendmail.o version.o $(LIB) $(SENDMAIL_LIB)

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

sendmail.o: $(srcdir)/sendmail.c

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

# At install we assume:  IF we can do symlinks, then if
# the target location has a symlink, we replace it.  If
# the target location has something else, we rename it,
# and place a symlink there.  If the target location has
# nothing, we place a symlink (if we can).. else we just
# comment (loudly!) to the user --- who on earth can have
# any modern system without symlinks ?
install: $(LIBDEB) sendmail
	@sdir=`echo $(SENDMAILPATH)|sed -e 's!/[^/]*$$!!'`; $(MKDIR) -p $$sdir;echo "  sdir = $$sdir"
	@$(INSTALL) -m 0755 sendmail $(prefix)$(MAILBIN)/sendmail.x ; \
	mv $(prefix)$(MAILBIN)/sendmail.x $(prefix)$(MAILBIN)/sendmail
	@if [ $(LN_S) = "ln -s" -a				\
	     "$(SENDMAILPATH)" != "$(MAILBIN)/sendmail" ]; then \
	    if [ -h $(SENDMAILPATH) ]; then			\
		test -f $(SENDMAILPATH) &&			\
			rm -f $(SENDMAILPATH) ;			\
		echo "ln -s $(MAILBIN)/sendmail $(SENDMAILPATH)" ; \
		ln -s $(MAILBIN)/sendmail $(SENDMAILPATH) ||	\
			echo "Failed! rc=$?" ;			\
	    else						\
		test -f $(SENDMAILPATH) &&			\
			mv -f $(SENDMAILPATH) $(SENDMAILPATH).orig;  \
		echo "ln -s $(MAILBIN)/sendmail $(SENDMAILPATH)"; \
		ln -s $(MAILBIN)/sendmail $(SENDMAILPATH) ||	\
			echo "Failed! rc=$?" ;			\
	    fi ;						\
	else							\
	    echo "********************************************************" ; \
	    echo "** $(SENDMAILPATH) needs to be updated to be" ;  	\
	    echo "**   a symlink (if possible) to $(MAILBIN)/sendmail" ;    \
	    echo "********************************************************" ; \
	fi

clean:
	-rm -f sendmail make.log *.o *.out *~
distclean: clean
	-rm -f Makefile

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

lint:	$(TOPDIR)/libc/llib-llibzc.ln $(TOPDIR)/lib/llib-llibz.ln
	lint $(INCL) $(SENDMAIL_INCL) $(TOPDIR)/libc/llib-llibzc.ln sendmail.c

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

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

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

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


depend:
	CPPDEP="${CPPDEP}" $(TOPDIR)/bin/mklibdep $(CFLAGS) $(SOURCE)

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