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