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
44 #-------------------------------------------------------------------------------
45 ALGORITHMS = $(BLOCK_CIPHERS) $(STREAM_CIPHERS) $(HASHES) $(PRNGS) $(MACS) \
46 $(ENCODINGS) $(SIGNATURE) $(PK_CIPHERS) $(AUX)
47 ALGORITHMS_OBJ = $(patsubst %,%_OBJ, $(ALGORITHMS))
48 ALGORITHMS_TESTBIN = $(patsubst %,%_TESTBIN, $(ALGORITHMS))
50 #-------------------------------------------------------------------------------
51 # define binary object in $(BIN_DIR)$(ALGO)/<obj>
52 define Assert_Template
56 $(foreach a, $(ALGORITHMS), $(eval $(call Assert_Template, \
58 $(addprefix $(BIN_DIR)$(call lc,$(a))/,$($(a)_OBJ)) \
61 $(foreach a, $(ALGORITHMS), $(eval $(call Assert_Template, \
63 $(addprefix $(BIN_DIR)$(call lc,$(a))/$(TEST_DIR),$($(a)_TESTBIN)) \
68 #-------------------------------------------------------------------------------
70 define TargetSource_Template
72 @echo "[cc]: $(1) <-- $(2)"
74 @$(CC) $(CFLAGS_A) $(addprefix -I./,$(3)) $(addprefix -D, $(4)) -c -o $(1) $(2)
79 define TargetSourceList_Template
81 @echo "[cc]: $(1) <-- $(2)"
83 @$(CC) $(CFLAGS_A) $(addprefix -I./,$(3)) $(addprefix -D, $(4)) $(LIST_OPT) -c -o /dev/null $(2) > $(1)
86 # ----------------------------------------------------------------------------
87 # Function: find_source_file
88 # Arguments: 1: name of the binary file (.o extension) to search
89 # 2: list of directorys to search for file
90 # Returns: Returns paths to source file (mathing the pattern in
92 # ----------------------------------------------------------------------------
93 SOURCE_PATTERN := %.S %.c
94 find_source_file = $(firstword $(foreach d, $(2), \
95 $(filter $(SOURCE_PATTERN), \
96 $(wildcard $(d)$(notdir $(patsubst %.o,%,$1)).*) \
101 $(foreach a, $(ALGORITHMS), \
102 $(foreach b, $($(a)_OBJ), \
103 $(eval $(call TargetSource_Template, \
104 $(BIN_DIR)$(call lc, $(a))/$(b), \
105 $(call find_source_file, $(b), $($(a)_DIR) $($(a)_INCDIR) $(GLOBAL_INCDIR) ),\
106 $($(a)_DIR) $($(a)_INCDIR) $(GLOBAL_INCDIR), \
112 $(foreach a, $(ALGORITHMS), \
113 $(foreach b, $($(a)_TESTBIN), \
114 $(eval $(call TargetSource_Template, \
115 $(BIN_DIR)$(call lc, $(a))/$(TEST_DIR)$(b), \
116 $(call find_source_file, $(b), $($(a)_DIR) $($(a)_INCDIR) $(GLOBAL_INCDIR) ),\
117 $($(a)_DIR) $($(a)_INCDIR) $(GLOBAL_INCDIR), \
124 $(foreach a, $(ALGORITHMS), \
125 $(foreach b, $($(a)_OBJ), \
126 $(eval $(call TargetSourceList_Template, \
127 $(LIST_DIR)$(call lc, $(a))/$(patsubst %.o,%.s,$(b)), \
128 $(call find_source_file, $(b), $($(a)_DIR) $($(a)_INCDIR) $(GLOBAL_INCDIR) ),\
129 $($(a)_DIR) $($(a)_INCDIR) $(GLOBAL_INCDIR), \
135 #-------------------------------------------------------------------------------
137 define MainTestElf_Template
139 @mkdir -p $(dir $(1))
141 @$(CC) $(CFLAGS_A) $(LDFLAGS)$(patsubst %.elf,%.map,$(1)) -o \
147 $(foreach a, $(ALGORITHMS), \
148 $(eval $(call MainTestElf_Template, \
149 $(BIN_DIR)$(call lc, $(a))/$(TEST_DIR)main-$(call lc, $(a))-test.elf, \
155 #-------------------------------------------------------------------------------
157 all: $(foreach algo, $(ALGORITHMS), $($(algo)_BINOBJ))
159 #-------------------------------------------------------------------------------
161 define TestBin_TEMPLATE
165 $(foreach algo, $(ALGORITHMS), $(eval $(call TestBin_TEMPLATE, \
167 $(BIN_DIR)$(call lc, $(algo))/$(TEST_DIR)main-$(call lc, $(algo))-test.elf \
170 #-------------------------------------------------------------------------------
172 define Listing_TEMPLATE
176 $(foreach algo, $(ALGORITHMS), $(eval $(call Listing_TEMPLATE, \
178 $(foreach obj,$($(algo)_OBJ), $(LIST_DIR)$(call lc, $(algo))/$(obj:.o=.s)) \
181 #-------------------------------------------------------------------------------
184 @echo "[objcopy]: $@"
185 @$(OBJCOPY) -j .text -j .data -O ihex $< $@
187 #-------------------------------------------------------------------------------
189 define Flash_Template
191 @echo "[flash]: $(2)"
192 @$(FLASHCMD)$(call first,$(2))
195 $(foreach algo, $(ALGORITHMS), $(eval $(call Flash_Template, \
197 $(BIN_DIR)$(call lc, $(algo))/$(TEST_DIR)main-$(call lc, $(algo))-test.hex \
200 #-------------------------------------------------------------------------------
202 define Speed_Template
203 $(1)_SPEED: $(1)_FLASH
204 @$(RUBY) $(SPEEDTOOL) -c $(SPEEDCMD) -t $(SPEEDLOG_DIR) -a $(call lc, $(1))
207 $(foreach algo, $(ALGORITHMS), $(eval $(call Speed_Template, \
212 hash_speed: $(foreach algo, $(HASHES), $(algo)_SPEED)
214 .PHONY: blockcipher_speed
215 blockcipher_speed: $(foreach algo, $(BLOCK_CIPHERS), $(algo)_SPEED)
216 #-------------------------------------------------------------------------------
222 $(SIZE) $(2) > $(strip $(SIZE_DIR))$(strip $(call lc, $(1))).size
225 $(foreach algo, $(ALGORITHMS), $(eval $(call Size_Template, \
226 $(strip $(algo)), $($(algo)_BINOBJ) \
230 hash_size: $(foreach algo, $(HASHES), $(algo)_SIZE)
232 .PHONY: blockcipher_size
233 blockcipher_size: $(foreach algo, $(BLOCK_CIPHERS), $(algo)_SIZE)
235 #-------------------------------------------------------------------------------
238 tests: $(foreach a, $(ALGORITHMS), $(a)_TESTBIN)
240 #-------------------------------------------------------------------------------
242 define TestRun_Template
243 $(1)_TESTRUN: $(1)_FLASH
249 $(RUBY) $(GET_TEST) $(TESTPORT) $(TESTPORTBAUDR) 8 1 nessie $(TESTLOG_DIR)$(TESTPREFIX) $(2)
252 $(foreach algo, $(ALGORITHMS),$(eval $(call TestRun_Template, $(algo), $(call lc,$(algo)) )))
254 all_testrun: $(foreach algo, $(ALGORITHMS), $(algo)_TESTRUN)
256 #-------------------------------------------------------------------------------
262 $(foreach algo, $(ALGORITHMS), \
263 $(eval $(call Obj_Template, \
277 cores: $(foreach algo, $(ALGORITHMS), $(algo)_OBJ)
279 .PHONY: blockchiphers
280 blockciphers: $(foreach algo, $(BLOCK_CIPHERS), $(algo)_OBJ)
282 .PHONY: streamchiphers
283 streamciphers: $(foreach algo, $(STREAM_CIPHERS), $(algo)_OBJ)
286 hashes: $(foreach algo, $(HASHES), $(algo)_OBJ)
289 macs: $(foreach algo, $(MACS), $(algo)_OBJ)
292 prngs: $(foreach algo, $(PRNGS), $(algo)_OBJ)
295 encodings: $(foreach algo, $(ENCODINGS), $(algo)_OBJ)
298 aux: $(foreach algo, $(AUX), $(algo)_OBJ)
301 #-------------------------------------------------------------------------------
308 @echo "infos on AVR-Crypto-lib:"
309 @echo " block ciphers:"
310 @echo " $(BLOCK_CIPHERS)"
311 @echo " stream ciphers:"
312 @echo " $(STREAM_CIPHERS)"
313 @echo " hash functions:"
315 @echo " MAC functions:"
317 @echo " PRNG functions:"
319 @echo " signature functions:"
320 @echo " $(SIGNATURE)"
321 @echo " public key ciphers:"
322 @echo " $(PK_CIPHERS)"
324 @echo " $(ENCODINGS)"
325 @echo " auxiliary functions:"
328 @echo " all - all algorithm cores"
329 @echo " cores - all algorithm cores"
330 @echo " listings - all algorithm core listings"
331 @echo " tests - all algorithm test programs"
332 @echo " stats - all algorithm size statistics"
333 @echo " blockciphers - all blockcipher cores"
334 @echo " streamciphers - all streamcipher cores"
335 @echo " hashes - all hash cores"
336 @echo " macs - all MAC cores"
337 @echo " prngs - all PRNG cores"
338 @echo " all_testrun - testrun all algorithms"
339 @echo " hash_size - measure size of all hash functions"
340 @echo " hash_speed - measure performance of all hash functions"
341 @echo " blockcipher_size - measure size of all blockciphers"
342 @echo " blockcipher_speed - measure performance of all blockciphers"
343 @echo " docu - build doxygen documentation"
344 @echo " clean - remove a lot of builded files"
345 @echo " depclean - also remove dependency files"
346 @echo " *_TESTBIN - build test program"
347 @echo " *_TESTRUN - run nessie test"
348 @echo " *_OBJ - build algorithm core"
349 @echo " *_FLASH - flash test program"
350 @echo " *_LIST - build assembler listing"
353 #-------------------------------------------------------------------------------
363 #-------------------------------------------------------------------------------
364 # dependency inclusion
367 DEPS := $(wildcard $(DEP_DIR)*.d)