X-Git-Url: https://git.cryptolib.org/?a=blobdiff_plain;f=Makefile;h=5a9090ca5dad511115b7313ee006989f87ec9a12;hb=4f50c75ee5a6cc88bf7ea71957ed509e298e6c25;hp=89f89134bca8ff792554eca5f59379083b521c14;hpb=3c995d0a8faeb9d37927d48e20fc45d839e066ea;p=avr-crypto-lib.git diff --git a/Makefile b/Makefile index 89f8913..5a9090c 100644 --- a/Makefile +++ b/Makefile @@ -1,92 +1,266 @@ -PRG = cast5 -# cryptotest -OBJ = main-cast5-test.o debug.o uart.o serial-tools.o cast5.o -# main.o debug.o uart.o serial-tools.o sha256-asm.o xtea-asm.o arcfour-asm.o prng.o cast5.o -MCU_TARGET = atmega32 -OPTIMIZE = -Os +# Makefile for the AVR-Crypto-Lib project +# author: Daniel Otte +SHELL = sh -DEFS = -LIBS = +BLOCK_CIPHERS := +STREAM_CIPHERS := +HASHES := +MACS := +PRNGS := +ENCODINGS := +AUX := -# You should not have to change anything below here. +# we use the gnu make standard library +include gmsl +include avr-makefile.inc -CC = avr-gcc +#------------------------------------------------------------------------------- +# inclusion of make stubs +include mkfiles/*.mk -# Override is only needed by avr-lib build system. +#------------------------------------------------------------------------------- +ALGORITHMS = $(BLOCK_CIPHERS) $(STREAM_CIPHERS) $(HASHES) $(PRNGS) $(MACS) \ + $(ENCODINGS) $(AUX) +ALGORITHMS_OBJ = $(patsubst %,%_OBJ, $(ALGORITHMS)) +ALGORITHMS_TEST_BIN = $(patsubst %,%_TEST_BIN, $(ALGORITHMS)) -override CFLAGS = -Wall -Wstrict-prototypes $(OPTIMIZE) -mmcu=$(MCU_TARGET) -$(DEFS) -override LDFLAGS = -Wl,-Map,$(PRG).map -override ASFLAGS = -mmcu=$(MCU_TARGET) +#------------------------------------------------------------------------------- +# define binary object in $(BIN_DIR)$(ALGO)/ +define Assert_Template +$(1) = $(2) +endef -OBJCOPY = avr-objcopy -OBJDUMP = avr-objdump +$(foreach a, $(ALGORITHMS), $(eval $(call Assert_Template, \ + $(a)_BINOBJ, \ + $(addprefix $(BIN_DIR)$(call lc,$(a))/,$($(a)_OBJ)) \ +))) -all: $(PRG).elf lst text eeprom +$(foreach a, $(ALGORITHMS), $(eval $(call Assert_Template, \ + $(a)_TESTBINOBJ, \ + $(addprefix $(BIN_DIR)$(call lc,$(a))/$(TEST_DIR),$($(a)_TEST_BIN)) \ +))) -$(PRG).elf: $(OBJ) - $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS) -clean: - rm -rf *.o $(PRG).elf *.eps *.png *.pdf *.bak - rm -rf *.lst *.map $(EXTRA_CLEAN_FILES) +#$(foreach a, $(ALGORITHMS), \ +# $(if $(def $(a)_DIR), \ +# $(eval $(call Assert_Template, \ +# $(a)_DIR, \ +# . \ +# ) \ +# )) \ +#) +# +#$(foreach a, $(ALGORITHMS), \ +# $(if $(call seq($(strip($($(a)_DIR))),)), \ +# $(eval $(call Assert_Template, \ +# $(a)_DIR, \ +# . \ +# ) \ +# )) \ +#) + +#------------------------------------------------------------------------------- +# +### ifeq 'blafoo' '' +### $(error no source ($(2)) for $(1) in TargetSource_Template) +### endif + +define TargetSource_Template +$(1): $(2) + @echo "[cc]: $(1) <-- $(2)" + @mkdir -p $(dir $(1)) + @$(CC) $(CFLAGS_A) -I./$(strip $(3)) -c -o $(1) $(2) +endef + +$(foreach a, $(ALGORITHMS), \ + $(foreach b, $($(a)_OBJ), \ + $(eval $(call TargetSource_Template, \ + $(BIN_DIR)$(call lc, $(a))/$(b), \ + $(filter %.S %.c, $(wildcard $($(a)_DIR)$(notdir $(patsubst %.o,%,$(b))).*)), \ + $($(a)_DIR) \ + )) \ + ) \ +) + +$(foreach a, $(ALGORITHMS), \ + $(foreach b, $($(a)_TEST_BIN), \ + $(eval $(call TargetSource_Template, \ + $(BIN_DIR)$(call lc, $(a))/$(TEST_DIR)$(b), \ + $(if $(call sne,$(strip $(filter %.S %.c, $(wildcard $(TESTSRC_DIR)$(notdir $(patsubst %.o,%,$(b))).*))),), \ + $(filter %.S %.c, $(wildcard $(TESTSRC_DIR)$(notdir $(patsubst %.o,%,$(b))).*)), \ + $(filter %.S %.c, $(wildcard ./$(notdir $(patsubst %.o,%,$(b))).*))\ + ), \ + $($(a)_DIR) \ + )) \ + ) \ +) +#------------------------------------------------------------------------------- + +define MainTestElf_Template +$(1): $(2) $(3) + @echo "[ld]: $(1)" + @$(CC) $(CFLAGS_A) $(LDFLAGS)$(patsubst %.elf,%.map,$(1)) -o \ + $(1) \ + $(2) $(3) \ + $(LIBS) +endef + +$(foreach a, $(ALGORITHMS), \ + $(eval $(call MainTestElf_Template, \ + $(BIN_DIR)$(call lc, $(a))/$(TEST_DIR)main-$(call lc, $(a))-test.elf, \ + $($(a)_BINOBJ), \ + $($(a)_TESTBINOBJ) \ + )) \ +) -lst: $(PRG).lst +#------------------------------------------------------------------------------- -%.lst: %.elf - $(OBJDUMP) -h -S $< > $@ +all: $(foreach algo, $(ALGORITHMS), $($(algo)_BINOBJ)) -# Rules for building the .text rom images +#------------------------------------------------------------------------------- -text: hex bin srec +define TestBin_TEMPLATE +$(1)_TEST_BIN: $(2) +endef -hex: $(PRG).hex -bin: $(PRG).bin -srec: $(PRG).srec +$(foreach algo, $(ALGORITHMS), $(eval $(call TestBin_TEMPLATE, \ + $(algo), \ + $(BIN_DIR)$(call lc, $(algo))/$(TEST_DIR)main-$(call lc, $(algo))-test.elf \ +))) + +#------------------------------------------------------------------------------- %.hex: %.elf - $(OBJCOPY) -j .text -j .data -O ihex $< $@ + @echo "[objcopy]: $@" + @$(OBJCOPY) -j .text -j .data -O ihex $< $@ + +#------------------------------------------------------------------------------- + +define Flash_Template +$(1)_FLASH: $(2) + @echo "[flash]: $(2)" + @$(FLASHCMD)$(call first,$(2)) +endef + +$(foreach algo, $(ALGORITHMS), $(eval $(call Flash_Template, \ + $(algo), \ + $(BIN_DIR)$(call lc, $(algo))/$(TEST_DIR)main-$(call lc, $(algo))-test.hex \ +))) + +#------------------------------------------------------------------------------- + +.PHONY: tests +tests: $(foreach a, $(ALGORITHMS), $(a)_TEST_BIN) -%.srec: %.elf - $(OBJCOPY) -j .text -j .data -O srec $< $@ +#------------------------------------------------------------------------------- -%.bin: %.elf - $(OBJCOPY) -j .text -j .data -O binary $< $@ +define TestRun_Template +$(1)_TESTRUN: $(1)_FLASH + @echo "[test]: $(1)" + $(RUBY) $(GET_TEST) $(TESTPORT) $(TESTPORTBAUDR) 8 1 nessie $(TESTLOG_DIR)$(TESTPREFIX) $(2) +endef -# Rules for building the .eeprom rom images +$(foreach algo, $(ALGORITHMS),$(eval $(call TestRun_Template, $(algo), $(call lc,$(algo)) ))) -eeprom: ehex ebin esrec +all_testrun: $(foreach algo, $(ALGORITHMS), $(algo)_TESTRUN) -ehex: $(PRG)_eeprom.hex -ebin: $(PRG)_eeprom.bin -esrec: $(PRG)_eeprom.srec +#------------------------------------------------------------------------------- -%_eeprom.hex: %.elf - $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@ +define Obj_Template +$(1)_OBJ: $(2) +endef -%_eeprom.srec: %.elf - $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O srec $< $@ +$(foreach algo, $(ALGORITHMS), \ + $(eval $(call Obj_Template, \ + $(algo), \ + $($(algo)_BINOBJ)\ + ))\ +) -%_eeprom.bin: %.elf - $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O binary $< $@ +.PHONY: cores +cores: $(foreach algo, $(ALGORITHMS), $(algo)_OBJ) -# Every thing below here is used by avr-libc's build system and can be ignored -# by the casual user. +.PHONY: blockchiphers +blockciphers: $(foreach algo, $(BLOCK_CIPHERS), $(algo)_OBJ) -FIG2DEV = fig2dev -EXTRA_CLEAN_FILES = *.hex *.bin *.srec +.PHONY: streamchiphers +streamciphers: $(foreach algo, $(STREAM_CIPHERS), $(algo)_OBJ) + +.PHONY: hashes +hashes: $(foreach algo, $(HASHES), $(algo)_OBJ) + +.PHONY: macs +macs: $(foreach algo, $(MACS), $(algo)_OBJ) + +.PHONY: prngs +prngs: $(foreach algo, $(PRNGS), $(algo)_OBJ) + +.PHONY: encodings +encodings: $(foreach algo, $(ENCODINGS), $(algo)_OBJ) + +.PHONY: aux +aux: $(foreach algo, $(AUX), $(algo)_OBJ) + + +#------------------------------------------------------------------------------- + + +.PHONY: help +help: info +.PHONY: info +info: + @echo "infos on AVR-Crypto-lib:" + @echo " block ciphers:" + @echo " $(BLOCK_CIPHERS)" + @echo " stream ciphers:" + @echo " $(STREAM_CIPHERS)" + @echo " hash functions:" + @echo " $(HASHES)" + @echo " MAC functions:" + @echo " $(MACS)" + @echo " PRNG functions:" + @echo " $(PRNGS)" + @echo " encodings:" + @echo " $(ENCODINGS)" + @echo " targets:" + @echo " all - all algorithm cores" + @echo " cores - all algorithm cores" + @echo " listings - all algorithm core listings" + @echo " tests - all algorithm test programs" + @echo " stats - all algorithm size statistics" + @echo " blockciphers - all blockcipher cores" + @echo " streamciphers - all streamcipher cores" + @echo " hashes - all hash cores" + @echo " macs - all MAC cores" + @echo " prngs - all PRNG cores" + @echo " all_testrun - testrun all algorithms" + @echo " docu - build doxygen documentation" + @echo " clean - remove a lot of builded files" + @echo " depclean - also remove dependency files" + @echo " *_TEST_BIN - build test program" + @echo " *_TESTRUN - run nessie test" + @echo " *_OBJ - build algorithm core" + @echo " *_FLASH - flash test program" + @echo " *_LIST - build assembler listing" + + +#------------------------------------------------------------------------------- + +.PHONY: clean +clean: + rm -rf $(BIN_DIR)* -dox: eps png pdf +.PHONY: depclean +depclean: clean + rm $(DEP_DIR)*.d -eps: $(PRG).eps -png: $(PRG).png -pdf: $(PRG).pdf +#------------------------------------------------------------------------------- +# dependency inclusion +# -%.eps: %.fig - $(FIG2DEV) -L eps $< $@ +DEPS := $(wildcard $(DEP_DIR)*.d) -%.pdf: %.fig - $(FIG2DEV) -L pdf $< $@ +ifneq ($(DEPS),) +include $(DEPS) +endif -%.png: %.fig - $(FIG2DEV) -L png $< $@