]> granicus.if.org Git - esp-idf/commitdiff
build system: When embedding binary files, fix re-generating on partial builds
authorAngus Gratton <angus@espressif.com>
Wed, 16 Nov 2016 00:45:39 +0000 (11:45 +1100)
committerAngus Gratton <angus@espressif.com>
Wed, 16 Nov 2016 22:18:51 +0000 (09:18 +1100)
When embedding a generated file (ie secure boot public key data), the
file was being re-generated each time.

make/component_wrapper.mk

index 005c996712254809d8e15455a543b9681a266c0c..2c073af761f9c3652137e17f932000a9d5da2134 100644 (file)
@@ -189,18 +189,29 @@ OBJCOPY_EMBED_ARGS := --input binary --output elf32-xtensa-le --binary-architect
 # txt files are null-terminated before being embedded (otherwise
 # identical behaviour.)
 #
-# Files are temporarily copied to the build directory before objcopy,
-# because objcopy generates the symbol name from the full command line
-# path to the input file.
 define GenerateEmbedTarget
-$(1).$(2).o: $(call resolvepath,$(1),$(COMPONENT_PATH)) | $$(dir $(1))
+
+# copy the input file into the build dir (using a subdirectory
+# in case the file already exists elsewhere in the build dir)
+embed_bin/$$(notdir $(1)): $(call resolvepath,$(1),$(COMPONENT_PATH)) | embed_bin
+       cp $$< $$@
+
+embed_txt/$$(notdir $(1)): $(call resolvepath,$(1),$(COMPONENT_PATH)) | embed_txt
+       cp $$< $$@
+       echo -ne '\0' >> $$@  # null-terminate text files
+
+# messing about with the embed_X subdirectory then using 'cd' for objcopy is because the
+# full path passed to OBJCOPY makes it into the name of the symbols in the .o file
+$(1).$(2).o: embed_$(2)/$$(notdir $(1)) | $$(dir $(1))
        $(summary) EMBED $$@
-       $(if $(filter-out $$(notdir $$(abspath $$<)),$$(abspath $$(notdir $$<))), cp $$< $$(notdir $$<) )  # copy input file to build dir, unless already in build dir
-       $$(if $$(subst bin,,$(2)),echo -ne '\0' >> $$(notdir $$<) )  # trailing NUL byte on text output
-       $(OBJCOPY) $(OBJCOPY_EMBED_ARGS) $$(notdir $$<) $$@
-       rm $$(notdir $$<)
+       cd embed_$(2); $(OBJCOPY) $(OBJCOPY_EMBED_ARGS) $$(notdir $$<) ../$$@
+
+CLEAN_FILES += embed_$(2)/$$(notdir $(1))
 endef
 
+embed_txt embed_bin:
+       mkdir -p $@
+
 # generate targets to embed binary & text files
 $(foreach binfile,$(COMPONENT_EMBED_FILES), $(eval $(call GenerateEmbedTarget,$(binfile),bin)))