#
#  Makefile(.in) for ZMailer's vacation program
#

srcdir = @srcdir@
VPATH = @srcdir@
@SET_MAKE@

SHELL=		/bin/sh
CC=		@CC@
COPTS=		@CFLAGS@
CPPFLAGS=	@CPPFLAGS@
CPPDEP=		@CPPDEP@
MAILBIN=	$(prefix)@MAILBIN@
MAILBIN_=	@MAILBIN@
MAILSHARE=	$(prefix)@MAILSHARE@
MANDIR=		$(prefix)@MANDIR@
INSTALL=	@INSTALL@
TOPDIR=		../..
LIBS=		@GENLIB@ -L$(TOPDIR)/libs -lzm -lzc @GETPWLIB@ @LIBRESOLV@ @LIBSOCKET@
LN_S=		"@LN_S@"
MKDIR=		@MKDIR@

VMSGDEF=	@MAILSHARE@/vacation.msg
DEFS=		@DEFS@ -DVMSGDEF='"$(VMSGDEF)"'
VACATIONPATH=	$(prefix)@VACATIONPATH@

INCL=		-I$(srcdir)/$(TOPDIR)/include -I$(TOPDIR)/include -I$(TOPDIR) @GENINCL@
DBMLIB=		@LIBLOCALDBMS@
CONVTIME= convtime.o
MANEXT=1

COPTS=		@CFLAGS@
CFLAGS=		$(COPTS) $(CPPFLAGS) $(DEFS) -DZMAILER $(INCL) @GENINCL@

SOURCE=		vacation.c convtime.c

all: vacation

vacation: vacation.o $(CONVTIME)
	rm -f $@
	$(CC) $(CFLAGS) -o $@ vacation.o $(CONVTIME) $(DBMLIB) $(LIBS)

vacation.o: $(srcdir)/vacation.c
	rm -f $@
	$(CC) $(CFLAGS) $(CCONFIG) -c $(srcdir)/vacation.c

clean:
	rm -f *.o *~ \#* vacation

distclean: clean
	rm -f Makefile vacation.sh $(TOPDIR)/man/vacation.1

install: vacation-inst
	-VACATIONDIR=`echo $(VACATIONPATH) | sed -e 's!/[^/]*$$!!'` ;	\
	if [ ! -f "$${VACATIONDIR}" -a ! -h "$${VACATIONDIR}" -a 	\
	     ! -d "$${VACATIONDIR}" ] ; then				\
		mkdir -p -m 755 "$${VACATIONDIR}" ; fi
	@if [ $(LN_S) = "ln -s" -a					\
	     "$(VACATIONPATH)" != "$(MAILBIN)/vacation.sh" ]; then	\
	    if [ -h "$(VACATIONPATH)" ]; then				\
		test -f "$(VACATIONPATH)" &&				\
			rm -f "$(VACATIONPATH)" ;			\
		echo "ln -s $(MAILBIN_)/vacation.sh $(VACATIONPATH)" ;	\
		ln -s $(MAILBIN_)/vacation.sh $(VACATIONPATH) ||	\
			echo "Failed! rc=$$?" ;				\
	    else							\
		test -f "$(VACATIONPATH)" &&				\
			mv -f $(VACATIONPATH) $(VACATIONPATH).orig;	\
		echo "ln -s $(MAILBIN_)/vacation.sh $(VACATIONPATH)";	\
		ln -s $(MAILBIN_)/vacation.sh $(VACATIONPATH) ||	\
			echo "Failed! rc=$$?" ;				\
	    fi ;							\
	else								\
	    echo "********************************************************" ; \
	    echo "** $(VACATIONPATH) needs to be updated to be" ;  	      \
	    echo "**   a symlink (if possible) to $(MAILBIN)/vacation.sh" ;  \
	    echo "********************************************************" ; \
	fi

vacation-inst: vacation
	@$(INSTALL) -m 755 vacation.sh $(MAILBIN)/vacation.sh
	-@rm -f $(MAILBIN)/vacation
	@cd $(MAILBIN) ; ln -s vacation.sh vacation
	@$(INSTALL) -m 755 vacation $(MAILBIN)/vacation.exe
	@if [ ! -f $(prefix)$(VMSGDEF) ] ; then				\
		$(INSTALL) -m 644 $(srcdir)/vacation.msg $(prefix)$(VMSGDEF); \
	else								\
		echo "** File $(prefix)$(VMSGDEF) already installed" ;	\
	fi
	@echo "** Add a symlink from somewhere in user paths to $(MAILBIN)/vacation"
	@echo "** to finish off the installation;  Also the location of the man-page"
	@echo "** might need reconsideration (now at $(prefix)$(MANDIR)/man$(MANEXT))"

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