1 # Makefile for the AVR-Crypto-Lib project
13 # we use the gnu make standard library
15 include avr-makefile.inc
17 #-------------------------------------------------------------------------------
18 # inclusion of make stubs
21 #-------------------------------------------------------------------------------
22 ALGORITHMS = $(BLOCK_CIPHERS) $(STREAM_CIPHERS) $(HASHES) $(PRNGS) $(MACS) \
24 ALGORITHMS_OBJ = $(patsubst %,%_OBJ, $(ALGORITHMS))
25 ALGORITHMS_TEST_BIN = $(patsubst %,%_TEST_BIN, $(ALGORITHMS))
27 #-------------------------------------------------------------------------------
28 # define binary object in $(BIN_DIR)$(ALGO)/<obj>
29 define Assert_Template
33 $(foreach a, $(ALGORITHMS), $(eval $(call Assert_Template, \
35 $(addprefix $(BIN_DIR)$(call lc,$(a))/,$($(a)_OBJ)) \
38 $(foreach a, $(ALGORITHMS), $(eval $(call Assert_Template, \
40 $(addprefix $(BIN_DIR)$(call lc,$(a))/$(TEST_DIR),$($(a)_TEST_BIN)) \
44 #$(foreach a, $(ALGORITHMS), \
45 # $(if $(def $(a)_DIR), \
46 # $(eval $(call Assert_Template, \
53 #$(foreach a, $(ALGORITHMS), \
54 # $(if $(call seq($(strip($($(a)_DIR))),)), \
55 # $(eval $(call Assert_Template, \
62 #-------------------------------------------------------------------------------
65 ### $(error no source ($(2)) for $(1) in TargetSource_Template)
68 define TargetSource_Template
70 @echo "[cc]: $(1) <-- $(2)"
72 @$(CC) $(CFLAGS_A) -I./$(strip $(3)) -c -o $(1) $(2)
75 $(foreach a, $(ALGORITHMS), \
76 $(foreach b, $($(a)_OBJ), \
77 $(eval $(call TargetSource_Template, \
78 $(BIN_DIR)$(call lc, $(a))/$(b), \
79 $(filter %.S %.c, $(wildcard $($(a)_DIR)$(notdir $(patsubst %.o,%,$(b))).*)), \
85 $(foreach a, $(ALGORITHMS), \
86 $(foreach b, $($(a)_TEST_BIN), \
87 $(eval $(call TargetSource_Template, \
88 $(BIN_DIR)$(call lc, $(a))/$(TEST_DIR)$(b), \
89 $(if $(call sne,$(strip $(filter %.S %.c, $(wildcard $(TESTSRC_DIR)$(notdir $(patsubst %.o,%,$(b))).*))),), \
90 $(filter %.S %.c, $(wildcard $(TESTSRC_DIR)$(notdir $(patsubst %.o,%,$(b))).*)), \
91 $(filter %.S %.c, $(wildcard ./$(notdir $(patsubst %.o,%,$(b))).*))\
97 #-------------------------------------------------------------------------------
99 define MainTestElf_Template
102 @$(CC) $(CFLAGS_A) $(LDFLAGS)$(patsubst %.elf,%.map,$(1)) -o \
108 $(foreach a, $(ALGORITHMS), \
109 $(eval $(call MainTestElf_Template, \
110 $(BIN_DIR)$(call lc, $(a))/$(TEST_DIR)main-$(call lc, $(a))-test.elf, \
116 #-------------------------------------------------------------------------------
118 all: $(foreach algo, $(ALGORITHMS), $($(algo)_BINOBJ))
120 #-------------------------------------------------------------------------------
122 define TestBin_TEMPLATE
126 $(foreach algo, $(ALGORITHMS), $(eval $(call TestBin_TEMPLATE, \
128 $(BIN_DIR)$(call lc, $(algo))/$(TEST_DIR)main-$(call lc, $(algo))-test.elf \
131 #-------------------------------------------------------------------------------
134 @echo "[objcopy]: $@"
135 @$(OBJCOPY) -j .text -j .data -O ihex $< $@
137 #-------------------------------------------------------------------------------
139 define Flash_Template
141 @echo "[flash]: $(2)"
142 @$(FLASHCMD)$(call first,$(2))
145 $(foreach algo, $(ALGORITHMS), $(eval $(call Flash_Template, \
147 $(BIN_DIR)$(call lc, $(algo))/$(TEST_DIR)main-$(call lc, $(algo))-test.hex \
150 #-------------------------------------------------------------------------------
153 tests: $(foreach a, $(ALGORITHMS), $(a)_TEST_BIN)
155 #-------------------------------------------------------------------------------
157 define TestRun_Template
158 $(1)_TESTRUN: $(1)_FLASH
160 $(RUBY) $(GET_TEST) $(TESTPORT) $(TESTPORTBAUDR) 8 1 nessie $(TESTLOG_DIR)$(TESTPREFIX) $(2)
163 $(foreach algo, $(ALGORITHMS),$(eval $(call TestRun_Template, $(algo), $(call lc,$(algo)) )))
165 all_testrun: $(foreach algo, $(ALGORITHMS), $(algo)_TESTRUN)
167 #-------------------------------------------------------------------------------
173 $(foreach algo, $(ALGORITHMS), \
174 $(eval $(call Obj_Template, \
181 cores: $(foreach algo, $(ALGORITHMS), $(algo)_OBJ)
183 .PHONY: blockchiphers
184 blockciphers: $(foreach algo, $(BLOCK_CIPHERS), $(algo)_OBJ)
186 .PHONY: streamchiphers
187 streamciphers: $(foreach algo, $(STREAM_CIPHERS), $(algo)_OBJ)
190 hashes: $(foreach algo, $(HASHES), $(algo)_OBJ)
193 macs: $(foreach algo, $(MACS), $(algo)_OBJ)
196 prngs: $(foreach algo, $(PRNGS), $(algo)_OBJ)
199 encodings: $(foreach algo, $(ENCODINGS), $(algo)_OBJ)
202 aux: $(foreach algo, $(AUX), $(algo)_OBJ)
205 #-------------------------------------------------------------------------------
212 @echo "infos on AVR-Crypto-lib:"
213 @echo " block ciphers:"
214 @echo " $(BLOCK_CIPHERS)"
215 @echo " stream ciphers:"
216 @echo " $(STREAM_CIPHERS)"
217 @echo " hash functions:"
219 @echo " MAC functions:"
221 @echo " PRNG functions:"
224 @echo " $(ENCODINGS)"
226 @echo " all - all algorithm cores"
227 @echo " cores - all algorithm cores"
228 @echo " listings - all algorithm core listings"
229 @echo " tests - all algorithm test programs"
230 @echo " stats - all algorithm size statistics"
231 @echo " blockciphers - all blockcipher cores"
232 @echo " streamciphers - all streamcipher cores"
233 @echo " hashes - all hash cores"
234 @echo " macs - all MAC cores"
235 @echo " prngs - all PRNG cores"
236 @echo " all_testrun - testrun all algorithms"
237 @echo " docu - build doxygen documentation"
238 @echo " clean - remove a lot of builded files"
239 @echo " depclean - also remove dependency files"
240 @echo " *_TEST_BIN - build test program"
241 @echo " *_TESTRUN - run nessie test"
242 @echo " *_OBJ - build algorithm core"
243 @echo " *_FLASH - flash test program"
244 @echo " *_LIST - build assembler listing"
247 #-------------------------------------------------------------------------------
257 #-------------------------------------------------------------------------------
258 # dependency inclusion
261 DEPS := $(wildcard $(DEP_DIR)*.d)