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 #-------------------------------------------------------------------------------
152 define Speed_Template
153 $(1)_SPEED: $(1)_FLASH
154 @$(RUBY) $(SPEEDTOOL) -c $(SPEEDCMD) -t $(SPEEDLOG_DIR) -a $(call lc, $(1))
157 $(foreach algo, $(ALGORITHMS), $(eval $(call Speed_Template, \
162 hash_speed: $(foreach algo, $(HASHES), $(algo)_SPEED)
164 #-------------------------------------------------------------------------------
170 $(SIZE) $(2) > $(strip $(SIZE_DIR))$(strip $(call lc, $(1))).size
173 $(foreach algo, $(ALGORITHMS), $(eval $(call Size_Template, \
174 $(strip $(algo)), $($(algo)_BINOBJ) \
178 hash_size: $(foreach algo, $(HASHES), $(algo)_SIZE)
180 #-------------------------------------------------------------------------------
183 tests: $(foreach a, $(ALGORITHMS), $(a)_TEST_BIN)
185 #-------------------------------------------------------------------------------
187 define TestRun_Template
188 $(1)_TESTRUN: $(1)_FLASH
190 $(RUBY) $(GET_TEST) $(TESTPORT) $(TESTPORTBAUDR) 8 1 nessie $(TESTLOG_DIR)$(TESTPREFIX) $(2)
193 $(foreach algo, $(ALGORITHMS),$(eval $(call TestRun_Template, $(algo), $(call lc,$(algo)) )))
195 all_testrun: $(foreach algo, $(ALGORITHMS), $(algo)_TESTRUN)
197 #-------------------------------------------------------------------------------
203 $(foreach algo, $(ALGORITHMS), \
204 $(eval $(call Obj_Template, \
211 cores: $(foreach algo, $(ALGORITHMS), $(algo)_OBJ)
213 .PHONY: blockchiphers
214 blockciphers: $(foreach algo, $(BLOCK_CIPHERS), $(algo)_OBJ)
216 .PHONY: streamchiphers
217 streamciphers: $(foreach algo, $(STREAM_CIPHERS), $(algo)_OBJ)
220 hashes: $(foreach algo, $(HASHES), $(algo)_OBJ)
223 macs: $(foreach algo, $(MACS), $(algo)_OBJ)
226 prngs: $(foreach algo, $(PRNGS), $(algo)_OBJ)
229 encodings: $(foreach algo, $(ENCODINGS), $(algo)_OBJ)
232 aux: $(foreach algo, $(AUX), $(algo)_OBJ)
235 #-------------------------------------------------------------------------------
242 @echo "infos on AVR-Crypto-lib:"
243 @echo " block ciphers:"
244 @echo " $(BLOCK_CIPHERS)"
245 @echo " stream ciphers:"
246 @echo " $(STREAM_CIPHERS)"
247 @echo " hash functions:"
249 @echo " MAC functions:"
251 @echo " PRNG functions:"
254 @echo " $(ENCODINGS)"
256 @echo " all - all algorithm cores"
257 @echo " cores - all algorithm cores"
258 @echo " listings - all algorithm core listings"
259 @echo " tests - all algorithm test programs"
260 @echo " stats - all algorithm size statistics"
261 @echo " blockciphers - all blockcipher cores"
262 @echo " streamciphers - all streamcipher cores"
263 @echo " hashes - all hash cores"
264 @echo " macs - all MAC cores"
265 @echo " prngs - all PRNG cores"
266 @echo " all_testrun - testrun all algorithms"
267 @echo " docu - build doxygen documentation"
268 @echo " clean - remove a lot of builded files"
269 @echo " depclean - also remove dependency files"
270 @echo " *_TEST_BIN - build test program"
271 @echo " *_TESTRUN - run nessie test"
272 @echo " *_OBJ - build algorithm core"
273 @echo " *_FLASH - flash test program"
274 @echo " *_LIST - build assembler listing"
277 #-------------------------------------------------------------------------------
287 #-------------------------------------------------------------------------------
288 # dependency inclusion
291 DEPS := $(wildcard $(DEP_DIR)*.d)