]> git.cryptolib.org Git - arm-crypto-lib.git/blob - Makefile
updated build system
[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) -I./$(strip $(3)) -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) \
97     )) \
98   ) \
99 )
100
101 $(foreach a, $(ALGORITHMS), \
102   $(foreach b, $($(a)_TEST_BIN), \
103     $(eval $(call TargetSource_Template, \
104       $(BIN_DIR)$(call lc, $(a))/$(TEST_DIR)$(b), \
105        $(call find_source_file, $(b), $($(a)_DIR) $($(a)_INCDIR) $(GLOBAL_INCDIR) ),\
106       $($(a)_DIR) \
107     )) \
108   ) \
109 )
110
111 #-------------------------------------------------------------------------------
112
113 define MainTestElf_Template
114 $(1): $(2) $(3)
115         @echo "[ld]: $(1)"
116         @$(CC) $(CFLAGS_A) $(LDFLAGS)$(patsubst %.elf,%.map,$(1)) -o \
117         $(1) \
118         $(2) $(3) \
119         $(LIBS)
120 endef
121
122 $(foreach a, $(ALGORITHMS), \
123     $(eval $(call MainTestElf_Template,  \
124         $(BIN_DIR)$(call lc, $(a))/$(TEST_DIR)main-$(call lc, $(a))-test.elf, \
125         $($(a)_BINOBJ), \
126         $($(a)_TESTBINOBJ) \
127         )) \
128 )
129
130 #-------------------------------------------------------------------------------
131
132 all: $(foreach algo, $(ALGORITHMS), $($(algo)_BINOBJ))
133
134 #-------------------------------------------------------------------------------
135
136 define TestBin_TEMPLATE
137 $(1)_TEST_BIN: $(2)
138 endef
139
140 $(foreach algo, $(ALGORITHMS), $(eval $(call TestBin_TEMPLATE, \
141     $(algo), \
142     $(BIN_DIR)$(call lc, $(algo))/$(TEST_DIR)main-$(call lc, $(algo))-test.elf \
143 )))
144
145 #-------------------------------------------------------------------------------
146
147 %.hex: %.elf
148         @echo "[objcopy]: $@"
149         @$(OBJCOPY) -j .text -j .data -O ihex $< $@
150
151 #-------------------------------------------------------------------------------
152
153 define Flash_Template
154 $(1)_FLASH: $(2)
155         @echo "[flash]: $(2)"
156         @$(FLASHCMD)$(call first,$(2))
157 endef
158
159 $(foreach algo, $(ALGORITHMS), $(eval $(call Flash_Template, \
160     $(algo), \
161     $(BIN_DIR)$(call lc, $(algo))/$(TEST_DIR)main-$(call lc, $(algo))-test.hex \
162 )))
163
164 #-------------------------------------------------------------------------------
165
166 define Speed_Template
167 $(1)_SPEED:  $(1)_FLASH
168         @$(RUBY) $(SPEEDTOOL) -c $(SPEEDCMD) -t $(SPEEDLOG_DIR) -a $(call lc, $(1))
169 endef
170
171 $(foreach algo, $(ALGORITHMS), $(eval $(call Speed_Template, \
172     $(algo), $(algo) \
173 )))
174
175 .PHONY: hash_speed
176 hash_speed: $(foreach algo, $(HASHES), $(algo)_SPEED)
177
178 .PHONY: blockcipher_speed
179 blockcipher_speed: $(foreach algo, $(BLOCK_CIPHERS), $(algo)_SPEED)
180 #-------------------------------------------------------------------------------
181
182
183 define Size_Template
184 $(1)_SIZE:  $(2)
185         @echo "[size] $(1)"
186         $(SIZE) $(2) > $(strip $(SIZE_DIR))$(strip $(call lc, $(1))).size
187 endef
188
189 $(foreach algo, $(ALGORITHMS), $(eval $(call Size_Template, \
190     $(strip $(algo)), $($(algo)_BINOBJ) \
191 )))
192
193 .PHONY: hash_size
194 hash_size: $(foreach algo, $(HASHES), $(algo)_SIZE)
195
196 .PHONY: blockcipher_size
197 blockcipher_size: $(foreach algo, $(BLOCK_CIPHERS), $(algo)_SIZE)
198
199 #-------------------------------------------------------------------------------
200
201 .PHONY: tests
202 tests: $(foreach a, $(ALGORITHMS), $(a)_TEST_BIN)
203
204 #-------------------------------------------------------------------------------
205
206 define TestRun_Template
207 $(1)_TESTRUN: $(1)_FLASH
208         @echo "[test]: $(1)"
209         $(RUBY) $(GET_TEST) $(TESTPORT) $(TESTPORTBAUDR) 8 1 nessie $(TESTLOG_DIR)$(TESTPREFIX) $(2)
210 endef
211
212 $(foreach algo, $(ALGORITHMS),$(eval $(call TestRun_Template, $(algo), $(call lc,$(algo)) )))
213
214 all_testrun: $(foreach algo, $(ALGORITHMS), $(algo)_TESTRUN)
215
216 #-------------------------------------------------------------------------------
217
218 define Obj_Template
219 $(1)_OBJ: $(2)
220 endef
221
222 $(foreach algo, $(ALGORITHMS), \
223     $(eval $(call Obj_Template, \
224         $(algo), \
225         $($(algo)_BINOBJ)\
226         ))\
227 )
228
229 .PHONY: cores
230 cores: $(foreach algo, $(ALGORITHMS), $(algo)_OBJ)
231
232 .PHONY: blockchiphers
233 blockciphers: $(foreach algo, $(BLOCK_CIPHERS), $(algo)_OBJ)
234
235 .PHONY: streamchiphers
236 streamciphers: $(foreach algo, $(STREAM_CIPHERS), $(algo)_OBJ)
237
238 .PHONY: hashes
239 hashes: $(foreach algo, $(HASHES), $(algo)_OBJ)
240
241 .PHONY: macs
242 macs: $(foreach algo, $(MACS), $(algo)_OBJ)
243
244 .PHONY: prngs
245 prngs: $(foreach algo, $(PRNGS), $(algo)_OBJ)
246
247 .PHONY: encodings
248 encodings: $(foreach algo, $(ENCODINGS), $(algo)_OBJ)
249
250 .PHONY: aux
251 aux: $(foreach algo, $(AUX), $(algo)_OBJ)
252
253
254 #-------------------------------------------------------------------------------
255
256
257 .PHONY: help
258 help: info
259 .PHONY: info
260 info:
261         @echo "infos on AVR-Crypto-lib:"
262         @echo "  block ciphers:"
263         @echo "    $(BLOCK_CIPHERS)"
264         @echo "  stream ciphers:"
265         @echo "    $(STREAM_CIPHERS)"
266         @echo "  hash functions:"
267         @echo "    $(HASHES)"
268         @echo "  MAC functions:"
269         @echo "    $(MACS)"
270         @echo "  PRNG functions:"
271         @echo "    $(PRNGS)"
272         @echo "  signature functions:"
273         @echo "    $(SIGNATURE)"
274         @echo "  public key ciphers:"
275         @echo "    $(PK_CIPHERS)"
276         @echo "  encodings:"
277         @echo "    $(ENCODINGS)"
278         @echo "  auxiliary functions:"
279         @echo "    $(AUX)"
280         @echo " targets:"
281         @echo "  all                - all algorithm cores"
282         @echo "  cores              - all algorithm cores"
283         @echo "  listings           - all algorithm core listings"
284         @echo "  tests              - all algorithm test programs"
285         @echo "  stats              - all algorithm size statistics"
286         @echo "  blockciphers       - all blockcipher cores"
287         @echo "  streamciphers      - all streamcipher cores"
288         @echo "  hashes             - all hash cores"
289         @echo "  macs               - all MAC cores"
290         @echo "  prngs              - all PRNG cores"
291         @echo "  all_testrun        - testrun all algorithms"
292         @echo "  hash_size          - measure size of all hash functions"
293         @echo "  hash_speed         - measure performance of all hash functions"
294         @echo "  blockcipher_size   - measure size of all blockciphers"
295         @echo "  blockcipher_speed  - measure performance of all blockciphers"
296         @echo "  docu               - build doxygen documentation"
297         @echo "  clean              - remove a lot of builded files"
298         @echo "  depclean           - also remove dependency files"
299         @echo "  *_TEST_BIN         - build test program"
300         @echo "  *_TESTRUN          - run nessie test"
301         @echo "  *_OBJ              - build algorithm core"
302         @echo "  *_FLASH            - flash test program"
303         @echo "  *_LIST             - build assembler listing"
304
305
306 #-------------------------------------------------------------------------------
307
308 .PHONY: clean
309 clean:
310         rm -rf $(BIN_DIR)*
311
312 .PHONY: depclean
313 depclean: clean
314         rm -f $(DEP_DIR)*.d
315
316 #-------------------------------------------------------------------------------
317 # dependency inclusion
318 #
319
320 DEPS := $(wildcard $(DEP_DIR)*.d)
321
322 ifneq ($(DEPS),)
323 include $(DEPS)
324 endif
325