summaryrefslogtreecommitdiff
path: root/Makefile
diff options
context:
space:
mode:
authorWei Fu <wefu@redhat.com>2021-09-30 13:11:20 +0300
committerAnup Patel <anup@brainfault.org>2021-10-20 12:40:52 +0300
commit422eda499cd6b69c0ca9f4cb06b3aceef17a3b27 (patch)
tree129d2f1b1d2d6ca462cfce58c2a1b8e5b33d60b4 /Makefile
parent67cbbcb100d321ec61f6424392562834083e9c98 (diff)
downloadopensbi-422eda499cd6b69c0ca9f4cb06b3aceef17a3b27.tar.xz
Makefile: Add build time and compiler info string
When we are doing opensbi development, we want to know the build time and compiler info for debug purpose. To enable this message, please add "BUILD_INFO=y", like: ``` make BUILD_INFO=y ``` NOTE: Using `BUILD_INFO=y` without specifying SOURCE_DATE_EPOCH will violate "reproducible builds". So it's ONLY for development and debug purpose, and should NOT be used in a product which follows "reproducible builds". Signed-off-by: Wei Fu <wefu@redhat.com> Reviewed-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile31
1 files changed, 31 insertions, 0 deletions
diff --git a/Makefile b/Makefile
index 16d9dca..8623c1c 100644
--- a/Makefile
+++ b/Makefile
@@ -150,6 +150,25 @@ endif
# Check whether the linker supports creating PIEs
OPENSBI_LD_PIE := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) $(USE_LD_FLAG) -fPIE -nostdlib -Wl,-pie -x c /dev/null -o /dev/null >/dev/null 2>&1 && echo y || echo n)
+# Build Info:
+# OPENSBI_BUILD_TIME_STAMP -- the compilation time stamp
+# OPENSBI_BUILD_COMPILER_VERSION -- the compiler version info
+BUILD_INFO ?= n
+ifeq ($(BUILD_INFO),y)
+OPENSBI_BUILD_DATE_FMT = +%Y-%m-%d %H:%M:%S %z
+ifdef SOURCE_DATE_EPOCH
+ OPENSBI_BUILD_TIME_STAMP ?= $(shell date -u -d "@$(SOURCE_DATE_EPOCH)" \
+ "$(OPENSBI_BUILD_DATE_FMT)" 2>/dev/null || \
+ date -u -r "$(SOURCE_DATE_EPOCH)" \
+ "$(OPENSBI_BUILD_DATE_FMT)" 2>/dev/null || \
+ date -u "$(OPENSBI_BUILD_DATE_FMT)")
+else
+ OPENSBI_BUILD_TIME_STAMP ?= $(shell date "$(OPENSBI_BUILD_DATE_FMT)")
+endif
+OPENSBI_BUILD_COMPILER_VERSION=$(shell $(CC) -v 2>&1 | grep ' version ' | \
+ sed 's/[[:space:]]*$$//')
+endif
+
# Setup list of objects.mk files
ifdef PLATFORM
platform-object-mks=$(shell if [ -d $(platform_src_dir)/ ]; then find $(platform_src_dir) -iname "objects.mk" | sort -r; fi)
@@ -247,6 +266,10 @@ GENFLAGS += -I$(include_dir)
ifneq ($(OPENSBI_VERSION_GIT),)
GENFLAGS += -DOPENSBI_VERSION_GIT="\"$(OPENSBI_VERSION_GIT)\""
endif
+ifeq ($(BUILD_INFO),y)
+GENFLAGS += -DOPENSBI_BUILD_TIME_STAMP="\"$(OPENSBI_BUILD_TIME_STAMP)\""
+GENFLAGS += -DOPENSBI_BUILD_COMPILER_VERSION="\"$(OPENSBI_BUILD_COMPILER_VERSION)\""
+endif
GENFLAGS += $(libsbiutils-genflags-y)
GENFLAGS += $(platform-genflags-y)
GENFLAGS += $(firmware-genflags-y)
@@ -398,6 +421,11 @@ $(build_dir)/%.dep: $(src_dir)/%.c
$(build_dir)/%.o: $(src_dir)/%.c
$(call compile_cc,$@,$<)
+ifeq ($(BUILD_INFO),y)
+$(build_dir)/lib/sbi/sbi_init.o: $(libsbi_dir)/sbi_init.c FORCE
+ $(call compile_cc,$@,$<)
+endif
+
$(build_dir)/%.dep: $(src_dir)/%.S
$(call compile_as_dep,$@,$<)
@@ -551,3 +579,6 @@ ifeq ($(install_root_dir),$(install_root_dir_default)/usr)
$(if $(V), @echo " RM $(install_root_dir_default)")
$(CMD_PREFIX)rm -rf $(install_root_dir_default)
endif
+
+.PHONY: FORCE
+FORCE: