#	Makefile for:
#	----------------------------------------------------------------------
#	Bounds Checking Project, by Richard W.M. Jones.
#	Library of checking functions linked by modified GCC.
#	----------------------------------------------------------------------

# The following mods from Mark W. Snitily should solve cross-compilation
# problems.	(RWMJ)
# ---
#
#  This makefile is run by the gcc dir's makefile:
#  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'.

# SHELL	= /bin/sh

OPTIMIZE= -O2

GCC_FOR_TARGET=gcc
GCC_CFLAGS=-funsigned-char
AR_FLAGS=r
srcdir=$(PWD:d:d:d).

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

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

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

OBJS	= alloca.o check.o error.o exstatic.o function.o globals.o init.o \
	  malloc/gmalloc.o objects.o print.o string.o
HEADERS = alloca.h bounds-l.h check.h ext-tree.h function.h \
	  mutex.h objects.h version.h ../VERSION

# MAKE	= make
RM = -del

# This is where `libcheck.a' ends up (in the gcc-x.x.x home directory).
INSTDIR	= $(srcdir)

mostlyclean:
	$(RM) libcheck.a $(OBJS) core
	cd malloc; $(MAKE) -f $(srcdir)/bounds/lib/malloc/Makefile clean

distclean: clean
	$(RM) *~ *.BAK

clean: mostlyclean
extraclean: mostlyclean

install: libcheck.a
	cp libcheck.a $(INSTDIR)/libcheck.a

libcheck.a: $(OBJS)
	$(RM) libcheck.a
	$(AR) $(AR_FLAGS) libcheck.a $(OBJS)
# ranlib is run in the parent directory's makefile.

alloca.o: $(srcdir)/bounds/lib/alloca.c
	$(GCC_FOR_TARGET) -fno-builtin -Wall $(OPTIMIZE) \
		-c $(GCC_CFLAGS) $(SUBDIR_INCLUDES) \
		$(srcdir)/bounds/lib/alloca.c -o alloca.o

string.o: $(srcdir)/bounds/lib/string.c
	$(GCC_FOR_TARGET) -fno-builtin -Wall $(OPTIMIZE) \
		-c $(GCC_CFLAGS) $(SUBDIR_INCLUDES) \
		$(srcdir)/bounds/lib/string.c -o string.o

malloc/gmalloc.o:
	cd malloc & $(MAKE) srcdir=$(srcdir) gmalloc.o

$(OBJS): $(HEADERS)
