1 # Makefile for the AVR-Crypto-Lib project
15 # we use the gnu make standard library
17 include avr-makefile.inc
19 #-------------------------------------------------------------------------------
20 # inclusion of make stubs
23 #-------------------------------------------------------------------------------
24 ALGORITHMS = $(BLOCK_CIPHERS) $(STREAM_CIPHERS) $(HASHES) $(PRNGS) $(MACS) \
25 $(ENCODINGS) $(SIGNATURE) $(PK_CIPHERS) $(AUX)
26 ALGORITHMS_OBJ = $(patsubst %,%_OBJ, $(ALGORITHMS))
27 ALGORITHMS_TEST_BIN = $(patsubst %,%_TEST_BIN, $(ALGORITHMS))
29 #-------------------------------------------------------------------------------
30 # define binary object in $(BIN_DIR)$(ALGO)/<obj>
31 define Assert_Template
35 $(foreach a, $(ALGORITHMS), $(eval $(call Assert_Template, \
37 $(addprefix $(BIN_DIR)$(call lc,$(a))/,$($(a)_OBJ)) \
40 $(foreach a, $(ALGORITHMS), $(eval $(call Assert_Template, \
42 $(addprefix $(BIN_DIR)$(call lc,$(a))/$(TEST_DIR),$($(a)_TEST_BIN)) \
46 #$(foreach a, $(ALGORITHMS), \
47 # $(if $(def $(a)_DIR), \
48 # $(eval $(call Assert_Template, \
55 #$(foreach a, $(ALGORITHMS), \
56 # $(if $(call seq($(strip($($(a)_DIR))),)), \
57 # $(eval $(call Assert_Template, \
64 #-------------------------------------------------------------------------------
67 ### $(error no source ($(2)) for $(1) in TargetSource_Template)
70 define TargetSource_Template
72 @echo "[cc]: $(1) <-- $(2)"
74 @$(CC) $(CFLAGS_A) -I./$(strip $(3)) -c -o $(1) $(2)
77 $(foreach a, $(ALGORITHMS), \
78 $(foreach b, $($(a)_OBJ), \
79 $(eval $(call TargetSource_Template, \
80 $(BIN_DIR)$(call lc, $(a))/$(b), \
81 $(filter %.S %.c, $(wildcard $($(a)_DIR)$(notdir $(patsubst %.o,%,$(b))).*)), \
87 $(foreach a, $(ALGORITHMS), \
88 $(foreach b, $($(a)_TEST_BIN), \
89 $(eval $(call TargetSource_Template, \
90 $(BIN_DIR)$(call lc, $(a))/$(TEST_DIR)$(b), \
91 $(if $(call sne,$(strip $(filter %.S %.c, $(wildcard $(TESTSRC_DIR)$(notdir $(patsubst %.o,%,$(b))).*))),), \
92 $(filter %.S %.c, $(wildcard $(TESTSRC_DIR)$(notdir $(patsubst %.o,%,$(b))).*)), \
93 $(filter %.S %.c, $(wildcard ./$(notdir $(patsubst %.o,%,$(b))).*))\
99 #-------------------------------------------------------------------------------
101 define MainTestElf_Template
104 @$(CC) $(CFLAGS_A) $(LDFLAGS)$(patsubst %.elf,%.map,$(1)) -o \
110 $(foreach a, $(ALGORITHMS), \
111 $(eval $(call MainTestElf_Template, \
112 $(BIN_DIR)$(call lc, $(a))/$(TEST_DIR)main-$(call lc, $(a))-test.elf, \
118 #-------------------------------------------------------------------------------
120 all: $(foreach algo, $(ALGORITHMS), $($(algo)_BINOBJ))
122 #-------------------------------------------------------------------------------
124 define TestBin_TEMPLATE
128 $(foreach algo, $(ALGORITHMS), $(eval $(call TestBin_TEMPLATE, \
130 $(BIN_DIR)$(call lc, $(algo))/$(TEST_DIR)main-$(call lc, $(algo))-test.elf \
133 #-------------------------------------------------------------------------------
136 @echo "[objcopy]: $@"
137 @$(OBJCOPY) -j .text -j .data -O ihex $< $@
139 #-------------------------------------------------------------------------------
141 define Flash_Template
143 @echo "[flash]: $(2)"
144 @$(FLASHCMD)$(call first,$(2))
147 $(foreach algo, $(ALGORITHMS), $(eval $(call Flash_Template, \
149 $(BIN_DIR)$(call lc, $(algo))/$(TEST_DIR)main-$(call lc, $(algo))-test.hex \
152 #-------------------------------------------------------------------------------
154 define Speed_Template
155 $(1)_SPEED: $(1)_FLASH
156 @$(RUBY) $(SPEEDTOOL) -c $(SPEEDCMD) -t $(SPEEDLOG_DIR) -a $(call lc, $(1))
159 $(foreach algo, $(ALGORITHMS), $(eval $(call Speed_Template, \
164 hash_speed: $(foreach algo, $(HASHES), $(algo)_SPEED)
166 #-------------------------------------------------------------------------------
172 $(SIZE) $(2) > $(strip $(SIZE_DIR))$(strip $(call lc, $(1))).size
175 $(foreach algo, $(ALGORITHMS), $(eval $(call Size_Template, \
176 $(strip $(algo)), $($(algo)_BINOBJ) \
180 hash_size: $(foreach algo, $(HASHES), $(algo)_SIZE)
182 #-------------------------------------------------------------------------------
185 tests: $(foreach a, $(ALGORITHMS), $(a)_TEST_BIN)
187 #-------------------------------------------------------------------------------
189 define TestRun_Template
190 $(1)_TESTRUN: $(1)_FLASH
192 $(RUBY) $(GET_TEST) $(TESTPORT) $(TESTPORTBAUDR) 8 1 nessie $(TESTLOG_DIR)$(TESTPREFIX) $(2)
195 $(foreach algo, $(ALGORITHMS),$(eval $(call TestRun_Template, $(algo), $(call lc,$(algo)) )))
197 all_testrun: $(foreach algo, $(ALGORITHMS), $(algo)_TESTRUN)
199 #-------------------------------------------------------------------------------
205 $(foreach algo, $(ALGORITHMS), \
206 $(eval $(call Obj_Template, \
213 cores: $(foreach algo, $(ALGORITHMS), $(algo)_OBJ)
215 .PHONY: blockchiphers
216 blockciphers: $(foreach algo, $(BLOCK_CIPHERS), $(algo)_OBJ)
218 .PHONY: streamchiphers
219 streamciphers: $(foreach algo, $(STREAM_CIPHERS), $(algo)_OBJ)
222 hashes: $(foreach algo, $(HASHES), $(algo)_OBJ)
225 macs: $(foreach algo, $(MACS), $(algo)_OBJ)
228 prngs: $(foreach algo, $(PRNGS), $(algo)_OBJ)
231 encodings: $(foreach algo, $(ENCODINGS), $(algo)_OBJ)
234 aux: $(foreach algo, $(AUX), $(algo)_OBJ)
237 #-------------------------------------------------------------------------------
244 @echo "infos on AVR-Crypto-lib:"
245 @echo " block ciphers:"
246 @echo " $(BLOCK_CIPHERS)"
247 @echo " stream ciphers:"
248 @echo " $(STREAM_CIPHERS)"
249 @echo " hash functions:"
251 @echo " MAC functions:"
253 @echo " PRNG functions:"
255 @echo " signature functions:"
256 @echo " $(SIGNATURE)"
257 @echo " public key ciphers:"
258 @echo " $(PK_CIPHERS)"
260 @echo " $(ENCODINGS)"
261 @echo " auxiliary functions:"
264 @echo " all - all algorithm cores"
265 @echo " cores - all algorithm cores"
266 @echo " listings - all algorithm core listings"
267 @echo " tests - all algorithm test programs"
268 @echo " stats - all algorithm size statistics"
269 @echo " blockciphers - all blockcipher cores"
270 @echo " streamciphers - all streamcipher cores"
271 @echo " hashes - all hash cores"
272 @echo " macs - all MAC cores"
273 @echo " prngs - all PRNG cores"
274 @echo " all_testrun - testrun all algorithms"
275 @echo " hash_size - measure size of all hash functions"
276 @echo " hash_speed - measure performance of all hash functions"
277 @echo " docu - build doxygen documentation"
278 @echo " clean - remove a lot of builded files"
279 @echo " depclean - also remove dependency files"
280 @echo " *_TEST_BIN - build test program"
281 @echo " *_TESTRUN - run nessie test"
282 @echo " *_OBJ - build algorithm core"
283 @echo " *_FLASH - flash test program"
284 @echo " *_LIST - build assembler listing"
287 #-------------------------------------------------------------------------------
297 #-------------------------------------------------------------------------------
298 # dependency inclusion
301 DEPS := $(wildcard $(DEP_DIR)*.d)