CC = gcc
CFLAGS = -g
OBJS = mallocJig.o realMalloc.o realCalloc.o
OUT = libjig.a
LIBC = /usr/lib/libc.a

all: $(OUT)

clean:
	rm -f $(OBJS) $(OUT) malloc.o calloc.o

$(OUT): $(OBJS)
	ar q $(OUT) $(OBJS)
	ranlib $(OUT)

malloc.o: $(LIBC)
	ar x $(LIBC) malloc.o

calloc.o: $(LIBC)
	ar x $(LIBC) calloc.o

# Note:  this part assumes that you have built the binary rewriting
# tool (binwrap) and have installed it in your search path.

realMalloc.o: malloc.o
	binwrap malloc.o tmp.o malloc realMalloc
	binwrap tmp.o realMalloc.o realloc realRealloc
	rm -f tmp.o

realCalloc.o: calloc.o
	binwrap calloc.o realCalloc.o calloc realCalloc
