# ASIO device clock: the estimate from the driver's time information.

CORE_DIR          := ../../..
LIBRETRO_COMM_DIR := $(CORE_DIR)/libretro-common

TARGET    := asio_clock_test
SOURCES_C := asio_clock_test.c
OBJS      := $(SOURCES_C:.c=.o)

INCDIRS   := -I$(LIBRETRO_COMM_DIR)/include -I$(CORE_DIR)
CFLAGS   += -Wall -Wno-variadic-macros $(INCDIRS) -D_GNU_SOURCE

ifneq ($(SANITIZER),)
CFLAGS  += -fsanitize=$(SANITIZER) -fno-omit-frame-pointer -g1
LDFLAGS += -fsanitize=$(SANITIZER)
else
CFLAGS  += -g1 -O1
endif

all: $(TARGET)

# The clock word's publish, reset and reader, taken from the driver.
asio_clock_driver.h: $(CORE_DIR)/audio/drivers/asio.c extract_clock.awk
	awk -f extract_clock.awk $(CORE_DIR)/audio/drivers/asio.c > $@.tmp && mv $@.tmp $@

asio_clock_test.o: asio_clock_driver.h

$(TARGET): $(OBJS)
	$(CC) -o $@ $(OBJS) $(LDFLAGS) -lm

%.o: %.c
	$(CC) $(CFLAGS) -std=c99 -pedantic -Wdeclaration-after-statement -Wno-long-long -c -o $@ $<

clean:
	rm -f $(OBJS) $(TARGET) asio_clock_driver.h

.PHONY: all clean
