
include Makefile.setup


BTREE_LOCKS = BTREE_$(LOCK_TYPE)
BTREE_LG_LOCKS = BTREE_LARGE_$(LOCK_TYPE)
BTREE_FINE = BTREE_FINE_$(LOCK_TYPE)
# 1 freelist
SINGLE_FREELIST = 1
BTREE_TRANS_SFL = BTREE_TM_$(SINGLE_FREELIST)
# Multiple freelists
MULTIPLE_FREELIST = 31
BTREE_TRANS_MFL = BTREE_TM_$(MULTIPLE_FREELIST)

BTREE_MULTI = BTREE_MULTI_TM
BTREE_LG_TRANS = BTREE_LARGE_TM
LARGE_NODE_SIZE = 1022
SMALL_NODE_SIZE = 9

OBJS = main.o


EXTRAFLAGS = -DSIMICS

all: $(TARGET) $(BTREE_LOCKS) $(BTREE_TRANS_SFL) $(BTREE_TRANS_MFL) $(BTREE_LG_TRANS) $(BTREE_LG_LOCKS) $(BTREE_MULTI) btree_c_main.s

$(TARGET): $(OBJS) $(LIBS)
	$(CC) $(OBJS) $(CFLAGS) -o $(TARGET) $(LDFLAGS) $(EXTRAFLAGS)

$(BTREE_TRANS_SFL): lock_dec.h btree_c.h btree_c_util.h btree_trans.c btree_c.o btree_c.h btree_c_util.o transaction.o btree_c_main.c
	$(CC) btree_trans.c btree_c.o btree_c_util.o transaction.o btree_c_main.c $(CFLAGS) -o $(BTREE_TRANS_SFL) $(LDFLAGS) $(EXTRAFLAGS) -DNODE_NUM_PAIRS=$(SMALL_NODE_SIZE) -DNUM_POOLS=$(SINGLE_FREELIST)

$(BTREE_TRANS_MFL): lock_dec.h btree_c.h btree_c_util.h btree_trans.c btree_c_multiple_freelist.o btree_c.h btree_c_util.o transaction.o btree_c_main.c
	$(CC) btree_trans.c btree_c_multiple_freelist.o btree_c_util.o transaction.o btree_c_main.c $(CFLAGS) -o $(BTREE_TRANS_MFL) $(LDFLAGS) $(EXTRAFLAGS) -DNODE_NUM_PAIRS=$(SMALL_NODE_SIZE) -DNUM_POOLS=$(MULTIPLE_FREELIST)

$(BTREE_LG_TRANS): lock_dec.h btree_c.h btree_trans.c btree_c_lg.o btree_c.h btree_c_util_lg.o transaction.o btree_c_main.c
	$(CC) btree_trans.c btree_c_lg.o btree_c_util_lg.o transaction.o btree_c_main.c $(CFLAGS) -o $(BTREE_LG_TRANS) $(LDFLAGS) $(EXTRAFLAGS) -DNODE_NUM_PAIRS=$(LARGE_NODE_SIZE) -DNUM_POOLS=$(SINGLE_FREELIST)

$(BTREE_LOCKS): lock_dec.h btree_c.h btree_c_util.h btree_locks.c btree_c.o btree_c.h btree_c_util.o transaction.o btree_c_main.c
	$(CC) btree_locks.c btree_c.o btree_c_util.o transaction.o btree_c_main.c $(CFLAGS) -o $(BTREE_LOCKS) $(LDFLAGS) $(EXTRAFLAGS) -DNODE_NUM_PAIRS=$(SMALL_NODE_SIZE) -DNUM_POOLS=$(SINGLE_FREELIST)

$(BTREE_LG_LOCKS): lock_dec.h btree_c.h btree_locks.c btree_c_util.o btree_c_lg.o btree_c.h btree_c_util.o transaction.o btree_c_main.c
	$(CC) btree_locks.c btree_c_lg.o btree_c_util.o transaction.o btree_c_main.c $(CFLAGS) -o $(BTREE_LG_LOCKS) $(LDFLAGS) $(EXTRAFLAGS) -DNODE_NUM_PAIRS=$(LARGE_NODE_SIZE) -DNUM_POOLS=$(SINGLE_FREELIST)

$(BTREE_FINE): btree_locks_fine.o transaction.o btree_c_locking.h
	$(M4) $(MACROS) btree_c_locking.H > btree_c_locking.h
	$(CC) btree_locks_fine.o transaction.o $(CFLAGS) -o $(BTREE_FINE) $(LDFLAGS) $(EXTRAFLAGS)

$(BTREE_MULTI): btree_c.h btree_trans.c btree_c.o btree_c.h btree_c_util.o transaction.o btree_c_multi_insert.c
	$(CC) btree_trans.c btree_c_multiple_freelist.o btree_c_util.o transaction.o btree_c_multi_insert.c $(CFLAGS) -o $(BTREE_MULTI) $(LDFLAGS) $(EXTRAFLAGS) -DNODE_NUM_PAIRS=$(SMALL_NODE_SIZE) -DNUM_POOLS=$(MULTIPLE_FREELIST)

#--------------------------------------------

btree_locks_fine.c: btree_locks_fine.C
	$(M4) $(MACROS) btree_locks_fine.C > btree_locks_fine.c

btree_c_locking.h: btree_c_locking.H
	$(M4) $(MACROS) btree_c_locking.H > btree_c_locking.h

btree_c_lg.o: btree_c.c btree_c.h
	$(CC) -c $(CFLAGS) -o btree_c_lg.o -DNODE_NUM_PAIRS=$(LARGE_NODE_SIZE) -DNUM_POOLS=$(SINGLE_FREELIST) btree_c.c

btree_c_multiple_freelist.o: btree_c.c btree_c.h
	$(CC) -c $(CFLAGS) -o btree_c_multiple_freelist.o -DNODE_NUM_PAIRS=$(SMALL_NODE_SIZE) -DNUM_POOLS=$(MULTIPLE_FREELIST) btree_c.c

btree_c_util_lg.o: btree_c_util.c btree_c_util.h
	$(CC) -c $(CFLAGS) -o btree_c_util_lg.o -DNODE_NUM_PAIRS=$(LARGE_NODE_SIZE) -DNUM_POOLS=$(SINGLE_FREELIST) btree_c_util.c

btree_c_main.s: btree_c_main.c
	$(CC) -S $(CFLAGS) btree_c_main.c -DNODE_NUM_PAIRS=$(SMALL_NODE_SIZE) -DNUM_POOLS=$(SINGLE_FREELIST)

btree_c_multi_insert.s: btree_c_multi_insert.c
	$(CC) -S $(CFLAGS) btree_c_multi_insert.c -DNODE_NUM_PAIRS=$(SMALL_NODE_SIZE) -DNUM_POOLS=$(SINGLE_FREELIST)

transaction.o: ../common/transaction.c ../common/transaction.h
	$(CC) -c $(CFLAGS) -o transaction.o ../common/transaction.c 

#--------------------------------------------

.SUFFIXES:
.SUFFIXES:	.o .c .C .h .H

.H.h:
	$(M4) $(MACROS) $*.H > $*.h

.C.c:
	$(M4) $(MACROS) $*.C > $*.c

.c.o:
	$(CC) -c $(CFLAGS) $*.c -DNODE_NUM_PAIRS=$(SMALL_NODE_SIZE) -DNUM_POOLS=$(SINGLE_FREELIST)

.c.s:
	$(CC) -S $(CFLAGS) $*.c

.C.o:
	$(M4) $(MACROS) $*.C > $*.c
	$(CC) -c $(CFLAGS) $*.c
#rm -f $(TARGET) $(BTREE_LOCKS) $(BTREE_TRANS) $(BTREE_LG_LOCKS) $(BTREE_LG_TRANS)
clean:
	rm -f $(TARGET) *.o *.c *.h

