# -*- makefile -*-
#
# $Id: Makefile,v 1.16 1995/05/11 12:52:10 brister Exp brister $
#

#
# USER LEVEL CONFIGURATION SECTION.
#

# top of the installation tree This is all you need to change to get
# sends to install and run in a different directory naming scheme.
TOP_DIR		= /usr/local/sends

# to go on '#!' lines
PERL		= /usr/bin/perl

#
# BELOW HERE SHOULDN'T NEED CHANGING
#

INSTALL		= install -c
RM		= rm -f
CAT		= cat
ECHO		= echo
CP		= cp -p
MKDIR		= mkdir -p
CHMOD		= chmod
SED		= sed
SHAR		= shar

# The compression method and the extension it adds to a file.
COMPRESS	= gzip
ZEXT		= gz
#COMPRESS	= compress
#ZEXT		= Z


# must have the 'f' flag. Check out the 'tar' rule for use.
TAR		= tar cf

# scripts require'd by other scripts
LIBS		= sends-config.pl sends-init.pl sendsConfigLib.pl

SRC		= mk-users.pl mk-zones.pl scan-ftp.pl do-users.pl do-hosts.pl
OBJS		= mk-users mk-zones scan-ftp do-users do-hosts
MANFILES	= man/sends.conf.5 man/sends.control.5 man/do-hosts.8 \
		  man/do-users.8 man/sends.hosts.5 man/sends.users.5
PAPERS		= papers/paper.ps papers/internals.ps papers/internals.lout

CRONSRC		= cronrun.often.tmpl
CRONJOBS	= cronrun.often

# files we give away.
DISTFILES	= Makefile README MANIFEST INSTALL sends.conf $(SRC) $(LIBS) $(CRONSRC)

# don't change these...
BIN_DIR		= $(TOP_DIR)/bin
LIB_DIR		= $(TOP_DIR)/lib
DATA_DIR	= $(TOP_DIR)/data

.SUFFIXES: .pl .tmpl

.pl:
	$(RM) $@
	$(SED)  -e '1s;/usr/bin/perl;$(PERL);' -e 's;"/usr/local/sends";"$(TOP_DIR)";' < $< > $@
	$(CHMOD) a-w,a+x $@

.tmpl: 
	$(RM) $@
	$(SED) -e 's;^SENDS_ROOT=sends_root_dir$$;SENDS_ROOT=$(TOP_DIR);' < $< > $@
	$(CHMOD) a-w,a+x $@



all: objs cronjobs $(LIBS)

objs: $(OBJS)

cronjobs: $(CRONJOBS)

install: all
	if [ ! -d $(BIN_DIR) ]; then $(MKDIR) $(BIN_DIR) ;fi 
	if [ ! -d $(LIB_DIR) ]; then $(MKDIR) $(LIB_DIR) ;fi
	$(INSTALL) -m 555 $(CRONJOBS) $(OBJS) $(BIN_DIR) 
	$(INSTALL) -m 444 $(LIBS) $(LIB_DIR) 

install-conf::
	if [ ! -d $(DATA_DIR) ]; then $(MKDIR) $(DATA_DIR) ;fi
	$(INSTALL) -m 444 sends.conf $(DATA_DIR)


# Directory to create in generating the tar file.
DIST_DIR	= sends-1.0
SAMPLE_DATA	= sample-data
TARFILE		= $(DIST_DIR).tar
ZIPPEDTAR	= $(TARFILE).$(ZEXT)
SHARFILE	= $(DIST_DIR).shar

$(DIST_DIR): $(DISTFILES) $(MANFILES) $(PAPERS)
	$(MKDIR) $(DIST_DIR)/src $(DIST_DIR)/man 
	$(MKDIR) $(DIST_DIR)/papers $(DIST_DIR)/sample-data
	$(CP) $(DISTFILES) $(DIST_DIR)/src
	$(CP) $(MANFILES) $(DIST_DIR)/man
	$(CP) $(PAPERS) $(DIST_DIR)/papers
	$(CP) -r $(SAMPLE_DATA) $(DIST_DIR)


shar: $(DIST_DIR)
	$(SHAR) $(DIST_DIR) > $(SHARFILE)


tar: $(DIST_DIR)
	$(TAR) $(TARFILE) $(DIST_DIR)
	$(COMPRESS) $(TARFILE)
	$(RM) -r $(DIST_DIR)


clean::
	$(RM) $(OBJS) $(CRONJOBS) *~ \#* $(TARFILE) $(ZIPPEDTAR) $(SHARFILE)
	$(RM) -r $(DIST_DIR)
