CPPFLAGS += -I../../../include -I../../../../common/interface/gen/host
# -I/root/depot/common/oska/main/posix/include -I/root/depot/common/oska/main/include -I/root/depot/common/sdioemb/main/include
CFLAGS += -g -Wall -Werror
LDFLAGS += 
LIBS += -lsdio -loska -lpthread -lrt

posix_tests := posix_test1 posix_test2 posix_fstest1 posix_fstest2 posix_fstest3 posix_fstest4
linux_tests := linux_test1 linux_test2

fstest1_sources := \
	../fstest1.c

fstest2_sources := \
	../fstest2.c

fstest3_sources := \
	../fstest3.c

fstest4_sources := \
	../fstest4.c

test1_sources := \
	../test1.c

test2_sources := \
	../test2.c

posix_libhydra := ../../../posix/libhydra_user.a
linux_libhydra := ../../../linux/userspace/libhydra_user.a

fstest1_objs := $(fstest1_sources:%.c=%.o)
fstest1_deps := $(fstest1_objs:%.o=%.d)

fstest2_objs := $(fstest2_sources:%.c=%.o)
fstest2_deps := $(fstest2_objs:%.o=%.d)

fstest3_objs := $(fstest3_sources:%.c=%.o)
fstest3_deps := $(fstest3_objs:%.o=%.d)

fstest4_objs := $(fstest4_sources:%.c=%.o)
fstest4_deps := $(fstest4_objs:%.o=%.d)

test1_objs := $(test1_sources:%.c=%.o)
test1_deps := $(test1_objs:%.o=%.d)

test2_objs := $(test2_sources:%.c=%.o)
test2_deps := $(test2_objs:%.o=%.d)

all: posix_libs linux_libs $(posix_tests) $(linux_tests)

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

posix_fstest1: $(fstest1_objs) $(posix_libhydra)
	$(CC) $(CPPFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)

posix_fstest2: $(fstest2_objs) $(posix_libhydra)
	$(CC) $(LDFLAGS) -o $@ $^ $(LIBS)

posix_fstest3: $(fstest3_objs) $(posix_libhydra)
	$(CC) $(LDFLAGS) -o $@ $^ $(LIBS)

posix_fstest4: $(fstest4_objs) $(posix_libhydra)
	$(CC) $(LDFLAGS) -o $@ $^ $(LIBS)

posix_test1: $(test1_objs) $(posix_libhydra)
	$(CC) $(LDFLAGS) -o $@ $^ $(LIBS)
posix_test2: $(test2_objs) $(posix_libhydra)
	$(CC) $(LDFLAGS) -o $@ $^ $(LIBS)

linux_test1: $(test1_objs) $(linux_libhydra)
	$(CC) $(LDFLAGS) -o $@ $^ $(LIBS)
linux_test2: $(test2_objs) $(linux_libhydra)
	$(CC) $(LDFLAGS) -o $@ $^ $(LIBS)

$(posix_libhydra): posix_libs
$(linux_libhydra): linux_libs

posix_libs:
	$(MAKE) -C ../../../posix libhydra_user.a
linux_libs:
	$(MAKE) -C ../../../linux/userspace libhydra_user.a

clean:
	rm -f $(fstest1_objs) $(fstest2_objs) $(fstest3_objs) $(fstest4_objs) $(fstest1_deps) $(test1_objs) $(test1_deps) $(test2_objs) $(test2_deps) $(posix_tests) $(linux_tests)

-include $(fstest1_deps) $(fstest2_deps) $(fstest3_deps) $(fstest4_deps) $(test1_deps) $(test2_deps)
