]> git.cryptolib.org Git - avr-crypto-lib.git/blob - Makefile
new makefile and modified build process
[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 .PHONY: tests
153 tests: $(foreach a, $(ALGORITHMS), $(a)_TEST_BIN)
154
155 #-------------------------------------------------------------------------------
156
157 define TestRun_Template
158 $(1)_TESTRUN: $(1)_FLASH
159         @echo "[test]: $(1)"
160         $(RUBY) $(GET_TEST) $(TESTPORT) $(TESTPORTBAUDR) 8 1 nessie $(TESTLOG_DIR)$(TESTPREFIX) $(2)
161 endef
162
163 $(foreach algo, $(ALGORITHMS),$(eval $(call TestRun_Template, $(algo), $(call lc,$(algo)) )))
164
165 all_testrun: $(foreach algo, $(ALGORITHMS), $(algo)_TESTRUN)
166
167 #-------------------------------------------------------------------------------
168
169 define Obj_Template
170 $(1)_OBJ: $(2)
171 endef
172
173 $(foreach algo, $(ALGORITHMS), \
174     $(eval $(call Obj_Template, \
175         $(algo), \
176         $($(algo)_BINOBJ)\
177         ))\
178 )
179
180 .PHONY: cores
181 cores: $(foreach algo, $(ALGORITHMS), $(algo)_OBJ)
182
183 .PHONY: blockchiphers
184 blockciphers: $(foreach algo, $(BLOCK_CIPHERS), $(algo)_OBJ)
185
186 .PHONY: streamchiphers
187 streamciphers: $(foreach algo, $(STREAM_CIPHERS), $(algo)_OBJ)
188
189 .PHONY: hashes
190 hashes: $(foreach algo, $(HASHES), $(algo)_OBJ)
191
192 .PHONY: macs
193 macs: $(foreach algo, $(MACS), $(algo)_OBJ)
194
195 .PHONY: prngs
196 prngs: $(foreach algo, $(PRNGS), $(algo)_OBJ)
197
198 .PHONY: encodings
199 encodings: $(foreach algo, $(ENCODINGS), $(algo)_OBJ)
200
201 .PHONY: aux
202 aux: $(foreach algo, $(AUX), $(algo)_OBJ)
203
204
205 #-------------------------------------------------------------------------------
206
207
208 .PHONY: help
209 help: info
210 .PHONY: info
211 info:
212         @echo "infos on AVR-Crypto-lib:"
213         @echo "  block ciphers:"
214         @echo "    $(BLOCK_CIPHERS)"
215         @echo "  stream ciphers:"
216         @echo "    $(STREAM_CIPHERS)"
217         @echo "  hash functions:"
218         @echo "    $(HASHES)"
219         @echo "  MAC functions:"
220         @echo "    $(MACS)"
221         @echo "  PRNG functions:"
222         @echo "    $(PRNGS)"
223         @echo "  encodings:"
224         @echo "    $(ENCODINGS)"
225         @echo " targets:"
226         @echo "  all           - all algorithm cores"
227         @echo "  cores         - all algorithm cores"
228         @echo "  listings      - all algorithm core listings"
229         @echo "  tests         - all algorithm test programs"
230         @echo "  stats         - all algorithm size statistics"
231         @echo "  blockciphers  - all blockcipher cores"
232         @echo "  streamciphers - all streamcipher cores"
233         @echo "  hashes        - all hash cores"
234         @echo "  macs          - all MAC cores"
235         @echo "  prngs         - all PRNG cores"
236         @echo "  all_testrun   - testrun all algorithms"
237         @echo "  docu          - build doxygen documentation"
238         @echo "  clean         - remove a lot of builded files"
239         @echo "  depclean      - also remove dependency files"
240         @echo "  *_TEST_BIN    - build test program"
241         @echo "  *_TESTRUN     - run nessie test"
242         @echo "  *_OBJ         - build algorithm core"
243         @echo "  *_FLASH       - flash test program"
244         @echo "  *_LIST        - build assembler listing"
245
246
247 #-------------------------------------------------------------------------------
248
249 .PHONY: clean
250 clean:
251         rm -rf $(BIN_DIR)*
252
253 .PHONY: depclean
254 depclean: clean
255         rm $(DEP_DIR)*.d
256
257 #-------------------------------------------------------------------------------
258 # dependency inclusion
259 #
260
261 DEPS := $(wildcard $(DEP_DIR)*.d)
262
263 ifneq ($(DEPS),)
264 include $(DEPS)
265 endif
266