]> git.cryptolib.org Git - arm-crypto-lib.git/blob - Makefile
adding trivium
[arm-crypto-lib.git] / Makefile
1 # Makefile for the ARM-Crypto-Lib project
2 #
3 #    This file is part of the AVR-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
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 #-------------------------------------------------------------------------------
44 ALGORITHMS = $(BLOCK_CIPHERS) $(STREAM_CIPHERS) $(HASHES) $(PRNGS) $(MACS) \
45                          $(ENCODINGS) $(SIGNATURE) $(PK_CIPHERS) $(AUX)
46 ALGORITHMS_OBJ = $(patsubst %,%_OBJ, $(ALGORITHMS))
47 ALGORITHMS_TEST_BIN = $(patsubst %,%_TEST_BIN, $(ALGORITHMS))
48
49 #-------------------------------------------------------------------------------
50 # define binary object in $(BIN_DIR)$(ALGO)/<obj>
51 define Assert_Template
52 $(1) = $(2)
53 endef
54
55 $(foreach a, $(ALGORITHMS), $(eval $(call Assert_Template, \
56     $(a)_BINOBJ, \
57     $(addprefix $(BIN_DIR)$(call lc,$(a))/,$($(a)_OBJ)) \
58 )))
59
60 $(foreach a, $(ALGORITHMS), $(eval $(call Assert_Template, \
61     $(a)_TESTBINOBJ, \
62     $(addprefix $(BIN_DIR)$(call lc,$(a))/$(TEST_DIR),$($(a)_TEST_BIN)) \
63 )))
64
65
66
67 #-------------------------------------------------------------------------------
68
69 define TargetSource_Template
70 $(1): $(2)
71         @echo "[cc]: $(1) <-- $(2)"
72         @mkdir -p $(dir $(1))
73         @$(CC) $(CFLAGS_A) $(addprefix -I./,$(3)) $(addprefix -D, $(4)) -c -o $(1) $(2)
74 endef
75
76 # ----------------------------------------------------------------------------
77 # Function:  find_source_file
78 # Arguments: 1: name of the binary file (.o extension) to search
79 #            2: list of directorys to search for file
80 # Returns:   Returns paths to source file (mathing the pattern in 
81 #            $(SOURCE_PATTERN)
82 # ----------------------------------------------------------------------------
83 SOURCE_PATTERN := %.S %.c 
84 find_source_file = $(firstword $(foreach d, $(2), \
85                      $(filter $(SOURCE_PATTERN),  \
86                        $(wildcard $(d)$(notdir $(patsubst %.o,%,$1)).*) \
87                      ) \
88                    ) )
89               
90               
91 $(foreach a, $(ALGORITHMS), \
92   $(foreach b, $($(a)_OBJ), \
93     $(eval $(call TargetSource_Template, \
94       $(BIN_DIR)$(call lc, $(a))/$(b), \
95       $(call find_source_file, $(b), $($(a)_DIR) $($(a)_INCDIR) $(GLOBAL_INCDIR) ),\
96       $($(a)_DIR) $($(a)_INCDIR) $(GLOBAL_INCDIR), \
97       $($(a)_DEF) \
98     )) \
99   ) \
100 )
101
102 $(foreach a, $(ALGORITHMS), \
103   $(foreach b, $($(a)_TEST_BIN), \
104     $(eval $(call TargetSource_Template, \
105       $(BIN_DIR)$(call lc, $(a))/$(TEST_DIR)$(b), \
106       $(call find_source_file, $(b), $($(a)_DIR) $($(a)_INCDIR) $(GLOBAL_INCDIR) ),\
107       $($(a)_DIR) $($(a)_INCDIR) $(GLOBAL_INCDIR), \
108       $($(a)_DEF) \
109     )) \
110   ) \
111 )
112
113 #-------------------------------------------------------------------------------
114
115 define MainTestElf_Template
116 $(1): $(2) $(3)
117         @echo "[ld]: $(1)"
118         @$(CC) $(CFLAGS_A) $(LDFLAGS)$(patsubst %.elf,%.map,$(1)) -o \
119         $(1) \
120         $(2) $(3) \
121         $(LIBS)
122 endef
123
124 $(foreach a, $(ALGORITHMS), \
125     $(eval $(call MainTestElf_Template,  \
126         $(BIN_DIR)$(call lc, $(a))/$(TEST_DIR)main-$(call lc, $(a))-test.elf, \
127         $($(a)_BINOBJ), \
128         $($(a)_TESTBINOBJ) \
129         )) \
130 )
131
132 #-------------------------------------------------------------------------------
133
134 all: $(foreach algo, $(ALGORITHMS), $($(algo)_BINOBJ))
135
136 #-------------------------------------------------------------------------------
137
138 define TestBin_TEMPLATE
139 $(1)_TESTBIN: $(2)
140 endef
141
142 $(foreach algo, $(ALGORITHMS), $(eval $(call TestBin_TEMPLATE, \
143     $(algo), \
144     $(BIN_DIR)$(call lc, $(algo))/$(TEST_DIR)main-$(call lc, $(algo))-test.elf \
145 )))
146
147 #-------------------------------------------------------------------------------
148
149 %.bin: %.elf
150         @echo "[objcopy]: $@"
151         @$(OBJCOPY) -O binary $< $@
152         
153 %.hex: %.elf
154         @echo "[objcopy]: $@"
155         @$(OBJCOPY) -j .text -j .data -O ihex $< $@
156
157 #-------------------------------------------------------------------------------
158
159 define Flash_Template
160 $(1)_FLASH: $(2)
161         @echo "[flash]: $(2)"
162         @$(call FLASHCMD, $(call first,$(2)))
163 endef
164
165 $(foreach algo, $(ALGORITHMS), $(eval $(call Flash_Template, \
166     $(algo), \
167     $(BIN_DIR)$(call lc, $(algo))/$(TEST_DIR)main-$(call lc, $(algo))-test.bin \
168 )))
169
170 #-------------------------------------------------------------------------------
171
172 define Speed_Template
173 $(1)_SPEED:  $(1)_FLASH
174         @$(RUBY) $(SPEEDTOOL) -c $(SPEEDCMD) -t $(SPEEDLOG_DIR) -a $(call lc, $(1))
175 endef
176
177 $(foreach algo, $(ALGORITHMS), $(eval $(call Speed_Template, \
178     $(algo), $(algo) \
179 )))
180
181 .PHONY: hash_speed
182 hash_speed: $(foreach algo, $(HASHES), $(algo)_SPEED)
183
184 .PHONY: blockcipher_speed
185 blockcipher_speed: $(foreach algo, $(BLOCK_CIPHERS), $(algo)_SPEED)
186 #-------------------------------------------------------------------------------
187
188
189 define Size_Template
190 $(1)_SIZE:  $(2)
191         @echo "[size] $(1)"
192         $(SIZE) $(2) > $(strip $(SIZE_DIR))$(strip $(call lc, $(1))).size
193 endef
194
195 $(foreach algo, $(ALGORITHMS), $(eval $(call Size_Template, \
196     $(strip $(algo)), $($(algo)_BINOBJ) \
197 )))
198
199 .PHONY: hash_size
200 hash_size: $(foreach algo, $(HASHES), $(algo)_SIZE)
201
202 .PHONY: blockcipher_size
203 blockcipher_size: $(foreach algo, $(BLOCK_CIPHERS), $(algo)_SIZE)
204
205 #-------------------------------------------------------------------------------
206
207 .PHONY: tests
208 tests: $(foreach a, $(ALGORITHMS), $(a)_TEST_BIN)
209
210 #-------------------------------------------------------------------------------
211
212 define TestRun_Template
213 $(1)_TESTRUN: $(1)_FLASH
214         @echo "[test]: $(1)"
215         $(RUBY) $(GET_TEST) $(TESTPORT) $(TESTPORTBAUDR) 8 1 nessie $(TESTLOG_DIR)$(TESTPREFIX) $(2)
216 endef
217
218 $(foreach algo, $(ALGORITHMS),$(eval $(call TestRun_Template, $(algo), $(call lc,$(algo)) )))
219
220 all_testrun: $(foreach algo, $(ALGORITHMS), $(algo)_TESTRUN)
221
222 #-------------------------------------------------------------------------------
223
224 define Obj_Template
225 $(1)_OBJ: $(2)
226 endef
227
228 $(foreach algo, $(ALGORITHMS), \
229     $(eval $(call Obj_Template, \
230         $(algo), \
231         $($(algo)_BINOBJ)\
232         ))\
233 )
234
235 .PHONY: cores
236 cores: $(foreach algo, $(ALGORITHMS), $(algo)_OBJ)
237
238 .PHONY: blockchiphers
239 blockciphers: $(foreach algo, $(BLOCK_CIPHERS), $(algo)_OBJ)
240
241 .PHONY: streamchiphers
242 streamciphers: $(foreach algo, $(STREAM_CIPHERS), $(algo)_OBJ)
243
244 .PHONY: hashes
245 hashes: $(foreach algo, $(HASHES), $(algo)_OBJ)
246
247 .PHONY: macs
248 macs: $(foreach algo, $(MACS), $(algo)_OBJ)
249
250 .PHONY: prngs
251 prngs: $(foreach algo, $(PRNGS), $(algo)_OBJ)
252
253 .PHONY: encodings
254 encodings: $(foreach algo, $(ENCODINGS), $(algo)_OBJ)
255
256 .PHONY: aux
257 aux: $(foreach algo, $(AUX), $(algo)_OBJ)
258
259
260 #-------------------------------------------------------------------------------
261
262
263 .PHONY: help
264 help: info
265 .PHONY: info
266 info:
267         @echo "infos on ARM-Crypto-lib:"
268         @echo "  block ciphers:"
269         @echo "    $(BLOCK_CIPHERS)"
270         @echo "  stream ciphers:"
271         @echo "    $(STREAM_CIPHERS)"
272         @echo "  hash functions:"
273         @echo "    $(HASHES)"
274         @echo "  MAC functions:"
275         @echo "    $(MACS)"
276         @echo "  PRNG functions:"
277         @echo "    $(PRNGS)"
278         @echo "  signature functions:"
279         @echo "    $(SIGNATURE)"
280         @echo "  public key ciphers:"
281         @echo "    $(PK_CIPHERS)"
282         @echo "  encodings:"
283         @echo "    $(ENCODINGS)"
284         @echo "  auxiliary functions:"
285         @echo "    $(AUX)"
286         @echo " targets:"
287         @echo "  all                - all algorithm cores"
288         @echo "  cores              - all algorithm cores"
289         @echo "  listings           - all algorithm core listings"
290         @echo "  tests              - all algorithm test programs"
291         @echo "  stats              - all algorithm size statistics"
292         @echo "  blockciphers       - all blockcipher cores"
293         @echo "  streamciphers      - all streamcipher cores"
294         @echo "  hashes             - all hash cores"
295         @echo "  macs               - all MAC cores"
296         @echo "  prngs              - all PRNG cores"
297         @echo "  all_testrun        - testrun all algorithms"
298         @echo "  hash_size          - measure size of all hash functions"
299         @echo "  hash_speed         - measure performance of all hash functions"
300         @echo "  blockcipher_size   - measure size of all blockciphers"
301         @echo "  blockcipher_speed  - measure performance of all blockciphers"
302         @echo "  docu               - build doxygen documentation"
303         @echo "  clean              - remove a lot of builded files"
304         @echo "  depclean           - also remove dependency files"
305         @echo "  *_TESTBIN          - build test program"
306         @echo "  *_TESTRUN          - run nessie test"
307         @echo "  *_OBJ              - build algorithm core"
308         @echo "  *_FLASH            - flash test program"
309         @echo "  *_LIST             - build assembler listing"
310
311
312 #-------------------------------------------------------------------------------
313
314 .PHONY: clean
315 clean:
316         rm -rf $(BIN_DIR)*
317
318 .PHONY: depclean
319 depclean: clean
320         rm -f $(DEP_DIR)*.d
321
322 #-------------------------------------------------------------------------------
323 # dependency inclusion
324 #
325
326 DEPS := $(wildcard $(DEP_DIR)*.d)
327
328 ifneq ($(DEPS),)
329 include $(DEPS)
330 endif
331