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))
39 #-------------------------------------------------------------------------------
40 ALGORITHMS = $(BLOCK_CIPHERS) $(STREAM_CIPHERS) $(HASHES) $(PRNGS) $(MACS) \
41 $(ENCODINGS) $(SIGNATURE) $(PK_CIPHERS) $(AUX)
42 ALGORITHMS_OBJ = $(patsubst %,%_OBJ, $(ALGORITHMS))
43 ALGORITHMS_TESTBIN = $(patsubst %,%_TESTBIN, $(ALGORITHMS))
45 #-------------------------------------------------------------------------------
46 # define binary object in $(BIN_DIR)$(ALGO)/<obj>
47 define Assert_Template
51 $(foreach a, $(ALGORITHMS), $(eval $(call Assert_Template, \
53 $(addprefix $(BIN_DIR)$(call lc,$(a))/,$($(a)_OBJ)) \
56 $(foreach a, $(ALGORITHMS), $(eval $(call Assert_Template, \
58 $(addprefix $(BIN_DIR)$(call lc,$(a))/$(TEST_DIR),$($(a)_TESTBIN)) \
63 #-------------------------------------------------------------------------------
67 define TargetSource_Template
69 @mkdir -p $(dir $(1)) $(DEP_DIR)
70 @echo "[cc]: $(1) <-- $(2)"
71 @$(CC) $(CFLAGS_A) $(addprefix -I./,$(3)) $(addprefix -D, $(4)) -c -o $(1) $(2)
76 define TargetSourceList_Template
78 @mkdir -p $(dir $(1)) $(DEP_DIR)
79 @echo "[cc]: $(1) <-- $(2)"
80 @$(CC) $(CFLAGS_A) $(addprefix -I./,$(3)) $(addprefix -D, $(4)) $(LIST_OPT) -c -o /dev/null $(2) > $(1)
83 # ----------------------------------------------------------------------------
84 # Function: find_source_file
85 # Arguments: 1: name of the binary file (.o extension) to search
86 # 2: list of directorys to search for file
87 # Returns: Returns paths to source file (mathing the pattern in
89 # ----------------------------------------------------------------------------
90 SOURCE_PATTERN := %.S %.c
91 find_source_file = $(firstword $(foreach d, $(2), \
92 $(filter $(SOURCE_PATTERN), \
93 $(wildcard $(d)$(notdir $(patsubst %.o,%,$1)).*) \
98 $(foreach a, $(ALGORITHMS), \
99 $(foreach b, $($(a)_OBJ), \
100 $(eval $(call TargetSource_Template, \
101 $(BIN_DIR)$(call lc, $(a))/$(b), \
102 $(call find_source_file, $(b), $($(a)_DIR) $($(a)_INCDIR) $(GLOBAL_INCDIR) ),\
103 $($(a)_DIR) $($(a)_INCDIR) $(GLOBAL_INCDIR), \
109 $(foreach a, $(ALGORITHMS), \
110 $(foreach b, $($(a)_TESTBIN), \
111 $(eval $(call TargetSource_Template, \
112 $(BIN_DIR)$(call lc, $(a))/$(TEST_DIR)$(b), \
113 $(call find_source_file, $(b), $($(a)_DIR) $($(a)_INCDIR) $(GLOBAL_INCDIR) ),\
114 $($(a)_DIR) $($(a)_INCDIR) $(GLOBAL_INCDIR), \
121 $(foreach a, $(ALGORITHMS), \
122 $(foreach b, $($(a)_OBJ), \
123 $(eval $(call TargetSourceList_Template, \
124 $(LIST_DIR)$(call lc, $(a))/$(patsubst %.o,%.s,$(b)), \
125 $(call find_source_file, $(b), $($(a)_DIR) $($(a)_INCDIR) $(GLOBAL_INCDIR) ),\
126 $($(a)_DIR) $($(a)_INCDIR) $(GLOBAL_INCDIR), \
132 EXTRALINK_BINOBJ = $(patsubst %, $(BIN_DIR)%, $(EXTRALINK))
134 $(foreach a, $(EXTRALINK), \
135 $(eval $(call TargetSource_Template, \
137 $(call find_source_file, $(a), $(GLOBAL_INCDIR) ),\
138 $($(a)_DIR) $($(a)_INCDIR) $(GLOBAL_INCDIR), \
143 #-------------------------------------------------------------------------------
145 define MainTestElf_Template
147 @mkdir -p $(dir $(1))
149 @$(CC) $(CFLAGS_A) $(LDFLAGS)$(patsubst %.elf,%.map,$(1)) -o \
151 $(2) $(3) $(EXTRALINK_BINOBJ)\
155 $(foreach a, $(ALGORITHMS), \
156 $(eval $(call MainTestElf_Template, \
157 $(BIN_DIR)$(call lc, $(a))/$(TEST_DIR)main-$(call lc, $(a))-test.elf, \
159 $($(a)_TESTBINOBJ), \
160 $(EXTRALINK_BINOBJ) \
164 #-------------------------------------------------------------------------------
166 all: $(foreach algo, $(ALGORITHMS), $($(algo)_BINOBJ))
168 #-------------------------------------------------------------------------------
170 define MakeDir_TEMPLATE
176 $(foreach d, DEP_DIR BIN_DIR TESTSRC_DIR TESTLOG_DIR SPEEDLOG_DIR SIZE_DIR LIST_DIR STAT_DIR AUTOASM_DIR, $(eval $(call MakeDir_TEMPLATE, \
180 $(foreach algo, $(ALGORITHMS), $(eval $(call MakeDir__TEMPLATE, \
181 $(BIN_DIR)$(call lc, $(algo))/$(TEST_DIR) \
184 define TestBin_TEMPLATE
188 $(foreach algo, $(ALGORITHMS), $(eval $(call TestBin_TEMPLATE, \
190 $(BIN_DIR)$(call lc, $(algo))/$(TEST_DIR)main-$(call lc, $(algo))-test.elf \
193 #-------------------------------------------------------------------------------
195 define Listing_TEMPLATE
199 $(foreach algo, $(ALGORITHMS), $(eval $(call Listing_TEMPLATE, \
201 $(foreach obj,$($(algo)_OBJ), $(LIST_DIR)$(call lc, $(algo))/$(obj:.o=.s)) \
204 #-------------------------------------------------------------------------------
207 @echo "[objcopy]: $@"
208 @$(OBJCOPY) -j .text -j .data -O ihex $< $@
210 #-------------------------------------------------------------------------------
212 define Flash_Template
214 @echo "[flash]: $(2)"
215 @$(FLASHCMD)$(call first,$(2))
218 $(foreach algo, $(ALGORITHMS), $(eval $(call Flash_Template, \
220 $(BIN_DIR)$(call lc, $(algo))/$(TEST_DIR)main-$(call lc, $(algo))-test.hex \
223 #-------------------------------------------------------------------------------
225 define Speed_Template
226 $(1)_SPEED: $(1)_FLASH
227 @$(RUBY) $(SPEEDTOOL) -c $(SPEEDCMD) -t $(SPEEDLOG_DIR) -a $(call lc, $(1))
230 $(foreach algo, $(ALGORITHMS), $(eval $(call Speed_Template, \
235 hash_speed: $(foreach algo, $(HASHES), $(algo)_SPEED)
237 .PHONY: blockcipher_speed
238 blockcipher_speed: $(foreach algo, $(BLOCK_CIPHERS), $(algo)_SPEED)
239 #-------------------------------------------------------------------------------
245 $(SIZE) $(2) > $(strip $(SIZE_DIR))$(strip $(call lc, $(1))).size
248 $(foreach algo, $(ALGORITHMS), $(eval $(call Size_Template, \
249 $(strip $(algo)), $($(algo)_BINOBJ) \
253 hash_size: $(foreach algo, $(HASHES), $(algo)_SIZE)
255 .PHONY: blockcipher_size
256 blockcipher_size: $(foreach algo, $(BLOCK_CIPHERS), $(algo)_SIZE)
258 #-------------------------------------------------------------------------------
261 tests: $(foreach a, $(ALGORITHMS), $(a)_TESTBIN)
263 #-------------------------------------------------------------------------------
265 define TestRun_Template
266 $(1)_TESTRUN: $(1)_FLASH
272 $(RUBY) $(GET_TEST) $(TESTPORT) $(TESTPORTBAUDR) 8 1 nessie $(TESTLOG_DIR)$(TESTPREFIX) $(2)
275 $(foreach algo, $(ALGORITHMS),$(eval $(call TestRun_Template, $(algo), $(call lc,$(algo)) )))
277 all_testrun: $(foreach algo, $(ALGORITHMS), $(algo)_TESTRUN)
279 #-------------------------------------------------------------------------------
285 $(foreach algo, $(ALGORITHMS), \
286 $(eval $(call Obj_Template, \
300 cores: $(foreach algo, $(ALGORITHMS), $(algo)_OBJ)
302 .PHONY: blockchiphers
303 blockciphers: $(foreach algo, $(BLOCK_CIPHERS), $(algo)_OBJ)
305 .PHONY: streamchiphers
306 streamciphers: $(foreach algo, $(STREAM_CIPHERS), $(algo)_OBJ)
309 hashes: $(foreach algo, $(HASHES), $(algo)_OBJ)
312 macs: $(foreach algo, $(MACS), $(algo)_OBJ)
315 prngs: $(foreach algo, $(PRNGS), $(algo)_OBJ)
318 encodings: $(foreach algo, $(ENCODINGS), $(algo)_OBJ)
321 aux: $(foreach algo, $(AUX), $(algo)_OBJ)
324 #-------------------------------------------------------------------------------
331 @echo "infos on AVR-Crypto-lib:"
332 @echo " block ciphers:"
333 @echo " $(BLOCK_CIPHERS)"
334 @echo " stream ciphers:"
335 @echo " $(STREAM_CIPHERS)"
336 @echo " hash functions:"
338 @echo " MAC functions:"
340 @echo " PRNG functions:"
342 @echo " signature functions:"
343 @echo " $(SIGNATURE)"
344 @echo " public key ciphers:"
345 @echo " $(PK_CIPHERS)"
347 @echo " $(ENCODINGS)"
348 @echo " auxiliary functions:"
351 @echo " all - all algorithm cores"
352 @echo " cores - all algorithm cores"
353 @echo " listings - all algorithm core listings"
354 @echo " tests - all algorithm test programs"
355 @echo " stats - all algorithm size statistics"
356 @echo " blockciphers - all blockcipher cores"
357 @echo " streamciphers - all streamcipher cores"
358 @echo " hashes - all hash cores"
359 @echo " macs - all MAC cores"
360 @echo " prngs - all PRNG cores"
361 @echo " all_testrun - testrun all algorithms"
362 @echo " hash_size - measure size of all hash functions"
363 @echo " hash_speed - measure performance of all hash functions"
364 @echo " blockcipher_size - measure size of all blockciphers"
365 @echo " blockcipher_speed - measure performance of all blockciphers"
366 @echo " docu - build doxygen documentation"
367 @echo " clean - remove a lot of builded files"
368 @echo " depclean - also remove dependency files"
369 @echo " *_TESTBIN - build test program"
370 @echo " *_TESTRUN - run nessie test"
371 @echo " *_OBJ - build algorithm core"
372 @echo " *_FLASH - flash test program"
373 @echo " *_LIST - build assembler listing"
376 #-------------------------------------------------------------------------------
386 #-------------------------------------------------------------------------------
387 # dependency inclusion
390 DEPS := $(wildcard $(DEP_DIR)*.d)