CPPFLAGS += -I../../include -I ../../../common/interface/gen/host/
CFLAGS += -Wall -g -Werror
LDFLAGS += -g
LIBS += -loska -lpthread -lrt

ifdef OSKADIR
CPPFLAGS += -I$(OSKADIR)/posix/include -I$(OSKADIR)/include
LDFLAGS += -L$(OSKADIR)/posix
endif
ifdef SDIOEMBDIR
CPPFLAGS += -I$(SDIOEMBDIR)/include
endif

programs := \
	chip_tests

tests := \
	test_service.c \
	test_q_pair.c \
	test_q_completer.c \
	test_loopback.c \
	test_sapi.c \
	test_driver.c \
	test_ptap.c \
	test_helpers.c \
	test_isp_client.c

chip_tests_sources := \
	$(tests) \
	main_tests.c

chip_tests_objs := $(chip_tests_sources:.c=.o)
chip_tests_deps := $(chip_tests_objs:.o=.d)

libhydra_core := ../../posix/libhydra.a

all: libs $(programs)

%.o: %.c
	@test -e $(dir $@) || mkdir -p $(dir $@)
	@$(CC) $(CPPFLAGS) -M  -MF $(@:.o=.d) -MT "$@ $(@:.o=.d)" $<
	$(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<

chip_tests: $(chip_tests_objs) $(libhydra_core)
	$(CC) -o $@ $(LDFLAGS) $^ $(LIBS)

$(libhydra_core): libs

libs:
	$(MAKE) -C ../../posix

clean:
	$(MAKE) -C ../../posix clean
	rm -f $(programs) *.o *.d

-include $(chip_tests_deps)
