#
ifndef ESP_ROOT
$(error ESP_ROOT must be set -- Please fix the environment...)
ifndef ESP_ARCH
$(error ESP_ARCH must be set -- Please fix the environment...)
endif
endif
#
IDIR  = $(ESP_ROOT)/include
include $(IDIR)/$(ESP_ARCH)
LDIR  = $(ESP_ROOT)/lib
ifdef ESP_BLOC
ODIR  = $(ESP_BLOC)/obj
TDIR  = $(ESP_BLOC)/test
else
ODIR  = ./
TDIR  = ./
endif
#

FILES = $(wildcard *Test.c)
TESTS = $(addprefix $(TDIR)/,$(FILES:.c=))

default:	$(TESTS)

# Build test executables
$(TDIR)/%Test: %Test.c ../*.c ../*.h $(IDIR)/aimTest.h $(LDIR)/libaimUtil.a $(LDIR)/libutils.a
	$(CC) $< -o $@  $(COPTS) $(DEFINE) -I$(IDIR) -I../ -L$(LDIR) -lutils -laimUtil -lcaps -locsm -legads \
		-lpthread $(RPATH) -ludunits2 -lm -ldl

# Run all tests
test:	$(TESTS)
	@for f in $(TESTS); \
	do \
	  printf "============================================================\n"; \
	  $$f \
	  && printf "%-35s passed (as expected)\n" $$f \
	  || printf "%-35s failed (as NOT expected)\n" $$f; \
	done

clean:
	-rm -f $(TESTS)

cleanall:	clean
