#
# audit suite
#
# entry points:
#	make all
#		to make everything
#	make clean
#		to delete .o files
#	make clobber
#		to delete .o files, libraries, and executables
#	make install
#		to make and then install everything
#	make man
#		to make the manual pages
#	make print_install_doc
#		to typeset the paper "The RIACS Intelligent
#		Auditing and Categorizing System"
#	make print_man
#		to print the manual pages
#	make version
#		to increment the version number
#	make <manual_page>
#		to make each manual page
#	make <program_name>
#		to make each program
#
#  Author:
#	Matt Bishop
#	Research Institute for Advanced Computer Science
#	NASA Ames Research Center
#	Moffett Field, CA  94035
#
#	mab@riacs.edu, ...!{ihnp4!ames,decvax!decwrl}!riacs!mab
#
#  Copyright:
#	(c) 1986 by the Research Institute for Advanced Computer
#		 Science and Matt Bishop
#
# we want everything optimized here
# CFLAGS: add -DCRAY for compiling on the Cray
#	  add -DNFS for compiling on an NFS-based system
#	  undefine -DALONE if you have the deszip package and want to use it
# DESLIB: define this to be the deszip library if you want to use it
# VERSION: set to -v to go from version n to version n+1 (big change)
#	   set to -r to go from release n to release n+1 (small change)
CFLAGS	= -O -DBSD4 -DALONE
DESLIB	=
VERSION	=
# parameters; these will change from system to system
# ROOTDIR is the root of the audit file tree
# AUDITOR is who the audit results get sent to
# CAT is the system cat(1) program
# DESTBIN is the directory where the auditing programs go
# DESTMAN is the directory where the manual pages go
# DESTSRC is the directory where the remote audit program sources go
# ECHO is the system echo(1) command
# FILESYS is the default file system to be audited
# LIMIT is the maximum age of the temporary ignore file
# LISTDIR is where auxiliary files and master lists go
# MAILER is the mailer used
# MINCT is the number of files below which THRESH is ignored
# REMCOPY is the name of the remote copy program
# REMEXEC is the name of the remote execution shell
# RM is the system rm(1) command
# SED is the system sed(1) command
# SHELL is the shell make runs these commands under
# SUBJECT is "yes" if MAILER knows about "-s" flag for subject header
# TEST is the shell's test(1) command
# THRESH is the (percentage) size at which a list file will be accepted.
# TIMEOUT is the usual time out interval
# TMPDIR is the directory where the temporary files go
ROOTDIR	= /toe/users/bishop/grants/audit.test
AUDITOR	= bishop
CAT	= /bin/cat
DESTBIN	= $(ROOTDIR)/=bin
DESTMAN	= /usr/local/man
DESTSRC	= $(ROOTDIR)/=src
ECHO	= /bin/echo
FILESYS = /bin
LIMIT	= 1
LISTDIR	= $(ROOTDIR)
MAILER	= Mail
MINCT	= 20
REMCOPY	= rcp
REMEXEC = rsh
RM	= /bin/rm
SED	= /bin/sed
SHELL	= /bin/sh
SUBJECT	= yes
TEST	= /bin/test
THRESH	= 10
TIMEOUT	= 0
TMPDIR	= $(ROOTDIR)/=tmp
# typeset command
EQN	= eqn
BIB	= bib
ROFF	= psroff
TBL	= tbl
# edit commands
EDIT	= sed -e 's:%%AUDITOR%%:$(AUDITOR):'	\
	      -e 's:%%CAT%%:$(CAT):'		\
	      -e 's:%%DELETE%%:$(RM):'		\
	      -e 's:%%ECHO%%:$(ECHO):'		\
	      -e 's:%%DESTBIN%%:$(DESTBIN):'	\
	      -e 's:%%DESTMAN%%:$(DESTMAN):'	\
	      -e 's:%%DESTSRC%%:$(DESTSRC):'	\
	      -e 's:%%EDIT%%:$(SED):'		\
	      -e 's:%%EGREP%%:$(EGREP):'	\
	      -e 's:%%FILESYS%%:$(FILESYS):'	\
	      -e 's:%%LIMIT%%:$(LIMIT):'	\
	      -e 's:%%LISTDIR%%:$(LISTDIR):'	\
	      -e 's:%%MAILER%%:$(MAILER):'	\
	      -e 's:%%MINCT%%:$(MINCT):'	\
	      -e 's:%%REMCOPY%%:$(REMCOPY):'	\
	      -e 's:%%REMEXEC%%:$(REMEXEC):'	\
	      -e 's:%%SUBJECT%%:$(SUBJECT):'	\
	      -e 's:%%TEST%%:$(TEST):'		\
	      -e 's:%%THRESH%%:$(THRESH):'	\
	      -e 's:%%TIMEOUT%%:$(TIMEOUT):'	\
	      -e 's:%%TMPDIR%%:$(TMPDIR):'
EDITALS	= sed -e 's:%%NETREC%%:$(CAT):'	-e 's:%%NETSEND%%:$(CAT):'
# programs
SRCSH	= audit.sh auditls.sh auditmail.sh gettype.sh rinstall.sh \
		runaudit.sh runaudit1.sh
SRCEXE	= auditcomm.c auditfmt.c auditgrep.c auditmerge.c auditpnm.c \
		auditscan.c cdes.c edprot.c timeout.c
OBJEXE	= auditcomm.o auditfmt.o auditgrep.o auditmerge.o auditpnm.o \
		auditscan.o cdes.o edprot.o timeout.o
EXECSH	= audit auditls auditmail gettype rinstall runaudit runaudit1
EXEC	= auditcomm auditfmt auditgrep auditmerge auditpnm auditscan \
		cdes edprot timeout
# these sources get saved so they can be sent to other machines
SRCREM	= auditls.sh auditscan.c cdes.c RMake
# manual pages
MANSRC	= audit.8.man runaudit.8.man rinstall.8.man
MANOBJ	= audit.8 runaudit.8 rinstall.8
MANSRC8	= auditcomm.8 auditfmt.8 auditgrep.8 auditls.8 auditmail.8 \
		auditmerge.8 auditpnm.8 auditscan.8 gettype.8
MAN1	= cdes.1 edprot.1 timeout.1
MAN8	= auditcomm.8 auditfmt.8 auditgrep.8 auditls.8 auditmail.8 \
		auditmerge.8 auditpnm.8 auditscan.8 gettype.8 $(MANOBJ)

# make everything but don't install it
all:	$(EXECSH) $(EXEC) $(MAN1) $(MAN8)

# install the cookies
install:	$(EXECSH) $(EXEC) $(MAN1) $(MAN8)
	-mkdir $(ROOTDIR)
	-mkdir $(LISTDIR)
	-mkdir $(TMPDIR)
	-mkdir $(DESTBIN)
	-cp $(EXECSH) $(EXEC) $(DESTBIN)
	-(cd $(DESTBIN); for i in $(EXECSH) $(EXEC); do chmod 755 $$i; done)
	-mkdir $(DESTSRC)
	-cp $(SRCREM) $(DESTSRC)
	-mkdir $(DESTMAN)
	-mkdir $(DESTMAN)/man1
	-cp $(MAN1) $(DESTMAN)/man1
	-(cd $(DESTMAN)/man1; for i in $(MAN1); do chmod 644 $$i; done)
	-mkdir $(DESTMAN)/man8
	-cp $(MAN8) $(DESTMAN)/man8
	-(cd $(DESTMAN)/man8; for i in $(MAN8); do chmod 644 $$i; done)

# make the programs
auditcomm:	auditcomm.o
	$(CC) $(CFLAGS) -o auditcomm auditcomm.o

auditfmt:	auditfmt.o
	$(CC) $(CFLAGS) -o auditfmt auditfmt.o

auditgrep:	auditgrep.o
	$(CC) $(CFLAGS) -o auditgrep auditgrep.o

auditmerge:	auditmerge.o
	$(CC) $(CFLAGS) -o auditmerge auditmerge.o

auditpnm:	auditpnm.o
	$(CC) $(CFLAGS) -o auditpnm auditpnm.o

auditscan:	auditscan.o
	$(CC) $(CFLAGS) -o auditscan auditscan.o

cdes:	cdes.o
	$(CC) $(CFLAGS) -o cdes cdes.o $(DESLIB)

edprot:	edprot.o
	$(CC) $(CFLAGS) -o edprot edprot.o

timeout:	timeout.o
	$(CC) $(CFLAGS) -o timeout timeout.o

# make the shell scripts
rinstall:	rinstall.sh
	< rinstall.sh $(EDIT) > rinstall
	chmod 755 rinstall

runaudit:	runaudit.sh
	< runaudit.sh $(EDIT) > runaudit
	chmod 755 runaudit

runaudit1:	runaudit1.sh
	< runaudit1.sh $(EDIT) > runaudit1
	chmod 755 runaudit1

audit:	audit.sh
	< audit.sh $(EDIT) > audit
	chmod 755 audit

auditmail:	auditmail.sh
	< auditmail.sh $(EDIT) > auditmail
	chmod 755 auditmail

auditls:	auditls.sh
	< auditls.sh $(EDIT) | $(EDITALS) > auditls
	chmod 755 auditls

gettype:	gettype.sh
	< gettype.sh $(EDIT) > gettype
	chmod 755 gettype

# make a man page
runaudit.8:	runaudit.8.man
	< runaudit.8.man $(EDIT) > runaudit.8

runaudit1.8:	runaudit1.8.man
	< runaudit1.8.man $(EDIT) > runaudit1.8

audit.8:	audit.8.man
	< audit.8.man $(EDIT) > audit.8

rinstall.8:	rinstall.8.man
	< rinstall.8.man $(EDIT) > rinstall.8

# version control
version:
	sh Version.sh $(VERSION) -hdartmouth.edu -wMatt.Bishop \
		-s $(SRCSH) -c $(SRCEXE) -m $(MANSRC) $(MAN1) $(MANSRC8)

# make and print the manual pages and documents
man:	$(MANOBJ)

print_man:	$(MANOBJ)
	$(ROFF) -man $(MAN1) $(MAN8)

print_audit_doc:
	$(BIB) audit.ms | $(EQN) | $(TBL) | $(ROFF) -ms

print_install_doc:
	$(TBL) install.ms | $(ROFF) -ms

# clean up
clean:
	rm -f $(OBJEXE)

clobber:	clean
	rm -f $(EXECSH) $(EXEC) $(MANOBJ)

