# Golden-verification: Mesa oracle vs our builder.
# The oracle compiles VENDORED Mesa source (rkt_task.c / rkt_regcmd.c) against
# shims; warnings there are Mesa's, so build it with -w. ourdump uses our own
# objects from the parent dir.
CC     ?= gcc
OFLAGS ?= -O2 -w
CFLAGS ?= -Wall -Wextra -O2

PARENT_OBJS = ../rkt_matmul.o ../rkt_matmul_cna.o ../rkt_matmul_coredpu.o

.PHONY: all diff clean
all: oracle ourdump

oracle: oracle.c rkt_task.c rkt_regcmd.c rkt_ml.h rkt_task.h rkt_regcmd.h rkt_registers.h
	$(CC) $(OFLAGS) -o $@ oracle.c rkt_task.c rkt_regcmd.c

ourdump: ourdump.c
	$(MAKE) -C .. selftest >/dev/null
	$(CC) $(CFLAGS) -I.. -o $@ ourdump.c $(PARENT_OBJS)

diff: oracle ourdump
	@./oracle  > oracle.txt
	@./ourdump > ours.txt
	@echo "oracle=$$(wc -l < oracle.txt) words   ours=$$(wc -l < ours.txt) words"
	@if diff -u oracle.txt ours.txt > golden.diff; then \
		echo "IDENTICAL — GOLDEN MATCH"; \
	else \
		echo "DIVERGENCE (see golden.diff):"; cat golden.diff; \
	fi

clean:
	rm -f oracle ourdump oracle.txt ours.txt golden.diff
