CXX = g++
CXXFLAGS = -std=c++17 -O3 -march=native -DEIGEN_NO_DEBUG
INCLUDES = -I./core/include -I./eigen-3.4.0

SRCS = core/src/intuitive_system.cpp \
       core/src/prototype.cpp \
       core/src/etalon_memory.cpp \
       core/src/difference_classes.cpp \
       core/src/hemispheres.cpp \
       core/src/goal_system.cpp \
       core/src/value_hierarchy.cpp \
       core/src/energy_curiosity.cpp \
       core/src/governor_ovsieichik.cpp \
       core/src/drift_detector.cpp \
       core/src/dream_consolidation.cpp \
       core/src/connectome.cpp \
       core/src/spectral_merge.cpp \
       core/src/cortex.cpp

OBJS = $(SRCS:.cpp=.o)

TARGET = libkokao_core.so
EXAMPLE = example_basic
BENCHMARK = benchmark_performance
BENCHMARK_FIXED = benchmark_performance_fixed
BENCHMARK_DATASETS = benchmark_datasets

all: $(TARGET) $(EXAMPLE) $(BENCHMARK) $(BENCHMARK_FIXED) $(BENCHMARK_DATASETS)

$(TARGET): $(OBJS)
	$(CXX) -shared -o $@ $^

%.o: %.cpp
	$(CXX) $(CXXFLAGS) $(INCLUDES) -fPIC -c $< -o $@

$(EXAMPLE): examples/basic_usage.cpp $(TARGET)
	$(CXX) $(CXXFLAGS) $(INCLUDES) -o $@ $< -L. -lkokao_core -Wl,-rpath,.

$(BENCHMARK): tests/benchmarks/benchmark_performance.cpp $(TARGET)
	$(CXX) $(CXXFLAGS) $(INCLUDES) -o $@ $< -L. -lkokao_core -Wl,-rpath,.

$(BENCHMARK_FIXED): tests/benchmarks/benchmark_performance_fixed.cpp $(TARGET)
	$(CXX) $(CXXFLAGS) $(INCLUDES) -o $@ $< -L. -lkokao_core -Wl,-rpath,.

$(BENCHMARK_DATASETS): tests/benchmarks/benchmark_datasets.cpp
	$(CXX) $(CXXFLAGS) $(INCLUDES) -o $@ $< -lpthread

test: tests/unit/test_intuitive_system.cpp tests/unit/test_prototype.cpp tests/unit/test_etalon_memory.cpp tests/unit/test_homeostasis.cpp tests/integration/test_cortex.cpp tests/unit/test_difference_classes.cpp tests/unit/test_goal_system.cpp tests/unit/test_serialization.cpp tests/unit/test_v13_1_features.cpp
	$(CXX) $(CXXFLAGS) $(INCLUDES) -o test_intuitive tests/unit/test_intuitive_system.cpp
	$(CXX) $(CXXFLAGS) $(INCLUDES) -o test_prototype tests/unit/test_prototype.cpp
	$(CXX) $(CXXFLAGS) $(INCLUDES) -o test_memory tests/unit/test_etalon_memory.cpp
	$(CXX) $(CXXFLAGS) $(INCLUDES) -o test_homeostasis tests/unit/test_homeostasis.cpp
	$(CXX) $(CXXFLAGS) $(INCLUDES) -o test_cortex tests/integration/test_cortex.cpp
	$(CXX) $(CXXFLAGS) $(INCLUDES) -o test_diff_classes tests/unit/test_difference_classes.cpp
	$(CXX) $(CXXFLAGS) $(INCLUDES) -o test_goal_system tests/unit/test_goal_system.cpp
	$(CXX) $(CXXFLAGS) $(INCLUDES) -o test_serialization tests/unit/test_serialization.cpp
	$(CXX) $(CXXFLAGS) $(INCLUDES) -o test_v13_1_features tests/unit/test_v13_1_features.cpp -lgtest -lgtest_main -lpthread
	./test_intuitive
	./test_prototype
	./test_memory
	./test_homeostasis
	./test_cortex
	./test_diff_classes
	./test_goal_system
	./test_serialization
	./test_v13_1_features
	@echo "=== ALL TESTS PASSED ==="

clean:
	rm -f $(OBJS) $(TARGET) $(EXAMPLE) $(BENCHMARK) $(BENCHMARK_FIXED) $(BENCHMARK_DATASETS) test_intuitive test_prototype test_memory test_homeostasis test_cortex test_diff_classes test_goal_system test_serialization test_v13_1_features

.PHONY: all clean test
