add-fen-loader (#5)
All checks were successful
Python tests (make) / test (push) Successful in 10s

Reviewed-on: #5
Co-authored-by: Josh <josh@joshuaschuett.com>
Co-committed-by: Josh <josh@joshuaschuett.com>
This commit is contained in:
2025-08-16 16:51:53 +00:00
committed by Josh
parent b9d2f096e0
commit c02ec7875d
7 changed files with 351 additions and 32 deletions

View File

@@ -1,5 +1,3 @@
# Makefile at project root
CC := gcc
CFLAGS := -O3 -fPIC -Wall -Wextra
LDFLAGS := -shared
@@ -9,38 +7,51 @@ INCDIR := engine/include
BUILDDIR := build
LIBNAME := libchess
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
SOEXT := dylib
else
SOEXT := so
endif
SRC := $(wildcard $(SRCDIR)/*.c)
# Exclude test.c from the shared lib build
SRC := $(filter-out $(SRCDIR)/test.c,$(wildcard $(SRCDIR)/*.c))
OBJ := $(patsubst $(SRCDIR)/%.c,$(BUILDDIR)/%.o,$(SRC))
LIB := $(BUILDDIR)/$(LIBNAME).$(SOEXT)
LIB := $(BUILDDIR)/$(LIBNAME).so
.PHONY: all clean clean-pycache test
# ---- test executable (engine/src/test.c) ----
TESTSRC := $(SRCDIR)/test.c
TESTOBJ := $(BUILDDIR)/test.o
TESTBIN := $(BUILDDIR)/print_board
.PHONY: all clean test test-exe run
all: $(LIB)
$(BUILDDIR):
@mkdir -p $(BUILDDIR)
# compile each .c into build/*.o
$(BUILDDIR)/%.o: $(SRCDIR)/%.c | $(BUILDDIR)
$(CC) $(CFLAGS) -I$(INCDIR) -c $< -o $@
# link shared library
$(LIB): $(OBJ)
$(CC) $(LDFLAGS) -o $@ $^
c-test-exe: $(TESTBIN)
$(TESTOBJ): $(TESTSRC) | $(BUILDDIR)
$(CC) -std=c11 -Wall -Wextra -O2 -I$(INCDIR) -c $< -o $@
$(TESTBIN): $(TESTOBJ) $(LIB)
$(CC) -O2 -o $@ $(TESTOBJ) -L$(BUILDDIR) -lchess -Wl,-rpath,'$$ORIGIN'
run-c-test: test-exe
LD_LIBRARY_PATH=$(BUILDDIR) $(TESTBIN) $(FEN)
clean:
@echo "Cleaning Python caches..."
@find . -type d -name "__pycache__" -exec rm -rf {} +
@find . -type d -name ".pytest_cache" -exec rm -rf {} +
@echo "Cleaning build and Python caches..."
@rm -rf $(BUILDDIR)
@find . -type d -name "__pycache__" -exec rm -rf {} +
@find . -type d -name ".pytest_cache" -exec rm -rf {} +
@find . -type f \( -name "*.pyc" -o -name "*.pyo" \) -delete
# run Python unit tests
test: all
python3 -m unittest -v && $(MAKE) clean
test:
@$(MAKE) clean
@$(MAKE) all
@python3 -m unittest -v; \
status=$$?; \
$(MAKE) clean; \
exit $$status