diff --git a/makefile b/makefile index 862f0ab..b8f210a 100644 --- a/makefile +++ b/makefile @@ -11,27 +11,31 @@ SRC := $(wildcard $(SRCDIR)/*.c) OBJ := $(patsubst $(SRCDIR)/%.c,$(BUILDDIR)/%.o,$(SRC)) LIB := $(BUILDDIR)/$(LIBNAME).so -.PHONY: all clean clean-pycache test +.PHONY: all clean test 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 $@ $^ 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 +# Always rebuild, and always clean afterward (even if tests fail) +test: + @$(MAKE) clean + @$(MAKE) all + @python3 -m unittest -v; \ + status=$$?; \ + $(MAKE) clean; \ + exit $$status