# Makefile for the tp library.
#
# Usage:
#   make test                 # run all ERT test suites
#   make test-shuffled        # run the suite in a random order (SHUFFLE_SEED=n reproduces)
#   make doctest              # execute README examples against the code
#   make benchmark            # run reproducible correctness-first benchmarks
#   make compile              # byte-compile the library modules
#   make compile-all          # byte-compile modules + tests + dev scripts
#   make clean                # remove compiled files
#
# WERROR=t turns byte-compile warnings into errors (used in CI).
# If dash.el is not on the default load-path, point LOAD_EXTRA at it:
#   make test LOAD_EXTRA="-L ~/.emacs.d/elpa/dash-20240510.1327"

EMACS ?= emacs
LOAD_EXTRA ?=
WERROR ?= nil
TEST_DIR = tests
LOADPATH = -L . -L $(TEST_DIR) $(LOAD_EXTRA)

SRC = tp-core.el tp-style.el tp-reactive.el tp-surface.el tp-layer.el tp-ops.el tp-search.el \
      tp-render.el tp-stack.el tp-query.el tp-palette.el tp-builtins.el tp.el
TESTS = $(wildcard $(TEST_DIR)/*-tests.el)
TEST_SUPPORT = $(TEST_DIR)/tp-doctest.el $(TEST_DIR)/tp-run-shuffled.el
DEV = $(TEST_SUPPORT) tp-benchmark.el

.PHONY: test test-shuffled doctest benchmark compile compile-all clean

test:
	$(EMACS) -Q --batch $(LOADPATH) -l tp.el $(patsubst %,-l %,$(TESTS)) \
	  -f ert-run-tests-batch-and-exit

test-shuffled:
	$(EMACS) -Q --batch $(LOADPATH) -l tp.el $(patsubst %,-l %,$(TESTS)) \
	  -l tp-run-shuffled.el

doctest:
	$(EMACS) -Q --batch $(LOADPATH) -l tp-doctest.el

benchmark:
	$(EMACS) -Q --batch $(LOADPATH) -l tp-benchmark.el -f tp-benchmark-run

compile: clean
	$(EMACS) -Q --batch $(LOADPATH) \
	  --eval "(setq byte-compile-error-on-warn $(WERROR))" \
	  -f batch-byte-compile $(SRC)

compile-all: clean
	$(EMACS) -Q --batch $(LOADPATH) \
	  --eval "(setq byte-compile-error-on-warn $(WERROR))" \
	  -f batch-byte-compile $(SRC) $(TESTS) $(DEV)

clean:
	rm -f *.elc $(TEST_DIR)/*.elc
