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/>.
32 # we use the gnu make standard library
34 include avr-makefile.inc
37 GLOBAL_INCDIR := ./ $(TESTSRC_DIR)
39 #-------------------------------------------------------------------------------
40 # inclusion of make stubs
43 #-------------------------------------------------------------------------------
44 ALGORITHMS = $(BLOCK_CIPHERS) $(STREAM_CIPHERS) $(HASHES) $(PRNGS) $(MACS) \
45 $(ENCODINGS) $(SIGNATURE) $(PK_CIPHERS) $(AUX)
46 ALGORITHMS_OBJ = $(patsubst %,%_OBJ, $(ALGORITHMS))
47 ALGORITHMS_TEST_BIN = $(patsubst %,%_TEST_BIN, $(ALGORITHMS))
49 #-------------------------------------------------------------------------------
50 # define binary object in $(BIN_DIR)$(ALGO)/<obj>
51 define Assert_Template
55 $(foreach a, $(ALGORITHMS), $(eval $(call Assert_Template, \
57 $(addprefix $(BIN_DIR)$(call lc,$(a))/,$($(a)_OBJ)) \
60 $(foreach a, $(ALGORITHMS), $(eval $(call Assert_Template, \
62 $(addprefix $(BIN_DIR)$(call lc,$(a))/$(TEST_DIR),$($(a)_TEST_BIN)) \
67 #-------------------------------------------------------------------------------
69 define TargetSource_Template
71 @echo "[cc]: $(1) <-- $(2)"
73 @$(CC) $(CFLAGS_A) $(addprefix -I./,$(3)) $(addprefix -D, $(4)) -c -o $(1) $(2)
76 # ----------------------------------------------------------------------------
77 # Function: find_source_file
78 # Arguments: 1: name of the binary file (.o extension) to search
79 # 2: list of directorys to search for file
80 # Returns: Returns paths to source file (mathing the pattern in
82 # ----------------------------------------------------------------------------
83 SOURCE_PATTERN := %.S %.c
84 find_source_file = $(firstword $(foreach d, $(2), \
85 $(filter $(SOURCE_PATTERN), \
86 $(wildcard $(d)$(notdir $(patsubst %.o,%,$1)).*) \
91 $(foreach a, $(ALGORITHMS), \
92 $(foreach b, $($(a)_OBJ), \
93 $(eval $(call TargetSource_Template, \
94 $(BIN_DIR)$(call lc, $(a))/$(b), \
95 $(call find_source_file, $(b), $($(a)_DIR) $($(a)_INCDIR) $(GLOBAL_INCDIR) ),\
96 $($(a)_DIR) $($(a)_INCDIR) $(GLOBAL_INCDIR), \
102 $(foreach a, $(ALGORITHMS), \
103 $(foreach b, $($(a)_TEST_BIN), \
104 $(eval $(call TargetSource_Template, \
105 $(BIN_DIR)$(call lc, $(a))/$(TEST_DIR)$(b), \
106 $(call find_source_file, $(b), $($(a)_DIR) $($(a)_INCDIR) $(GLOBAL_INCDIR) ),\
107 $($(a)_DIR) $($(a)_INCDIR) $(GLOBAL_INCDIR), \
113 #-------------------------------------------------------------------------------
115 define MainTestElf_Template
118 @$(CC) $(CFLAGS_A) $(LDFLAGS)$(patsubst %.elf,%.map,$(1)) -o \
124 $(foreach a, $(ALGORITHMS), \
125 $(eval $(call MainTestElf_Template, \
126 $(BIN_DIR)$(call lc, $(a))/$(TEST_DIR)main-$(call lc, $(a))-test.elf, \
132 #-------------------------------------------------------------------------------
134 all: $(foreach algo, $(ALGORITHMS), $($(algo)_BINOBJ))
136 #-------------------------------------------------------------------------------
138 define TestBin_TEMPLATE
142 $(foreach algo, $(ALGORITHMS), $(eval $(call TestBin_TEMPLATE, \
144 $(BIN_DIR)$(call lc, $(algo))/$(TEST_DIR)main-$(call lc, $(algo))-test.elf \
147 #-------------------------------------------------------------------------------
150 @echo "[objcopy]: $@"
151 @$(OBJCOPY) -j .text -j .data -O ihex $< $@
153 #-------------------------------------------------------------------------------
155 define Flash_Template
157 @echo "[flash]: $(2)"
158 @$(FLASHCMD)$(call first,$(2))
161 $(foreach algo, $(ALGORITHMS), $(eval $(call Flash_Template, \
163 $(BIN_DIR)$(call lc, $(algo))/$(TEST_DIR)main-$(call lc, $(algo))-test.hex \
166 #-------------------------------------------------------------------------------
168 define Speed_Template
169 $(1)_SPEED: $(1)_FLASH
170 @$(RUBY) $(SPEEDTOOL) -c $(SPEEDCMD) -t $(SPEEDLOG_DIR) -a $(call lc, $(1))
173 $(foreach algo, $(ALGORITHMS), $(eval $(call Speed_Template, \
178 hash_speed: $(foreach algo, $(HASHES), $(algo)_SPEED)
180 .PHONY: blockcipher_speed
181 blockcipher_speed: $(foreach algo, $(BLOCK_CIPHERS), $(algo)_SPEED)
182 #-------------------------------------------------------------------------------
188 $(SIZE) $(2) > $(strip $(SIZE_DIR))$(strip $(call lc, $(1))).size
191 $(foreach algo, $(ALGORITHMS), $(eval $(call Size_Template, \
192 $(strip $(algo)), $($(algo)_BINOBJ) \
196 hash_size: $(foreach algo, $(HASHES), $(algo)_SIZE)
198 .PHONY: blockcipher_size
199 blockcipher_size: $(foreach algo, $(BLOCK_CIPHERS), $(algo)_SIZE)
201 #-------------------------------------------------------------------------------
204 tests: $(foreach a, $(ALGORITHMS), $(a)_TEST_BIN)
206 #-------------------------------------------------------------------------------
208 define TestRun_Template
209 $(1)_TESTRUN: $(1)_FLASH
211 $(RUBY) $(GET_TEST) $(TESTPORT) $(TESTPORTBAUDR) 8 1 nessie $(TESTLOG_DIR)$(TESTPREFIX) $(2)
214 $(foreach algo, $(ALGORITHMS),$(eval $(call TestRun_Template, $(algo), $(call lc,$(algo)) )))
216 all_testrun: $(foreach algo, $(ALGORITHMS), $(algo)_TESTRUN)
218 #-------------------------------------------------------------------------------
224 $(foreach algo, $(ALGORITHMS), \
225 $(eval $(call Obj_Template, \
235 cores: $(foreach algo, $(ALGORITHMS), $(algo)_OBJ)
237 .PHONY: blockchiphers
238 blockciphers: $(foreach algo, $(BLOCK_CIPHERS), $(algo)_OBJ)
240 .PHONY: streamchiphers
241 streamciphers: $(foreach algo, $(STREAM_CIPHERS), $(algo)_OBJ)
244 hashes: $(foreach algo, $(HASHES), $(algo)_OBJ)
247 macs: $(foreach algo, $(MACS), $(algo)_OBJ)
250 prngs: $(foreach algo, $(PRNGS), $(algo)_OBJ)
253 encodings: $(foreach algo, $(ENCODINGS), $(algo)_OBJ)
256 aux: $(foreach algo, $(AUX), $(algo)_OBJ)
259 #-------------------------------------------------------------------------------
266 @echo "infos on AVR-Crypto-lib:"
267 @echo " block ciphers:"
268 @echo " $(BLOCK_CIPHERS)"
269 @echo " stream ciphers:"
270 @echo " $(STREAM_CIPHERS)"
271 @echo " hash functions:"
273 @echo " MAC functions:"
275 @echo " PRNG functions:"
277 @echo " signature functions:"
278 @echo " $(SIGNATURE)"
279 @echo " public key ciphers:"
280 @echo " $(PK_CIPHERS)"
282 @echo " $(ENCODINGS)"
283 @echo " auxiliary functions:"
286 @echo " all - all algorithm cores"
287 @echo " cores - all algorithm cores"
288 @echo " listings - all algorithm core listings"
289 @echo " tests - all algorithm test programs"
290 @echo " stats - all algorithm size statistics"
291 @echo " blockciphers - all blockcipher cores"
292 @echo " streamciphers - all streamcipher cores"
293 @echo " hashes - all hash cores"
294 @echo " macs - all MAC cores"
295 @echo " prngs - all PRNG cores"
296 @echo " all_testrun - testrun all algorithms"
297 @echo " hash_size - measure size of all hash functions"
298 @echo " hash_speed - measure performance of all hash functions"
299 @echo " blockcipher_size - measure size of all blockciphers"
300 @echo " blockcipher_speed - measure performance of all blockciphers"
301 @echo " docu - build doxygen documentation"
302 @echo " clean - remove a lot of builded files"
303 @echo " depclean - also remove dependency files"
304 @echo " *_TEST_BIN - build test program"
305 @echo " *_TESTRUN - run nessie test"
306 @echo " *_OBJ - build algorithm core"
307 @echo " *_FLASH - flash test program"
308 @echo " *_LIST - build assembler listing"
311 #-------------------------------------------------------------------------------
321 #-------------------------------------------------------------------------------
322 # dependency inclusion
325 DEPS := $(wildcard $(DEP_DIR)*.d)