# sw/examples -- small Linux user programs for the unit on tpu_mcore: the MPU (the matrix array) and the VPU, in AI and in
# plain arithmetic.  Each folder is one program (main.c, its header says what it shows); README.md lists them.
#     make            build/<name> for every example (static, the image's own compiler: no file but the program goes to the board)
#     make test       upload each over ssh and run it (run_tests.sh; IP = the board's Linux, DBG = its debug link)
#     make clean
HB   ?= riscv32-buildroot-linux-musl-     # on PATH: linux/build/output/host/bin after ./build.sh
AME  := .
CFLAGS := -O2 -static -Wall -I$(AME)
IP   ?= 192.168.77.5
DBG  ?= 192.168.77.3
EX   := $(patsubst %/main.c,%,$(wildcard */main.c))
all: $(EX:%=build/%) build/superresolution
build/%: %/main.c l8ex.h $(AME)/ame.h
	@mkdir -p build
	$(HB)gcc $(CFLAGS) -o $@ $<
build/superresolution: superresolution/sr_gemm.c superresolution/libtpu.c superresolution/libtpu.h
	@mkdir -p build
	$(HB)gcc -O2 -static -Wall -Isuperresolution -o $@ superresolution/sr_gemm.c superresolution/libtpu.c
test: all
	sh run_tests.sh $(IP) $(DBG) $(EX) superresolution
clean:
	rm -rf build
.PHONY: all test clean
