
CC = gcc
MKDIR = /bin/mkdir
RM = /bin/rm
TAR = /bin/tar
CP = /bin/cp

HAS = -DHAS_POPCNT # -DHAS_PREFETCH
DEFINITIONS = -Dx86_64 $(HAS)
FLAGS = -Wall -I../include
OPTIONS = -g -O3 -fstrict-aliasing -fomit-frame-pointer -fno-exceptions

CFLAGS += $(OPTIONS) $(FLAGS) $(DEFINITIONS)

ALTRO = ROBBO_BASE_BRIEF \
        ROBBO_TRIPLE_INFO \
        triple3.sh \
        triple4.sh \
        triple5.sh \
        tripleZ.sh \
        triple33.sh \
        triple42.sh \
        triple51.sh \
        triple6Z.sh \
        maximal.6 \
        maximal.6Z \

ALTRO += md5.33 md5.42 md5.6Z

TOTAL_SOURCES = Robbo_gen.c \
                          Robbo_conto.c \
                          Robbo_utilita.c \
                          Robbo_cache.c \
                          Robbo_iniz.c \
                          Robbo_iniz_IO.c \
                          Robbo_mfa.c \
                          RobboTotalBuild.c \
                          Robbo_comp.c \
                          Robbo_decomp.c \
                          Robbo_popolare.c \
                          Robbo_mobilita.c \
                          Robbo_extra.c \
                          Robbo_suffix.c \

EXTERNAL_SOURCES = arrays.c \
                   magic_mult.c \
                   SLAB_MEMORY.c \
                   MEM_HANDLER.c # copied to the there

TRIPLE_SOURCES = RobboTripleBuild.c \
                 RobboTripleHuffmann.c

ALL = $(TRIPLE_SOURCES) $(TOTAL_SOURCES) $(EXTERNAL_SOURCES) $(ALTRO) Makefile

RobboGlueing_SOURCES = Robbo_utilita.c \
                       Robbo_cache.c \
                       Robbo_iniz.c \
                       Robbo_decomp.c \
                       Robbo_iniz_IO.c \
                       Robbo_mobilita.c \
                       Robbo_mfa.c

RobboTotalBuild_SOURCES = $(TOTAL_SOURCES) $(EXTERNAL_SOURCES)
RobboTotalBuild_OBJECTS = $(RobboTotalBuild_SOURCES:.c=.o)

RobboTripleBuild_SOURCES = $(TRIPLE_SOURCES) $(RobboGlueing_SOURCES) $(EXTERNAL_SOURCES)

RobboTripleBuild_OBJECTS = $(RobboTripleBuild_SOURCES:.c=.o)

WORKING_DIR = RobboBuild

all: RobboTotalBuild RobboTripleBuild
RobboTotalBuild: $(RobboTotalBuild_OBJECTS) $(RobboTotalBuild_HEADERS)
	$(CC) $(CFLAGS) -o RobboTotalBuild $(RobboTotalBuild_OBJECTS) -lpthread

RobboTripleBuild: $(RobboTripleBuild_OBJECTS) $(RobboTripleBuild_HEADERS)
	$(CC) $(CFLAGS) -o RobboTripleBuild $(RobboTripleBuild_OBJECTS) -lpthread

%.o: %.c # Makefile
	$(CC) $(CFLAGS) -o $@ -c $<
archive:
	$(RM) -rf $(WORKING_DIR) *.tar # ensure
	$(MKDIR) $(WORKING_DIR)
	$(CP) $(ALL) $(WORKING_DIR) # inner classes ?
	$(TAR) cf $(WORKING_DIR).tar $(WORKING_DIR)/*
	$(RM) -rf $(WORKING_DIR)

clean:
	$(RM) -f *.o *~ RobboTotalBuild RobboTripleBuild
