TARGET = test
LIBS = -lm -fsanitize=address,undefined
CC = gcc
CFLAGS = -O1 -g -fsanitize=address,undefined -fno-omit-frame-pointer -Wall -Wextra -Wundef \
         -std=gnu99 -I. -I../.. -I../../motor -DNO_STM32
SOURCES = main.c ../../motor/audio_stream.c
OBJECTS = $(notdir $(SOURCES:.c=.o))

.PHONY: default all clean run

default: $(TARGET)
all: default

# The ring's size is in the header, and a stale object built against another
# one writes past the end of the struct.
%.o: %.c ../../motor/audio_stream.h
	$(CC) $(CFLAGS) -c $< -o $@

%.o: ../../motor/%.c ../../motor/audio_stream.h
	$(CC) $(CFLAGS) -c $< -o $@

$(TARGET): $(OBJECTS)
	$(CC) $(OBJECTS) -Wall $(LIBS) -o $@

clean:
	rm -f $(OBJECTS) $(TARGET)

run: $(TARGET)
	./$(TARGET)
