# $Header: /nfs/ephemeral/smoke/src/zmailer/lm/RCS/Makefile,v 1.2 89/12/17 22:34:27 rayan Exp $
# This Makefile is set up to make a debugging malloc called libmalloc_d.a
# Also generates testmalloc and simumalloc, two regression tests.
#
# To make a production malloc, type 'make clean libmalloc'
#
# If you're impatient, and want it all in one file, type 'make onefile.o'
# and it'll merge the all the source into one file. Bit bigger, but
# avoids Unix linker misunderstandings if these are not in libc, and
# ensures the debugging routines are linked in whether called or not.
# On some machines, mv onefile.o libmalloc_d.a will work. On some, it
# upsets the linker.
#
# 'make dist' runs 'bundle' to create a shell archive on stdout.
#
# 'make veryclean' cleans out lib*.a as well.
#
# 'make depend' runs 'mkdep' (from BSD src or named) to create dependencies.
#
# 'make .lint' runs lint.
#
# 'make install' puts all the OBJS in $(ARCHIVE), ranlibs it, and
# puts malloc.h in INCDIR.
#

SHELL=		/bin/sh
LIBMALLOC=libmalloc_d.a
ARCHIVE = $(HOME)/lib/$(LIBMALLOC)

DEFINES= $(NORMALDEFS) $(DEBUGDEFS)

LIBDIR=$(HOME)/lib
INCDIR=$(HOME)/include

#CC = gcc -ansi -Wall # -pedantic # add -pedantic if you fixed your includes.
CDEBUGFLAGS=-g #-O
LINT=lint

SPLAYOBJ = splay/sptree.o
SPLAYSRC = splay/sptree.c
SPLAYHDR = splay/sptree.h

SRCS = _calloc.c _cfree.c _emalloc.c _free.c \
	_malloc.c _memalign.c _realloc.c \
	_strdup.c _strsave.c _valloc.c _zmailer.c botch.c \
	dumpheap.c emalloc.c \
	leak.c malloc.c memalign.c \
	setdebug.c setsbrk.c \
	setslop.c setstats.c stats.c strdup.c strsave.c \
	trace.c valloc.c verify.c

OBJS = _calloc.o _cfree.o _emalloc.o _free.o \
	_malloc.o _memalign.o _realloc.o \
	_strdup.o _strsave.o _valloc.o _zmailer.o botch.o \
	dumpheap.o emalloc.o \
	leak.o malloc.o memalign.o \
	setdebug.o setsbrk.o \
	setslop.o setstats.o stats.o strdup.o strsave.o \
	trace.o valloc.o verify.o

# HDRS, DOCS, TESTS and EXTRAS are used when making distributions.
# so please keep them uptodate.
# bundle is smart enough not to include object files, RCS, executables,
# etc, and does subdirectories right, but there's often other files
# in the development directory...

# globals.c, mversion.c are included in malloc.c.
HDRS = align.h assert.h defs.h externs.h globals.c globals.h globrename.h \
	malloc.h trace.h mversion.c

DOCS = README NOTE TODO CHANGES malloc.doc Makefile

TESTS = testmalloc.c test.out testsbrk.c teststomp.c tests regress \
	simumalloc.c testrun.sh plot.sh munge.sh

EXTRAS = splay

# DEBUGDEFS are set for libmalloc_d.a. Say 'make libmalloc' to get
# DEBUGDEFS=$(FASTDEFS)
DEBUGDEFS=-DDEBUG -DTRACE

# FASTDEFS are used when the 'libmalloc' target is made.
#
# -DTRACE and -DPROFILESIZES shouldn't introduce very much overhead since the
# former is turned off (one 'if'), and the latter is one 'if' + increment.
# So you can keep them even in the fast production version. 
# You may want to define -DBUGCOMPATIBILITY if you want malloc(0) to
# do the same thing as malloc(1). Some suntools programs expect this 
# behaviour. So does Xlib, and the X server has done it at least once.
# (Note that SVID requires malloc(0) to return NULL, and the 
# May 13, 1988 ANSI C draft says that you can either return a NULL pointer
# or a unique pointer (typically decisive standard...) 
FASTDEFS=#-DBUGCOMPATIBILITY -DTRACE -DPROFILESIZES


#  NORMALDEFS are used for both debugging and non-debugging versions
# -DSHORTNAMES makes sure all internal global symbols are unique within 6
# characters. Avoid defining unless your linker is braindead.
# -DUSESTDIO is to make this use fputs() instead of write() for trace
# and debugging output. write() is preferable since it is unbuffered,
# and does not call malloc() or suchlike. Avoid defining if possible.

NORMALDEFS=# -DSHORTNAMES -DUSESTDIO

INCLUDES=-I./splay -I../include

LN = ln -s
OLDCC = cc
OLDCFLAGS = -O
AR = ar
ARFLAGS = ruv
RANLIB=		ranlib # : ar does the work of ranlib under System V

LDFLAGS=#-Bstatic

CFLAGS = $(CDEBUGFLAGS) $(INCLUDES) $(DEFINES)

all: $(LIBMALLOC) #testmalloc simumalloc teststomp .lint

libmalloc:
	make -f Makefile $(MFLAGS) CC="$(CC)" DEBUGDEFS="$(FASTDEFS)" \
		LIBMALLOC=libmalloc.a CDEBUGFLAGS="$(CDEBUGFLAGS)"

testmalloc: testmalloc.o $(LIBMALLOC)
	$(CC) $(CFLAGS) -o testmalloc testmalloc.o $(LIBMALLOC) ${LDFLAGS}

teststomp: teststomp.o $(LIBMALLOC)
	$(CC) $(CFLAGS) -o teststomp teststomp.o $(LIBMALLOC) ${LDFLAGS}

simumalloc: simumalloc.c $(LIBMALLOC)
	$(CC) -DMYMALLOC $(INCLUDES) $(CDEBUGFLAGS) -o simumalloc \
		simumalloc.c $(LIBMALLOC) ${LDFLAGS}

$(LIBMALLOC): $(OBJS) $(SPLAYOBJ)
	rm -f $(LIBMALLOC)
	$(AR) $(ARFLAGS) $(LIBMALLOC) $(OBJS) $(SPLAYOBJ)
	$(RANLIB) $(LIBMALLOC)

$(SPLAYOBJ): .foo
	cd splay; make $(MFLAGS) DEFINES="$(DEFINES)" \
		LIBMALLOC=../$(LIBMALLOC) CC="$(CC)"

onefile: onefile.o

onefile.c: $(SRCS) $(SPLAYSRC)
	rm -f onefile.c
	cat $(SRCS) $(SPLAYSRC) | sed '/RCSID/d' > onefile.c
	
.lint: $(SRCS)
	$(LINT) $(LINTFLAGS) $(DEFINES) $(INCLUDES) $(SRCS) $(SPLAYSRC)
	touch .lint

.foo:

clean:
	-rm -f *.o *.a \#* *~ *.sL
	-rm -f core a.out gmon.out mon.out testmalloc simumalloc \
		teststomp onefile.c prof.out Makefile.bak
	cd splay; make clean

veryclean: clean
	-rm -f libmalloc.a libmalloc_d.a make.log make.out

install:
	@echo 'You did remember to rcs it, no?'
	$(AR) $(ARFLAGS) $(ARCHIVE) $(OBJS) $(SPLAYOBJ)
	$(RANLIB) $(ARCHIVE)
	install -c -m 644 malloc.h $(INCDIR)
	
.id: $(SRCS)
	mkid $(SRCS) $(SPLAYSRC) $(HDRS) $(SPLAYHDR)
	touch .id

dist:
	@rm -f Makefile.bak
	@mv Makefile Makefile.bak;\
	sed '/^# DO NOT PUT ANYTHING/,$$d' Makefile.bak > Makefile; \
	(bundle -v $(DOCS) $(SRCS) $(HDRS) $(TESTS) $(EXTRAS)); \
	mv Makefile.bak Makefile

depend: onefile.c
	../bin/mkdep $(INCLUDES) $(DEFINES) $(SRCS) onefile.c

# DO NOT DELETE THIS LINE -- mkdep uses it.
# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY.

_calloc.o: _calloc.c defs.h externs.h assert.h align.h globals.h globrename.h
_calloc.o: trace.h
_cfree.o: _cfree.c defs.h externs.h assert.h align.h globals.h globrename.h
_cfree.o: trace.h
_emalloc.o: _emalloc.c defs.h externs.h assert.h align.h globals.h globrename.h
_emalloc.o: trace.h
_free.o: _free.c defs.h externs.h assert.h align.h globals.h globrename.h
_free.o: trace.h
_malloc.o: _malloc.c defs.h externs.h assert.h align.h globals.h globrename.h
_malloc.o: trace.h
_memalign.o: _memalign.c defs.h externs.h assert.h align.h globals.h
_memalign.o: globrename.h trace.h
_realloc.o: _realloc.c defs.h externs.h assert.h align.h globals.h globrename.h
_realloc.o: trace.h
_strdup.o: _strdup.c defs.h externs.h assert.h align.h globals.h globrename.h
_strdup.o: trace.h
_strsave.o: _strsave.c defs.h externs.h assert.h align.h globals.h globrename.h
_strsave.o: trace.h
_valloc.o: _valloc.c defs.h externs.h assert.h align.h globals.h globrename.h
_valloc.o: trace.h
_zmailer.o: _zmailer.c defs.h externs.h assert.h align.h globals.h globrename.h
_zmailer.o: trace.h ../include/splay.h ../include/listutils.h
_zmailer.o: ../include/malloc.h
botch.o: botch.c defs.h externs.h assert.h align.h globals.h globrename.h
dumpheap.o: dumpheap.c defs.h externs.h assert.h align.h globals.h globrename.h
emalloc.o: emalloc.c defs.h externs.h assert.h align.h globals.h globrename.h
leak.o: leak.c defs.h externs.h assert.h align.h globals.h globrename.h
leak.o: splay/sptree.h
malloc.o: malloc.c defs.h externs.h assert.h align.h globals.c globrename.h
malloc.o: mversion.c
memalign.o: memalign.c defs.h externs.h assert.h align.h globals.h globrename.h
setdebug.o: setdebug.c defs.h externs.h assert.h align.h globals.h globrename.h
setsbrk.o: setsbrk.c defs.h externs.h assert.h align.h globals.h globrename.h
setslop.o: setslop.c defs.h externs.h assert.h align.h globals.h globrename.h
setstats.o: setstats.c defs.h externs.h assert.h align.h globals.h globrename.h
stats.o: stats.c defs.h externs.h assert.h align.h globals.h globrename.h
strdup.o: strdup.c defs.h externs.h assert.h align.h
strsave.o: strsave.c defs.h externs.h assert.h align.h
trace.o: trace.c defs.h externs.h assert.h align.h globals.h globrename.h
valloc.o: valloc.c defs.h externs.h assert.h align.h globals.h globrename.h
verify.o: verify.c defs.h externs.h assert.h align.h globals.h globrename.h
onefile.o: onefile.c defs.h externs.h assert.h align.h globals.h globrename.h
onefile.o: trace.h defs.h globals.h trace.h defs.h globals.h trace.h defs.h
onefile.o: globals.h trace.h defs.h globals.h trace.h defs.h globals.h trace.h
onefile.o: defs.h globals.h trace.h defs.h globals.h trace.h defs.h globals.h
onefile.o: trace.h defs.h globals.h trace.h defs.h globals.h trace.h
onefile.o: ../include/splay.h ../include/listutils.h ../include/malloc.h defs.h
onefile.o: globals.h defs.h globals.h defs.h globals.h defs.h globals.h
onefile.o: splay/sptree.h defs.h globals.c globrename.h mversion.c defs.h
onefile.o: globals.h defs.h globals.h defs.h globals.h defs.h globals.h defs.h
onefile.o: globals.h defs.h globals.h defs.h defs.h defs.h globals.h defs.h
onefile.o: globals.h defs.h globals.h splay/sptree.h

# IF YOU PUT ANYTHING HERE IT WILL GO AWAY
