From 4a783f24c578f245633ee7272934b53c0b8bd0be Mon Sep 17 00:00:00 2001 From: Jerome Forissier Date: Wed, 14 Aug 2024 18:18:16 +0200 Subject: [PATCH] kernel/link.mk: fix missing build number in version string on first build Fix an issue with the build number in the version string. While at it, factor out the duplicated code into mk/macros.mk. Before: $ rm -rf out/ $ make out/arm-plat-vexpress/core/version.o UPD out/arm-plat-vexpress/core/.buildcount GEN out/arm-plat-vexpress/core/version.o cat: out/arm-plat-vexpress/core/.buildcount: No such file or directory In addition to the error message, note the missing build number after the hash sign: $ strings out/arm-plat-vexpress/core/version.o | grep UTC 4.3.0-48-g9c97e7d52 (gcc version 11.4.0 (Ubuntu 11.4.0-1ubuntu1~22.04)) # Wed Aug 14 16:17:07 UTC 2024 arm After: $ rm -rf out/ $ make out/arm-plat-vexpress/core/version.o UPD out/arm-plat-vexpress/core/.buildcount GEN out/arm-plat-vexpress/core/version.o $ strings out/arm-plat-vexpress/core/version.o | grep UTC 4.3.0-48-g9c97e7d52-dev (gcc version 11.4.0 (Ubuntu 11.4.0-1ubuntu1~22.04)) #1 Wed Aug 14 16:17:24 UTC 2024 arm Signed-off-by: Jerome Forissier Reviewed-by: Jens Wiklander --- core/arch/arm/kernel/link.mk | 33 --------------------------------- core/arch/riscv/kernel/link.mk | 34 ---------------------------------- mk/macros.mk | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 67 deletions(-) diff --git a/core/arch/arm/kernel/link.mk b/core/arch/arm/kernel/link.mk index d1d52722442..11fe79d982c 100644 --- a/core/arch/arm/kernel/link.mk +++ b/core/arch/arm/kernel/link.mk @@ -140,39 +140,6 @@ $(link-script-pp): $(link-script) $(link-script-extra-deps) $(q)$(CPPcore) -P -MT $@ -MD -MF $(link-script-dep) \ $(link-script-cppflags) $< -o $@ -define update-buildcount - @$(cmd-echo-silent) ' UPD $(1)' - $(q)if [ ! -f $(1) ]; then \ - mkdir -p $(dir $(1)); \ - echo 1 >$(1); \ - else \ - expr 0`cat $(1)` + 1 >$(1); \ - fi -endef - -# filter-out to workaround objdump warning -version-o-cflags = $(filter-out -g3,$(CFLAGS) $(core-platform-cflags) \ - $(platform-cflags) $(cflagscore)) -# SOURCE_DATE_EPOCH defined for reproducible builds -ifneq ($(SOURCE_DATE_EPOCH),) -date-opts = -d @$(SOURCE_DATE_EPOCH) -endif -DATE_STR = `LC_ALL=C date -u $(date-opts)` -BUILD_COUNT_STR = `cat $(link-out-dir)/.buildcount` -CORE_CC_VERSION = `$(CCcore) -v 2>&1 | grep "version " | sed 's/ *$$//'` -define gen-version-o - $(call update-buildcount,$(link-out-dir)/.buildcount) - @$(cmd-echo-silent) ' GEN $(link-out-dir)/version.o' - $(q)cd $(link-out-dir) && \ - echo -e "const char core_v_str[] =" \ - "\"$(TEE_IMPL_VERSION) \"" \ - "\"($(CORE_CC_VERSION)) \"" \ - "\"#$(BUILD_COUNT_STR) \"" \ - "\"$(DATE_STR) \"" \ - "\"$(CFG_KERN_LINKER_ARCH)\";\n" \ - | $(CCcore) $(version-o-cflags) \ - -xc - -c -o version.o -endef $(link-out-dir)/version.o: $(call gen-version-o) diff --git a/core/arch/riscv/kernel/link.mk b/core/arch/riscv/kernel/link.mk index 6511586e2a5..d7b676cbf43 100644 --- a/core/arch/riscv/kernel/link.mk +++ b/core/arch/riscv/kernel/link.mk @@ -51,40 +51,6 @@ $(link-script-pp): $(link-script) $(link-script-extra-deps) $(q)$(CPPcore) -P -MT $@ -MD -MF $(link-script-dep) \ $(link-script-cppflags) $< -o $@ -define update-buildcount - @$(cmd-echo-silent) ' UPD $(1)' - $(q)if [ ! -f $(1) ]; then \ - mkdir -p $(dir $(1)); \ - echo 1 >$(1); \ - else \ - expr 0`cat $(1)` + 1 >$(1); \ - fi -endef - -# filter-out to workaround objdump warning -version-o-cflags = $(filter-out -g3,$(CFLAGS) $(core-platform-cflags) \ - $(platform-cflags) $(cflagscore)) -# SOURCE_DATE_EPOCH defined for reproducible builds -ifneq ($(SOURCE_DATE_EPOCH),) -date-opts = -d @$(SOURCE_DATE_EPOCH) -endif -DATE_STR = `LC_ALL=C date -u $(date-opts)` -BUILD_COUNT_STR = `cat $(link-out-dir)/.buildcount` -CORE_CC_VERSION = `$(CCcore) -v 2>&1 | grep "version " | sed 's/ *$$//'` -define gen-version-o - $(call update-buildcount,$(link-out-dir)/.buildcount) - @$(cmd-echo-silent) ' GEN $(link-out-dir)/version.o' - $(q)cd $(link-out-dir) && \ - echo -e "const char core_v_str[] =" \ - "\"$(TEE_IMPL_VERSION) \"" \ - "\"($(CORE_CC_VERSION)) \"" \ - "\"#$(BUILD_COUNT_STR) \"" \ - "\"$(DATE_STR) \"" \ - "\"$(CFG_KERN_LINKER_ARCH)\";\n" \ - | $(CCcore) $(version-o-cflags) \ - -xc - -c -o version.o -endef - $(link-out-dir)/version.o: $(call gen-version-o) diff --git a/mk/macros.mk b/mk/macros.mk index 277ecf2212c..93d13fb22b2 100644 --- a/mk/macros.mk +++ b/mk/macros.mk @@ -7,3 +7,37 @@ define mv-if-changed mv $1 $2; \ fi endef + +define update-buildcount + @$(cmd-echo-silent) ' UPD $(1)' + $(q)if [ ! -f $(1) ]; then \ + mkdir -p $(dir $(1)); \ + echo 1 >$(1); \ + else \ + expr 0`cat $(1)` + 1 >$(1); \ + fi +endef + +# filter-out to workaround objdump warning +version-o-cflags = $(filter-out -g3,$(CFLAGS) $(core-platform-cflags) \ + $(platform-cflags) $(cflagscore)) +# SOURCE_DATE_EPOCH defined for reproducible builds +ifneq ($(SOURCE_DATE_EPOCH),) +date-opts = -d @$(SOURCE_DATE_EPOCH) +endif +DATE_STR = `LC_ALL=C date -u $(date-opts)` +CORE_CC_VERSION = `$(CCcore) -v 2>&1 | grep "version " | sed 's/ *$$//'` +define gen-version-o + $(call update-buildcount,$(link-out-dir)/.buildcount) + @$(cmd-echo-silent) ' GEN $(link-out-dir)/version.o' + $(q)cd $(link-out-dir) && \ + BUILD_COUNT_STR=`cat .buildcount` && \ + echo -e "const char core_v_str[] =" \ + "\"$(TEE_IMPL_VERSION) \"" \ + "\"($(CORE_CC_VERSION)) \"" \ + "\"#$${BUILD_COUNT_STR} \"" \ + "\"$(DATE_STR) \"" \ + "\"$(CFG_KERN_LINKER_ARCH)\";\n" \ + | $(CCcore) $(version-o-cflags) \ + -xc - -c -o version.o +endef