# Copyright 2026 Stephen Bouche
# SPDX-License-Identifier: GPL-3.0-or-later
# The Little FOCer V4 power button sampler, lifted out of its hwconf and
# driven through shutdown.c's 0.7 s majority vote. SRC= points it at
# another copy of the hwconf (e.g. the version before upstream 3a25d74f).
SRC ?= ../../hwconf/shaman/Little_FOCer_4/hw_Little_FOCer_V4.c
CC = gcc
CFLAGS = -O2 -g -Wall -Wextra -std=gnu99

.PHONY: default all clean run

default: test
all: default

sampler.inc: $(SRC)
	awk '/^static (volatile )?(bool|int|systime_t) shutdown_/ {print} \
	     /^bool hw_sample_shutdown_button\(void\)/ {f=1} f {print} f && /^}/ {f=0}' $(SRC) > $@
	grep -q 'hw_sample_shutdown_button' $@

test: main.c sampler.inc
	$(CC) $(CFLAGS) main.c -o $@

clean:
	rm -f test sampler.inc

run: test
	./test
