1 # Makefile for the AVR-Crypto-Lib project
11 # we use the gnu make standard library
13 include avr-makefile.inc
16 ALGORITHMS = $(BLOCK_CIPHERS) $(STREAM_CIPHERS) $(HASHES) $(PRNGS) $(MACS) $(ENCODINGS)
17 ALGORITHMS_OBJ = $(patsubst %,%_OBJ, $(ALGORITHMS))
18 ALGORITHMS_TEST_BIN = $(patsubst %,%_TEST_BIN, $(ALGORITHMS))
20 define OBJinBINDIR_TEMPLATE
24 $(foreach a, $(ALGORITHMS_OBJ), $(eval $(call OBJinBINDIR_TEMPLATE, $(a), $(patsubst %.o,$(BIN_DIR)%.o,$($(a))))))
26 $(foreach a, $(ALGORITHMS_TEST_BIN), $(eval $(call OBJinBINDIR_TEMPLATE, $(a), $(patsubst %.o,$(TESTBIN_DIR)%.o,$($(a))))))
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))
33 ALGORITHMS_LC = $(call lc,$(ALGORITHMS))
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))
39 #-------------------------------------------------------------------------------
41 all: $(foreach algo, $(ALGORITHMS), $(algo)_OBJ)
43 #-------------------------------------------------------------------------------
45 define MAIN_OBJ_TEMPLATE
49 @$(CC) $(CFLAGS) $(LDFLAGS)$(patsubst %.elf,%.map,$(2)) -o \
55 $(foreach algo, $(ALGORITHMS), $(eval $(call MAIN_OBJ_TEMPLATE, \
57 $(TESTBIN_DIR)main-$(call lc,$(algo))-test.elf, \
58 $(patsubst %.o,%.o,$($(algo)_TEST_BIN)), \
59 $(patsubst %.o,%.o,$($(algo)_OBJ)) )))
64 #-------------------------------------------------------------------------------
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:"
76 @echo " MAC functions:"
78 @echo " PRNG functions:"
82 # @echo " ALGORITHMS_TEST_BIN:"
83 # @echo " $(ALGORITHMS_TEST_BIN)"
84 # @echo " ALGORITHMS_TEST_TARGET_ELF:"
85 # @echo " $(ALGORITHMS_TEST_TARGET_ELF)"
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"
107 #-------------------------------------------------------------------------------
112 @$(CC) $(CFLAGS) -c -o $@ $<
116 @$(CC) $(ASFLAGS) -c -o $@ $<
118 $(TESTBIN_DIR)%.o: $(TESTSRC_DIR)%.c
120 @$(CC) $(CFLAGS) -c -o $@ $<
122 $(TESTBIN_DIR)%.o: $(TESTSRC_DIR)%.S
124 @$(CC) $(ASFLAGS) -c -o $@ $<
126 $(TESTBIN_DIR)%.o: %.c
128 @$(CC) $(CFLAGS) -c -o $@ $<
130 $(TESTBIN_DIR)%.o: %.S
132 @$(CC) $(ASFLAGS) -c -o $@ $<
138 @$(CC) $(CFLAGS) -c -o $@ $<
142 @$(CC) $(ASFLAGS) -c -o $@ $<
144 #-------------------------------------------------------------------------------
148 # @echo " ALGO: $(1)"
152 $(foreach algo, $(ALGORITHMS), $(eval $(call OBJ_TEMPLATE, $(algo), $($(algo)_OBJ))))
155 #-------------------------------------------------------------------------------
157 define TESTBIN_TEMPLATE
161 $(foreach algo, $(ALGORITHMS), $(eval $(call TESTBIN_TEMPLATE, $(algo), $($(algo)_TEST_BIN))))
163 #-------------------------------------------------------------------------------
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))
172 #-------------------------------------------------------------------------------
176 @echo "[size]: $(1)_size.txt"
177 @$(SIZE) $(2) > $(1)_size.txt
180 $(foreach algo, $(ALGORITHMS), $(eval $(call SIZE_TEMPLATE, $(STAT_DIR)$(call lc,$(algo)), $($(algo)_OBJ))))
182 #-------------------------------------------------------------------------------
184 define FLASH_TEMPLATE
186 @echo "[flash]: $(2)"
187 @$(FLASHCMD)$(call first,$(2))
190 $(foreach algo, $(ALGORITHMS),$(eval $(call FLASH_TEMPLATE, $(algo), $(TESTBIN_DIR)main-$(call lc,$(algo))-test.hex) ))
192 #-------------------------------------------------------------------------------
194 define TESTRUN_TEMPLATE
195 $(1)_TESTRUN: $(1)_FLASH
197 $(RUBY) $(GET_TEST) $(TESTPORT) $(TESTPORTBAUDR) 8 1 nessie $(TESTLOG_DIR)$(TESTPREFIX) $(2)
200 $(foreach algo, $(ALGORITHMS),$(eval $(call TESTRUN_TEMPLATE, $(algo), $(call lc,$(algo)) )))
202 all_testrun: $(foreach algo, $(ALGORITHMS), $(algo)_TESTRUN)
204 #-------------------------------------------------------------------------------
206 define LISTING_TEMPLATE
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)))) ))))
216 listings: $(patsubst %,%_LIST,$(ALGORITHMS))
219 $(LIST_DIR)%.lst: $(TESTBIN_DIR)%.elf
220 $(OBJDUMP) -h -S $< > $@
222 $(LIST_DIR)%.lst: $(BIN_DIR)%.o
223 $(OBJDUMP) -h -S $< > $@
225 $(LIST_DIR)%.lst: $(TESTBIN_DIR)%.o
226 $(OBJDUMP) -h -S $< > $@
228 #-------------------------------------------------------------------------------
231 cores: $(ALGORITHMS_OBJ)
234 blockciphers: $(patsubst %, %_OBJ, $(BLOCK_CIPHERS))
236 .PHONY: streamciphers
237 streamciphers: $(patsubst %, %_OBJ, $(STREAM_CIPHERS))
240 hashes: $(patsubst %, %_OBJ, $(HASHES))
243 macs: $(patsubst %, %_OBJ, $(MACS))
246 prngs: $(patsubst %, %_OBJ, $(PRNGS))
249 encodings: $(patsubst %, %_OBJ, $(ENCODINGS))
251 tests: $(ALGORITHMS_TEST_BIN) \
252 $(ALGORITHMS_TEST_TARGET_ELF) \
253 $(ALGORITHMS_TEST_TARGET_HEX)
256 stats: $(SIZESTAT_FILE)
257 @cat $(STAT_DIR)$(SIZESTAT_FILE)
259 $(SIZESTAT_FILE): $(patsubst %, $(STAT_DIR)%_size.txt, $(ALGORITHMS_LC))
260 $(RUBY) sumsize.rb $^ > $(STAT_DIR)$(SIZESTAT_FILE)
262 #-------------------------------------------------------------------------------
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
276 $(MAKE) -p -B -n -f $^ > $@
279 $(MAKE2GRAPH) $^ > $@
282 $(TWOPI) -Tpng -o $@ $^
285 $(TWOPI) -Tsvg -o $@ $^
288 make-info: make.png make.svg
291 # Rules for building the .text rom images
294 @echo "[objcopy]: $@"
295 @$(OBJCOPY) -j .text -j .data -O ihex $< $@
298 @echo "[objcopy]: $@"
299 @$(OBJCOPY) -j .text -j .data -O srec $< $@
302 @echo "[objcopy]: $@"
303 @$(OBJCOPY) -j .text -j .data -O binary $< $@
305 # Rules for building the .eeprom rom images
309 @echo "[objcopy]: $@"
310 @$(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@
313 @echo "[objcopy]: $@"
314 @$(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O srec $< $@
317 @echo "[objcopy]: $@"
318 @$(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O binary $< $@
321 # Every thing below here is used by avr-libc's build system and can be ignored
322 # by the casual user.
325 EXTRA_CLEAN_FILES = *.hex *.bin *.srec
329 $(FIG2DEV) -L eps $< $@
332 $(FIG2DEV) -L pdf $< $@
335 $(FIG2DEV) -L png $< $@
338 DEPS := $(wildcard $(DEP_DIR)*.d)