MADRE_HOME = ../..
include $(MADRE_HOME)/local.mk
INC_DIR = $(MADRE_HOME)/include
COMPILE = $(COMPILER) -c -I$(INC_DIR)
LINK = $(LINKER)

# can also use -DMADRE_BMAN_DEBUG=1

all: util.o lred.o bman.o mem.o common.o

util.o: Makefile $(INC_DIR)/util.h util.c
	$(COMPILE) util.c

lred.o: Makefile $(INC_DIR)/lred.h $(INC_DIR)/util.h lred.c
	$(COMPILE) lred.c

bman.o: Makefile $(INC_DIR)/bman.h $(INC_DIR)/lred.h $(INC_DIR)/util.h bman.c
	$(COMPILE) bman.c

mem.o : Makefile $(INC_DIR)/madre.h $(INC_DIR)/util.h mem.c
	$(COMPILE) -DDEBUG=0 mem.c 

common.o : Makefile \
           $(INC_DIR)/madre.h \
           $(INC_DIR)/util.h \
           $(INC_DIR)/lred.h \
           $(INC_DIR)/bman.h \
           $(INC_DIR)/contigBred.h \
           $(INC_DIR)/cyclicSchedulerBred.h \
           $(INC_DIR)/cycleShiftBred.h \
           $(INC_DIR)/unitBred.h \
           $(INC_DIR)/unitCyclicBred.h \
           common.c
	$(COMPILE) -I$(INC_DIR) common.c 

lredtest.o: Makefile $(INC_DIR)/lred.h $(INC_DIR)/util.h lredtest.c
	$(COMPILE) lredtest.c

lredtest: util.o lred.o lredtest.o mem.o
	$(LINK) -o lredtest util.o lred.o lredtest.o mem.o $(LIBRARIES)

bmantest.o: Makefile $(INC_DIR)/bman.h $(INC_DIR)/util.h \
            $(INC_DIR)/lred.h bmantest.c
	$(COMPILE) bmantest.c

bmantest: util.o lred.o bman.o bmantest.o mem.o
	$(LINK) -o bmantest util.o lred.o bman.o bmantest.o mem.o $(LIBRARIES)

clean:
	-rm -f *.o lredtest bmantest

check_clean:
	-rm -f lredtest bmantest

check: lredtest bmantest
	$(SHORT_RUN) 1 ./lredtest
	$(SHORT_RUN) 1 ./bmantest
