-ALGORITHMS_OBJ_IMM = $(foreach a, $(ALGORITHMS_OBJ), $($(a)))
-ALGORITHMS_TEST_BIN = $(patsubst %,%_TEST_BIN, $(ALGORITHMS))
-ALGORITHMS_TEST_BIN_MAIN = $(foreach a, $(ALGORITHMS_TEST_BIN), $(firstword $($(a))))
-ALGORITHMS_TEST_BIN_MAIN_ELF = $(patsubst %.o, %.elf, $(ALGORITHMS_TEST_BIN_MAIN))
-ALGORITHMS_TEST_BIN_MAIN_HEX = $(patsubst %.o, %.hex, $(ALGORITHMS_TEST_BIN_MAIN))
-
-ALGORITHMS_TEST_BIN_IMM = $(foreach a, $(ALGORITHMS_TEST_BIN), $($(a)))
-ALGORITHMS_NESSIE_TEST = $(patsubst %,%_NESSIE_TEST, $(ALGORITHMS))
-ALGORITHMS_PERFORMANCE_TEST = $(patsubst %,%_PERORMANCE_TEST, $(ALGORITHMS))
-
-#ALGORITHMS_LC = #algorithm names in lowercase
-#ALGORITHMS_LC = $(foreach a, $(ALGORITHMS), $$(lc Text))
-ALGORITHMS_LC = $(call lc,$(ALGORITHMS))
-PRG = remove_me
-
-DEFS =
-LIBS =
-
-define BLA_TEMPLATE2
-$(2): $(3)
- @echo "[gcc]: $$@"
-# echo $$^
- @$(CC) $(CFLAGS) $(LDFLAGS)$(patsubst %.elf,%.map,$(2)) -o \
- $(2) \
- $(3) \
+ALGORITHMS_TESTBIN = $(patsubst %,%_TESTBIN, $(ALGORITHMS))
+
+#-------------------------------------------------------------------------------
+# define binary object in $(BIN_DIR)$(ALGO)/<obj>
+define Assert_Template
+$(1) = $(2)
+endef
+
+$(foreach a, $(ALGORITHMS), $(eval $(call Assert_Template, \
+ $(a)_BINOBJ, \
+ $(addprefix $(BIN_DIR)$(call lc,$(a))/,$($(a)_OBJ)) \
+)))
+
+$(foreach a, $(ALGORITHMS), $(eval $(call Assert_Template, \
+ $(a)_TESTBINOBJ, \
+ $(addprefix $(BIN_DIR)$(call lc,$(a))/$(TEST_DIR),$($(a)_TESTBIN)) \
+)))
+
+
+
+#-------------------------------------------------------------------------------
+
+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
+
+
+
+define TargetSourceList_Template
+$(1): $(2)
+ @echo "[cc]: $(1) <-- $(2)"
+ @mkdir -p $(dir $(1))
+ @$(CC) $(CFLAGS_A) $(addprefix -I./,$(3)) $(addprefix -D, $(4)) $(LIST_OPT) -c -o /dev/null $(2) > $(1)
+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)_TESTBIN), \
+ $(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) \
+ )) \
+ ) \
+)
+
+
+$(foreach a, $(ALGORITHMS), \
+ $(foreach b, $($(a)_OBJ), \
+ $(eval $(call TargetSourceList_Template, \
+ $(LIST_DIR)$(call lc, $(a))/$(patsubst %.o,%.s,$(b)), \
+ $(call find_source_file, $(b), $($(a)_DIR) $($(a)_INCDIR) $(GLOBAL_INCDIR) ),\
+ $($(a)_DIR) $($(a)_INCDIR) $(GLOBAL_INCDIR), \
+ $($(a)_DEF), \
+ )) \
+ ) \
+)
+
+#-------------------------------------------------------------------------------
+
+define MainTestElf_Template
+$(1): $(2) $(3)
+ @mkdir -p $(dir $(1))
+ @echo "[ld]: $(1)"
+ @$(CC) $(CFLAGS_A) $(LDFLAGS)$(patsubst %.elf,%.map,$(1)) -o \
+ $(1) \
+ $(2) $(3) \