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/>.
30 # we use the gnu make standard library
33 GLOBAL_INCDIR := ./ $(TESTSRC_DIR)
35 #-------------------------------------------------------------------------------
36 # inclusion of make stubs
40 #-------------------------------------------------------------------------------
41 ALGORITHMS = $(BLOCK_CIPHERS) $(STREAM_CIPHERS) $(HASHES) $(PRNGS) $(MACS) \
42 $(ENCODINGS) $(SIGNATURE) $(PK_CIPHERS) $(AUX)
43 ALGORITHMS_OBJ = $(patsubst %,%_OBJ, $(ALGORITHMS))
44 ALGORITHMS_TESTBIN = $(patsubst %,%_TESTBIN, $(ALGORITHMS))
46 #-------------------------------------------------------------------------------
47 # define binary object in $(BIN_DIR)$(ALGO)/<obj>
48 define Assert_Template
52 $(foreach a, $(ALGORITHMS), $(eval $(call Assert_Template, \
54 $(addprefix $(BIN_DIR)$(call lc,$(a))/,$($(a)_OBJ)) \
57 $(foreach a, $(ALGORITHMS), $(eval $(call Assert_Template, \
59 $(addprefix $(BIN_DIR)$(call lc,$(a))/$(TEST_DIR),$($(a)_TESTBIN)) \
64 #-------------------------------------------------------------------------------
68 define TargetSource_Template
70 @mkdir -p $(dir $(1)) $(DEP_DIR)
71 @echo "[cc]: $(1) <-- $(2)"
72 @$(CC) $(CFLAGS_A) $(addprefix -I./,$(3)) $(addprefix -D, $(4)) -c -o $(1) $(2)
77 define TargetSourceList_Template
79 @mkdir -p $(dir $(1)) $(DEP_DIR)
80 @echo "[cc]: $(1) <-- $(2)"
81 @$(CC) $(CFLAGS_A) $(addprefix -I./,$(3)) $(addprefix -D, $(4)) $(LIST_OPT) -c -o /dev/null $(2) > $(1)
84 # ----------------------------------------------------------------------------
85 # Function: find_source_file
86 # Arguments: 1: name of the binary file (.o extension) to search
87 # 2: list of directorys to search for file
88 # Returns: Returns paths to source file (mathing the pattern in
90 # ----------------------------------------------------------------------------
91 SOURCE_PATTERN := %.S %.c
92 find_source_file = $(firstword $(foreach d, $(2), \
93 $(filter $(SOURCE_PATTERN), \
94 $(wildcard $(d)$(notdir $(patsubst %.o,%,$1)).*) \
99 $(foreach a, $(ALGORITHMS), \
100 $(foreach b, $($(a)_OBJ), \
101 $(eval $(call TargetSource_Template, \
102 $(BIN_DIR)$(call lc, $(a))/$(b), \
103 $(call find_source_file, $(b), $($(a)_DIR) $($(a)_INCDIR) $(GLOBAL_INCDIR) ),\
104 $($(a)_DIR) $($(a)_INCDIR) $(GLOBAL_INCDIR), \
110 $(foreach a, $(ALGORITHMS), \
111 $(foreach b, $($(a)_TESTBIN), \
112 $(eval $(call TargetSource_Template, \
113 $(BIN_DIR)$(call lc, $(a))/$(TEST_DIR)$(b), \
114 $(call find_source_file, $(b), $($(a)_DIR) $($(a)_INCDIR) $(GLOBAL_INCDIR) ),\
115 $($(a)_DIR) $($(a)_INCDIR) $(GLOBAL_INCDIR), \
122 $(foreach a, $(ALGORITHMS), \
123 $(foreach b, $($(a)_OBJ), \
124 $(eval $(call TargetSourceList_Template, \
125 $(LIST_DIR)$(call lc, $(a))/$(patsubst %.o,%.s,$(b)), \
126 $(call find_source_file, $(b), $($(a)_DIR) $($(a)_INCDIR) $(GLOBAL_INCDIR) ),\
127 $($(a)_DIR) $($(a)_INCDIR) $(GLOBAL_INCDIR), \
133 EXTRALINK_BINOBJ = $(patsubst %, $(BIN_DIR)%, $(EXTRALINK))
135 $(foreach a, $(EXTRALINK), \
136 $(eval $(call TargetSource_Template, \
138 $(call find_source_file, $(a), $(GLOBAL_INCDIR) ),\
139 $($(a)_DIR) $($(a)_INCDIR) $(GLOBAL_INCDIR), \
144 #-------------------------------------------------------------------------------
146 define MainTestElf_Template
148 @mkdir -p $(dir $(1))
150 @$(CC) $(CFLAGS_A) $(LDFLAGS)$(patsubst %.elf,%.map,$(1)) -o \
152 $(2) $(3) $(EXTRALINK_BINOBJ)\
156 $(foreach a, $(ALGORITHMS), \
157 $(eval $(call MainTestElf_Template, \
158 $(BIN_DIR)$(call lc, $(a))/$(TEST_DIR)main-$(call lc, $(a))-test.elf, \
160 $($(a)_TESTBINOBJ), \
161 $(EXTRALINK_BINOBJ) \
165 #-------------------------------------------------------------------------------
167 all: $(foreach algo, $(ALGORITHMS), $($(algo)_BINOBJ))
169 #-------------------------------------------------------------------------------
171 define MakeDir_TEMPLATE
177 $(foreach d, DEP_DIR BIN_DIR TESTSRC_DIR TESTLOG_DIR SPEEDLOG_DIR SIZE_DIR LIST_DIR STAT_DIR AUTOASM_DIR, $(eval $(call MakeDir_TEMPLATE, \
181 $(foreach algo, $(ALGORITHMS), $(eval $(call MakeDir__TEMPLATE, \
182 $(BIN_DIR)$(call lc, $(algo))/$(TEST_DIR) \
185 define TestBin_TEMPLATE
189 $(foreach algo, $(ALGORITHMS), $(eval $(call TestBin_TEMPLATE, \
191 $(BIN_DIR)$(call lc, $(algo))/$(TEST_DIR)main-$(call lc, $(algo))-test.elf \
194 #-------------------------------------------------------------------------------
196 define Listing_TEMPLATE
200 $(foreach algo, $(ALGORITHMS), $(eval $(call Listing_TEMPLATE, \
202 $(foreach obj,$($(algo)_OBJ), $(LIST_DIR)$(call lc, $(algo))/$(obj:.o=.s)) \
205 #-------------------------------------------------------------------------------
208 @echo "[objcopy]: $@"
209 @$(OBJCOPY) -j .text -j .data -O ihex $< $@
211 #-------------------------------------------------------------------------------
213 define Flash_Template
215 @echo "[flash]: $(2)"
216 @$(FLASHCMD)$(call first,$(2))
219 $(foreach algo, $(ALGORITHMS), $(eval $(call Flash_Template, \
221 $(BIN_DIR)$(call lc, $(algo))/$(TEST_DIR)main-$(call lc, $(algo))-test.hex \
224 #-------------------------------------------------------------------------------
226 define Speed_Template
227 $(1)_SPEED: $(1)_FLASH
228 @$(RUBY) $(SPEEDTOOL) -c $(SPEEDCMD) -t $(SPEEDLOG_DIR) -a $(call lc, $(1))
231 $(foreach algo, $(ALGORITHMS), $(eval $(call Speed_Template, \
236 hash_speed: $(foreach algo, $(HASHES), $(algo)_SPEED)
238 .PHONY: blockcipher_speed
239 blockcipher_speed: $(foreach algo, $(BLOCK_CIPHERS), $(algo)_SPEED)
240 #-------------------------------------------------------------------------------
246 $(SIZE) $(2) > $(strip $(SIZE_DIR))$(strip $(call lc, $(1))).size
249 $(foreach algo, $(ALGORITHMS), $(eval $(call Size_Template, \
250 $(strip $(algo)), $($(algo)_BINOBJ) \
254 hash_size: $(foreach algo, $(HASHES), $(algo)_SIZE)
256 .PHONY: blockcipher_size
257 blockcipher_size: $(foreach algo, $(BLOCK_CIPHERS), $(algo)_SIZE)
259 #-------------------------------------------------------------------------------
262 tests: $(foreach a, $(ALGORITHMS), $(a)_TESTBIN)
264 #-------------------------------------------------------------------------------
266 define TestRun_Template
267 $(1)_TESTRUN: $(1)_FLASH
273 $(RUBY) $(GET_TEST) $(TESTPORT) $(TESTPORTBAUDR) 8 1 nessie $(TESTLOG_DIR)$(TESTPREFIX) $(2)
276 $(foreach algo, $(ALGORITHMS),$(eval $(call TestRun_Template, $(algo), $(call lc,$(algo)) )))
278 all_testrun: $(foreach algo, $(ALGORITHMS), $(algo)_TESTRUN)
280 #-------------------------------------------------------------------------------
286 $(foreach algo, $(ALGORITHMS), \
287 $(eval $(call Obj_Template, \
301 cores: $(foreach algo, $(ALGORITHMS), $(algo)_OBJ)
303 .PHONY: blockchiphers
304 blockciphers: $(foreach algo, $(BLOCK_CIPHERS), $(algo)_OBJ)
306 .PHONY: streamchiphers
307 streamciphers: $(foreach algo, $(STREAM_CIPHERS), $(algo)_OBJ)
310 hashes: $(foreach algo, $(HASHES), $(algo)_OBJ)
313 macs: $(foreach algo, $(MACS), $(algo)_OBJ)
316 prngs: $(foreach algo, $(PRNGS), $(algo)_OBJ)
319 encodings: $(foreach algo, $(ENCODINGS), $(algo)_OBJ)
322 aux: $(foreach algo, $(AUX), $(algo)_OBJ)
325 #-------------------------------------------------------------------------------
332 @echo "infos on AVR-Crypto-lib:"
333 @echo " block ciphers:"
334 @echo " $(BLOCK_CIPHERS)"
335 @echo " stream ciphers:"
336 @echo " $(STREAM_CIPHERS)"
337 @echo " hash functions:"
339 @echo " MAC functions:"
341 @echo " PRNG functions:"
343 @echo " signature functions:"
344 @echo " $(SIGNATURE)"
345 @echo " public key ciphers:"
346 @echo " $(PK_CIPHERS)"
348 @echo " $(ENCODINGS)"
349 @echo " auxiliary functions:"
352 @echo " all - all algorithm cores"
353 @echo " cores - all algorithm cores"
354 @echo " listings - all algorithm core listings"
355 @echo " tests - all algorithm test programs"
356 @echo " stats - all algorithm size statistics"
357 @echo " blockciphers - all blockcipher cores"
358 @echo " streamciphers - all streamcipher cores"
359 @echo " hashes - all hash cores"
360 @echo " macs - all MAC cores"
361 @echo " prngs - all PRNG cores"
362 @echo " all_testrun - testrun all algorithms"
363 @echo " hash_size - measure size of all hash functions"
364 @echo " hash_speed - measure performance of all hash functions"
365 @echo " blockcipher_size - measure size of all blockciphers"
366 @echo " blockcipher_speed - measure performance of all blockciphers"
367 @echo " docu - build doxygen documentation"
368 @echo " clean - remove a lot of builded files"
369 @echo " depclean - also remove dependency files"
370 @echo " *_TESTBIN - build test program"
371 @echo " *_TESTRUN - run nessie test"
372 @echo " *_OBJ - build algorithm core"
373 @echo " *_FLASH - flash test program"
374 @echo " *_LIST - build assembler listing"
377 #-------------------------------------------------------------------------------
387 #-------------------------------------------------------------------------------
388 # dependency inclusion
391 DEPS := $(wildcard $(DEP_DIR)*.d)