1 # Makefile for the micro-crypt project
10 # we use the gnu make standard library
12 include avr-makefile.inc
15 ALGORITHMS = $(BLOCK_CIPHERS) $(STREAM_CIPHERS) $(HASHES) $(PRNGS) $(MACS)
16 ALGORITHMS_OBJ = $(patsubst %,%_OBJ, $(ALGORITHMS))
17 define OBJinBINDIR_TEMPLATE
20 $(foreach a, $(ALGORITHMS_OBJ), $(eval $(call OBJinBINDIR_TEMPLATE, $(a), $(patsubst %.o,$(BIN_DIR)%.o,$($(a))))))
21 ALGORITHMS_TEST_BIN = $(patsubst %,%_TEST_BIN, $(ALGORITHMS))
22 $(foreach a, $(ALGORITHMS_TEST_BIN), $(eval $(call OBJinBINDIR_TEMPLATE, $(a), $(patsubst %.o,$(BIN_DIR)%.o,$($(a))))))
23 ALGORITHMS_TEST_BIN_MAIN = $(foreach a, $(ALGORITHMS_TEST_BIN), $(firstword $($(a))))
24 ALGORITHMS_TEST_BIN_MAIN_ELF = $(patsubst $(BIN_DIR)%.o, $(TESTBIN_DIR)%.elf, $(ALGORITHMS_TEST_BIN_MAIN))
25 ALGORITHMS_TEST_BIN_MAIN_HEX = $(patsubst $(BIN_DIR)%.o, $(TESTBIN_DIR)%.hex, $(ALGORITHMS_TEST_BIN_MAIN))
27 ALGORITHMS_TEST_BIN_IMM = $(foreach a, $(ALGORITHMS_TEST_BIN), $($(a)))
28 ALGORITHMS_NESSIE_TEST = $(patsubst %,%_NESSIE_TEST, $(ALGORITHMS))
29 ALGORITHMS_PERFORMANCE_TEST = $(patsubst %,%_PERORMANCE_TEST, $(ALGORITHMS))
31 ALGORITHMS_LC = $(call lc,$(ALGORITHMS))
34 #-------------------------------------------------------------------------------
36 all: $(foreach algo, $(ALGORITHMS), $(algo)_OBJ)
38 #-------------------------------------------------------------------------------
44 @$(CC) $(CFLAGS) $(LDFLAGS)$(patsubst %.elf,%.map,$(2)) -o \
50 $(foreach algo, $(ALGORITHMS), $(eval $(call BLA_TEMPLATE2, $(algo), $(patsubst $(BIN_DIR)%.o,$(TESTBIN_DIR)%.elf,$(firstword $($(algo)_TEST_BIN))), $(patsubst %.o,%.o,$($(algo)_TEST_BIN)) )))
52 #-------------------------------------------------------------------------------
56 @echo "infos on micro-crypt:"
57 @echo " block ciphers:"
58 @echo " $(BLOCK_CIPHERS)"
59 @echo " stream ciphers:"
60 @echo " $(STREAM_CIPHERS)"
61 @echo " hash functions:"
63 @echo " MAC functions:"
65 @echo " PRNG functions:"
70 @$(CC) $(CFLAGS) -c -o $@ $<
74 @$(CC) $(ASFLAGS) -c -o $@ $<
78 @$(CC) $(CFLAGS) -c -o $@ $<
82 @$(CC) $(ASFLAGS) -c -o $@ $<
86 cores: $(ALGORITHMS_OBJ)
89 blockciphers: $(patsubst %, %_OBJ, $(BLOCK_CIPHERS))
92 streamciphers: $(patsubst %, %_OBJ, $(STREAM_CIPHERS))
95 hashes: $(patsubst %, %_OBJ, $(HASHES))
98 macs: $(patsubst %, %_OBJ, $(MACS))
101 prngs: $(patsubst %, %_OBJ, $(PRNGS))
103 tests: $(ALGORITHMS_TEST_BIN) \
104 $(ALGORITHMS_TEST_BIN_MAIN_ELF) \
105 $(ALGORITHMS_TEST_BIN_MAIN_HEX)
108 stats: $(SIZESTAT_FILE)
111 $(SIZESTAT_FILE): $(patsubst %, %_size.txt, $(ALGORITHMS_LC))
112 $(RUBY) sumsize.rb $^ > $(SIZESTAT_FILE)
113 @cat $(SIZESTAT_FILE)
114 #-------------------------------------------------------------------------------
118 # @echo " ALGO: $(1)"
122 $(foreach algo, $(ALGORITHMS), $(eval $(call OBJ_TEMPLATE, $(algo), $($(algo)_OBJ))))
124 #-------------------------------------------------------------------------------
126 $(BLOCK_CIPHERS_OBJ): $(patsubst %,%_OBJ, $(BLOCK_CIPHERS))
127 $(STREAM_CIPHERS_OBJ): $(patsubst %,%_OBJ, $(STREAM_CIPHERS))
128 $(HASHES_OBJ): $(patsubst %,%_OBJ, $(HASHES))
129 $(PRNGS_OBJ): $(patsubst %,%_OBJ, $(PRNGS))
130 $(MACS_OBJ): $(patsubst %,%_OBJ, $(MACS))
132 $(ALGORITHMS_TEST_BIN): $(ALGORITHMS_TEST_BIN_IMM)
134 #-------------------------------------------------------------------------------
138 @echo "[size]: $(1)_size.txt"
139 @$(SIZE) $(2) > $(1)_size.txt
142 $(foreach algo, $(ALGORITHMS), $(eval $(call SIZE_TEMPLATE, $(call lc,$(algo)), $($(algo)_OBJ))))
144 #-------------------------------------------------------------------------------
146 define FLASH_TEMPLATE
148 @echo "[flash]: $(2)"
149 @$(FLASHCMD)$(call first,$(2))
152 $(foreach algo, $(ALGORITHMS),$(eval $(call FLASH_TEMPLATE, $(algo), \
153 $(patsubst %.o,%.hex,$(firstword $($(algo)_TEST_BIN)))) ))
155 #-------------------------------------------------------------------------------
159 rm -rf $(BIN_DIR)*.o *.o $(TESTBIN_DIR)*.elf $(TESTBIN_DIR)* *.elf *.eps *.png *.pdf *.bak *_size.txt
160 rm -rf *.lst *.map $(EXTRA_CLEAN_FILES) $(SIZESTAT_FILE)
169 $(OBJDUMP) -h -S $< > $@
171 # Rules for building the .text rom images
174 $(OBJCOPY) -j .text -j .data -O ihex $< $@
177 $(OBJCOPY) -j .text -j .data -O srec $< $@
180 $(OBJCOPY) -j .text -j .data -O binary $< $@
182 # Rules for building the .eeprom rom images
186 $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@
189 $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O srec $< $@
192 $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O binary $< $@
195 # Every thing below here is used by avr-libc's build system and can be ignored
196 # by the casual user.
199 EXTRA_CLEAN_FILES = *.hex *.bin *.srec
203 $(FIG2DEV) -L eps $< $@
206 $(FIG2DEV) -L pdf $< $@
209 $(FIG2DEV) -L png $< $@
212 DEPS := $(wildcard $(DEP_DIR)*.d)