42 lines
920 B
Makefile
42 lines
920 B
Makefile
CC := gcc
|
|
CFLAGS := -O3 -fPIC -Wall -Wextra
|
|
LDFLAGS := -shared
|
|
|
|
SRCDIR := engine/src
|
|
INCDIR := engine/include
|
|
BUILDDIR := build
|
|
LIBNAME := libchess
|
|
|
|
SRC := $(wildcard $(SRCDIR)/*.c)
|
|
OBJ := $(patsubst $(SRCDIR)/%.c,$(BUILDDIR)/%.o,$(SRC))
|
|
LIB := $(BUILDDIR)/$(LIBNAME).so
|
|
|
|
.PHONY: all clean test
|
|
|
|
all: $(LIB)
|
|
|
|
$(BUILDDIR):
|
|
@mkdir -p $(BUILDDIR)
|
|
|
|
$(BUILDDIR)/%.o: $(SRCDIR)/%.c | $(BUILDDIR)
|
|
$(CC) $(CFLAGS) -I$(INCDIR) -c $< -o $@
|
|
|
|
$(LIB): $(OBJ)
|
|
$(CC) $(LDFLAGS) -o $@ $^
|
|
|
|
clean:
|
|
@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
|
|
|
|
# Always rebuild, and always clean afterward (even if tests fail)
|
|
test:
|
|
@$(MAKE) clean
|
|
@$(MAKE) all
|
|
@python3 -m unittest -v; \
|
|
status=$$?; \
|
|
$(MAKE) clean; \
|
|
exit $$status
|