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
37 include $(sort $(wildcard mkfiles/*.mk))
41 #-------------------------------------------------------------------------------
42 ALGORITHMS = $(BLOCK_CIPHERS) $(STREAM_CIPHERS) $(HASHES) $(PRNGS) $(MACS) \
43 $(ENCODINGS) $(SIGNATURE) $(PK_CIPHERS) $(AUX)
44 ALGORITHMS_OBJ = $(patsubst %,%_OBJ, $(ALGORITHMS))
45 ALGORITHMS_TESTBIN = $(patsubst %,%_TESTBIN, $(ALGORITHMS))
47 #-------------------------------------------------------------------------------
48 # define binary object in $(BIN_DIR)$(ALGO)/<obj>
49 define Assert_Template
53 $(foreach a, $(ALGORITHMS), $(eval $(call Assert_Template, \
55 $(addprefix $(BIN_DIR)$(call lc,$(a))/,$($(a)_OBJ)) \
58 $(foreach a, $(ALGORITHMS), $(eval $(call Assert_Template, \
60 $(addprefix $(BIN_DIR)$(call lc,$(a))/$(TEST_DIR),$($(a)_TESTBIN)) \
65 #-------------------------------------------------------------------------------
67 define GenericTarget_Template
71 define TargetSource_Template
73 @mkdir -p $(dir $(1)) $(DEP_DIR)
74 @echo "[cc]: $(1) <-- $(2)"
75 @$(CC) $(CFLAGS_A) $(addprefix -I./,$(3)) $(addprefix -D, $(4)) -c -o $(1) $(2)
80 define TargetSourceList_Template
82 @mkdir -p $(dir $(1)) $(DEP_DIR)
83 @echo "[lst]: $(1) <-- $(2)"
84 @$(CC) $(CFLAGS_A) $(addprefix -I./,$(3)) $(addprefix -D, $(4)) $(LIST_OPT) -c -o /dev/null $(2) > $(1)
87 # ----------------------------------------------------------------------------
88 # Function: find_source_file
89 # Arguments: 1: name of the binary file (.o extension) to search
90 # 2: list of directorys to search for file
91 # Returns: Returns paths to source file (mathing the pattern in
93 # ----------------------------------------------------------------------------
94 SOURCE_PATTERN := %.S %.c
95 find_source_file = $(firstword $(foreach d, $(2), \
96 $(filter $(SOURCE_PATTERN), \
97 $(wildcard $(d)$(notdir $(patsubst %.o,%,$1)).*) \
102 $(foreach a, $(ALGORITHMS), \
103 $(foreach b, $($(a)_OBJ), \
104 $(eval $(call TargetSource_Template, \
105 $(BIN_DIR)$(call lc, $(a))/$(b), \
106 $(call find_source_file, $(b), $($(a)_DIR) $($(a)_INCDIR) $(GLOBAL_INCDIR) ),\
107 $($(a)_DIR) $($(a)_INCDIR) $(GLOBAL_INCDIR), \
113 $(foreach a, $(ALGORITHMS), \
114 $(foreach b, $($(a)_TESTBIN), \
115 $(eval $(call TargetSource_Template, \
116 $(BIN_DIR)$(call lc, $(a))/$(TEST_DIR)$(b), \
117 $(call find_source_file, $(b), $($(a)_DIR) $($(a)_INCDIR) $(GLOBAL_INCDIR) ),\
118 $($(a)_DIR) $($(a)_INCDIR) $(GLOBAL_INCDIR), \
125 $(foreach a, $(ALGORITHMS), \
126 $(foreach b, $($(a)_OBJ), \
127 $(eval $(call TargetSourceList_Template, \
128 $(LIST_DIR)$(call lc, $(a))/$(patsubst %.o,%.s,$(b)), \
129 $(call find_source_file, $(b), $($(a)_DIR) $($(a)_INCDIR) $(GLOBAL_INCDIR) ),\
130 $($(a)_DIR) $($(a)_INCDIR) $(GLOBAL_INCDIR), \
136 EXTRALINK_BINOBJ = $(patsubst %, $(BIN_DIR)%, $(EXTRALINK))
138 $(foreach a, $(EXTRALINK), \
139 $(eval $(call TargetSource_Template, \
141 $(call find_source_file, $(a), $(GLOBAL_INCDIR) ),\
142 $($(a)_DIR) $($(a)_INCDIR) $(GLOBAL_INCDIR), \
147 #-------------------------------------------------------------------------------
149 define MainTestElf_Template
151 @mkdir -p $(dir $(1))
153 @$(CC) $(CFLAGS_A) $(LDFLAGS)$(patsubst %.elf,%.map,$(1)) -o \
155 $(2) $(3) $(EXTRALINK_BINOBJ)\
159 $(foreach a, $(ALGORITHMS), \
160 $(eval $(call MainTestElf_Template, \
161 $(BIN_DIR)$(call lc, $(a))/$(TEST_DIR)main-$(call lc, $(a))-test.elf, \
163 $($(a)_TESTBINOBJ), \
164 $(EXTRALINK_BINOBJ) \
168 #-------------------------------------------------------------------------------
170 all: $(foreach algo, $(ALGORITHMS), $($(algo)_BINOBJ))
172 #-------------------------------------------------------------------------------
174 define MakeDir_TEMPLATE
180 $(foreach d, DEP_DIR BIN_DIR TESTSRC_DIR TESTLOG_DIR SPEEDLOG_DIR SIZE_DIR LIST_DIR STAT_DIR, $(eval $(call MakeDir_TEMPLATE, \
184 $(foreach algo, $(ALGORITHMS), $(eval $(call MakeDir__TEMPLATE, \
185 $(BIN_DIR)$(call lc, $(algo))/$(TEST_DIR) \
188 define TestBin_TEMPLATE
192 $(foreach algo, $(ALGORITHMS), $(eval $(call TestBin_TEMPLATE, \
194 $(BIN_DIR)$(call lc, $(algo))/$(TEST_DIR)main-$(call lc, $(algo))-test.hex \
197 #-------------------------------------------------------------------------------
199 define Listing_TEMPLATE
203 $(foreach algo, $(ALGORITHMS), $(eval $(call Listing_TEMPLATE, \
205 $(foreach obj,$($(algo)_OBJ), $(LIST_DIR)$(call lc, $(algo))/$(obj:.o=.s)) \
208 #-------------------------------------------------------------------------------
211 @echo "[objcopy]: $@"
212 @$(OBJCOPY) -j .text -j .data -O ihex $< $@
214 ifneq ($(HASH_TOOL),)
215 @echo -n "[$(HASH_TOOL)]: "
220 #-------------------------------------------------------------------------------
222 define Flash_Template
224 @echo "[flash]: $(2)"
225 @$(FLASHCMD)$(call first,$(2))
228 $(foreach algo, $(ALGORITHMS), $(eval $(call Flash_Template, \
230 $(BIN_DIR)$(call lc, $(algo))/$(TEST_DIR)main-$(call lc, $(algo))-test.hex \
233 #-------------------------------------------------------------------------------
235 define Speed_Template
236 $(1)_SPEED: $(1)_FLASH
237 @$(RUBY) $(SPEEDTOOL) -c $(SPEEDCMD) -t $(SPEEDLOG_DIR) -a $(call lc, $(1))
240 $(foreach algo, $(ALGORITHMS), $(eval $(call Speed_Template, \
245 hash_speed: $(foreach algo, $(HASHES), $(algo)_SPEED)
247 .PHONY: blockcipher_speed
248 blockcipher_speed: $(foreach algo, $(BLOCK_CIPHERS), $(algo)_SPEED)
249 #-------------------------------------------------------------------------------
254 @mkdir -p $(dir $(1))
258 $(foreach algo, $(ALGORITHMS), $(eval $(call Size_Template, \
259 $(strip $(SIZE_DIR))$(strip $(call lc, $(algo))).size,$($(algo)_BINOBJ),$(algo) \
265 @mkdir -p $(dir $(strip $(SIZE_DIR))$(strip $(call lc, $(1))).size)
266 @$(SIZE) $(2) > $(strip $(SIZE_DIR))$(strip $(call lc, $(1))).size
269 $(foreach algo, $(ALGORITHMS), $(eval $(call GenericTarget_Template, \
270 $(strip $(algo))_SIZE,$(strip $(SIZE_DIR))$(strip $(call lc, $(algo))).size \
274 hash_size: $(foreach algo, $(HASHES), $(algo)_SIZE)
276 .PHONY: blockcipher_size
277 blockcipher_size: $(foreach algo, $(BLOCK_CIPHERS), $(algo)_SIZE)
280 size: $(foreach algo, $(ALGORITHMS), $(algo)_SIZE)
284 rm -vf $(strip $(SIZE_DIR))*.size
286 #-------------------------------------------------------------------------------
289 tests: $(foreach a, $(ALGORITHMS), $(a)_TESTBIN)
291 #-------------------------------------------------------------------------------
293 define TestRun_Template
294 $(1)_TESTRUN: $(1)_FLASH
300 $(RUBY) $(GET_TEST) $(TESTPORT) $(TESTPORTBAUDR) 8 1 nessie $(TESTLOG_DIR)$(TESTPREFIX) $(2)
303 $(foreach algo, $(ALGORITHMS),$(eval $(call TestRun_Template, $(algo), $(call lc,$(algo)) )))
305 all_testrun: $(foreach algo, $(ALGORITHMS), $(algo)_TESTRUN)
307 #-------------------------------------------------------------------------------
313 $(foreach algo, $(ALGORITHMS), \
314 $(eval $(call Obj_Template, \
328 cores: $(foreach algo, $(ALGORITHMS), $(algo)_OBJ)
330 .PHONY: blockchiphers
331 blockciphers: $(foreach algo, $(BLOCK_CIPHERS), $(algo)_OBJ)
333 .PHONY: streamchiphers
334 streamciphers: $(foreach algo, $(STREAM_CIPHERS), $(algo)_OBJ)
337 hashes: $(foreach algo, $(HASHES), $(algo)_OBJ)
340 macs: $(foreach algo, $(MACS), $(algo)_OBJ)
343 prngs: $(foreach algo, $(PRNGS), $(algo)_OBJ)
346 encodings: $(foreach algo, $(ENCODINGS), $(algo)_OBJ)
349 aux: $(foreach algo, $(AUX), $(algo)_OBJ)
352 #-------------------------------------------------------------------------------
359 @echo "infos on AVR-Crypto-lib:"
360 @echo " block ciphers:"
361 @echo " $(BLOCK_CIPHERS)"
362 @echo " stream ciphers:"
363 @echo " $(STREAM_CIPHERS)"
364 @echo " hash functions:"
366 @echo " MAC functions:"
368 @echo " PRNG functions:"
370 @echo " signature functions:"
371 @echo " $(SIGNATURE)"
372 @echo " public key ciphers:"
373 @echo " $(PK_CIPHERS)"
375 @echo " $(ENCODINGS)"
376 @echo " auxiliary functions:"
379 @echo " all - all algorithm cores"
380 @echo " cores - all algorithm cores"
381 @echo " listings - all algorithm core listings"
382 @echo " tests - all algorithm test programs"
383 @echo " size - all algorithm size statistics"
384 @echo " blockciphers - all blockcipher cores"
385 @echo " streamciphers - all streamcipher cores"
386 @echo " hashes - all hash cores"
387 @echo " macs - all MAC cores"
388 @echo " prngs - all PRNG cores"
389 @echo " all_testrun - testrun all algorithms"
390 @echo " hash_size - measure size of all hash functions"
391 @echo " hash_speed - measure performance of all hash functions"
392 @echo " blockcipher_size - measure size of all blockciphers"
393 @echo " blockcipher_speed - measure performance of all blockciphers"
394 @echo " docu - build doxygen documentation"
395 @echo " clean - remove a lot of builded files"
396 @echo " depclean - also remove dependency files"
397 @echo " *_TESTBIN - build test program"
398 @echo " *_TESTRUN - run nessie test"
399 @echo " *_OBJ - build algorithm core"
400 @echo " *_FLASH - flash test program"
401 @echo " *_LIST - build assembler listing"
404 #-------------------------------------------------------------------------------
414 #-------------------------------------------------------------------------------
415 # dependency inclusion
418 DEPS := $(wildcard $(DEP_DIR)*.d)