]> git.cryptolib.org Git - arm-crypto-lib.git/blob - Makefile
AES makestub added
[arm-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 arm-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.elf \
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 #-------------------------------------------------------------------------------
183
184
185 define Size_Template
186 $(1)_SIZE:  $(2)
187         @echo "[size] $(1)"
188         $(SIZE) $(2) > $(strip $(SIZE_DIR))$(strip $(call lc, $(1))).size
189 endef
190
191 $(foreach algo, $(ALGORITHMS), $(eval $(call Size_Template, \
192     $(strip $(algo)), $($(algo)_BINOBJ) \
193 )))
194
195 .PHONY: hash_size
196 hash_size: $(foreach algo, $(HASHES), $(algo)_SIZE)
197
198 #-------------------------------------------------------------------------------
199
200 .PHONY: tests
201 tests: $(foreach a, $(ALGORITHMS), $(a)_TEST_BIN)
202
203 #-------------------------------------------------------------------------------
204
205 define TestRun_Template
206 $(1)_TESTRUN: $(1)_FLASH
207         @echo "[test]: $(1)"
208         $(RUBY) $(GET_TEST) $(TESTPORT) $(TESTPORTBAUDR) 8 1 nessie $(TESTLOG_DIR)$(TESTPREFIX) $(2)
209 endef
210
211 $(foreach algo, $(ALGORITHMS),$(eval $(call TestRun_Template, $(algo), $(call lc,$(algo)) )))
212
213 all_testrun: $(foreach algo, $(ALGORITHMS), $(algo)_TESTRUN)
214
215 #-------------------------------------------------------------------------------
216
217 define Obj_Template
218 $(1)_OBJ: $(2)
219 endef
220
221 $(foreach algo, $(ALGORITHMS), \
222     $(eval $(call Obj_Template, \
223         $(algo), \
224         $($(algo)_BINOBJ)\
225         ))\
226 )
227
228 .PHONY: cores
229 cores: $(foreach algo, $(ALGORITHMS), $(algo)_OBJ)
230
231 .PHONY: blockchiphers
232 blockciphers: $(foreach algo, $(BLOCK_CIPHERS), $(algo)_OBJ)
233
234 .PHONY: streamchiphers
235 streamciphers: $(foreach algo, $(STREAM_CIPHERS), $(algo)_OBJ)
236
237 .PHONY: hashes
238 hashes: $(foreach algo, $(HASHES), $(algo)_OBJ)
239
240 .PHONY: macs
241 macs: $(foreach algo, $(MACS), $(algo)_OBJ)
242
243 .PHONY: prngs
244 prngs: $(foreach algo, $(PRNGS), $(algo)_OBJ)
245
246 .PHONY: encodings
247 encodings: $(foreach algo, $(ENCODINGS), $(algo)_OBJ)
248
249 .PHONY: aux
250 aux: $(foreach algo, $(AUX), $(algo)_OBJ)
251
252
253 #-------------------------------------------------------------------------------
254
255
256 .PHONY: help
257 help: info
258 .PHONY: info
259 info:
260         @echo "infos on AVR-Crypto-lib:"
261         @echo "  block ciphers:"
262         @echo "    $(BLOCK_CIPHERS)"
263         @echo "  stream ciphers:"
264         @echo "    $(STREAM_CIPHERS)"
265         @echo "  hash functions:"
266         @echo "    $(HASHES)"
267         @echo "  MAC functions:"
268         @echo "    $(MACS)"
269         @echo "  PRNG functions:"
270         @echo "    $(PRNGS)"
271         @echo "  signature functions:"
272         @echo "    $(SIGNATURE)"
273         @echo "  public key ciphers:"
274         @echo "    $(PK_CIPHERS)"
275         @echo "  encodings:"
276         @echo "    $(ENCODINGS)"
277         @echo "  auxiliary functions:"
278         @echo "    $(AUX)"
279         @echo " targets:"
280         @echo "  all           - all algorithm cores"
281         @echo "  cores         - all algorithm cores"
282         @echo "  listings      - all algorithm core listings"
283         @echo "  tests         - all algorithm test programs"
284         @echo "  stats         - all algorithm size statistics"
285         @echo "  blockciphers  - all blockcipher cores"
286         @echo "  streamciphers - all streamcipher cores"
287         @echo "  hashes        - all hash cores"
288         @echo "  macs          - all MAC cores"
289         @echo "  prngs         - all PRNG cores"
290         @echo "  all_testrun   - testrun all algorithms"
291         @echo "  hash_size     - measure size of all hash functions"
292         @echo "  hash_speed    - measure performance of all hash functions"
293         @echo "  docu          - build doxygen documentation"
294         @echo "  clean         - remove a lot of builded files"
295         @echo "  depclean      - also remove dependency files"
296         @echo "  *_TEST_BIN    - build test program"
297         @echo "  *_TESTRUN     - run nessie test"
298         @echo "  *_OBJ         - build algorithm core"
299         @echo "  *_FLASH       - flash test program"
300         @echo "  *_LIST        - build assembler listing"
301
302
303 #-------------------------------------------------------------------------------
304
305 .PHONY: clean
306 clean:
307         rm -rf $(BIN_DIR)*
308
309 .PHONY: depclean
310 depclean: clean
311         rm $(DEP_DIR)*.d
312
313 #-------------------------------------------------------------------------------
314 # dependency inclusion
315 #
316
317 DEPS := $(wildcard $(DEP_DIR)*.d)
318
319 ifneq ($(DEPS),)
320 include $(DEPS)
321 endif
322