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
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 @echo "[cc]: $(1) <-- $(2)"
104 @mkdir -p $(dir $(1))
105 @$(CC) $(CFLAGS_A) $(addprefix -I./,$(3)) $(addprefix -D, $(4)) -c -o $(1) $(2)
108 # ----------------------------------------------------------------------------
109 # Function: find_source_file
110 # Arguments: 1: name of the binary file (.o extension) to search
111 # 2: list of directorys to search for file
112 # Returns: Returns paths to source file (mathing the pattern in
114 # ----------------------------------------------------------------------------
115 SOURCE_PATTERN := %.S %.c
116 find_source_file = $(firstword $(foreach d, $(2), \
117 $(filter $(SOURCE_PATTERN), \
118 $(wildcard $(d)$(notdir $(patsubst %.o,%,$1)).*) \
123 $(foreach a, $(ALGORITHMS), \
124 $(foreach b, $($(a)_OBJ), \
125 $(eval $(call TargetSource_Template, \
126 $(BIN_DIR)$(call lc, $(a))/$(b), \
127 $(call find_source_file, $(b), $($(a)_DIR) $($(a)_INCDIR) $(GLOBAL_INCDIR) ),\
128 $($(a)_DIR) $($(a)_INCDIR) $(GLOBAL_INCDIR), \
134 $(foreach a, $(ALGORITHMS), \
135 $(foreach b, $($(a)_TESTBIN), \
136 $(eval $(call TargetSource_Template, \
137 $(BIN_DIR)$(call lc, $(a))/$(TEST_DIR)$(b), \
138 $(call find_source_file, $(b), $($(a)_DIR) $($(a)_INCDIR) $(GLOBAL_INCDIR) ),\
139 $($(a)_DIR) $($(a)_INCDIR) $(GLOBAL_INCDIR), \
145 $(foreach a, $(LIB_OBJECTS), \
146 $(eval $(call TargetSource_Template, \
148 $(call find_source_file, $(notdir $(a)), $(LIB_SRCDIRS) ),\
149 $(LIB_SRCDIRS) $(GLOBAL_INCDIR), \
155 #-------------------------------------------------------------------------------
157 define MainTestElf_Template
160 @mkdir -p $(dir $(1))
161 $(CC) $(CFLAGS_A) $(LDFLAGS)$(patsubst %.elf,%.map,$(1)) -o \
164 $(addprefix -l, $(LIBS))
167 $(foreach a, $(ALGORITHMS), \
168 $(eval $(call MainTestElf_Template, \
169 $(BIN_DIR)$(call lc, $(a))/$(TEST_DIR)main-$(call lc, $(a))-test.elf, \
175 #-------------------------------------------------------------------------------
177 all: $(foreach algo, $(ALGORITHMS), $($(algo)_BINOBJ))
179 #-------------------------------------------------------------------------------
181 define TestBin_TEMPLATE
185 $(foreach algo, $(ALGORITHMS), $(eval $(call TestBin_TEMPLATE, \
187 $(BIN_DIR)$(call lc, $(algo))/$(TEST_DIR)main-$(call lc, $(algo))-test.elf \
190 #-------------------------------------------------------------------------------
193 @echo "[objcopy]: $@"
194 @$(OBJCOPY) -O binary $< $@
197 @echo "[objcopy]: $@"
198 @$(OBJCOPY) -j .text -j .data -O ihex $< $@
200 #-------------------------------------------------------------------------------
202 define Flash_Template
204 @echo "[flash]: $(2)"
205 @$(call FLASHCMD, $(call first,$(2)))
208 $(foreach algo, $(ALGORITHMS), $(eval $(call Flash_Template, \
210 $(BIN_DIR)$(call lc, $(algo))/$(TEST_DIR)main-$(call lc, $(algo))-test.bin \
213 #-------------------------------------------------------------------------------
215 define Speed_Template
216 $(1)_SPEED: $(1)_FLASH
217 @$(RUBY) $(SPEEDTOOL) -c $(SPEEDCMD) -t $(SPEEDLOG_DIR) -a $(call lc, $(1))
220 $(foreach algo, $(ALGORITHMS), $(eval $(call Speed_Template, \
225 hash_speed: $(foreach algo, $(HASHES), $(algo)_SPEED)
227 .PHONY: blockcipher_speed
228 blockcipher_speed: $(foreach algo, $(BLOCK_CIPHERS), $(algo)_SPEED)
229 #-------------------------------------------------------------------------------
235 $(SIZE) $(2) > $(strip $(SIZE_DIR))$(strip $(call lc, $(1))).size
238 $(foreach algo, $(ALGORITHMS), $(eval $(call Size_Template, \
239 $(strip $(algo)), $($(algo)_BINOBJ) \
243 hash_size: $(foreach algo, $(HASHES), $(algo)_SIZE)
245 .PHONY: blockcipher_size
246 blockcipher_size: $(foreach algo, $(BLOCK_CIPHERS), $(algo)_SIZE)
248 #-------------------------------------------------------------------------------
251 tests: $(foreach a, $(ALGORITHMS), $(a)_TESTBIN)
253 #-------------------------------------------------------------------------------
255 define TestRun_Template
256 $(1)_TESTRUN: $(1)_FLASH
258 $(RUBY) $(GET_TEST) $(TESTPORT) $(TESTPORTBAUDR) 8 1 nessie $(TESTLOG_DIR)$(TESTPREFIX) $(2)
261 $(foreach algo, $(ALGORITHMS),$(eval $(call TestRun_Template, $(algo), $(call lc,$(algo)) )))
263 all_testrun: $(foreach algo, $(ALGORITHMS), $(algo)_TESTRUN)
265 #-------------------------------------------------------------------------------
271 $(foreach algo, $(ALGORITHMS), \
272 $(eval $(call Obj_Template, \
279 cores: $(foreach algo, $(ALGORITHMS), $(algo)_OBJ)
281 .PHONY: blockchiphers
282 blockciphers: $(foreach algo, $(BLOCK_CIPHERS), $(algo)_OBJ)
284 .PHONY: streamchiphers
285 streamciphers: $(foreach algo, $(STREAM_CIPHERS), $(algo)_OBJ)
288 hashes: $(foreach algo, $(HASHES), $(algo)_OBJ)
291 macs: $(foreach algo, $(MACS), $(algo)_OBJ)
294 prngs: $(foreach algo, $(PRNGS), $(algo)_OBJ)
297 encodings: $(foreach algo, $(ENCODINGS), $(algo)_OBJ)
300 aux: $(foreach algo, $(AUX), $(algo)_OBJ)
308 @echo $(foreach a, $(LIB_ALGOS), '\t$(a)\n')
309 @echo "LIB_OBJECTS ="
310 @echo $(foreach a, $(LIB_OBJECTS), '\t$(a)\n')
311 @echo "LIB_SRCDIRS ="
312 @echo $(foreach a, $(LIB_SRCDIRS), '\t$(a)\n')
314 $(BIN_DIR)$(LIB_DIR)$(LIB_NAME): $(LIB_OBJECTS)
317 @echo "[chmod]: <objects>"
321 @echo "[ar]: $@ <-- <objects>"
325 lib: $(BIN_DIR)$(LIB_DIR)$(LIB_NAME)
328 #-------------------------------------------------------------------------------
335 @echo "infos on ARM-Crypto-lib:"
336 @echo " block ciphers:"
337 @echo " $(BLOCK_CIPHERS)"
338 @echo " stream ciphers:"
339 @echo " $(STREAM_CIPHERS)"
340 @echo " hash functions:"
342 @echo " MAC functions:"
344 @echo " PRNG functions:"
346 @echo " signature functions:"
347 @echo " $(SIGNATURE)"
348 @echo " public key ciphers:"
349 @echo " $(PK_CIPHERS)"
351 @echo " $(ENCODINGS)"
352 @echo " auxiliary functions:"
355 @echo " all - all algorithm cores"
356 @echo " cores - all algorithm cores"
357 @echo " lib - make library archive"
358 @echo " listings - all algorithm core listings"
359 @echo " tests - all algorithm test programs"
360 @echo " stats - all algorithm size statistics"
361 @echo " blockciphers - all blockcipher cores"
362 @echo " streamciphers - all streamcipher cores"
363 @echo " hashes - all hash cores"
364 @echo " macs - all MAC cores"
365 @echo " prngs - all PRNG cores"
366 @echo " all_testrun - testrun all algorithms"
367 @echo " hash_size - measure size of all hash functions"
368 @echo " hash_speed - measure performance of all hash functions"
369 @echo " blockcipher_size - measure size of all blockciphers"
370 @echo " blockcipher_speed - measure performance of all blockciphers"
371 @echo " docu - build doxygen documentation"
372 @echo " clean - remove a lot of builded files"
373 @echo " depclean - also remove dependency files"
374 @echo " *_TESTBIN - build test program"
375 @echo " *_TESTRUN - run nessie test"
376 @echo " *_OBJ - build algorithm core"
377 @echo " *_FLASH - flash test program"
378 @echo " *_LIST - build assembler listing"
381 #-------------------------------------------------------------------------------
385 @echo "[rm]: $(BIN_DIR)*"
386 @$(RM) -rf $(BIN_DIR)*
390 @echo "[rm]: $(DEP_DIR)*.d"
391 @$(RM) -f $(DEP_DIR)*.d
393 #-------------------------------------------------------------------------------
394 # dependency inclusion
397 DEPS := $(wildcard $(DEP_DIR)*.d)