/*
 *     Copyright 1988 Massachusetts Institute of Technology.
 *
 *     For copying and distribution information, see the file
 *     "mit-copying.h".
 *
 *     $Id: Imakefile,v 1.18 1995/10/24 19:37:03 jik Exp $
 *
 */

/*
 * If you are compiling on a system that has an st_blocks field in
 * the stat structure whose value represents the number of 512-byte
 * blocks taken up by the file, add -DUSE_BLOCKS to the DEFINES
 * variable below.  If you don't know whether or not to define it,
 * run "make block-test".
 * 
 * If you are using a system where malloc(0) or realloc(ptr, 0)
 * returns 0 even when it succeeds, then set MALLOC below to
 * -DMALLOC_0_RETURNS_NULL.  If you don't know whether or not to
 * define it, run "make malloc-test".
 */

INSTALLDIR=	$(ATHBINDIR)
TMPDIR=		/tmp
#ifdef _IBMR2
MALLOC=		-DMALLOC_0_RETURNS_NULL
#endif
#ifdef _IBMR2
DEFINES=	$(AFSDEFINES) $(MALLOC) -DUSE_BLOCKS -DPOSIX
#else
#ifdef SVR4
DEFINES=	$(AFSDEFINES) $(MALLOC) -DUSE_BLOCKS -DPOSIX -DSYSV
#else
DEFINES=	$(AFSDEFINES) $(MALLOC) -DUSE_BLOCKS
#endif /* SVR4 */
#endif /* _IBMR2 */


#ifdef DeleteDevelopment
#ifdef UseInstalled
IMAKE= imake
IFLAGS= -I$(IRULESRC) -DTOPDIR=TOPDIR -DDeleteDevelopment
#else
UTILDIR=$(TOP)/util/bin/
IMAKE= $(UTILDIR)imake
IFLAGS= -I$(IRULESRC) -DDeleteDevelopment
#endif
#endif

/*
 * These variables apply only if you want this program to recognize
 * Andrew File System mount points.  If you don't want to support AFS,
 * then set all the variables starting with "AFS" to nothing.
 */

#ifndef HaveAFS
#if defined(i386) || (defined(sun) && defined(SVR4))
#define HaveAFS 0
#else
#define HaveAFS 1
#endif /* i386 */
#endif /* ! defined(HaveAFS) */

#if HaveAFS
#ifdef OV
SYSNAME=	$(shell fs sysname | sed "s/.*'\\(.*\\)'.*/\\1/")
AFSDIR=		/ua/afs/newest/$(SYSNAME)
AFSINC=		$(AFSDIR)/include
AFSLIB=		$(AFSDIR)/lib
#else /* ! OV */
#ifndef DeleteDevelopment
AFSINC=		/usr/local/include
AFSLIB=		/usr/local/lib
#else
AFSINC=		/afs/rel-eng/project/release/current/build/@sys/third/common/afs/dest/include
AFSLIB=		/afs/rel-eng/project/release/current/build/@sys/third/common/afs/dest/lib
#endif /* !DeleteDevelopment */
#endif /* OV */
     
AFSLIBS=	-L$(AFSLIB) $(AFSLIB)/afs/libsys.a -lrx -llwp $(AFSLIB)/afs/util.a
AFSDEFINES=	-I$(AFSINC) -DAFS_MOUNTPOINTS
#endif /* AFS */


/* You probably won't have to edit anything below this line. */

LIBS= 		$(AFSLIBS) -lcom_err

SRCS= 		delete.c undelete.c directories.c pattern.c util.c\
		expunge.c lsdel.c col.c shell_regexp.c\
		errors.c stack.c
INCS= 		col.h delete.h directories.h expunge.h lsdel.h\
		mit-copying.h pattern.h undelete.h util.h\
		shell_regexp.h errors.h stack.h
ETS=		delete_errs.h delete_errs.c
ETSRCS=		delete_errs.et

MANS= 		man1/delete.1 man1/expunge.1 man1/lsdel.1 man1/purge.1\
		man1/undelete.1

ARCHIVE=	README Makefile PATCHLEVEL $(SRCS) $(INCS) $(MANS)\
		$(ETSRCS) block-test.sh block-test.c malloc-test.c
ARCHIVEDIRS= 	man1

DELETEOBJS= 	delete.o util.o delete_errs.o errors.o
UNDELETEOBJS= 	undelete.o directories.o util.o pattern.o\
		shell_regexp.o delete_errs.o errors.o stack.o
EXPUNGEOBJS= 	expunge.o directories.o pattern.o util.o col.o\
		shell_regexp.o delete_errs.o errors.o stack.o
LSDELOBJS= 	lsdel.o util.o directories.o pattern.o col.o\
		shell_regexp.o delete_errs.o errors.o stack.o

DELETESRC= 	delete.c util.c delete_errs.c errors.c
UNDELETESRC= 	undelete.c directories.c util.c pattern.c\
		shell_regexp.c delete_errs.c errors.c stack.c
EXPUNGESRC= 	expunge.c directories.c pattern.c util.c col.c\
		shell_regexp.c delete_errs.c errors.c stack.c
LSDELSRC= 	lsdel.c util.c directories.c pattern.c col.c\
		shell_regexp.c delete_errs.c errors.c stack.c

SimpleProgram(delete,$(DELETEOBJS),$(LIBS),$(INSTALLDIR))
SimpleProgram(undelete,$(UNDELETEOBJS),$(LIBS),$(INSTALLDIR))
SimpleProgram(expunge,$(EXPUNGEOBJS),$(LIBS),$(INSTALLDIR))
SimpleProgram(lsdel,$(LSDELOBJS),$(LIBS),$(INSTALLDIR))

install_man(man1/delete.1,delete.1)
install_man(man1/expunge.1,expunge.1)
install_man(man1/lsdel.1,lsdel.1)
install_man(man1/purge.1,purge.1)
install_man(man1/undelete.1,undelete.1)

/*
 * The symlink from $(INSTALLDIR)/delete to
 * $(DESTDIR)/$(ATHRBINDIR)/delete should probably eventually go away.
 */
install::
	-$(RM) $(DESTDIR)$(INSTALLDIR)/purge
	-ln -s expunge $(DESTDIR)$(INSTALLDIR)/purge
	-ln -s $(INSTALLDIR)/delete $(DESTDIR)$(ATHRBINDIR)/delete

error_table(delete_errs)

create_depend($(SRCS) delete_errs.c)

tar: $(ARCHIVE)
	tar cvf - $(ARCHIVE) | compress > delete.tar.Z

shar: $(ARCHIVE)
	makekit -oMANIFEST $(ARCHIVEDIRS) $(ARCHIVE)

patch: $(ARCHIVE)
	makepatch $(ARCHIVE)
	mv patch delete.patch`cat PATCHLEVEL`
	shar delete.patch`cat PATCHLEVEL` > delete.patch`cat PATCHLEVEL`.shar

block-test: block-test.sh
	CC=$(CC); TMPDIR=$(TMPDIR); export CC TMPDIR; . ./block-test.sh

malloc-test: malloc-test.c
	@$(CC) -o malloc-test malloc-test.c
	@./malloc-test
	@rm malloc-test
