#
# ZMailer compatible programs that replace standard UNIX distribution programs
#
@SET_MAKE@
CC=		@CC@
DEFS=		@DEFS@
COPTS=		@CFLAGS@
CPPDEP=		@CPPDEP@
prefix=		@prefix@
exec_prefix=	@exec_prefix@
MAILBIN=	@MAILBIN@
RMAIL_INCL=	
RMAIL_LIB=	@LIBRESOLV@ @LIBSOCKET@
INSTALL=	@INSTALL@
TOPDIR=		../..
RMAILPATH=	@RMAILPATH@
LN_S=		"@LN_S@"
#
INCL=   -I$(TOPDIR)/include -I$(TOPDIR)
LIB=    -L$(TOPDIR)/libs -lz -lzc
LIBDEB= $(TOPDIR)/libs/libtag
CFLAGS= $(COPTS) $(DEFS) $(INCL) $(RMAIL_INCL)
#BIN=    /bin
SOURCE=	rmail.c $(TOPDIR)/lib/linebuffer.c

rmail-a: $(LIBDEB) rmail

rmail:	rmail.o linebuffer.o version.o $(LIBDEB)
	$(CC) $(CFLAGS) -o $@ rmail.o linebuffer.o version.o $(LIB) $(RMAIL_LIB)

version.c: rmail.c
	@make -f $(TOPDIR)/Makefile $@

linebuffer.o: $(TOPDIR)/lib/linebuffer.c
	$(CC) $(CFLAGS) -DZ_IO_H -c $(TOPDIR)/lib/linebuffer.c

# 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) rmail
	$(INSTALL) -m 0755 rmail $(MAILBIN)/rmail.x ; \
	mv $(MAILBIN)/rmail.x $(MAILBIN)/rmail
	@if [ $(LN_S) = "ln -s" ]; then				\
	    if [ -h $(RMAILPATH) ]; then			\
		rm -f $(RMAILPATH) ;				\
		ln -s $(MAILBIN)/rmail $(RMAILPATH) ;		\
	    else						\
		mv -f $(RMAILPATH) $(RMAILPATH).orig ;		\
		ln -s $(MAILBIN)/rmail $(RMAILPATH) ;		\
	    fi ;						\
	else							\
	    echo "********************************************************" ; \
	    echo "** $(RMAILPATH) needs to be updated to be" ;	  \
	    echo "**   a symlink (if possible) to $(MAILBIN)/rmail" ;  \
	    echo "********************************************************" ; \
	fi

old-install: $(LIBDEB) rmail
	@if ls -ld $(BIN)/rmail | egrep -e '->' > /dev/null ; then \
		echo $(INSTALL) -m 0755 rmail $(BIN)/rmail ; \
		$(INSTALL) -m 0755 rmail $(BIN)/rmail ; \
	else \
		if test ! -f $(BIN)/rmail.bak; then \
			echo mv -f $(BIN)/rmail $(BIN)/rmail.bak ; \
			mv -f $(BIN)/rmail $(BIN)/rmail.bak ; \
		fi ; \
		echo $(INSTALL) -m 0755 rmail $(BIN)/rmail ; \
		$(INSTALL) -m 0755 rmail $(BIN)/rmail ; \
	fi

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

lint:	$(TOPDIR)/libc/llib-llibzc.ln $(TOPDIR)/lib/llib-llibz.ln
	lint -u $(INCL) $(RMAIL_INCL) $(TOPDIR)/lib/llib-llibz.ln $(TOPDIR)/libc/llib-llibzc.ln rmail.c

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

$(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/libz.a-a:
	cd $(TOPDIR)/lib ; $(MAKE) $(MFLAGS)
$(TOPDIR)/lib/libz.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.
