2 # Makefile for the AVR-Crypto-Lib project
4 # This file is part of the AVR-Crypto-Lib.
5 # Copyright (C) 2010 Daniel Otte (daniel.otte@rub.de)
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
32 # we use the gnu make standard library
35 GLOBAL_INCDIR := ./ $(TESTSRC_DIR)
37 #-------------------------------------------------------------------------------
38 # inclusion of make stubs
39 include $(sort $(wildcard mkfiles/*.mk))
41 #-------------------------------------------------------------------------------
42 # define binary object in $(BIN_DIR)$(ALGO)/<obj>
43 define Assert_Template
51 #-------------------------------------------------------------------------------
52 ALGORITHMS = $(BLOCK_CIPHERS) $(STREAM_CIPHERS) $(HASHES) $(PRNGS) $(MACS) \
53 $(ENCODINGS) $(SIGNATURE) $(PK_CIPHERS) $(AUX)
54 ALGORITHMS_OBJ = $(patsubst %,%_OBJ, $(ALGORITHMS))
55 ALGORITHMS_TESTBIN = $(patsubst %,%_TESTBIN, $(ALGORITHMS))
61 $(foreach a, $(LIB_ALGOS), $(eval $(call Add_Template, \
65 LIB_OBJECTS := $(addprefix $(BIN_DIR)$(LIB_DIR), $(sort $(LIB_OBJECTS)))
67 $(foreach a, $(LIB_ALGOS), $(eval $(call Add_Template, \
72 $(foreach a, $(LIB_ALGOS), $(eval $(call Add_Template, \
76 LIB_SRCDIRS := $(sort $(LIB_SRCDIRS))
78 $(foreach a, $(LIB_ALGOS), $(eval $(call Add_Template, \
82 LIB_DEFINES := $(sort $(LIB_DEFINES))
85 #-------------------------------------------------------------------------------
86 # define binary object in $(BIN_DIR)$(ALGO)/<obj>
87 $(foreach a, $(ALGORITHMS), $(eval $(call Assert_Template, \
89 $(addprefix $(BIN_DIR)$(call lc,$(a))/,$($(a)_OBJ)) \
92 $(foreach a, $(ALGORITHMS), $(eval $(call Assert_Template, \
94 $(addprefix $(BIN_DIR)$(call lc,$(a))/$(TEST_DIR),$($(a)_TESTBIN)) \
99 #-------------------------------------------------------------------------------
101 define TargetSource_Template
103 @mkdir -p $(dir $(1)) $(DEP_DIR)
104 @echo "[cc]: $(1) <-- $(2)"
105 @$(CC) $(CFLAGS_A) $(addprefix -I./,$(3)) $(addprefix -D, $(4)) -c -o $(1) $(2)
110 define TargetSourceList_Template
112 @mkdir -p $(dir $(1)) $(DEP_DIR)
113 @echo "[cc]: $(1) <-- $(2)"
114 @$(CC) $(CFLAGS_A) $(addprefix -I./,$(3)) $(addprefix -D, $(4)) $(LIST_OPT) -c -o /dev/null $(2) > $(1)
117 # ----------------------------------------------------------------------------
118 # Function: find_source_file
119 # Arguments: 1: name of the binary file (.o extension) to search
120 # 2: list of directorys to search for file
121 # Returns: Returns paths to source file (mathing the pattern in
123 # ----------------------------------------------------------------------------
124 SOURCE_PATTERN := %.S %.c
125 find_source_file = $(firstword $(foreach d, $(2), \
126 $(filter $(SOURCE_PATTERN), \
127 $(wildcard $(d)$(notdir $(patsubst %.o,%,$1)).*) \
132 $(foreach a, $(ALGORITHMS), \
133 $(foreach b, $($(a)_OBJ), \
134 $(eval $(call TargetSource_Template, \
135 $(BIN_DIR)$(call lc, $(a))/$(b), \
136 $(call find_source_file, $(b), $($(a)_DIR) $($(a)_INCDIR) $(GLOBAL_INCDIR) ),\
137 $($(a)_DIR) $($(a)_INCDIR) $(GLOBAL_INCDIR), \
143 $(foreach a, $(ALGORITHMS), \
144 $(foreach b, $($(a)_TESTBIN), \
145 $(eval $(call TargetSource_Template, \
146 $(BIN_DIR)$(call lc, $(a))/$(TEST_DIR)$(b), \
147 $(call find_source_file, $(b), $($(a)_DIR) $($(a)_INCDIR) $(GLOBAL_INCDIR) ),\
148 $($(a)_DIR) $($(a)_INCDIR) $(GLOBAL_INCDIR), \
155 $(foreach a, $(ALGORITHMS), \
156 $(foreach b, $($(a)_OBJ), \
157 $(eval $(call TargetSourceList_Template, \
158 $(LIST_DIR)$(call lc, $(a))/$(patsubst %.o,%.s,$(b)), \
159 $(call find_source_file, $(b), $($(a)_DIR) $($(a)_INCDIR) $(GLOBAL_INCDIR) ),\
160 $($(a)_DIR) $($(a)_INCDIR) $(GLOBAL_INCDIR), \
166 EXTRALINK_BINOBJ = $(patsubst %, $(BIN_DIR)%, $(EXTRALINK))
168 $(foreach a, $(EXTRALINK), \
169 $(eval $(call TargetSource_Template, \
171 $(call find_source_file, $(a), $(GLOBAL_INCDIR) ),\
172 $($(a)_DIR) $($(a)_INCDIR) $(GLOBAL_INCDIR), \
178 $(foreach a, $(LIB_OBJECTS), \
179 $(eval $(call TargetSource_Template, \
181 $(call find_source_file, $(notdir $(a)), $(LIB_SRCDIRS) ),\
182 $(LIB_SRCDIRS) $(GLOBAL_INCDIR), \
188 #-------------------------------------------------------------------------------
190 define MainTestElf_Template
192 @mkdir -p $(dir $(1))
194 @$(CC) $(CFLAGS_A) $(LDFLAGS)$(patsubst %.elf,%.map,$(1)) -o \
196 $(2) $(3) $(EXTRALINK_BINOBJ)\
197 $(addprefix -l,$(LIBS))
200 $(foreach a, $(ALGORITHMS), \
201 $(eval $(call MainTestElf_Template, \
202 $(BIN_DIR)$(call lc, $(a))/$(TEST_DIR)main-$(call lc, $(a))-test.elf, \
204 $($(a)_TESTBINOBJ), \
205 $(EXTRALINK_BINOBJ) \
209 #-------------------------------------------------------------------------------
211 all: $(foreach algo, $(ALGORITHMS), $($(algo)_BINOBJ))
213 #-------------------------------------------------------------------------------
215 define MakeDir_TEMPLATE
221 $(foreach d, DEP_DIR BIN_DIR TESTSRC_DIR TESTLOG_DIR SPEEDLOG_DIR SIZE_DIR LIST_DIR STAT_DIR AUTOASM_DIR, $(eval $(call MakeDir_TEMPLATE, \
225 $(foreach algo, $(ALGORITHMS), $(eval $(call MakeDir__TEMPLATE, \
226 $(BIN_DIR)$(call lc, $(algo))/$(TEST_DIR) \
229 define TestBin_TEMPLATE
233 $(foreach algo, $(ALGORITHMS), $(eval $(call TestBin_TEMPLATE, \
235 $(BIN_DIR)$(call lc, $(algo))/$(TEST_DIR)main-$(call lc, $(algo))-test.elf \
238 #-------------------------------------------------------------------------------
240 define Listing_TEMPLATE
244 $(foreach algo, $(ALGORITHMS), $(eval $(call Listing_TEMPLATE, \
246 $(foreach obj,$($(algo)_OBJ), $(LIST_DIR)$(call lc, $(algo))/$(obj:.o=.s)) \
249 #-------------------------------------------------------------------------------
251 @echo "[objcopy]: $@"
252 @$(OBJCOPY) -O binary $< $@
255 @echo "[objcopy]: $@"
256 @$(OBJCOPY) -j .text -j .data -O ihex $< $@
258 #-------------------------------------------------------------------------------
260 define Flash_Template
262 @echo "[flash]: $(2)"
263 @$(call FLASHCMD, $(call first,$(2)))
266 $(foreach algo, $(ALGORITHMS), $(eval $(call Flash_Template, \
268 $(BIN_DIR)$(call lc, $(algo))/$(TEST_DIR)main-$(call lc, $(algo))-test.bin \
271 #-------------------------------------------------------------------------------
273 define Speed_Template
274 $(1)_SPEED: $(1)_FLASH
275 @$(RUBY) $(SPEEDTOOL) -c $(SPEEDCMD) -t $(SPEEDLOG_DIR) -a $(call lc, $(1))
278 $(foreach algo, $(ALGORITHMS), $(eval $(call Speed_Template, \
283 hash_speed: $(foreach algo, $(HASHES), $(algo)_SPEED)
285 .PHONY: blockcipher_speed
286 blockcipher_speed: $(foreach algo, $(BLOCK_CIPHERS), $(algo)_SPEED)
287 #-------------------------------------------------------------------------------
293 $(SIZE) $(2) > $(strip $(SIZE_DIR))$(strip $(call lc, $(1))).size
296 $(foreach algo, $(ALGORITHMS), $(eval $(call Size_Template, \
297 $(strip $(algo)), $($(algo)_BINOBJ) \
301 hash_size: $(foreach algo, $(HASHES), $(algo)_SIZE)
303 .PHONY: blockcipher_size
304 blockcipher_size: $(foreach algo, $(BLOCK_CIPHERS), $(algo)_SIZE)
306 #-------------------------------------------------------------------------------
309 tests: $(foreach a, $(ALGORITHMS), $(a)_TESTBIN)
311 #-------------------------------------------------------------------------------
313 define TestRun_Template
314 $(1)_TESTRUN: $(1)_FLASH
320 $(RUBY) $(GET_TEST) $(TESTPORT) $(TESTPORTBAUDR) 8 1 nessie $(TESTLOG_DIR)$(TESTPREFIX) $(2)
323 $(foreach algo, $(ALGORITHMS),$(eval $(call TestRun_Template, $(algo), $(call lc,$(algo)) )))
325 all_testrun: $(foreach algo, $(ALGORITHMS), $(algo)_TESTRUN)
327 #-------------------------------------------------------------------------------
333 $(foreach algo, $(ALGORITHMS), \
334 $(eval $(call Obj_Template, \
348 cores: $(foreach algo, $(ALGORITHMS), $(algo)_OBJ)
350 .PHONY: blockchiphers
351 blockciphers: $(foreach algo, $(BLOCK_CIPHERS), $(algo)_OBJ)
353 .PHONY: streamchiphers
354 streamciphers: $(foreach algo, $(STREAM_CIPHERS), $(algo)_OBJ)
357 hashes: $(foreach algo, $(HASHES), $(algo)_OBJ)
360 macs: $(foreach algo, $(MACS), $(algo)_OBJ)
363 prngs: $(foreach algo, $(PRNGS), $(algo)_OBJ)
366 encodings: $(foreach algo, $(ENCODINGS), $(algo)_OBJ)
369 aux: $(foreach algo, $(AUX), $(algo)_OBJ)
374 @echo $(foreach a, $(LIB_ALGOS), '\t$(a)\n')
375 @echo "LIB_OBJECTS ="
376 @echo $(foreach a, $(LIB_OBJECTS), '\t$(a)\n')
377 @echo "LIB_SRCDIRS ="
378 @echo $(foreach a, $(LIB_SRCDIRS), '\t$(a)\n')
380 $(BIN_DIR)$(LIB_DIR)$(LIB_NAME): $(LIB_OBJECTS)
383 @echo "[chmod]: <objects>"
387 @echo "[ar]: $@ <-- <objects>"
391 lib: $(BIN_DIR)$(LIB_DIR)$(LIB_NAME)
393 #-------------------------------------------------------------------------------
400 @echo "infos on ARM-Crypto-lib:"
401 @echo " block ciphers:"
402 @echo " $(BLOCK_CIPHERS)"
403 @echo " stream ciphers:"
404 @echo " $(STREAM_CIPHERS)"
405 @echo " hash functions:"
407 @echo " MAC functions:"
409 @echo " PRNG functions:"
411 @echo " signature functions:"
412 @echo " $(SIGNATURE)"
413 @echo " public key ciphers:"
414 @echo " $(PK_CIPHERS)"
416 @echo " $(ENCODINGS)"
417 @echo " auxiliary functions:"
420 @echo " all - all algorithm cores"
421 @echo " cores - all algorithm cores"
422 @echo " listings - all algorithm core listings"
423 @echo " tests - all algorithm test programs"
424 @echo " stats - all algorithm size statistics"
425 @echo " blockciphers - all blockcipher cores"
426 @echo " streamciphers - all streamcipher cores"
427 @echo " hashes - all hash cores"
428 @echo " macs - all MAC cores"
429 @echo " prngs - all PRNG cores"
430 @echo " lib - create library
431 @echo " all_testrun - testrun all algorithms"
432 @echo " hash_size - measure size of all hash functions"
433 @echo " hash_speed - measure performance of all hash functions"
434 @echo " blockcipher_size - measure size of all blockciphers"
435 @echo " blockcipher_speed - measure performance of all blockciphers"
436 @echo " docu - build doxygen documentation"
437 @echo " clean - remove a lot of builded files"
438 @echo " depclean - also remove dependency files"
439 @echo " *_TESTBIN - build test program"
440 @echo " *_TESTRUN - run nessie test"
441 @echo " *_OBJ - build algorithm core"
442 @echo " *_FLASH - flash test program"
443 @echo " *_LIST - build assembler listing"
446 #-------------------------------------------------------------------------------
450 @echo "[rm]: $(BIN_DIR)*"
455 @echo "[rm]: $(DEP_DIR)*.d"
458 #-------------------------------------------------------------------------------
459 # dependency inclusion
462 DEPS := $(wildcard $(DEP_DIR)*.d)