]> git.cryptolib.org Git - arm-crypto-lib.git/blob - Makefile
fixing sha256
[arm-crypto-lib.git] / Makefile
1 # Makefile for the ARM-Crypto-Lib project
2 #
3 #    This file is part of the ARM-Crypto-Lib.
4 #    Copyright (C) 2010 Daniel Otte (daniel.otte@rub.de)
5 #
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.
10 #
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.
15 #
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/>.
18
19 SHELL = sh
20
21 BLOCK_CIPHERS  :=
22 STREAM_CIPHERS :=
23 HASHES         :=
24 MACS           :=
25 PRNGS          :=
26 ENCODINGS      :=
27 SIGNATURE      :=
28 PK_CIPHERS     :=
29 AUX            :=
30 LIB_ALGOS      :=
31
32 # we use the gnu make standard library
33 include gmsl
34 include arm-makefile.inc
35
36
37 GLOBAL_INCDIR := ./ $(TESTSRC_DIR)
38
39 #-------------------------------------------------------------------------------
40 # inclusion of make stubs
41 include mkfiles/*.mk
42
43 define Assert_Template
44 $(1) = $(2)
45 endef
46
47 define Add_Template
48 $(1) += $(2)
49 endef
50
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))
56
57 LIB_OBJECTS := 
58 LIB_SRCDIRS := 
59 LIB_DEFINES :=
60
61 $(foreach a, $(LIB_ALGOS), $(eval $(call Add_Template, \
62   LIB_OBJECTS, \
63   $($(a)_OBJ)  \
64 )))
65 LIB_OBJECTS := $(addprefix $(BIN_DIR)$(LIB_DIR), $(sort $(LIB_OBJECTS)))
66
67 $(foreach a, $(LIB_ALGOS), $(eval $(call Add_Template, \
68   LIB_SRCDIRS, \
69   $($(a)_DIR)  \
70 )))
71
72 $(foreach a, $(LIB_ALGOS), $(eval $(call Add_Template, \
73   LIB_SRCDIRS, \
74   $($(a)_INCDIR)  \
75 )))
76 LIB_SRCDIRS := $(sort $(LIB_SRCDIRS)) 
77
78 $(foreach a, $(LIB_ALGOS), $(eval $(call Add_Template, \
79   LIB_DEFINES, \
80   $($(a)_DEF)  \
81 )))
82 LIB_DEFINES := $(sort $(LIB_DEFINES)) 
83
84
85 #-------------------------------------------------------------------------------
86 # define binary object in $(BIN_DIR)$(ALGO)/<obj>
87 $(foreach a, $(ALGORITHMS), $(eval $(call Assert_Template, \
88     $(a)_BINOBJ, \
89     $(addprefix $(BIN_DIR)$(call lc,$(a))/,$($(a)_OBJ)) \
90 )))
91
92 $(foreach a, $(ALGORITHMS), $(eval $(call Assert_Template, \
93     $(a)_TESTBINOBJ, \
94     $(addprefix $(BIN_DIR)$(call lc,$(a))/$(TEST_DIR),$($(a)_TESTBIN)) \
95 )))
96
97
98
99 #-------------------------------------------------------------------------------
100
101 define TargetSource_Template
102 $(1): $(2)
103         @echo "[cc]: $(1) <-- $(2)"
104         @mkdir -p $(dir $(1))
105         @$(CC) $(CFLAGS_A) $(addprefix -I./,$(3)) $(addprefix -D, $(4)) -c -o $(1) $(2)
106 endef
107
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 
113 #            $(SOURCE_PATTERN)
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)).*) \
119                      ) \
120                    ) )
121               
122               
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), \
129       $($(a)_DEF) \
130     )) \
131   ) \
132 )
133
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), \
140       $($(a)_DEF) \
141     )) \
142   ) \
143 )
144
145 $(foreach a, $(LIB_OBJECTS), \
146   $(eval $(call TargetSource_Template, \
147     $(a), \
148     $(call find_source_file, $(notdir $(a)), $(LIB_SRCDIRS) ),\
149     $(LIB_SRCDIRS) $(GLOBAL_INCDIR), \
150     $(LIB_DEFINES) \
151     ) \
152   ) \
153 )
154
155 #-------------------------------------------------------------------------------
156
157 define MainTestElf_Template
158 $(1): $(2) $(3)
159         @echo "[ld]: $(1)"
160         @mkdir -p $(dir $(1))
161         $(CC) $(CFLAGS_A) $(LDFLAGS)$(patsubst %.elf,%.map,$(1)) -o \
162         $(1) \
163         $(2) $(3) \
164         $(addprefix -l, $(LIBS))
165 endef
166
167 $(foreach a, $(ALGORITHMS), \
168     $(eval $(call MainTestElf_Template,  \
169         $(BIN_DIR)$(call lc, $(a))/$(TEST_DIR)main-$(call lc, $(a))-test.elf, \
170         $($(a)_BINOBJ), \
171         $($(a)_TESTBINOBJ) \
172         )) \
173 )
174
175 #-------------------------------------------------------------------------------
176
177 all: $(foreach algo, $(ALGORITHMS), $($(algo)_BINOBJ))
178
179 #-------------------------------------------------------------------------------
180
181 define TestBin_TEMPLATE
182 $(1)_TESTBIN: $(2)
183 endef
184
185 $(foreach algo, $(ALGORITHMS), $(eval $(call TestBin_TEMPLATE, \
186     $(algo), \
187     $(BIN_DIR)$(call lc, $(algo))/$(TEST_DIR)main-$(call lc, $(algo))-test.elf \
188 )))
189
190 #-------------------------------------------------------------------------------
191
192 %.bin: %.elf
193         @echo "[objcopy]: $@"
194         @$(OBJCOPY) -O binary $< $@
195         
196 %.hex: %.elf
197         @echo "[objcopy]: $@"
198         @$(OBJCOPY) -j .text -j .data -O ihex $< $@
199
200 #-------------------------------------------------------------------------------
201
202 define Flash_Template
203 $(1)_FLASH: $(2)
204         @echo "[flash]: $(2)"
205         @$(call FLASHCMD, $(call first,$(2)))
206 endef
207
208 $(foreach algo, $(ALGORITHMS), $(eval $(call Flash_Template, \
209     $(algo), \
210     $(BIN_DIR)$(call lc, $(algo))/$(TEST_DIR)main-$(call lc, $(algo))-test.bin \
211 )))
212
213 #-------------------------------------------------------------------------------
214
215 define Speed_Template
216 $(1)_SPEED:  $(1)_FLASH
217         @$(RUBY) $(SPEEDTOOL) -c $(SPEEDCMD) -t $(SPEEDLOG_DIR) -a $(call lc, $(1))
218 endef
219
220 $(foreach algo, $(ALGORITHMS), $(eval $(call Speed_Template, \
221     $(algo), $(algo) \
222 )))
223
224 .PHONY: hash_speed
225 hash_speed: $(foreach algo, $(HASHES), $(algo)_SPEED)
226
227 .PHONY: blockcipher_speed
228 blockcipher_speed: $(foreach algo, $(BLOCK_CIPHERS), $(algo)_SPEED)
229 #-------------------------------------------------------------------------------
230
231
232 define Size_Template
233 $(1)_SIZE:  $(2)
234         @echo "[size] $(1)"
235         $(SIZE) $(2) > $(strip $(SIZE_DIR))$(strip $(call lc, $(1))).size
236 endef
237
238 $(foreach algo, $(ALGORITHMS), $(eval $(call Size_Template, \
239     $(strip $(algo)), $($(algo)_BINOBJ) \
240 )))
241
242 .PHONY: hash_size
243 hash_size: $(foreach algo, $(HASHES), $(algo)_SIZE)
244
245 .PHONY: blockcipher_size
246 blockcipher_size: $(foreach algo, $(BLOCK_CIPHERS), $(algo)_SIZE)
247
248 #-------------------------------------------------------------------------------
249
250 .PHONY: tests
251 tests: $(foreach a, $(ALGORITHMS), $(a)_TESTBIN)
252
253 #-------------------------------------------------------------------------------
254
255 define TestRun_Template
256 $(1)_TESTRUN: $(1)_FLASH
257         @echo "[test]: $(1)"
258         $(RUBY) $(GET_TEST) $(TESTPORT) $(TESTPORTBAUDR) 8 1 nessie $(TESTLOG_DIR)$(TESTPREFIX) $(2)
259 endef
260
261 $(foreach algo, $(ALGORITHMS),$(eval $(call TestRun_Template, $(algo), $(call lc,$(algo)) )))
262
263 all_testrun: $(foreach algo, $(ALGORITHMS), $(algo)_TESTRUN)
264
265 #-------------------------------------------------------------------------------
266
267 define Obj_Template
268 $(1)_OBJ: $(2)
269 endef
270
271 $(foreach algo, $(ALGORITHMS), \
272     $(eval $(call Obj_Template, \
273         $(algo), \
274         $($(algo)_BINOBJ)\
275         ))\
276 )
277
278 .PHONY: cores
279 cores: $(foreach algo, $(ALGORITHMS), $(algo)_OBJ)
280
281 .PHONY: blockchiphers
282 blockciphers: $(foreach algo, $(BLOCK_CIPHERS), $(algo)_OBJ)
283
284 .PHONY: streamchiphers
285 streamciphers: $(foreach algo, $(STREAM_CIPHERS), $(algo)_OBJ)
286
287 .PHONY: hashes
288 hashes: $(foreach algo, $(HASHES), $(algo)_OBJ)
289
290 .PHONY: macs
291 macs: $(foreach algo, $(MACS), $(algo)_OBJ)
292
293 .PHONY: prngs
294 prngs: $(foreach algo, $(PRNGS), $(algo)_OBJ)
295
296 .PHONY: encodings
297 encodings: $(foreach algo, $(ENCODINGS), $(algo)_OBJ)
298
299 .PHONY: aux
300 aux: $(foreach algo, $(AUX), $(algo)_OBJ)
301
302
303
304
305 .PHONY: lib_info
306 lib_info:
307         @echo "LIB_ALGOS ="
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')
313
314 $(BIN_DIR)$(LIB_DIR)$(LIB_NAME): $(LIB_OBJECTS)
315         @echo "[rm]:  old $@"
316         @$(RM) -f $@
317         @echo "[chmod]: <objects>"
318         @$(CHMOD) 644 $^
319 #       $(CHGRP) root $^
320 #       $(CHOWN) root $^
321         @echo "[ar]:  $@ <-- <objects>"
322         @$(AR) qc $@ $^
323
324 .PHONY: lib
325 lib: $(BIN_DIR)$(LIB_DIR)$(LIB_NAME)
326
327
328 #-------------------------------------------------------------------------------
329
330
331 .PHONY: help
332 help: info
333 .PHONY: info
334 info:
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:"
341         @echo "    $(HASHES)"
342         @echo "  MAC functions:"
343         @echo "    $(MACS)"
344         @echo "  PRNG functions:"
345         @echo "    $(PRNGS)"
346         @echo "  signature functions:"
347         @echo "    $(SIGNATURE)"
348         @echo "  public key ciphers:"
349         @echo "    $(PK_CIPHERS)"
350         @echo "  encodings:"
351         @echo "    $(ENCODINGS)"
352         @echo "  auxiliary functions:"
353         @echo "    $(AUX)"
354         @echo " targets:"
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"
379
380
381 #-------------------------------------------------------------------------------
382
383 .PHONY: clean
384 clean:
385         @echo "[rm]:  $(BIN_DIR)*"
386         @$(RM) -rf $(BIN_DIR)*
387
388 .PHONY: depclean
389 depclean: clean
390         @echo "[rm]:  $(DEP_DIR)*.d"
391         @$(RM) -f $(DEP_DIR)*.d
392
393 #-------------------------------------------------------------------------------
394 # dependency inclusion
395 #
396
397 DEPS := $(wildcard $(DEP_DIR)*.d)
398
399 ifneq ($(DEPS),)
400 include $(DEPS)
401 endif
402