/*
 *     Copyright 1988 Massachusetts Institute of Technology.
 *
 *     For copying and distribution information, see the file
 *     "mit-copying.h".
 *
 *     $Id: Imakefile,v 1.5 1996/02/19 01:28:04 svalente 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) 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".
 */

#if defined(_IBMR2) || defined(linux) || defined(__NetBSD__)
OSDEFS=		-DMALLOC_0_RETURNS_NULL
#endif

INSTALLDIR=	$(ATHBINDIR)
TMPDIR=		/tmp
DEFINES=	$(AFSDEFINES) $(OSDEFS) -DUSE_BLOCKS


#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.
 */

#ifdef AfsDir
#ifdef __NetBSD__
AFSOSLIBS=	-lcompat
#endif
AFSLIBS= -L$(AFSDIR)/lib $(AFSDIR)/lib/afs/libsys.a -lrx -llwp $(AFSOSLIBS)
AFSDEFINES=	-I$(AFSDIR)/include -DAFS_MOUNTPOINTS
#endif


/* 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 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

all:: delete_errs.h

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
