X-Git-Url: https://git.cryptolib.org/?a=blobdiff_plain;f=Makefile;h=d9e8d033bfb74800e8e4fd97e04acce0a364fba2;hb=9023000e91b6065961051339700526c98f8438e8;hp=09457bec100e72b4547c7a8b9fa95e8e7f118c80;hpb=96ebafd201c9e8441c7677577b24aa402c1defc6;p=avr-crypto-lib.git diff --git a/Makefile b/Makefile index 09457be..d9e8d03 100644 --- a/Makefile +++ b/Makefile @@ -1,237 +1,371 @@ -# Makefile for the micro-crypt project -# author: Daniel Otte - -BLOCK_CIPHERS := -STREAM_CIPHERS := +# Makefile for the AVR-Crypto-Lib project +# +# This file is part of the AVR-Crypto-Lib. +# Copyright (C) 2010 Daniel Otte (daniel.otte@rub.de) +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +SHELL = sh + +BLOCK_CIPHERS := +STREAM_CIPHERS := HASHES := MACS := -PRNGS := +PRNGS := +ENCODINGS := +SIGNATURE := +PK_CIPHERS := +AUX := + # we use the gnu make standard library include gmsl include avr-makefile.inc -include *.mk -ALGORITHMS = $(BLOCK_CIPHERS) $(STREAM_CIPHERS) $(HASHES) $(PRNGS) $(MACS) + +GLOBAL_INCDIR := ./ $(TESTSRC_DIR) + +#------------------------------------------------------------------------------- +# inclusion of make stubs +include mkfiles/0*.mk +include mkfiles/*.mk + +#------------------------------------------------------------------------------- +ALGORITHMS = $(BLOCK_CIPHERS) $(STREAM_CIPHERS) $(HASHES) $(PRNGS) $(MACS) \ + $(ENCODINGS) $(SIGNATURE) $(PK_CIPHERS) $(AUX) ALGORITHMS_OBJ = $(patsubst %,%_OBJ, $(ALGORITHMS)) -ALGORITHMS_OBJ_IMM = $(foreach a, $(ALGORITHMS_OBJ), $($(a))) -ALGORITHMS_TEST_BIN = $(patsubst %,%_TEST_BIN, $(ALGORITHMS)) -ALGORITHMS_TEST_BIN_MAIN = $(foreach a, $(ALGORITHMS_TEST_BIN), $(firstword $($(a)))) -ALGORITHMS_TEST_BIN_MAIN_ELF = $(patsubst %.o, %.elf, $(ALGORITHMS_TEST_BIN_MAIN)) -ALGORITHMS_TEST_BIN_MAIN_HEX = $(patsubst %.o, %.hex, $(ALGORITHMS_TEST_BIN_MAIN)) +ALGORITHMS_TESTBIN = $(patsubst %,%_TESTBIN, $(ALGORITHMS)) + +#------------------------------------------------------------------------------- +# define binary object in $(BIN_DIR)$(ALGO)/ +define Assert_Template +$(1) = $(2) +endef + +$(foreach a, $(ALGORITHMS), $(eval $(call Assert_Template, \ + $(a)_BINOBJ, \ + $(addprefix $(BIN_DIR)$(call lc,$(a))/,$($(a)_OBJ)) \ +))) -ALGORITHMS_TEST_BIN_IMM = $(foreach a, $(ALGORITHMS_TEST_BIN), $($(a))) -ALGORITHMS_NESSIE_TEST = $(patsubst %,%_NESSIE_TEST, $(ALGORITHMS)) -ALGORITHMS_PERFORMANCE_TEST = $(patsubst %,%_PERORMANCE_TEST, $(ALGORITHMS)) +$(foreach a, $(ALGORITHMS), $(eval $(call Assert_Template, \ + $(a)_TESTBINOBJ, \ + $(addprefix $(BIN_DIR)$(call lc,$(a))/$(TEST_DIR),$($(a)_TESTBIN)) \ +))) -ALGORITHMS_LC = $(call lc,$(ALGORITHMS)) -PRG = remove_me #------------------------------------------------------------------------------- -define BLA_TEMPLATE2 -$(2): $(3) - @echo "[gcc]: $$@" -# echo $$^ - @$(CC) $(CFLAGS) $(LDFLAGS)$(patsubst %.elf,%.map,$(2)) -o \ - $(2) \ - $(3) \ - $(LIBS) +define TargetSource_Template +$(1): $(2) + @echo "[cc]: $(1) <-- $(2)" + @mkdir -p $(dir $(1)) + @$(CC) $(CFLAGS_A) $(addprefix -I./,$(3)) $(addprefix -D, $(4)) -c -o $(1) $(2) endef -$(foreach algo, $(ALGORITHMS), $(eval $(call BLA_TEMPLATE2, $(algo), $(patsubst %.o,%.elf,$(firstword $($(algo)_TEST_BIN))), $($(algo)_TEST_BIN) ))) -#------------------------------------------------------------------------------- -.PHONY: info -info: - @echo "infos on micro-crypt:" - @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 " LC functions:" -# @echo " $(ALGORITHMS_LC)" - -# echo $(ALGORITHMS_TEST_BIN_MAIN) -# echo $(ALGORITHMS) -# echo $(firstword $(XTEA_TEST_BIN)) -# echo $(patsubst %.o,%.elf,$(firstword $(XTEA_TEST_BIN))) -# echo $(ALGORITHMS_OBJ) -# echo $(ALGORITHMS_OBJ_IMM) -# echo $(ALGORITHMS_TEST_BIN) -# echo $(ALGORITHMS_NESSIE_TEST) -# echo $(ALGORITHMS_PERFORMANCE_TEST) - -%.o: %.c - @echo "[gcc]: $@" - @$(CC) $(CFLAGS) -c -o $@ $< - -%.o: %.S - @echo "[as] : $@" - @$(CC) $(ASFLAGS) -c -o $@ $< +define TargetSourceList_Template +$(1): $(2) + @echo "[cc]: $(1) <-- $(2)" + @mkdir -p $(dir $(1)) + @$(CC) $(CFLAGS_A) $(addprefix -I./,$(3)) $(addprefix -D, $(4)) $(LIST_OPT) -c -o /dev/null $(2) > $(1) +endef +# ---------------------------------------------------------------------------- +# Function: find_source_file +# Arguments: 1: name of the binary file (.o extension) to search +# 2: list of directorys to search for file +# Returns: Returns paths to source file (mathing the pattern in +# $(SOURCE_PATTERN) +# ---------------------------------------------------------------------------- +SOURCE_PATTERN := %.S %.c +find_source_file = $(firstword $(foreach d, $(2), \ + $(filter $(SOURCE_PATTERN), \ + $(wildcard $(d)$(notdir $(patsubst %.o,%,$1)).*) \ + ) \ + ) ) + + +$(foreach a, $(ALGORITHMS), \ + $(foreach b, $($(a)_OBJ), \ + $(eval $(call TargetSource_Template, \ + $(BIN_DIR)$(call lc, $(a))/$(b), \ + $(call find_source_file, $(b), $($(a)_DIR) $($(a)_INCDIR) $(GLOBAL_INCDIR) ),\ + $($(a)_DIR) $($(a)_INCDIR) $(GLOBAL_INCDIR), \ + $($(a)_DEF), \ + )) \ + ) \ +) + +$(foreach a, $(ALGORITHMS), \ + $(foreach b, $($(a)_TESTBIN), \ + $(eval $(call TargetSource_Template, \ + $(BIN_DIR)$(call lc, $(a))/$(TEST_DIR)$(b), \ + $(call find_source_file, $(b), $($(a)_DIR) $($(a)_INCDIR) $(GLOBAL_INCDIR) ),\ + $($(a)_DIR) $($(a)_INCDIR) $(GLOBAL_INCDIR), \ + $($(a)_DEF) \ + )) \ + ) \ +) + + +$(foreach a, $(ALGORITHMS), \ + $(foreach b, $($(a)_OBJ), \ + $(eval $(call TargetSourceList_Template, \ + $(LIST_DIR)$(call lc, $(a))/$(patsubst %.o,%.s,$(b)), \ + $(call find_source_file, $(b), $($(a)_DIR) $($(a)_INCDIR) $(GLOBAL_INCDIR) ),\ + $($(a)_DIR) $($(a)_INCDIR) $(GLOBAL_INCDIR), \ + $($(a)_DEF), \ + )) \ + ) \ +) -.PHONY: cores -cores: $(ALGORITHMS_OBJ) - -.PHONY: blockciphers -blockciphers: $(patsubst %, %_OBJ, $(BLOCK_CIPHERS)) - -.PHONY: streamciphers -streamciphers: $(patsubst %, %_OBJ, $(STREAM_CIPHERS)) - -.PHONY: hashes -hashes: $(patsubst %, %_OBJ, $(HASHES)) - -.PHONY: macs -macs: $(patsubst %, %_OBJ, $(MACS)) - -.PHONY: prngs -prngs: $(patsubst %, %_OBJ, $(PRNGS)) - -tests: $(ALGORITHMS_TEST_BIN) \ - $(ALGORITHMS_TEST_BIN_MAIN_ELF) \ - $(ALGORITHMS_TEST_BIN_MAIN_HEX) - -.PHONY: stats -stats: $(SIZESTAT_FILE) -#$(patsubst %, %_size.txt, $(ALGORITHMS_LC)) - - -$(SIZESTAT_FILE): $(patsubst %, %_size.txt, $(ALGORITHMS_LC)) - $(RUBY) sumsize.rb $^ > $(SIZESTAT_FILE) - @cat $(SIZESTAT_FILE) -#------------------------------------------------------------------------------- - -define OBJ_TEMPLATE -$(1)_OBJ: $(2) -# @echo " ALGO: $(1)" -# @echo " REQ: $(2)" +#------------------------------------------------------------------------------- + +define MainTestElf_Template +$(1): $(2) $(3) + @mkdir -p $(dir $(1)) + @echo "[ld]: $(1)" + @$(CC) $(CFLAGS_A) $(LDFLAGS)$(patsubst %.elf,%.map,$(1)) -o \ + $(1) \ + $(2) $(3) \ + $(LIBS) endef -$(foreach algo, $(ALGORITHMS), $(eval $(call OBJ_TEMPLATE, $(algo), $($(algo)_OBJ)))) +$(foreach a, $(ALGORITHMS), \ + $(eval $(call MainTestElf_Template, \ + $(BIN_DIR)$(call lc, $(a))/$(TEST_DIR)main-$(call lc, $(a))-test.elf, \ + $($(a)_BINOBJ), \ + $($(a)_TESTBINOBJ) \ + )) \ +) #------------------------------------------------------------------------------- -$(BLOCK_CIPHERS_OBJ): $(patsubst %,%_OBJ, $(BLOCK_CIPHERS)) -$(STREAM_CIPHERS_OBJ): $(patsubst %,%_OBJ, $(STREAM_CIPHERS)) -$(HASHES_OBJ): $(patsubst %,%_OBJ, $(HASHES)) -$(PRNGS_OBJ): $(patsubst %,%_OBJ, $(PRNGS)) -$(MACS_OBJ): $(patsubst %,%_OBJ, $(MACS)) +all: $(foreach algo, $(ALGORITHMS), $($(algo)_BINOBJ)) -$(ALGORITHMS_TEST_BIN): $(ALGORITHMS_TEST_BIN_IMM) +#------------------------------------------------------------------------------- + +define TestBin_TEMPLATE +$(1)_TESTBIN: $(2) +endef + +$(foreach algo, $(ALGORITHMS), $(eval $(call TestBin_TEMPLATE, \ + $(algo), \ + $(BIN_DIR)$(call lc, $(algo))/$(TEST_DIR)main-$(call lc, $(algo))-test.elf \ +))) #------------------------------------------------------------------------------- -define SIZE_TEMPLATE -$(1)_size.txt: $(2) - @echo "[size]: $(1)_size.txt" - @$(SIZE) $(2) > $(1)_size.txt +define Listing_TEMPLATE +$(1)_LIST: $(2) endef -$(foreach algo, $(ALGORITHMS), $(eval $(call SIZE_TEMPLATE, $(call lc,$(algo)), $($(algo)_OBJ)))) +$(foreach algo, $(ALGORITHMS), $(eval $(call Listing_TEMPLATE, \ + $(algo), \ + $(foreach obj,$($(algo)_OBJ), $(LIST_DIR)$(call lc, $(algo))/$(obj:.o=.s)) \ +))) + +#------------------------------------------------------------------------------- + +%.hex: %.elf + @echo "[objcopy]: $@" + @$(OBJCOPY) -j .text -j .data -O ihex $< $@ #------------------------------------------------------------------------------- -define FLASH_TEMPLATE +define Flash_Template $(1)_FLASH: $(2) @echo "[flash]: $(2)" @$(FLASHCMD)$(call first,$(2)) endef -$(foreach algo, $(ALGORITHMS),$(eval $(call FLASH_TEMPLATE, $(algo), \ - $(patsubst %.o,%.hex,$(firstword $($(algo)_TEST_BIN)))) )) +$(foreach algo, $(ALGORITHMS), $(eval $(call Flash_Template, \ + $(algo), \ + $(BIN_DIR)$(call lc, $(algo))/$(TEST_DIR)main-$(call lc, $(algo))-test.hex \ +))) #------------------------------------------------------------------------------- - -.PHONY: all -all: $(foreach algo, $(ALGORITHMS), $(algo)_OBJ) -#all: $(PRG).elf lst text eeprom +define Speed_Template +$(1)_SPEED: $(1)_FLASH + @$(RUBY) $(SPEEDTOOL) -c $(SPEEDCMD) -t $(SPEEDLOG_DIR) -a $(call lc, $(1)) +endef -.PHONY: clean -clean: - rm -rf *.o *.elf *.eps *.png *.pdf *.bak *_size.txt - rm -rf *.lst *.map $(EXTRA_CLEAN_FILES) $(SIZESTAT_FILE) -xclean: clean - rm -rf *.d +$(foreach algo, $(ALGORITHMS), $(eval $(call Speed_Template, \ + $(algo), $(algo) \ +))) -flash: - $(ERASECMD) - $(FLASHCMD) - -lst: $(PRG).lst +.PHONY: hash_speed +hash_speed: $(foreach algo, $(HASHES), $(algo)_SPEED) -%.lst: %.elf - $(OBJDUMP) -h -S $< > $@ +.PHONY: blockcipher_speed +blockcipher_speed: $(foreach algo, $(BLOCK_CIPHERS), $(algo)_SPEED) +#------------------------------------------------------------------------------- -# Rules for building the .text rom images -text: hex bin srec +define Size_Template +$(1)_SIZE: $(2) + @echo "[size] $(1)" + $(SIZE) $(2) > $(strip $(SIZE_DIR))$(strip $(call lc, $(1))).size +endef -hex: $(PRG).hex -bin: $(PRG).bin -srec: $(PRG).srec +$(foreach algo, $(ALGORITHMS), $(eval $(call Size_Template, \ + $(strip $(algo)), $($(algo)_BINOBJ) \ +))) -%.hex: %.elf - $(OBJCOPY) -j .text -j .data -O ihex $< $@ +.PHONY: hash_size +hash_size: $(foreach algo, $(HASHES), $(algo)_SIZE) + +.PHONY: blockcipher_size +blockcipher_size: $(foreach algo, $(BLOCK_CIPHERS), $(algo)_SIZE) + +#------------------------------------------------------------------------------- + +.PHONY: tests +tests: $(foreach a, $(ALGORITHMS), $(a)_TESTBIN) + +#------------------------------------------------------------------------------- + +define TestRun_Template +$(1)_TESTRUN: $(1)_FLASH + @echo "[reset]" + @sleep 3 + @$(RESETCMD) + @sleep 1 + @echo "[test]: $(1)" + $(RUBY) $(GET_TEST) $(TESTPORT) $(TESTPORTBAUDR) 8 1 nessie $(TESTLOG_DIR)$(TESTPREFIX) $(2) +endef + +$(foreach algo, $(ALGORITHMS),$(eval $(call TestRun_Template, $(algo), $(call lc,$(algo)) ))) + +all_testrun: $(foreach algo, $(ALGORITHMS), $(algo)_TESTRUN) + +#------------------------------------------------------------------------------- + +define Obj_Template +$(1)_OBJ: $(2) +endef + +$(foreach algo, $(ALGORITHMS), \ + $(eval $(call Obj_Template, \ + $(algo), \ + $($(algo)_BINOBJ)\ + ))\ +) + +.PHONY: all +all: cores -%.srec: %.elf - $(OBJCOPY) -j .text -j .data -O srec $< $@ +.PHONY: reset +reset: + $(RESETCMD) -%.bin: %.elf - $(OBJCOPY) -j .text -j .data -O binary $< $@ +.PHONY: cores +cores: $(foreach algo, $(ALGORITHMS), $(algo)_OBJ) -# Rules for building the .eeprom rom images +.PHONY: blockchiphers +blockciphers: $(foreach algo, $(BLOCK_CIPHERS), $(algo)_OBJ) -eeprom: ehex ebin esrec +.PHONY: streamchiphers +streamciphers: $(foreach algo, $(STREAM_CIPHERS), $(algo)_OBJ) -ehex: $(PRG)_eeprom.hex -ebin: $(PRG)_eeprom.bin -esrec: $(PRG)_eeprom.srec +.PHONY: hashes +hashes: $(foreach algo, $(HASHES), $(algo)_OBJ) -%_eeprom.hex: %.elf - $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@ +.PHONY: macs +macs: $(foreach algo, $(MACS), $(algo)_OBJ) -%_eeprom.srec: %.elf - $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O srec $< $@ +.PHONY: prngs +prngs: $(foreach algo, $(PRNGS), $(algo)_OBJ) -%_eeprom.bin: %.elf - $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O binary $< $@ - - -# Every thing below here is used by avr-libc's build system and can be ignored -# by the casual user. +.PHONY: encodings +encodings: $(foreach algo, $(ENCODINGS), $(algo)_OBJ) -FIG2DEV = fig2dev -EXTRA_CLEAN_FILES = *.hex *.bin *.srec +.PHONY: aux +aux: $(foreach algo, $(AUX), $(algo)_OBJ) -dox: eps png pdf -eps: $(PRG).eps -png: $(PRG).png -pdf: $(PRG).pdf +#------------------------------------------------------------------------------- -%.eps: %.fig - $(FIG2DEV) -L eps $< $@ +.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 " signature functions:" + @echo " $(SIGNATURE)" + @echo " public key ciphers:" + @echo " $(PK_CIPHERS)" + @echo " encodings:" + @echo " $(ENCODINGS)" + @echo " auxiliary functions:" + @echo " $(AUX)" + @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 " hash_size - measure size of all hash functions" + @echo " hash_speed - measure performance of all hash functions" + @echo " blockcipher_size - measure size of all blockciphers" + @echo " blockcipher_speed - measure performance of all blockciphers" + @echo " docu - build doxygen documentation" + @echo " clean - remove a lot of builded files" + @echo " depclean - also remove dependency files" + @echo " *_TESTBIN - build test program" + @echo " *_TESTRUN - run nessie test" + @echo " *_OBJ - build algorithm core" + @echo " *_FLASH - flash test program" + @echo " *_LIST - build assembler listing" + + +#------------------------------------------------------------------------------- -%.pdf: %.fig - $(FIG2DEV) -L pdf $< $@ +.PHONY: clean +clean: + rm -rf $(BIN_DIR)* -%.png: %.fig - $(FIG2DEV) -L png $< $@ +.PHONY: depclean +depclean: clean + rm -f $(DEP_DIR)*.d + +#------------------------------------------------------------------------------- +# dependency inclusion +# +DEPS := $(wildcard $(DEP_DIR)*.d) -DEPS := $(wildcard *.d) ifneq ($(DEPS),) include $(DEPS) endif