PK_CIPHERS :=
AUX :=
+
# we use the gnu make standard library
include gmsl
include avr-makefile.inc
+
+GLOBAL_INCDIR := ./ $(TESTSRC_DIR)
+
#-------------------------------------------------------------------------------
# inclusion of make stubs
+include mkfiles/0*.mk
include mkfiles/*.mk
#-------------------------------------------------------------------------------
ALGORITHMS = $(BLOCK_CIPHERS) $(STREAM_CIPHERS) $(HASHES) $(PRNGS) $(MACS) \
$(ENCODINGS) $(SIGNATURE) $(PK_CIPHERS) $(AUX)
ALGORITHMS_OBJ = $(patsubst %,%_OBJ, $(ALGORITHMS))
-ALGORITHMS_TEST_BIN = $(patsubst %,%_TEST_BIN, $(ALGORITHMS))
+ALGORITHMS_TESTBIN = $(patsubst %,%_TESTBIN, $(ALGORITHMS))
#-------------------------------------------------------------------------------
# define binary object in $(BIN_DIR)$(ALGO)/<obj>
$(foreach a, $(ALGORITHMS), $(eval $(call Assert_Template, \
$(a)_TESTBINOBJ, \
- $(addprefix $(BIN_DIR)$(call lc,$(a))/$(TEST_DIR),$($(a)_TEST_BIN)) \
+ $(addprefix $(BIN_DIR)$(call lc,$(a))/$(TEST_DIR),$($(a)_TESTBIN)) \
)))
-#$(foreach a, $(ALGORITHMS), \
-# $(if $(def $(a)_DIR), \
-# $(eval $(call Assert_Template, \
-# $(a)_DIR, \
-# . \
-# ) \
-# )) \
-#)
-#
-#$(foreach a, $(ALGORITHMS), \
-# $(if $(call seq($(strip($($(a)_DIR))),)), \
-# $(eval $(call Assert_Template, \
-# $(a)_DIR, \
-# . \
-# ) \
-# )) \
-#)
#-------------------------------------------------------------------------------
-#
-### ifeq 'blafoo' ''
-### $(error no source ($(2)) for $(1) in TargetSource_Template)
-### endif
define TargetSource_Template
$(1): $(2)
@echo "[cc]: $(1) <-- $(2)"
@mkdir -p $(dir $(1))
- @$(CC) $(CFLAGS_A) -I./$(strip $(3)) -c -o $(1) $(2)
+ @$(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), \
- $(filter %.S %.c, $(wildcard $($(a)_DIR)$(notdir $(patsubst %.o,%,$(b))).*)), \
- $($(a)_DIR) \
+ $(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), \
+ $(foreach b, $($(a)_TESTBIN), \
$(eval $(call TargetSource_Template, \
- $(BIN_DIR)$(call lc, $(a))/$(TEST_DIR)$(b), \
- $(if $(call sne,$(strip $(filter %.S %.c, $(wildcard $(TESTSRC_DIR)$(notdir $(patsubst %.o,%,$(b))).*))),), \
- $(filter %.S %.c, $(wildcard $(TESTSRC_DIR)$(notdir $(patsubst %.o,%,$(b))).*)), \
- $(filter %.S %.c, $(wildcard ./$(notdir $(patsubst %.o,%,$(b))).*))\
- ), \
- $($(a)_DIR) \
+ $(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) \
#-------------------------------------------------------------------------------
define TestBin_TEMPLATE
-$(1)_TEST_BIN: $(2)
+$(1)_TESTBIN: $(2)
endef
$(foreach algo, $(ALGORITHMS), $(eval $(call TestBin_TEMPLATE, \
#-------------------------------------------------------------------------------
+define Listing_TEMPLATE
+$(1)_LIST: $(2)
+endef
+
+$(foreach algo, $(ALGORITHMS), $(eval $(call Listing_TEMPLATE, \
+ $(algo), \
+ $(foreach obj,$($(algo)_OBJ), $(LIST_DIR)$(call lc, $(algo))/$(obj:.o=.s)) \
+)))
+
+#-------------------------------------------------------------------------------
+
%.hex: %.elf
@echo "[objcopy]: $@"
@$(OBJCOPY) -j .text -j .data -O ihex $< $@
#-------------------------------------------------------------------------------
.PHONY: tests
-tests: $(foreach a, $(ALGORITHMS), $(a)_TEST_BIN)
+tests: $(foreach a, $(ALGORITHMS), $(a)_TESTBIN)
#-------------------------------------------------------------------------------
define TestRun_Template
$(1)_TESTRUN: $(1)_FLASH
+ @echo "[reset]"
+ @sleep 3
+ @$(RESETCMD)
+ @sleep 1
@echo "[test]: $(1)"
$(RUBY) $(GET_TEST) $(TESTPORT) $(TESTPORTBAUDR) 8 1 nessie $(TESTLOG_DIR)$(TESTPREFIX) $(2)
endef
))\
)
+.PHONY: all
+all: cores
+
+.PHONY: reset
+reset:
+ $(RESETCMD)
+
.PHONY: cores
cores: $(foreach algo, $(ALGORITHMS), $(algo)_OBJ)
@echo " docu - build doxygen documentation"
@echo " clean - remove a lot of builded files"
@echo " depclean - also remove dependency files"
- @echo " *_TEST_BIN - build test program"
+ @echo " *_TESTBIN - build test program"
@echo " *_TESTRUN - run nessie test"
@echo " *_OBJ - build algorithm core"
@echo " *_FLASH - flash test program"