# The pin and mode names script/lua_vesc_io.c's vesc.gpio_* take, against the
# names LispBM's gpio-* take.
#
# gpio_name_is, gpio_strip and gpio_mode_index are cut out of the real source
# rather than copied, as tests/lua_adc does, and the extraction is checked.

TOP = ../..
SRC = $(TOP)/script/lua_vesc_io.c

CFLAGS = -std=gnu99 -O1 -g -Wall -Wextra -I. -fsanitize=address,undefined

all: test

gpio_names.inc: $(SRC) Makefile
	@sed -n '/^static bool gpio_name_is(/,/^static bool gpio_pin(/p' $(SRC) \
		| sed '$$d' > $@
	@grep -q 'static int gpio_mode_index' $@ || { echo "gpio_names.inc is"\
		" missing gpio_mode_index: the markers in $(SRC) moved"; rm -f $@; exit 1; }

test: main.c gpio_names.inc
	gcc $(CFLAGS) -o $@ main.c

run: test
	./test

clean:
	rm -f test gpio_names.inc
