]> git.cryptolib.org Git - avr-crypto-lib.git/blob - Makefile
moving from uart to cli
[avr-crypto-lib.git] / Makefile
1 # Makefile for the AVR-Crypto-Lib project
2 # author: Daniel Otte
3
4 BLOCK_CIPHERS  := 
5 STREAM_CIPHERS := 
6 HASHES         :=
7 MACS           :=
8 PRNGS          := 
9 ENCODINGS      :=
10
11 # we use the gnu make standard library
12 include gmsl
13 include avr-makefile.inc
14 include mkfiles/*.mk
15
16 ALGORITHMS = $(BLOCK_CIPHERS) $(STREAM_CIPHERS) $(HASHES) $(PRNGS) $(MACS) $(ENCODINGS)
17 ALGORITHMS_OBJ = $(patsubst %,%_OBJ, $(ALGORITHMS))
18 ALGORITHMS_TEST_BIN = $(patsubst %,%_TEST_BIN, $(ALGORITHMS))
19
20 define OBJinBINDIR_TEMPLATE
21 $(1) = $(2)
22 endef
23
24 $(foreach a, $(ALGORITHMS_OBJ), $(eval $(call OBJinBINDIR_TEMPLATE, $(a), $(patsubst %.o,$(BIN_DIR)%.o,$($(a))))))
25
26 $(foreach a, $(ALGORITHMS_TEST_BIN), $(eval $(call OBJinBINDIR_TEMPLATE, $(a), $(patsubst %.o,$(TESTBIN_DIR)%.o,$($(a))))))
27
28
29 #ALGORITHMS_TEST_BIN_IMM =  $(foreach a, $(ALGORITHMS_TEST_BIN), $($(a)))
30 ALGORITHMS_NESSIE_TEST = $(patsubst %,%_NESSIE_TEST, $(ALGORITHMS))
31 ALGORITHMS_PERFORMANCE_TEST = $(patsubst %,%_PERORMANCE_TEST, $(ALGORITHMS))
32
33 ALGORITHMS_LC = $(call lc,$(ALGORITHMS))
34
35 ALGORITHMS_TEST_TARGET_ELF = $(patsubst %, $(TESTBIN_DIR)main-%-test.elf, $(ALGORITHMS_LC))
36 ALGORITHMS_TEST_TARGET_HEX = $(patsubst %, $(TESTBIN_DIR)main-%-test.hex, $(ALGORITHMS_LC))
37
38
39 #-------------------------------------------------------------------------------
40
41 all: $(foreach algo, $(ALGORITHMS), $(algo)_OBJ)
42
43 #-------------------------------------------------------------------------------
44
45 define MAIN_OBJ_TEMPLATE
46 $(2): $(3) $(4)
47         @echo "[ld] : $$@"
48 #       echo $$^
49         @$(CC) $(CFLAGS) $(LDFLAGS)$(patsubst %.elf,%.map,$(2)) -o \
50         $(2) \
51         $(3) $(4) \
52         $(LIBS)
53 endef
54
55 $(foreach algo, $(ALGORITHMS), $(eval $(call MAIN_OBJ_TEMPLATE, \
56    $(algo), \
57    $(TESTBIN_DIR)main-$(call lc,$(algo))-test.elf, \
58    $(patsubst %.o,%.o,$($(algo)_TEST_BIN)), \
59    $(patsubst %.o,%.o,$($(algo)_OBJ))  )))
60
61
62
63
64 #-------------------------------------------------------------------------------
65 .PHONY: help
66 help: info
67
68 info:
69         @echo "infos on AVR-Crypto-lib:"
70         @echo "  block ciphers:"
71         @echo "    $(BLOCK_CIPHERS)"
72         @echo "  stream ciphers:"
73         @echo "    $(STREAM_CIPHERS)"
74         @echo "  hash functions:"
75         @echo "    $(HASHES)"
76         @echo "  MAC functions:"
77         @echo "    $(MACS)"
78         @echo "  PRNG functions:"
79         @echo "    $(PRNGS)"
80         @echo "  encodings:"
81         @echo "    $(ENCODINGS)"
82 #       @echo "  ALGORITHMS_TEST_BIN:"
83 #       @echo "    $(ALGORITHMS_TEST_BIN)"
84 #       @echo "  ALGORITHMS_TEST_TARGET_ELF:"
85 #       @echo "    $(ALGORITHMS_TEST_TARGET_ELF)"
86         @echo " targets:"
87         @echo "  all           - all algorithm cores"
88         @echo "  cores         - all algorithm cores"
89         @echo "  listings      - all algorithm core listings"
90         @echo "  tests         - all algorithm test programs"
91         @echo "  stats         - all algorithm size statistics"
92         @echo "  blockciphers  - all blockcipher cores"
93         @echo "  streamciphers - all streamcipher cores"
94         @echo "  hashes        - all hash cores"
95         @echo "  macs          - all MAC cores"
96         @echo "  prngs         - all PRNG cores"
97         @echo "  all_testrun   - testrun all algorithms"
98         @echo "  docu          - build doxygen documentation"
99         @echo "  clean         - remove a lot of builded files"
100         @echo "  xclean        - also remove dependency files"
101         @echo "  *_TEST_BIN    - build test program"
102         @echo "  *_TESTRUN     - run nessie test"
103         @echo "  *_OBJ         - build algorithm core"
104         @echo "  *_FLASH       - flash test program"
105         @echo "  *_LIST        - build assembler listing"
106
107 #-------------------------------------------------------------------------------
108         
109
110 $(BIN_DIR)%.o: %.c
111         @echo "[gcc]:  $@"
112         @$(CC) $(CFLAGS)  -c -o $@ $<
113
114 $(BIN_DIR)%.o: %.S
115         @echo "[as] :  $@"
116         @$(CC) $(ASFLAGS) -c -o $@ $<
117
118 $(TESTBIN_DIR)%.o: $(TESTSRC_DIR)%.c
119         @echo "[gcc]:  $@"
120         @$(CC) $(CFLAGS)  -c -o $@ $<
121
122 $(TESTBIN_DIR)%.o: $(TESTSRC_DIR)%.S
123         @echo "[as] :  $@"
124         @$(CC) $(ASFLAGS) -c -o $@ $<
125
126 $(TESTBIN_DIR)%.o: %.c
127         @echo "[gcc]:  $@"
128         @$(CC) $(CFLAGS)  -c -o $@ $<
129
130 $(TESTBIN_DIR)%.o: %.S
131         @echo "[as] :  $@"
132         @$(CC) $(ASFLAGS) -c -o $@ $<
133
134
135
136 %.o: %.c
137         @echo "[gcc]:  $@"
138         @$(CC) $(CFLAGS)  -c -o $@ $<
139
140 %.o: %.S
141         @echo "[as] :  $@"
142         @$(CC) $(ASFLAGS) -c -o $@ $<
143
144 #-------------------------------------------------------------------------------
145         
146 define OBJ_TEMPLATE
147 $(1)_OBJ: $(2)
148 #       @echo " ALGO: $(1)"
149 #       @echo " REQ:  $(2)"
150 endef
151
152 $(foreach algo, $(ALGORITHMS), $(eval $(call OBJ_TEMPLATE, $(algo), $($(algo)_OBJ))))
153
154
155 #-------------------------------------------------------------------------------
156
157 define TESTBIN_TEMPLATE
158 $(1)_TEST_BIN: $(2)
159 endef
160
161 $(foreach algo, $(ALGORITHMS), $(eval $(call TESTBIN_TEMPLATE, $(algo), $($(algo)_TEST_BIN))))
162
163 #-------------------------------------------------------------------------------
164
165 $(BLOCK_CIPHERS_OBJ): $(patsubst %,%_OBJ, $(BLOCK_CIPHERS)) 
166 $(STREAM_CIPHERS_OBJ): $(patsubst %,%_OBJ, $(STREAM_CIPHERS))
167 $(HASHES_OBJ): $(patsubst %,%_OBJ, $(HASHES))
168 $(PRNGS_OBJ): $(patsubst %,%_OBJ, $(PRNGS))
169 $(MACS_OBJ): $(patsubst %,%_OBJ, $(MACS))
170 $(ENCODINGS_OBJ): $(patsubst %,%_OBJ, $(ENCODINGS))
171
172 #-------------------------------------------------------------------------------
173
174 define SIZE_TEMPLATE
175 $(1)_size.txt: $(2)
176         @echo "[size]: $(1)_size.txt"
177         @$(SIZE) $(2) > $(1)_size.txt
178 endef
179
180 $(foreach algo, $(ALGORITHMS), $(eval $(call SIZE_TEMPLATE, $(STAT_DIR)$(call lc,$(algo)), $($(algo)_OBJ))))
181
182 #-------------------------------------------------------------------------------
183
184 define FLASH_TEMPLATE
185 $(1)_FLASH: $(2)
186         @echo "[flash]: $(2)"
187         @$(FLASHCMD)$(call first,$(2))
188 endef
189
190 $(foreach algo, $(ALGORITHMS),$(eval $(call FLASH_TEMPLATE, $(algo), $(TESTBIN_DIR)main-$(call lc,$(algo))-test.hex) ))  
191
192 #-------------------------------------------------------------------------------
193
194 define TESTRUN_TEMPLATE
195 $(1)_TESTRUN: $(1)_FLASH
196         @echo "[test]: $(1)"
197         $(RUBY) $(GET_TEST)  $(TESTPORT) $(TESTPORTBAUDR) 8 1 nessie $(TESTLOG_DIR)$(TESTPREFIX) $(2)
198 endef
199
200 $(foreach algo, $(ALGORITHMS),$(eval $(call TESTRUN_TEMPLATE, $(algo), $(call lc,$(algo)) )))
201
202 all_testrun: $(foreach algo, $(ALGORITHMS), $(algo)_TESTRUN)
203
204 #-------------------------------------------------------------------------------
205
206 define LISTING_TEMPLATE
207 $(1)_LIST: $(2)
208 endef
209
210 $(foreach algo, $(ALGORITHMS),$(eval $(call LISTING_TEMPLATE,$(call uc, $(algo)), \
211  $(patsubst %,$(LIST_DIR)%, \
212   $(patsubst $(BIN_DIR)%,%, \
213   $(patsubst $(TESTBIN_DIR)%,%, \
214   $(patsubst %.o,%.lst,$($(algo)_OBJ)))) ))))
215
216 listings: $(patsubst %,%_LIST,$(ALGORITHMS))
217
218
219 $(LIST_DIR)%.lst: $(TESTBIN_DIR)%.elf
220         $(OBJDUMP) -h -S $< > $@
221
222 $(LIST_DIR)%.lst: $(BIN_DIR)%.o
223         $(OBJDUMP) -h -S $< > $@
224
225 $(LIST_DIR)%.lst: $(TESTBIN_DIR)%.o
226         $(OBJDUMP) -h -S $< > $@
227
228 #-------------------------------------------------------------------------------
229
230 .PHONY: cores
231 cores: $(ALGORITHMS_OBJ)
232
233 .PHONY: blockciphers
234 blockciphers: $(patsubst %, %_OBJ, $(BLOCK_CIPHERS))
235
236 .PHONY: streamciphers
237 streamciphers: $(patsubst %, %_OBJ, $(STREAM_CIPHERS))
238
239 .PHONY:  hashes
240 hashes: $(patsubst %, %_OBJ, $(HASHES))
241
242 .PHONY:  macs
243 macs: $(patsubst %, %_OBJ, $(MACS))
244
245 .PHONY:  prngs
246 prngs: $(patsubst %, %_OBJ, $(PRNGS))
247
248 .PHONY:  encodings
249 encodings: $(patsubst %, %_OBJ, $(ENCODINGS))
250
251 tests: $(ALGORITHMS_TEST_BIN) \
252        $(ALGORITHMS_TEST_TARGET_ELF) \
253        $(ALGORITHMS_TEST_TARGET_HEX)
254
255 .PHONY:  stats
256 stats: $(SIZESTAT_FILE)
257         @cat $(STAT_DIR)$(SIZESTAT_FILE)        
258         
259 $(SIZESTAT_FILE): $(patsubst %, $(STAT_DIR)%_size.txt, $(ALGORITHMS_LC))
260         $(RUBY) sumsize.rb $^ > $(STAT_DIR)$(SIZESTAT_FILE)
261         
262 #-------------------------------------------------------------------------------        
263
264
265 .PHONY: clean
266 clean:
267         rm -rf $(BIN_DIR)*.o *.o $(TESTBIN_DIR)*.elf $(TESTBIN_DIR)* *.elf *.eps *.png *.pdf *.bak
268         rm -rf *.lst *.map $(EXTRA_CLEAN_FILES) $(STAT_DIR)$(SIZESTAT_FILE) $(STAT_DIR)*_size.txt
269 xclean: clean
270         rm -rf $(DEP_DIR)*.d
271
272 docu:
273         doxygen
274
275 make.dump: Makefile
276         $(MAKE) -p -B -n -f $^ > $@
277
278 make.dot: make.dump
279         $(MAKE2GRAPH) $^ > $@
280
281 make.png: make.dot
282         $(TWOPI) -Tpng -o $@ $^
283
284 make.svg: make.dot
285         $(TWOPI) -Tsvg -o $@ $^
286
287 .PHONY: make-info
288 make-info: make.png make.svg
289
290
291 # Rules for building the .text rom images
292
293 %.hex: %.elf
294         @echo "[objcopy]: $@"
295         @$(OBJCOPY) -j .text -j .data -O ihex $< $@
296
297 %.srec: %.elf
298         @echo "[objcopy]: $@"
299         @$(OBJCOPY) -j .text -j .data -O srec $< $@
300
301 %.bin: %.elf
302         @echo "[objcopy]: $@"
303         @$(OBJCOPY) -j .text -j .data -O binary $< $@
304
305 # Rules for building the .eeprom rom images
306
307
308 %_eeprom.hex: %.elf
309         @echo "[objcopy]: $@"
310         @$(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@
311
312 %_eeprom.srec: %.elf
313         @echo "[objcopy]: $@"
314         @$(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O srec $< $@
315
316 %_eeprom.bin: %.elf
317         @echo "[objcopy]: $@"
318         @$(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O binary $< $@
319         
320         
321 # Every thing below here is used by avr-libc's build system and can be ignored
322 # by the casual user.
323
324 FIG2DEV          = fig2dev
325 EXTRA_CLEAN_FILES       = *.hex *.bin *.srec
326
327
328 %.eps: %.fig
329         $(FIG2DEV) -L eps $< $@
330
331 %.pdf: %.fig
332         $(FIG2DEV) -L pdf $< $@
333
334 %.png: %.fig
335         $(FIG2DEV) -L png $< $@
336
337
338 DEPS := $(wildcard $(DEP_DIR)*.d)
339
340 ifneq ($(DEPS),)
341 include $(DEPS)
342 endif
343