1 # Makefile for the ARM-Crypto-Lib project
3 # This file is part of the ARM-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
42 include $(sort $(wildcard mkfiles/*.mk))
44 define Assert_Template
52 #-------------------------------------------------------------------------------
53 ALGORITHMS = $(BLOCK_CIPHERS) $(STREAM_CIPHERS) $(HASHES) $(PRNGS) $(MACS) \
54 $(ENCODINGS) $(SIGNATURE) $(PK_CIPHERS) $(AUX)
55 ALGORITHMS_OBJ = $(patsubst %,%_OBJ, $(ALGORITHMS))
56 ALGORITHMS_TESTBIN = $(patsubst %,%_TESTBIN, $(ALGORITHMS))
62 $(foreach a, $(LIB_ALGOS), $(eval $(call Add_Template, \
66 LIB_OBJECTS := $(addprefix $(BIN_DIR)$(LIB_DIR), $(sort $(LIB_OBJECTS)))
68 $(foreach a, $(LIB_ALGOS), $(eval $(call Add_Template, \
73 $(foreach a, $(LIB_ALGOS), $(eval $(call Add_Template, \
77 LIB_SRCDIRS := $(sort $(LIB_SRCDIRS))
79 $(foreach a, $(LIB_ALGOS), $(eval $(call Add_Template, \
83 LIB_DEFINES := $(sort $(LIB_DEFINES))
86 #-------------------------------------------------------------------------------
87 # define binary object in $(BIN_DIR)$(ALGO)/<obj>
88 $(foreach a, $(ALGORITHMS), $(eval $(call Assert_Template, \
90 $(addprefix $(BIN_DIR)$(call lc,$(a))/,$($(a)_OBJ)) \
93 $(foreach a, $(ALGORITHMS), $(eval $(call Assert_Template, \
95 $(addprefix $(BIN_DIR)$(call lc,$(a))/$(TEST_DIR),$($(a)_TESTBIN)) \
100 #-------------------------------------------------------------------------------
102 define TargetSource_Template
104 @echo "[cc]: $(1) <-- $(2)"
105 @mkdir -p $(dir $(1))
106 @$(CC) $(CFLAGS_A) $(addprefix -I./,$(3)) $(addprefix -D, $(4)) -c -o $(1) $(2)
109 # ----------------------------------------------------------------------------
110 # Function: find_source_file
111 # Arguments: 1: name of the binary file (.o extension) to search
112 # 2: list of directorys to search for file
113 # Returns: Returns paths to source file (mathing the pattern in
115 # ----------------------------------------------------------------------------
116 SOURCE_PATTERN := %.S %.c
117 find_source_file = $(firstword $(foreach d, $(2), \
118 $(filter $(SOURCE_PATTERN), \
119 $(wildcard $(d)$(notdir $(patsubst %.o,%,$1)).*) \
124 $(foreach a, $(ALGORITHMS), \
125 $(foreach b, $($(a)_OBJ), \
126 $(eval $(call TargetSource_Template, \
127 $(BIN_DIR)$(call lc, $(a))/$(b), \
128 $(call find_source_file, $(b), $($(a)_DIR) $($(a)_INCDIR) $(GLOBAL_INCDIR) ),\
129 $($(a)_DIR) $($(a)_INCDIR) $(GLOBAL_INCDIR), \
135 $(foreach a, $(ALGORITHMS), \
136 $(foreach b, $($(a)_TESTBIN), \
137 $(eval $(call TargetSource_Template, \
138 $(BIN_DIR)$(call lc, $(a))/$(TEST_DIR)$(b), \
139 $(call find_source_file, $(b), $($(a)_DIR) $($(a)_INCDIR) $(GLOBAL_INCDIR) ),\
140 $($(a)_DIR) $($(a)_INCDIR) $(GLOBAL_INCDIR), \
146 $(foreach a, $(LIB_OBJECTS), \
147 $(eval $(call TargetSource_Template, \
149 $(call find_source_file, $(notdir $(a)), $(LIB_SRCDIRS) ),\
150 $(LIB_SRCDIRS) $(GLOBAL_INCDIR), \
156 #-------------------------------------------------------------------------------
158 define MainTestElf_Template
161 @mkdir -p $(dir $(1))
162 @$(CC) $(CFLAGS_A) $(LDFLAGS)$(patsubst %.elf,%.map,$(1)) -o \
165 $(addprefix -l, $(LIBS))
168 $(foreach a, $(ALGORITHMS), \
169 $(eval $(call MainTestElf_Template, \
170 $(BIN_DIR)$(call lc, $(a))/$(TEST_DIR)main-$(call lc, $(a))-test.elf, \
176 #-------------------------------------------------------------------------------
178 all: $(foreach algo, $(ALGORITHMS), $($(algo)_BINOBJ))
180 #-------------------------------------------------------------------------------
182 define TestBin_TEMPLATE
186 $(foreach algo, $(ALGORITHMS), $(eval $(call TestBin_TEMPLATE, \
188 $(BIN_DIR)$(call lc, $(algo))/$(TEST_DIR)main-$(call lc, $(algo))-test.elf \
191 #-------------------------------------------------------------------------------
194 @echo "[objcopy]: $@"
195 @$(OBJCOPY) -O binary $< $@
198 @echo "[objcopy]: $@"
199 @$(OBJCOPY) -j .text -j .data -O ihex $< $@
201 #-------------------------------------------------------------------------------
203 define Flash_Template
205 @echo "[flash]: $(2)"
206 @$(call FLASHCMD, $(call first,$(2)))
209 $(foreach algo, $(ALGORITHMS), $(eval $(call Flash_Template, \
211 $(BIN_DIR)$(call lc, $(algo))/$(TEST_DIR)main-$(call lc, $(algo))-test.bin \
214 #-------------------------------------------------------------------------------
216 define Speed_Template
217 $(1)_SPEED: $(1)_FLASH
218 @$(RUBY) $(SPEEDTOOL) -c $(SPEEDCMD) -t $(SPEEDLOG_DIR) -a $(call lc, $(1))
221 $(foreach algo, $(ALGORITHMS), $(eval $(call Speed_Template, \
226 hash_speed: $(foreach algo, $(HASHES), $(algo)_SPEED)
228 .PHONY: blockcipher_speed
229 blockcipher_speed: $(foreach algo, $(BLOCK_CIPHERS), $(algo)_SPEED)
230 #-------------------------------------------------------------------------------
236 $(SIZE) $(2) > $(strip $(SIZE_DIR))$(strip $(call lc, $(1))).size
239 $(foreach algo, $(ALGORITHMS), $(eval $(call Size_Template, \
240 $(strip $(algo)), $($(algo)_BINOBJ) \
244 hash_size: $(foreach algo, $(HASHES), $(algo)_SIZE)
246 .PHONY: blockcipher_size
247 blockcipher_size: $(foreach algo, $(BLOCK_CIPHERS), $(algo)_SIZE)
249 #-------------------------------------------------------------------------------
252 tests: $(foreach a, $(ALGORITHMS), $(a)_TESTBIN)
254 #-------------------------------------------------------------------------------
256 define TestRun_Template
257 $(1)_TESTRUN: $(1)_FLASH
259 $(RUBY) $(GET_TEST) $(TESTPORT) $(TESTPORTBAUDR) 8 1 nessie $(TESTLOG_DIR)$(TESTPREFIX) $(2)
262 $(foreach algo, $(ALGORITHMS),$(eval $(call TestRun_Template, $(algo), $(call lc,$(algo)) )))
264 all_testrun: $(foreach algo, $(ALGORITHMS), $(algo)_TESTRUN)
266 #-------------------------------------------------------------------------------
272 $(foreach algo, $(ALGORITHMS), \
273 $(eval $(call Obj_Template, \
280 cores: $(foreach algo, $(ALGORITHMS), $(algo)_OBJ)
282 .PHONY: blockchiphers
283 blockciphers: $(foreach algo, $(BLOCK_CIPHERS), $(algo)_OBJ)
285 .PHONY: streamchiphers
286 streamciphers: $(foreach algo, $(STREAM_CIPHERS), $(algo)_OBJ)
289 hashes: $(foreach algo, $(HASHES), $(algo)_OBJ)
292 macs: $(foreach algo, $(MACS), $(algo)_OBJ)
295 prngs: $(foreach algo, $(PRNGS), $(algo)_OBJ)
298 encodings: $(foreach algo, $(ENCODINGS), $(algo)_OBJ)
301 aux: $(foreach algo, $(AUX), $(algo)_OBJ)
309 @echo $(foreach a, $(LIB_ALGOS), '\t$(a)\n')
310 @echo "LIB_OBJECTS ="
311 @echo $(foreach a, $(LIB_OBJECTS), '\t$(a)\n')
312 @echo "LIB_SRCDIRS ="
313 @echo $(foreach a, $(LIB_SRCDIRS), '\t$(a)\n')
315 $(BIN_DIR)$(LIB_DIR)$(LIB_NAME): $(LIB_OBJECTS)
318 @echo "[chmod]: <objects>"
322 @echo "[ar]: $@ <-- <objects>"
326 lib: $(BIN_DIR)$(LIB_DIR)$(LIB_NAME)
329 #-------------------------------------------------------------------------------
336 @echo "infos on ARM-Crypto-lib:"
337 @echo " block ciphers:"
338 @echo " $(BLOCK_CIPHERS)"
339 @echo " stream ciphers:"
340 @echo " $(STREAM_CIPHERS)"
341 @echo " hash functions:"
343 @echo " MAC functions:"
345 @echo " PRNG functions:"
347 @echo " signature functions:"
348 @echo " $(SIGNATURE)"
349 @echo " public key ciphers:"
350 @echo " $(PK_CIPHERS)"
352 @echo " $(ENCODINGS)"
353 @echo " auxiliary functions:"
356 @echo " all - all algorithm cores"
357 @echo " cores - all algorithm cores"
358 @echo " lib - make library archive"
359 @echo " listings - all algorithm core listings"
360 @echo " tests - all algorithm test programs"
361 @echo " stats - all algorithm size statistics"
362 @echo " blockciphers - all blockcipher cores"
363 @echo " streamciphers - all streamcipher cores"
364 @echo " hashes - all hash cores"
365 @echo " macs - all MAC cores"
366 @echo " prngs - all PRNG cores"
367 @echo " all_testrun - testrun all algorithms"
368 @echo " hash_size - measure size of all hash functions"
369 @echo " hash_speed - measure performance of all hash functions"
370 @echo " blockcipher_size - measure size of all blockciphers"
371 @echo " blockcipher_speed - measure performance of all blockciphers"
372 @echo " docu - build doxygen documentation"
373 @echo " clean - remove a lot of builded files"
374 @echo " depclean - also remove dependency files"
375 @echo " *_TESTBIN - build test program"
376 @echo " *_TESTRUN - run nessie test"
377 @echo " *_OBJ - build algorithm core"
378 @echo " *_FLASH - flash test program"
379 @echo " *_LIST - build assembler listing"
382 #-------------------------------------------------------------------------------
386 @echo "[rm]: $(BIN_DIR)*"
387 @$(RM) -rf $(BIN_DIR)*
391 @echo "[rm]: $(DEP_DIR)*.d"
392 @$(RM) -f $(DEP_DIR)*.d
394 #-------------------------------------------------------------------------------
395 # dependency inclusion
398 DEPS := $(wildcard $(DEP_DIR)*.d)