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