# Platform detection
ifeq ($(OS),Windows_NT)
    PLATFORM := windows
else
    UNAME_S := $(shell uname -s 2>/dev/null || echo Unknown)
    ifeq ($(UNAME_S),Linux)
        PLATFORM := linux
    else
        $(error Unsupported platform: $(UNAME_S))
    endif
endif

# Platform settings
ifeq ($(PLATFORM),windows)
    BIN = GreKo.exe
    PLATFORM_OBJ = win32.o
else
    BIN = GreKo
    PLATFORM_OBJ = unix.o
endif

# Compiler and flags
CPP = g++
CPPFLAGS = -Wall -O3 -DFAST_BITBOARDS

ifeq ($(PLATFORM),windows)
    LD_PARAMS = -static -static-libgcc -static-libstdc++
else
    CPPFLAGS += -std=c++11 -pthread
    LD_PARAMS = -static -static-libgcc -static-libstdc++ -pthread
endif

# Object files
OBJ = bitboards.o   \
      eval.o        \
      eval_params.o \
      learn.o       \
      main.o        \
      moves.o       \
      notation.o    \
      position.o    \
      search.o      \
      utils.o       \
      $(PLATFORM_OBJ)

.PHONY: all clean

all: $(BIN)

clean:
	rm -f $(BIN) $(OBJ)

$(BIN): $(OBJ)
	$(CPP) $(LD_PARAMS) $(OBJ) -o $(BIN)
	strip $(BIN)

%.o: %.cpp
	$(CPP) $(CPPFLAGS) -c $< -o $@

eval.o: eval_params.h
eval_params.o: eval_params.h
