#
# Makefile for the backup system.  Since it isn't wise (or possible)
# to run setuid or setgid perl scripts, we use a C wrapper program
# that is setgid which runs perl on the script.  So installation
# consists of putting a bunch of scripts somewhere and in putting the
# compiled wrappers somewhere.  
#
# This Makefile provides several entries:
#	all		compiles the wrappers
#	install		copies the wrappers and scripts as needed to
#			the suitable places.
#	clean		removes junk from this directory
#	print		prints everything
#
# There are several variables here at the beginning that you might
# want to hack on.
#

#
# PERL is the pathname of perl as installed on your systems.
#
PERL =	/usr/local/bin/dperl

#
# SDIR is the directory in which all scripts should be placed.
#
SDIR =	/usr/local/utils/nbu/scripts

#
# BDIR is the directory in which all binaries should be placed.
# MDIR is where the man pages are put.
#
BDIR =	/usr/local/utils/nbu
MDIR = /usr/local/man

#
# PRINTER is the name of the printer to print things to.  Note that
# the print: entry below uses 'enscript' and 'up' - you may need to
# change it to suit your environment (or get enscript and up!)
#
PRINTER =	np

#
# BACKUP is the name of the group that owns and can access the backup
# database files.  The backup programs run setgid to backup in the hopes
# that they will be able to write them.
#
BACKUP =	backup

#
# You might need to change these also...
#
RM =	/bin/rm
LN =	/bin/ln
CC =	cc
CP =	/bin/cp
CHGRP =	/bin/chgrp
CHMOD =	/bin/chmod
#
# What strrchr to use - strrchr or rindex.
#
STRRCHR = strrchr			# Suns, Encore, HP, BBN Butterfly
#STRRCHR = rindex			# Pyramid
#
# What setreuid to use - define SETRESUID if this system uses it rather than
# setreuid.
#
#SETRESUID = 				# Sun, Encore, Pyramid, Butterfly
#SETRESUID = -DSETRESUID		# HP
SETRESUID = -DSETUID			# Solaris

#
#----------------------------------------------------------------------
# The rest of the stuff shouldn't be changed in general.
#

#
# list of the executable programs we will generate from the wrapper.
#
EXEC =				\
	add-tape		\
	all-backups		\
	backup-dump		\
	backup-null		\
	backup-report		\
	backup-gtar		\
	check-backups		\
	clean-db		\
	db-edit			\
	do-backups		\
	getback			\
	getdata			\
	list-backups		\
	move-tape		\
	offsite			\
	pmt			\
	restore-dump		\
	restore-gtar		\
	reuse			\
	run-clean-db		\
	show			\
	single-begin		\
	single-end		\
	sybase-helper		\
	tape-check		\
	unlock-dumpdates

#
# list of the Perl scripts that are used in the backup system 
#
SCRIPTS = 			\
	add-tape.perl		\
	all-backups.perl	\
	backup-dump.perl	\
	backup-null.perl	\
	backup-report.perl	\
	backup-gtar.perl	\
	backuplib.perl		\
	check-backups.perl	\
	clean-db.perl		\
	db-edit.perl		\
	do-backups.perl		\
	getback.perl		\
	getdata.perl		\
	lib-db.perl		\
	lib-deadman.perl	\
	lib-lock.perl		\
	lib-log.perl		\
	lib-misc.perl		\
	lib-unctime.perl	\
	lib-tape.perl		\
	list-backups.perl	\
	move-tape.perl		\
	offsite.perl		\
	pmt.perl		\
	restore-dump.perl	\
	restore-gtar.perl	\
	reuse.perl		\
	run-clean-db.perl	\
	show.perl		\
	single-begin.perl	\
	single-end.perl		\
	sybase-helper.perl	\
	tape-check.perl		\
	unlock-dumpdates.perl

#
# other miscellaneous stuff
#
OTHER =	global.defs local.defs

#
# Man pages
#
MAN8 =	add-tape.8		\
	all-backups.8		\
	backup-report.8		\
	check-backups.8		\
	clean-db.8		\
	db-edit.8		\
	do-backups.8		\
	getback.8		\
	getdata.8		\
	list-backups.8		\
	move-tape.8		\
	offsite.8		\
	pmt.8			\
	reuse.8			\
	run-clean-db.8		\
	show.8			\
	single-begin.8		\
	single-end.8		\
	unlock-dumpdates.8

MAN5 =	backup.config.5		\
	backups.5

#
#----------------------------------------------------------------------
# The entry points...
#
# all: compiles everything, places it in the current directory.
#
all:	wrapper

#
# For all the things that use the wrapper, here's how to make them...
#	-DSETSAME tells wrapper to set the uid = euid and gid = egid
#	-DPERL is the path to perl
#	-DSCRIPT is the path to the script directory $SDIR
#
wrapper:	wrapper.c
	$(CC) -o wrapper -DSETSAME -DPERL=\"$(PERL)\" -DSCRIPT=\"$(SDIR)\" -DSTRRCHR=$(STRRCHR) $(SETRESUID) wrapper.c

#
# install: copy to SDIR and BDIR
#
install:	install-scripts install-other install-progs install-links

install-scripts:	maketime.scripts

install-progs:		maketime.progs

install-other:		maketime.other

install-links:		maketime.links

install-man:		maketime.man

maketime.other:		$(OTHER)
	@for NAME in $? ; \
		do echo Installing $$NAME ; \
		$(CP) $$NAME $(SDIR) ; \
		$(CHMOD) 0644 $(SDIR)/$$NAME ; \
	done
	-touch maketime.other

maketime.scripts:	$(SCRIPTS)
	@for NAME in $? ; \
		do echo Installing $$NAME ; \
		$(CP) $$NAME $(SDIR) ; \
		$(CHMOD) 0644 $(SDIR)/$$NAME ; \
	done
	-touch maketime.scripts

maketime.progs:		wrapper
	@for NAME in $? ; \
		do echo Installing $$NAME ; \
		$(CP) $$NAME $(BDIR) ; \
		$(CHGRP) $(BACKUP) $(BDIR)/$$NAME ; \
		$(CHMOD) g+s $(BDIR)/$$NAME ; \
	done
	-touch maketime.progs

maketime.links:			
	@for NAME in $(EXEC) ; \
		do echo Remake $$NAME link ; \
		$(RM) -f $(BDIR)/$$NAME ; \
		$(LN) -s $(BDIR)/wrapper $(BDIR)/$$NAME ; \
	done
	-touch maketime.links

maketime.man:		
	@for NAME in $(MAN8) ; \
		do echo Install $$NAME ; \
		$(CP) ../man/$$NAME $(MDIR)/man8 ; \
	done
	@for NAME in $(MAN5) ; \
		do echo Install $$NAME ; \
		$(CP) ../man/$$NAME $(MDIR)/man5 ; \
	done
	-touch maketime.man
	
#
# clean: clean up this messy directory
#
clean:
	$(RM) -i -f *~ *.o wrapper *.unknown maketime.*

#
# syntax: check perl syntax
#
syntax:
	@for NAME in $(SCRIPTS) global.defs local.defs ; \
		do perl -c $$NAME ; \
	done

#
# variables: check for unknown variables
#
variables:
	-@for NAME in $(SCRIPTS) ; \
		do echo $$NAME ; \
		NNAME=`basename $$NAME .perl` ; \
		perl -w -c $$NAME > $$NNAME.unknown 2>&1 ; \
	done

#
# print: print everything in a nice way
#
print:
	enscript -G -p - $(SCRIPTS) $(OTHER) wrapper.c | up -n 4up | lpr -P $(PRINTER)

