1 # Makefile for the ARM-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 arm-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) -O binary $< $@
154 @echo "[objcopy]: $@"
155 @$(OBJCOPY) -j .text -j .data -O ihex $< $@
157 #-------------------------------------------------------------------------------
159 define Flash_Template
161 @echo "[flash]: $(2)"
162 @$(call FLASHCMD, $(call first,$(2)))
165 $(foreach algo, $(ALGORITHMS), $(eval $(call Flash_Template, \
167 $(BIN_DIR)$(call lc, $(algo))/$(TEST_DIR)main-$(call lc, $(algo))-test.bin \
170 #-------------------------------------------------------------------------------
172 define Speed_Template
173 $(1)_SPEED: $(1)_FLASH
174 @$(RUBY) $(SPEEDTOOL) -c $(SPEEDCMD) -t $(SPEEDLOG_DIR) -a $(call lc, $(1))
177 $(foreach algo, $(ALGORITHMS), $(eval $(call Speed_Template, \
182 hash_speed: $(foreach algo, $(HASHES), $(algo)_SPEED)
184 .PHONY: blockcipher_speed
185 blockcipher_speed: $(foreach algo, $(BLOCK_CIPHERS), $(algo)_SPEED)
186 #-------------------------------------------------------------------------------
192 $(SIZE) $(2) > $(strip $(SIZE_DIR))$(strip $(call lc, $(1))).size
195 $(foreach algo, $(ALGORITHMS), $(eval $(call Size_Template, \
196 $(strip $(algo)), $($(algo)_BINOBJ) \
200 hash_size: $(foreach algo, $(HASHES), $(algo)_SIZE)
202 .PHONY: blockcipher_size
203 blockcipher_size: $(foreach algo, $(BLOCK_CIPHERS), $(algo)_SIZE)
205 #-------------------------------------------------------------------------------
208 tests: $(foreach a, $(ALGORITHMS), $(a)_TEST_BIN)
210 #-------------------------------------------------------------------------------
212 define TestRun_Template
213 $(1)_TESTRUN: $(1)_FLASH
215 $(RUBY) $(GET_TEST) $(TESTPORT) $(TESTPORTBAUDR) 8 1 nessie $(TESTLOG_DIR)$(TESTPREFIX) $(2)
218 $(foreach algo, $(ALGORITHMS),$(eval $(call TestRun_Template, $(algo), $(call lc,$(algo)) )))
220 all_testrun: $(foreach algo, $(ALGORITHMS), $(algo)_TESTRUN)
222 #-------------------------------------------------------------------------------
228 $(foreach algo, $(ALGORITHMS), \
229 $(eval $(call Obj_Template, \
236 cores: $(foreach algo, $(ALGORITHMS), $(algo)_OBJ)
238 .PHONY: blockchiphers
239 blockciphers: $(foreach algo, $(BLOCK_CIPHERS), $(algo)_OBJ)
241 .PHONY: streamchiphers
242 streamciphers: $(foreach algo, $(STREAM_CIPHERS), $(algo)_OBJ)
245 hashes: $(foreach algo, $(HASHES), $(algo)_OBJ)
248 macs: $(foreach algo, $(MACS), $(algo)_OBJ)
251 prngs: $(foreach algo, $(PRNGS), $(algo)_OBJ)
254 encodings: $(foreach algo, $(ENCODINGS), $(algo)_OBJ)
257 aux: $(foreach algo, $(AUX), $(algo)_OBJ)
260 #-------------------------------------------------------------------------------
267 @echo "infos on ARM-Crypto-lib:"
268 @echo " block ciphers:"
269 @echo " $(BLOCK_CIPHERS)"
270 @echo " stream ciphers:"
271 @echo " $(STREAM_CIPHERS)"
272 @echo " hash functions:"
274 @echo " MAC functions:"
276 @echo " PRNG functions:"
278 @echo " signature functions:"
279 @echo " $(SIGNATURE)"
280 @echo " public key ciphers:"
281 @echo " $(PK_CIPHERS)"
283 @echo " $(ENCODINGS)"
284 @echo " auxiliary functions:"
287 @echo " all - all algorithm cores"
288 @echo " cores - all algorithm cores"
289 @echo " listings - all algorithm core listings"
290 @echo " tests - all algorithm test programs"
291 @echo " stats - all algorithm size statistics"
292 @echo " blockciphers - all blockcipher cores"
293 @echo " streamciphers - all streamcipher cores"
294 @echo " hashes - all hash cores"
295 @echo " macs - all MAC cores"
296 @echo " prngs - all PRNG cores"
297 @echo " all_testrun - testrun all algorithms"
298 @echo " hash_size - measure size of all hash functions"
299 @echo " hash_speed - measure performance of all hash functions"
300 @echo " blockcipher_size - measure size of all blockciphers"
301 @echo " blockcipher_speed - measure performance of all blockciphers"
302 @echo " docu - build doxygen documentation"
303 @echo " clean - remove a lot of builded files"
304 @echo " depclean - also remove dependency files"
305 @echo " *_TESTBIN - build test program"
306 @echo " *_TESTRUN - run nessie test"
307 @echo " *_OBJ - build algorithm core"
308 @echo " *_FLASH - flash test program"
309 @echo " *_LIST - build assembler listing"
312 #-------------------------------------------------------------------------------
322 #-------------------------------------------------------------------------------
323 # dependency inclusion
326 DEPS := $(wildcard $(DEP_DIR)*.d)