###############################################################################
# Makefile for the DMalloc library.
# $Id: Makefile.all.in,v 1.62 1995/12/29 01:39:50 gray Exp $
###############################################################################

# default root installation directory
prefix = @prefix@
exec_prefix = @exec_prefix@

srcdir = @srcdir@
VPATH = @srcdir@

bindir = $(exec_prefix)/bin
libdir = $(exec_prefix)/lib
shlibdir = $(exec_prefix)/shlib
incdir = $(prefix)/include
infodir = $(prefix)/info

# default c-compiler
CC = @CC@

DEFS = -DSTDC_HEADERS=@STDC_HEADERS@
INCS = -I. -I$(srcdir)
LIBS = -L. @LIBS@

LIBNAME	= dmalloc

LIBRARY	= lib$(LIBNAME).a
SHLIBRARY = lib$(LIBNAME).so

# library with dmalloc disabled
LIB_DIS	= libdmalloclp.a
SHLIB_DIS = libdmalloclp.so

UTIL = dmalloc
INFOFILE = dmalloc.info

CCFLAGS = @CFLAGS@
LDFLAGS = @LDFLAGS@

INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_DATA = @INSTALL_DATA@

###############################################################################
# End of system configuration section.
###############################################################################

SHELL = /bin/sh

HFLS = dmalloc.h
OBJS = arg_check.o chunk.o compat.o dmalloc_lp.o env.o error.o heap.o malloc.o

CFLAGS = $(CCFLAGS)
TEST = dmalloc_t

all : $(LIBRARY) $(LIB_DIS) $(UTIL) $(INFOFILE)

clean :
	rm -f a.out core *.o *.t
	rm -f $(LIBRARY) $(LIB_DIS) $(TEST) $(UTIL) dmalloc.h

realclean : clean

distclean : clean
	rm -f Makefile config.status config.cache config.log conf.h dmalloc.h.2
	rm -f settings.h
#	rm -f configure

installdirs :
	$(srcdir)/mkinstalldirs $(incdir) $(libdir) $(infodir) $(bindir)
# may want to add $(shlibdir) to this list

installincs : $(HFLS)
	$(INSTALL_DATA) $(HFLS) $(incdir)

installlib : installincs $(LIBRARY) $(LIB_DIS) $(INFOFILE)
	$(INSTALL_DATA) $(LIBRARY) $(libdir)
	@RANLIB@ $(libdir)/$(LIBRARY)
	$(INSTALL_DATA) $(LIB_DIS) $(libdir)
	@RANLIB@ $(libdir)/$(LIB_DIS)
	$(INSTALL_DATA) $(srcdir)/$(INFOFILE) $(infodir)
#	$(INSTALL_DATA) $(srcdir)/$(SHLIBRARY)   $(shlibdir)

install : installdirs installlib $(UTIL)
	$(INSTALL_PROGRAM) $(UTIL) $(bindir)

dmalloc.h.2 : configure
	$(SHELL) configure

settings.h : $(srcdir)/settings.dist $(srcdir)/configure
	$(SHELL) $(srcdir)/configure

dmalloc.h : $(srcdir)/dmalloc.h.1 dmalloc.h.2 $(srcdir)/dmalloc.h.3
	rm -f $@ $@.t
	cat $(srcdir)/dmalloc.h.1 dmalloc.h.2 $(srcdir)/dmalloc.h.3 > $@.t
	mv $@.t $@

shlib : ${SHLIBRARY}

${SHLIBRARY} : $(LIBRARY)
#	ld -shared -o $@ -all $(LIBRARY) -all -soname $@ -none -lc

$(LIBRARY) : $(OBJS)
	ar cr $(LIBRARY) $?
	@RANLIB@ $@

$(LIB_DIS) : dmalloc_lp.o
	ar cr $(LIB_DIS) $?
	@RANLIB@ $@

noansi : dmalloc.h Deansify.pl
	perl $(srcdir)/Deansify.pl *.[ch]

utils : $(UTIL)

$(UTIL) : $(UTIL).o argv.o compat.o env.o
	rm -f $@
	$(CC) $(LDFLAGS) $(UTIL).o argv.o compat.o env.o $(LIBS)
	mv a.out $@

tests : $(TEST)

$(TEST) : $(TEST).o argv.o $(LIBRARY)
	rm -f $@
	$(CC) $(LDFLAGS) $(TEST).o argv.o $(LIBS) -l$(LIBNAME)
	mv a.out $@

check light : $(TEST)
	./$(TEST) -s -t 10000
	./$(TEST) -s -t 10000
	./$(TEST) -s -t 10000
	./$(TEST) -s -t 10000
	./$(TEST) -s -t 10000

heavy : $(TEST) light
	./$(TEST) -s -t 100000
	./$(TEST) -s -t 100000
	./$(TEST) -s -t 100000

.c.o :
	rm -f $@
	$(CC) $(CFLAGS) $(CPPFLAGS) $(DEFS) $(INCS) -c $< -o ./$@

.texi.info :
	makeinfo --no-split $<

#
# auto configure settings
#
Makefile : $(srcdir)/Makefile.in
	$(SHELL) config.status

conf.h : $(srcdir)/conf.h.in
	$(SHELL) config.status

config.status : $(srcdir)/configure
	$(SHELL) config.status --recheck

$(srcdir)/configure : $(srcdir)/configure.in
	cd $(srcdir); autoconf

###############################################################################
#
# These dependencies are automatically generated.  Do not edit by hand.
#

arg_check.o: arg_check.c dmalloc.h conf.h settings.h chunk.h dmalloc_loc.h \
  debug_val.h error.h arg_check.h
argv.o: argv.c argv.h argv_loc.h
chunk.o: chunk.c dmalloc.h conf.h settings.h chunk.h dmalloc_loc.h chunk_loc.h \
  compat.h debug_val.h error.h error_str.h error_val.h heap.h
compat.o: compat.c dmalloc.h conf.h settings.h compat.h dmalloc_loc.h
crc.o: crc.c
dmalloc.o: dmalloc.c argv.h conf.h settings.h dmalloc.h compat.h dmalloc_loc.h \
  debug_tok.h debug_val.h env.h error_str.h error_val.h version.h
dmalloc_lp.o: dmalloc_lp.c dmalloc.h conf.h settings.h dmalloc_loc.h \
  dmalloc_lp.h
dmalloc_t.o: dmalloc_t.c argv.h dmalloc.h conf.h settings.h
env.o: env.c conf.h settings.h dmalloc.h dmalloc_loc.h debug_tok.h debug_val.h \
  env.h error.h
error.o: error.c conf.h settings.h dmalloc.h compat.h dmalloc_loc.h debug_val.h \
  env.h error.h error_val.h version.h
heap.o: heap.c dmalloc.h conf.h settings.h chunk.h dmalloc_loc.h compat.h \
  debug_val.h error.h error_val.h heap.h
malloc.o: malloc.c conf.h settings.h return.h dmalloc.h chunk.h dmalloc_loc.h \
  compat.h debug_val.h env.h error.h error_str.h error_val.h heap.h dmalloc_lp.h
