SIM_ROOT := $(abspath ../../..)
RTL_ROOT := $(abspath $(SIM_ROOT)/../rtl)
include $(SIM_ROOT)/mk/rtl-sources.mk

TOPLEVEL := match_engine_pipeline
COCOTB_TEST_MODULES := tests.modules.match_engine_pipeline.test_match_engine_pipeline
VERILOG_SOURCES := $(RTL_MATCH_ENGINE)

# Allow override from command line (e.g. make TOPK_K=1)
TOPK_K ?= 4
EXTRA_ARGS += +define+TOPK_K=$(TOPK_K)
export TOPK_K

# Parameter-specific build directory so K variants never collide.
SIM_BUILD := sim_build/k_$(TOPK_K)

include $(SIM_ROOT)/mk/cocotb-common.mk

# ── K-specific test targets ──────────────────────────────────────────────
# Recompile with K=1 and filter to the K=1 test.
.PHONY: test-k1

test-k1:
	$(MAKE) -B -f Makefile results.xml TOPK_K=1 \
	  COCOTB_TEST_FILTER=match_engine_topk_k1

# Also remove all module-local build artifacts, including legacy and variant dirs.
clean::
	rm -rf sim_build
