# keymatrix — one target per verb.
#
# The folder is meant to be copied out of soleprint and used on its own — it has
# to be, since it must run on ethbox's WSL, which has no spr on its path. So
# everything here is derived from where this file sits rather than written down:
# copy the directory anywhere, `cd` into it, and `make` works.
#
#   make probe  OUT=~/wdir/semester/peripheral-matrix   read this machine
#   make check  SRC=~/wdir/semester/peripheral-matrix   findings
#   make shadow SRC=...                                 the posture table
#   make shadow SRC=... ARGS="--posture A"              one posture
#
# There is no `make apply`, and there is no apply verb to wrap. nrft is managed
# by hand: report recipes, do not apply them.
#
# The logic lives in the Python, never here. Each target is one invocation.

HERE   := $(patsubst %/,%,$(dir $(abspath $(lastword $(MAKEFILE_LIST)))))
PKG    := $(notdir $(HERE))
PARENT := $(patsubst %/,%,$(dir $(HERE)))
PY     ?= python3

KM := PYTHONPATH=$(PARENT) $(PY) -m $(PKG)

OUT  ?= .
SRC  ?= .
ARGS ?=

.PHONY: probe check shadow doctor help

help:
	@sed -n '2,17p' $(lastword $(MAKEFILE_LIST)) | sed 's/^# \{0,1\}//'

probe:
	$(KM) probe --output $(OUT) $(ARGS)

check:
	$(KM) check --source $(SRC) $(ARGS)

shadow:
	$(KM) shadow --source $(SRC) $(ARGS)

# Asks about the machine, never fails — rig's `make doctor` level.
doctor:
	@echo "python   : $$($(PY) --version)"
	@echo "gsettings: $$(command -v gsettings || echo MISSING)"
	@echo "dconf    : $$(command -v dconf || echo MISSING)"
	@echo "localectl: $$(command -v localectl || echo MISSING)"
	@echo "session  : $${XDG_SESSION_TYPE:-unknown} / $${XDG_CURRENT_DESKTOP:-unknown}"
	@echo "endpoint : $$(PYTHONPATH=$(PARENT) $(PY) -c 'from $(PKG).endpoint import resolve_endpoint, platform_kind; print(resolve_endpoint(), "/", platform_kind())')"
