1 # Makefile for the AVR-Crypto-Lib project
3 # This file is part of the AVR-Crypto-Lib.
4 # Copyright (C) 2010 Daniel Otte (daniel.otte@rub.de)
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
31 # we use the gnu make standard library
33 include avr-makefile.inc
35 #-------------------------------------------------------------------------------
36 # inclusion of make stubs
39 #-------------------------------------------------------------------------------
40 ALGORITHMS = $(BLOCK_CIPHERS) $(STREAM_CIPHERS) $(HASHES) $(PRNGS) $(MACS) \
41 $(ENCODINGS) $(SIGNATURE) $(PK_CIPHERS) $(AUX)
42 ALGORITHMS_OBJ = $(patsubst %,%_OBJ, $(ALGORITHMS))
43 ALGORITHMS_TEST_BIN = $(patsubst %,%_TEST_BIN, $(ALGORITHMS))
45 #-------------------------------------------------------------------------------
46 # define binary object in $(BIN_DIR)$(ALGO)/<obj>
47 define Assert_Template
51 $(foreach a, $(ALGORITHMS), $(eval $(call Assert_Template, \
53 $(addprefix $(BIN_DIR)$(call lc,$(a))/,$($(a)_OBJ)) \
56 $(foreach a, $(ALGORITHMS), $(eval $(call Assert_Template, \
58 $(addprefix $(BIN_DIR)$(call lc,$(a))/$(TEST_DIR),$($(a)_TEST_BIN)) \
62 #$(foreach a, $(ALGORITHMS), \
63 # $(if $(def $(a)_DIR), \
64 # $(eval $(call Assert_Template, \
71 #$(foreach a, $(ALGORITHMS), \
72 # $(if $(call seq($(strip($($(a)_DIR))),)), \
73 # $(eval $(call Assert_Template, \
80 #-------------------------------------------------------------------------------
83 ### $(error no source ($(2)) for $(1) in TargetSource_Template)
86 define TargetSource_Template
88 @echo "[cc]: $(1) <-- $(2)"
90 @$(CC) $(CFLAGS_A) -I./$(strip $(3)) -c -o $(1) $(2)
93 $(foreach a, $(ALGORITHMS), \
94 $(foreach b, $($(a)_OBJ), \
95 $(eval $(call TargetSource_Template, \
96 $(BIN_DIR)$(call lc, $(a))/$(b), \
97 $(filter %.S %.c, $(wildcard $($(a)_DIR)$(notdir $(patsubst %.o,%,$(b))).*)), \
103 $(foreach a, $(ALGORITHMS), \
104 $(foreach b, $($(a)_TEST_BIN), \
105 $(eval $(call TargetSource_Template, \
106 $(BIN_DIR)$(call lc, $(a))/$(TEST_DIR)$(b), \
107 $(if $(call sne,$(strip $(filter %.S %.c, $(wildcard $(TESTSRC_DIR)$(notdir $(patsubst %.o,%,$(b))).*))),), \
108 $(filter %.S %.c, $(wildcard $(TESTSRC_DIR)$(notdir $(patsubst %.o,%,$(b))).*)), \
109 $(filter %.S %.c, $(wildcard ./$(notdir $(patsubst %.o,%,$(b))).*))\
115 #-------------------------------------------------------------------------------
117 define MainTestElf_Template
120 @$(CC) $(CFLAGS_A) $(LDFLAGS)$(patsubst %.elf,%.map,$(1)) -o \
126 $(foreach a, $(ALGORITHMS), \
127 $(eval $(call MainTestElf_Template, \
128 $(BIN_DIR)$(call lc, $(a))/$(TEST_DIR)main-$(call lc, $(a))-test.elf, \
134 #-------------------------------------------------------------------------------
136 all: $(foreach algo, $(ALGORITHMS), $($(algo)_BINOBJ))
138 #-------------------------------------------------------------------------------
140 define TestBin_TEMPLATE
144 $(foreach algo, $(ALGORITHMS), $(eval $(call TestBin_TEMPLATE, \
146 $(BIN_DIR)$(call lc, $(algo))/$(TEST_DIR)main-$(call lc, $(algo))-test.elf \
149 #-------------------------------------------------------------------------------
152 @echo "[objcopy]: $@"
153 @$(OBJCOPY) -j .text -j .data -O ihex $< $@
155 #-------------------------------------------------------------------------------
157 define Flash_Template
159 @echo "[flash]: $(2)"
160 @$(FLASHCMD)$(call first,$(2))
163 $(foreach algo, $(ALGORITHMS), $(eval $(call Flash_Template, \
165 $(BIN_DIR)$(call lc, $(algo))/$(TEST_DIR)main-$(call lc, $(algo))-test.hex \
168 #-------------------------------------------------------------------------------
170 define Speed_Template
171 $(1)_SPEED: $(1)_FLASH
172 @$(RUBY) $(SPEEDTOOL) -c $(SPEEDCMD) -t $(SPEEDLOG_DIR) -a $(call lc, $(1))
175 $(foreach algo, $(ALGORITHMS), $(eval $(call Speed_Template, \
180 hash_speed: $(foreach algo, $(HASHES), $(algo)_SPEED)
182 .PHONY: blockcipher_speed
183 blockcipher_speed: $(foreach algo, $(BLOCK_CIPHERS), $(algo)_SPEED)
184 #-------------------------------------------------------------------------------
190 $(SIZE) $(2) > $(strip $(SIZE_DIR))$(strip $(call lc, $(1))).size
193 $(foreach algo, $(ALGORITHMS), $(eval $(call Size_Template, \
194 $(strip $(algo)), $($(algo)_BINOBJ) \
198 hash_size: $(foreach algo, $(HASHES), $(algo)_SIZE)
200 .PHONY: blockcipher_size
201 blockcipher_size: $(foreach algo, $(BLOCK_CIPHERS), $(algo)_SIZE)
203 #-------------------------------------------------------------------------------
206 tests: $(foreach a, $(ALGORITHMS), $(a)_TEST_BIN)
208 #-------------------------------------------------------------------------------
210 define TestRun_Template
211 $(1)_TESTRUN: $(1)_FLASH
213 $(RUBY) $(GET_TEST) $(TESTPORT) $(TESTPORTBAUDR) 8 1 nessie $(TESTLOG_DIR)$(TESTPREFIX) $(2)
216 $(foreach algo, $(ALGORITHMS),$(eval $(call TestRun_Template, $(algo), $(call lc,$(algo)) )))
218 all_testrun: $(foreach algo, $(ALGORITHMS), $(algo)_TESTRUN)
220 #-------------------------------------------------------------------------------
226 $(foreach algo, $(ALGORITHMS), \
227 $(eval $(call Obj_Template, \
234 cores: $(foreach algo, $(ALGORITHMS), $(algo)_OBJ)
236 .PHONY: blockchiphers
237 blockciphers: $(foreach algo, $(BLOCK_CIPHERS), $(algo)_OBJ)
239 .PHONY: streamchiphers
240 streamciphers: $(foreach algo, $(STREAM_CIPHERS), $(algo)_OBJ)
243 hashes: $(foreach algo, $(HASHES), $(algo)_OBJ)
246 macs: $(foreach algo, $(MACS), $(algo)_OBJ)
249 prngs: $(foreach algo, $(PRNGS), $(algo)_OBJ)
252 encodings: $(foreach algo, $(ENCODINGS), $(algo)_OBJ)
255 aux: $(foreach algo, $(AUX), $(algo)_OBJ)
258 #-------------------------------------------------------------------------------
265 @echo "infos on AVR-Crypto-lib:"
266 @echo " block ciphers:"
267 @echo " $(BLOCK_CIPHERS)"
268 @echo " stream ciphers:"
269 @echo " $(STREAM_CIPHERS)"
270 @echo " hash functions:"
272 @echo " MAC functions:"
274 @echo " PRNG functions:"
276 @echo " signature functions:"
277 @echo " $(SIGNATURE)"
278 @echo " public key ciphers:"
279 @echo " $(PK_CIPHERS)"
281 @echo " $(ENCODINGS)"
282 @echo " auxiliary functions:"
285 @echo " all - all algorithm cores"
286 @echo " cores - all algorithm cores"
287 @echo " listings - all algorithm core listings"
288 @echo " tests - all algorithm test programs"
289 @echo " stats - all algorithm size statistics"
290 @echo " blockciphers - all blockcipher cores"
291 @echo " streamciphers - all streamcipher cores"
292 @echo " hashes - all hash cores"
293 @echo " macs - all MAC cores"
294 @echo " prngs - all PRNG cores"
295 @echo " all_testrun - testrun all algorithms"
296 @echo " hash_size - measure size of all hash functions"
297 @echo " hash_speed - measure performance of all hash functions"
298 @echo " blockcipher_size - measure size of all blockciphers"
299 @echo " blockcipher_speed - measure performance of all blockciphers"
300 @echo " docu - build doxygen documentation"
301 @echo " clean - remove a lot of builded files"
302 @echo " depclean - also remove dependency files"
303 @echo " *_TEST_BIN - build test program"
304 @echo " *_TESTRUN - run nessie test"
305 @echo " *_OBJ - build algorithm core"
306 @echo " *_FLASH - flash test program"
307 @echo " *_LIST - build assembler listing"
310 #-------------------------------------------------------------------------------
320 #-------------------------------------------------------------------------------
321 # dependency inclusion
324 DEPS := $(wildcard $(DEP_DIR)*.d)