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

VERSION = 0.143

# HAS = -DHAS_POPCNT # -DHAS_PREFETCH # for the why ?
DEFINITIONS = -Dx86_64 # $(HAS)
DEFINITIONS += -DVERSION=\"$(VERSION)\"
# DEFINITIONS += -DMAGIC_BITBOARDS # in now
DEFINITIONS += -DUSE_ARRAYS_OWN
FLAGS = -Wall -I../include
OPTIONS = -g -O3 -fstrict-aliasing -fomit-frame-pointer -fno-exceptions

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

RobboExplorer_SOURCES = RobboExplorer.c \
                        RobboExplorer_glue.c \
                        RobboExplorer_extra.c

Robbo_Borrow_SOURCES = mobility.c \
                       Robbo_mfa.c \
                       move_gen.c \
                       set_position.c \
                       utility.c

RobboHACK_Sources = arrays_own.c magic_mult.c

SOURCES = $(RobboExplorer_SOURCES) $(RobboHACK_Sources) $(Robbo_Borrow_SOURCES)
OBJECTS = $(SOURCES:.c=.o)
AOBJECTS = $(SOURCES:.c=.ao)
ALTRO_DIR = RobboExplorerDir
ALL = $(SOURCES) RobboBaseLibUsage.h
DL_LIB = -ldl

all: RobboExplorer

RobboExplorer: $(OBJECTS)
	$(CC) $(CFLAGS) -o RobboExplorer $(OBJECTS) $(DL_LIB)
RobboExplorerStaticLink: $(AOBJECTS)
	$(CC) $(CFLAGS) -o RobboExplorer $(AOBJECTS) ../RobboBaseLib.so
%.o: %.c # Makefile
	$(CC) $(CFLAGS) -o $@ -c $<
%.ao: %.c # Makefile
	$(CC) $(CFLAGS) -DSTATIC_LINKERY -o $@ -c $<
clean:
	$(RM) -rf *~ $(OBJECTS) $(OBJECTS) RobboExplorer

archive:
	$(RM) -rf $(ALTRO_DIR) *.tar # ensure
	$(MKDIR) $(ALTRO_DIR)
	$(CP) $(ALL) Makefile $(ALTRO_DIR)
	$(TAR) cf RobboExplorerSource.tar $(ALTRO_DIR)/*
	$(RM) -rf $(ALTRO_DIR)
