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