+# ----------------------------------------------------------------------------
+# 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)_DEFINES), \
+ )) \
+ ) \
+)
+
+$(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)_DEFINES) \
+ )) \
+ ) \
+)
+
+#-------------------------------------------------------------------------------
+
+define MainTestElf_Template
+$(1): $(2) $(3)
+ @echo "[ld]: $(1)"
+ @$(CC) $(CFLAGS_A) $(LDFLAGS)$(patsubst %.elf,%.map,$(1)) -o \
+ $(1) \
+ $(2) $(3) \