# Copyright (C) 1991, 1992, 1993 Free Software Foundation, Inc.
# This file is part of the GNU C Library.

# The GNU C Library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Library General Public License
# as published by the Free Software Foundation; either version 2 of
# the License, or (at your option) any later version.

# The GNU C Library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Library General Public License for more details.

# You should have received a copy of the GNU Library General Public
# License along with the GNU C Library; see the file COPYING.LIB.  If
# not, write to the Free Software Foundation, Inc., 675 Mass Ave,
# Cambridge, MA 02139, USA.

# Makefile for standalone distribution of malloc.

#----------------------------------------------------------------------
# Bounds Checking GCC, Written By Richard W.M. Jones.
# This code is derived from the GNU C library's malloc which is distributed
# under the GNU copyleft described above. The modifications to this code
# by Richard W.M. Jones are also covered by the GNU copyleft above.
#----------------------------------------------------------------------

#  This makefile is run by the gcc dir's makefile when building libcheck.a:
#  thisdir1=`pwd`; \
#  srcdir1=`cd $(srcdir); pwd`; \
#  cd bounds/lib; \
#  $(MAKE) $(MAKEFLAGS) -f $$srcdir1/bounds/lib/Makefile libcheck.a \
#    srcdir=$$srcdir1 tooldir=$(tooldir) AR="$(AR)" AR_FLAGS="$(AR_FLAGS)" \
#    GCC_FOR_TARGET="$$thisdir1/xgcc -B$$thisdir1/" \
#    GCC_CFLAGS="$(GCC_CFLAGS)" incinstalldir=$$thisdir1/include
#  Two targets are used by ../Makefile: `all' and `mostlyclean'.
#
#  The bounds/lib/Makefile invokes this makefile by:
#  cd malloc; \
#  $(MAKE) -f $(srcdir)/bounds/lib/malloc/Makefile gmalloc.o \
#    srcdir=$(srcdir) tooldir=$(tooldir) AR="$(AR)" AR_FLAGS="$(AR_FLAGS)" \
#    GCC_FOR_TARGET="$(srcdir)/xgcc -B$(srcdir)/" \
#    GCC_CFLAGS="$(GCC_CFLAGS)"

# SHELL	= /bin/sh

OPTIMIZE= -O2

GCC_FOR_TARGET=gcc

# Always search these dirs when compiling.
SUBDIR_INCLUDES = -I$(srcdir)/bounds/lib/malloc -I../../.. -I$(srcdir) -I$(srcdir)/config

# Use this on System V.
CPPFLAGS = -DUSG

.c.o:
	$(GCC_FOR_TARGET) -Wall $(OPTIMIZE) $(CPPFLAGS) \
		-c $(GCC_CFLAGS) $(SUBDIR_INCLUDES) $<

# If we were not invoked from the gcc dir invoke make
# in the gcc dir and reinvoke this makefile by the bounds/lib/Makefile.
# That's necessary to get the right values for srcdir, etc.
all:
	cd ../../..; $(MAKE) sublibcheck.a

sources = bounds.c calloc.c cfree.c free.c malloc.c \
	  mcheck.c memalign.c morecore.c mstats.c mtrace.c \
	  realloc.c valloc.c vm-limit.c
objects = $(sources:.c=.o)
headers = getpages.h malloc.h mem-limi.h obstack.h

# Patched by M.W.Snitily here so we should always pick up the right linker. If
# people have problems here, could they mail me so we can work on a better
# way to get the right linker ...

gmalloc.o: $(objects)
	ld -r -o $@ $(objects)
$(objects): $(headers)

.PHONY: clean realclean malloc-clean malloc-realclean
clean malloc-clean:
	-rm -f gmalloc.o *.o core
realclean malloc-realclean: clean
	-rm -f TAGS tags *~

# For inside the C library.
malloc.tar malloc.tar.Z: FORCE
	$(MAKE) -C .. $@
FORCE:
