# Makefile — DIOPTRA Defense Research Group (Kernel ABI 100 + SIGILLUM + Web Hub)
CC      := cc
CFLAGS  := -std=c11 -O2 -Wall -Wextra -Werror -fno-fast-math -ffp-contract=off -frounding-math
FMA_FLG := -std=c11 -O2 -Wall -Wextra -Werror -ffp-contract=fast

.PHONY: all c11 fma-neg fixtures parity sigillum-test guardrails simul-diff kit web-build web-check worker-test manifest ci clean

all: c11 fma-neg parity sigillum-test guardrails simul-diff kit manifest web-build web-check worker-test

c11:
	@mkdir -p build
	$(CC) $(CFLAGS) -Ikernel/c11/include kernel/c11/src/*.c -lm -o build/dioptra_c11

fma-neg:
	@mkdir -p build
	$(CC) $(FMA_FLG) -Ikernel/c11/include kernel/c11/fma_neg_control.c -lm -o build/dioptra_fma_control
	python3 -I tests/parity/test_fma_negative_control.py build/dioptra_fma_control

fixtures:
	python3 -I tests/parity/gen_fixtures.py

parity: c11
	python3 -I tests/parity/run_parity.py --c11 build/dioptra_c11 --manifest tests/fixtures/manifest.json

sigillum-test:
	python3 -I tests/sigillum/test_gate_and_tamper.py
	python3 -I sigillum/circuit_eval.py --self-test
	python3 -I sigillum/epistemic_guard.py --self-test

guardrails:
	python3 -I tests/guardrails/test_static_guardrails.py

simul-diff:
	python3 -I simul/scale_diff.py

kit:
	@mkdir -p dist/kits
	python3 -I kernel/py/dioptra_kernel/replay_kit.py --preset SYN-SWARM-72H --out dist/kits/demo-swarm.tar.gz
	python3 -I kernel/py/dioptra_kernel/replay_kit.py --verify dist/kits/demo-swarm.tar.gz

manifest: parity fma-neg
	python3 -I sigillum/gate_cli.py --build-release-manifest dist/release-manifest.json

web-build: manifest simul-diff
	node tools/build_site.mjs

web-check: web-build
	node tools/check_site.mjs

worker-test:
	node tests/worker_contract_test.mjs

ci: all
	@echo "[DIOPTRA CI] ALL GATES PASSED (160/160 PARITY, FMA NEG-CTRL, SIGILLUM, GR-01..04, WEB, WORKER)"

clean:
	rm -rf build dist public
