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