
EPONYM = RobboBaseLib
VERSION = 0.65
CC = gcc
CD = cd
CP = cp
RM = rm
MAKE = make
MKDIR = mkdir
TAR = tar
FLAGS = -Wall
OPTIONS = -g -O3 -fstrict-aliasing -fomit-frame-pointer -fno-exceptions -fPIC
INCLUDE = include/
CFLAGS += $(OPTIONS) $(FLAGS) $(DEFINITIONS) -I$(INCLUDE)

DEFINITIONS = -DVERSION=\"$(VERSION)\"
# DEFINITIONS += -DIMPEL_GAVIOTA_DEBUG
# DEFINITIONS += -DGAVIOTA_COMPLIANCE
LIBS = -ldl # dynamic load linker 
LIBS += -lpthread # value

TOTAL_DIR = RobboTotalCode
TRIPLE_DIR = RobboTripleCode
ALTRO_DIR = $(EPONYM)-$(VERSION)

GAVIOTA_HEADERS = GaviotaDebug.h \
                  GaviotaCompliance.h
GAVIOTA_SOURCES =  GaviotaDebug.c \
                   GaviotaComplianceRealm.c \
                   GaviotaComplianceProbe.c

LIB_HEADERS = RobboBaseLibExternal.h \
              RobboBaseLibUsage.h
LIB_SOURCES = RobboBaseLibExternal.c

TESTING_SOURCES = RobboBaseLibTester.c

TRIPLE_SOURCES = $(TRIPLE_DIR)/magic_mult.c \
                 $(TRIPLE_DIR)/RobboTriple.c \
                 $(TRIPLE_DIR)/RobboTripleDisk.c \
                 $(TRIPLE_DIR)/RobboTripleGlue.c \
                 $(TRIPLE_DIR)/RobboTriple_iniz.c \
                 $(TRIPLE_DIR)/RobboTripleMakeUndo.c \
                 $(TRIPLE_DIR)/RobboTripleScore.c \
                 $(TRIPLE_DIR)/RobboTripleValue.c \
                 $(TRIPLE_DIR)/RobboTripleUtil.c

TOTAL_SOURCES = $(TOTAL_DIR)/Robbo_cache.c \
                $(TOTAL_DIR)/Robbo_iniz.c \
                $(TOTAL_DIR)/RobboTotal_iniz.c \
                $(TOTAL_DIR)/Robbo_decomp.c \
                $(TOTAL_DIR)/Robbo_iniz_IO.c \
                $(TOTAL_DIR)/RobboTotalUtil.c \
                $(TOTAL_DIR)/Robbo_usage.c

HEADERS = $(INCLUDE)/bits.h \
          $(INCLUDE)/IH-board.h \
          $(INCLUDE)/IH-win-linux.h \
          $(INCLUDE)/RobboLito_def.h \
          $(INCLUDE)/RobboTripleBase.h \
          $(INCLUDE)/RobboTotalBase.h \
          $(INCLUDE)/win32bits.h \
          $(INCLUDE)/win64bits.h

LIB_OBJECTS = $(LIB_SOURCES:.c=.o)
TOTAL_OBJECTS = $(TOTAL_SOURCES:.c=.o)
TRIPLE_OBJECTS = $(TRIPLE_SOURCES:.c=.o)
SOURCES = $(LIB_SOURCES) $(GAVIOTA_SOURCES) $(TOTAL_SOURCES) $(TRIPLE_SOURCES)
OBJECTS = $(LIB_OBJECTS) $(TOTAL_OBJECTS) $(TRIPLE_OBJECTS) #$(GAVIOTA_OBJECTS)
MORE = Makefile ROBBO_BASE_LIB_READ_ME BAD_INDEX.LIST # ensure

all: RobboBaseLib.so # HACK

RobboBaseLib.so: $(OBJECTS) $(HEADERS) Makefile
	# $(CD) $(TOTAL_DIR) && $(MAKE) && $(CD) ..
	# $(CD) $(TRIPLE_DIR) && $(MAKE) && $(CD) ..
	$(CC) $(CFLAGS) -shared -o $(EPONYM).so $(OBJECTS) $(LIBS)
	$(CC) $(CFLAGS) -o RobboBaseLibTester RobboBaseLibTester.c $(LIBS)
	# incur -lpthread upon above
clean:
	$(RM) -f *.o $(EPONYM).so include/*~
	$(CD) $(TOTAL_DIR) && $(MAKE) clean && $(CD) ..
	$(CD) $(TRIPLE_DIR) && $(MAKE) clean && $(CD) ..

archive:
	$(RM) -rf $(ALTRO_DIR) *.tar # ensure
	$(MKDIR) $(ALTRO_DIR)
	$(CP) -r $(INCLUDE) $(ALTRO_DIR)
	$(CP) $(LIB_SOURCES) $(LIB_HEADERS) $(ALTRO_DIR)
	$(CP) $(TESTING_SOURCES) $(TESTING_HEADERS) $(ALTRO_DIR)
	$(CP) $(GAVIOTA_SOURCES) $(GAVIOTA_HEADERS) $(ALTRO_DIR)
	$(CP) $(MORE) $(ALTRO_DIR)
	$(MKDIR) $(ALTRO_DIR)/$(TRIPLE_DIR)
	$(CP) $(TRIPLE_SOURCES) $(ALTRO_DIR)/$(TRIPLE_DIR)
	$(CP) $(TRIPLE_DIR)/Makefile $(ALTRO_DIR)/$(TRIPLE_DIR)
	$(MKDIR) $(ALTRO_DIR)/$(TOTAL_DIR)
	$(CP) $(TOTAL_SOURCES) $(ALTRO_DIR)/$(TOTAL_DIR)
	$(CP) $(TOTAL_DIR)/Makefile $(ALTRO_DIR)/$(TOTAL_DIR)
	$(CP) $(TOTAL_DIR)/maximal_loss.info $(ALTRO_DIR)/$(TOTAL_DIR) # hack
	$(TAR) -cf $(EPONYM)-$(VERSION).tar $(ALTRO_DIR)/*
	$(RM) -rf $(ALTRO_DIR)
