+define TargetSource_Template
+$(1): $(2)
+ @echo "[cc]: $(1) <-- $(2)"
+ @mkdir -p $(dir $(1))
+ @$(CC) $(CFLAGS_A) $(addprefix -I./,$(3)) $(addprefix -D, $(4)) -c -o $(1) $(2)
+endef
+
+# ----------------------------------------------------------------------------
+# Function: find_source_file
+# Arguments: 1: name of the binary file (.o extension) to search
+# 2: list of directorys to search for file
+# Returns: Returns paths to source file (mathing the pattern in
+# $(SOURCE_PATTERN)
+# ----------------------------------------------------------------------------
+SOURCE_PATTERN := %.S %.c
+find_source_file = $(firstword $(foreach d, $(2), \
+ $(filter $(SOURCE_PATTERN), \
+ $(wildcard $(d)$(notdir $(patsubst %.o,%,$1)).*) \
+ ) \
+ ) )
+
+
+$(foreach a, $(ALGORITHMS), \
+ $(foreach b, $($(a)_OBJ), \
+ $(eval $(call TargetSource_Template, \
+ $(BIN_DIR)$(call lc, $(a))/$(b), \
+ $(call find_source_file, $(b), $($(a)_DIR) $($(a)_INCDIR) $(GLOBAL_INCDIR) ),\
+ $($(a)_DIR) $($(a)_INCDIR) $(GLOBAL_INCDIR), \
+ $($(a)_DEF), \
+ )) \
+ ) \
+)
+
+$(foreach a, $(ALGORITHMS), \
+ $(foreach b, $($(a)_TEST_BIN), \
+ $(eval $(call TargetSource_Template, \
+ $(BIN_DIR)$(call lc, $(a))/$(TEST_DIR)$(b), \
+ $(call find_source_file, $(b), $($(a)_DIR) $($(a)_INCDIR) $(GLOBAL_INCDIR) ),\
+ $($(a)_DIR) $($(a)_INCDIR) $(GLOBAL_INCDIR), \
+ $($(a)_DEF) \
+ )) \
+ ) \
+)