Skip to content

Commit

Permalink
kernel/link.mk: fix missing build number in version string on first b…
Browse files Browse the repository at this point in the history
…uild

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 <jerome.forissier@linaro.org>
  • Loading branch information
jforissier committed Aug 14, 2024
1 parent 9c97e7d commit 47c4021
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 67 deletions.
33 changes: 0 additions & 33 deletions core/arch/arm/kernel/link.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
34 changes: 0 additions & 34 deletions core/arch/riscv/kernel/link.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
34 changes: 34 additions & 0 deletions mk/macros.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 47c4021

Please sign in to comment.