# Tv Makefile
#
# SYNOPSIS:
#
#   make [all]  - makes everything.
#   make TARGET - makes the given target.
#   make clean  - removes all files generated by make.

# iutest root directory
IUTEST_DIR = ..

# Flags passed to the preprocessor.
CCFLAGS_ += -I$(IUTEST_DIR)/include

#
# Flags passed to the C++ compiler.
CCFLAGS += -g -Wall -Wextra
CCFLAGS += $(DEFS)


TARGETS = iutest_all_tests \
          iutest_assertion_only_tests \
          iutest_disabled_tests \
          iutest_env_var_tests \
          iutest_environment_tests \
          iutest_filter_tests \
          iutest_help_tests \
          iutest_listener_tests \
          iutest_minimum_tests \
          iutest_no_test_tests \
          iutest_param_test_tests \
          iutest_register_duplicate_tests \
          iutest_register_tests \
          iutest_repeat_tests \
          iutest_spi_failure_tests \
          iutest_uninitialize_tests
          
OBJS   := $(TARGETS:%=%.o)
SRCS   := $(TARGETS:%=%.c)
RUNNER := $(TARGETS:%=run_%)


# All iutest headers.  Usually you shouldn't change this
# definition.
IUTEST_HEADERS = $(IUTEST_DIR)/include/*.h \
                 $(IUTEST_DIR)/include/impl/*.inl \
                 $(IUTEST_DIR)/include/internal/*.h \
                 $(IUTEST_DIR)/include/listener/*.h

# House-keeping build targets.

.PHONY: clean default all run test

default: $(TARGETS)

all: default test

clean:
	rm -f $(TARGETS) *.o

run: test
test: $(RUNNER)

run_% : %
	@echo $<
	./$< $(RUN_OPTION)

# Builds a sample test.  

ifdef USE_LIB
CCFLAGS_ += -DIUTEST_C_USE_LIB=1 -L../lib
$(TARGETS) : $(SRCS) $(IUTEST_HEADERS) Makefile
	$(CC) $(CCFLAGS_) $(CCFLAGS) -o $@ $@.c -liutest_c

else

$(TARGETS) : $(SRCS) $(IUTEST_HEADERS) Makefile
	$(CC) $(CCFLAGS_) $(CCFLAGS) -o $@ $@.c

endif
