X-Git-Url: https://git.cryptolib.org/?p=arm-crypto-lib.git;a=blobdiff_plain;f=Makefile;h=9570d5c6945fae0b6a0bc53fad22967bb38744f0;hp=7fd75c6ecadec696e1dc227306bfed6e2e3d466b;hb=7390f9235d6bc08b7fe34a5f43a04bd3b58f6ea6;hpb=f59c19cdaa2b415ea72a30083ee7df085c2a6ae9 diff --git a/Makefile b/Makefile index 7fd75c6..9570d5c 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ -# Makefile for the AVR-Crypto-Lib project +# Makefile for the ARM-Crypto-Lib project # -# This file is part of the AVR-Crypto-Lib. +# This file is part of the ARM-Crypto-Lib. # Copyright (C) 2010 Daniel Otte (daniel.otte@rub.de) # # This program is free software: you can redistribute it and/or modify @@ -27,27 +27,64 @@ ENCODINGS := SIGNATURE := PK_CIPHERS := AUX := +LIB_ALGOS := # we use the gnu make standard library include gmsl include arm-makefile.inc + +GLOBAL_INCDIR := ./ $(TESTSRC_DIR) + #------------------------------------------------------------------------------- # inclusion of make stubs -include mkfiles/*.mk + +include $(sort $(wildcard mkfiles/*.mk)) + +define Assert_Template +$(1) = $(2) +endef + +define Add_Template +$(1) += $(2) +endef #------------------------------------------------------------------------------- ALGORITHMS = $(BLOCK_CIPHERS) $(STREAM_CIPHERS) $(HASHES) $(PRNGS) $(MACS) \ $(ENCODINGS) $(SIGNATURE) $(PK_CIPHERS) $(AUX) ALGORITHMS_OBJ = $(patsubst %,%_OBJ, $(ALGORITHMS)) -ALGORITHMS_TEST_BIN = $(patsubst %,%_TEST_BIN, $(ALGORITHMS)) +ALGORITHMS_TESTBIN = $(patsubst %,%_TESTBIN, $(ALGORITHMS)) + +LIB_OBJECTS := +LIB_SRCDIRS := +LIB_DEFINES := + +$(foreach a, $(LIB_ALGOS), $(eval $(call Add_Template, \ + LIB_OBJECTS, \ + $($(a)_OBJ) \ +))) +LIB_OBJECTS := $(addprefix $(BIN_DIR)$(LIB_DIR), $(sort $(LIB_OBJECTS))) + +$(foreach a, $(LIB_ALGOS), $(eval $(call Add_Template, \ + LIB_SRCDIRS, \ + $($(a)_DIR) \ +))) + +$(foreach a, $(LIB_ALGOS), $(eval $(call Add_Template, \ + LIB_SRCDIRS, \ + $($(a)_INCDIR) \ +))) +LIB_SRCDIRS := $(sort $(LIB_SRCDIRS)) + +$(foreach a, $(LIB_ALGOS), $(eval $(call Add_Template, \ + LIB_DEFINES, \ + $($(a)_DEF) \ +))) +LIB_DEFINES := $(sort $(LIB_DEFINES)) + #------------------------------------------------------------------------------- # 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)) \ @@ -55,72 +92,77 @@ $(foreach a, $(ALGORITHMS), $(eval $(call Assert_Template, \ $(foreach a, $(ALGORITHMS), $(eval $(call Assert_Template, \ $(a)_TESTBINOBJ, \ - $(addprefix $(BIN_DIR)$(call lc,$(a))/$(TEST_DIR),$($(a)_TEST_BIN)) \ + $(addprefix $(BIN_DIR)$(call lc,$(a))/$(TEST_DIR),$($(a)_TESTBIN)) \ ))) -#$(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) + @$(CC) $(CFLAGS_A) $(addprefix -I./,$(3)) $(addprefix -D, $(4)) -c -o $(1) $(2) 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), \ - $(filter %.S %.c, $(wildcard $($(a)_DIR)$(notdir $(patsubst %.o,%,$(b))).*)), \ - $($(a)_DIR) \ + $(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)_TEST_BIN), \ + $(foreach b, $($(a)_TESTBIN), \ $(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) \ + $(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, $(LIB_OBJECTS), \ + $(eval $(call TargetSource_Template, \ + $(a), \ + $(call find_source_file, $(notdir $(a)), $(LIB_SRCDIRS) ),\ + $(LIB_SRCDIRS) $(GLOBAL_INCDIR), \ + $(LIB_DEFINES) \ + ) \ + ) \ +) + #------------------------------------------------------------------------------- define MainTestElf_Template $(1): $(2) $(3) @echo "[ld]: $(1)" + @mkdir -p $(dir $(1)) @$(CC) $(CFLAGS_A) $(LDFLAGS)$(patsubst %.elf,%.map,$(1)) -o \ $(1) \ $(2) $(3) \ - $(LIBS) + $(addprefix -l, $(LIBS)) endef $(foreach a, $(ALGORITHMS), \ @@ -138,7 +180,7 @@ all: $(foreach algo, $(ALGORITHMS), $($(algo)_BINOBJ)) #------------------------------------------------------------------------------- define TestBin_TEMPLATE -$(1)_TEST_BIN: $(2) +$(1)_TESTBIN: $(2) endef $(foreach algo, $(ALGORITHMS), $(eval $(call TestBin_TEMPLATE, \ @@ -148,6 +190,10 @@ $(foreach algo, $(ALGORITHMS), $(eval $(call TestBin_TEMPLATE, \ #------------------------------------------------------------------------------- +%.bin: %.elf + @echo "[objcopy]: $@" + @$(OBJCOPY) -O binary $< $@ + %.hex: %.elf @echo "[objcopy]: $@" @$(OBJCOPY) -j .text -j .data -O ihex $< $@ @@ -157,12 +203,12 @@ $(foreach algo, $(ALGORITHMS), $(eval $(call TestBin_TEMPLATE, \ define Flash_Template $(1)_FLASH: $(2) @echo "[flash]: $(2)" - @$(FLASHCMD)$(call first,$(2)) + @$(call 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.elf \ + $(BIN_DIR)$(call lc, $(algo))/$(TEST_DIR)main-$(call lc, $(algo))-test.bin \ ))) #------------------------------------------------------------------------------- @@ -179,6 +225,8 @@ $(foreach algo, $(ALGORITHMS), $(eval $(call Speed_Template, \ .PHONY: hash_speed hash_speed: $(foreach algo, $(HASHES), $(algo)_SPEED) +.PHONY: blockcipher_speed +blockcipher_speed: $(foreach algo, $(BLOCK_CIPHERS), $(algo)_SPEED) #------------------------------------------------------------------------------- @@ -195,10 +243,13 @@ $(foreach algo, $(ALGORITHMS), $(eval $(call Size_Template, \ .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)_TEST_BIN) +tests: $(foreach a, $(ALGORITHMS), $(a)_TESTBIN) #------------------------------------------------------------------------------- @@ -250,6 +301,31 @@ encodings: $(foreach algo, $(ENCODINGS), $(algo)_OBJ) aux: $(foreach algo, $(AUX), $(algo)_OBJ) + + +.PHONY: lib_info +lib_info: + @echo "LIB_ALGOS =" + @echo $(foreach a, $(LIB_ALGOS), '\t$(a)\n') + @echo "LIB_OBJECTS =" + @echo $(foreach a, $(LIB_OBJECTS), '\t$(a)\n') + @echo "LIB_SRCDIRS =" + @echo $(foreach a, $(LIB_SRCDIRS), '\t$(a)\n') + +$(BIN_DIR)$(LIB_DIR)$(LIB_NAME): $(LIB_OBJECTS) + @echo "[rm]: old $@" + @$(RM) -f $@ + @echo "[chmod]: " + @$(CHMOD) 644 $^ +# $(CHGRP) root $^ +# $(CHOWN) root $^ + @echo "[ar]: $@ <-- " + @$(AR) qc $@ $^ + +.PHONY: lib +lib: $(BIN_DIR)$(LIB_DIR)$(LIB_NAME) + + #------------------------------------------------------------------------------- @@ -257,7 +333,7 @@ aux: $(foreach algo, $(AUX), $(algo)_OBJ) help: info .PHONY: info info: - @echo "infos on AVR-Crypto-lib:" + @echo "infos on ARM-Crypto-lib:" @echo " block ciphers:" @echo " $(BLOCK_CIPHERS)" @echo " stream ciphers:" @@ -277,38 +353,43 @@ info: @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 " 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" + @echo " all - all algorithm cores" + @echo " cores - all algorithm cores" + @echo " lib - make library archive" + @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" #------------------------------------------------------------------------------- .PHONY: clean clean: - rm -rf $(BIN_DIR)* + @echo "[rm]: $(BIN_DIR)*" + @$(RM) -rf $(BIN_DIR)* .PHONY: depclean depclean: clean - rm $(DEP_DIR)*.d + @echo "[rm]: $(DEP_DIR)*.d" + @$(RM) -f $(DEP_DIR)*.d #------------------------------------------------------------------------------- # dependency inclusion