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