forked from Mirrors/opensbi
Makefile: Avoid repeated evaluation of shell commands
Recursively expanded variables (defined with '=') are expanded at evaluation time. These version information variables are evaluated inside a recipe as part of GENFLAGS. As a result, the shell commands are executed separately for each compiler invocation. Convert the version information variables to be simply expanded, so the shell commands are executed only once, at Makefile evaluation time. This speeds up the build by as much as 75%. A separate check is needed to maintain the behavior of preferring the value of OPENSBI_BUILD_TIME_STAMP from the environment. Signed-off-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Xiang W <wxjstz@126.com> Reviewed-by: Anup Patel <anup@brainfault.org> Link: https://lore.kernel.org/r/20250313035755.3796610-1-samuel.holland@sifive.com Signed-off-by: Anup Patel <anup@brainfault.org>
This commit is contained in:

committed by
Anup Patel

parent
aa40c53ce4
commit
2142618f12
14
Makefile
14
Makefile
@@ -94,11 +94,11 @@ OPENSBI_VERSION_MINOR=`grep "define OPENSBI_VERSION_MINOR" $(include_dir)/sbi/sb
|
|||||||
OPENSBI_VERSION_GIT=
|
OPENSBI_VERSION_GIT=
|
||||||
|
|
||||||
# Detect 'git' presence before issuing 'git' commands
|
# Detect 'git' presence before issuing 'git' commands
|
||||||
GIT_AVAIL=$(shell command -v git 2> /dev/null)
|
GIT_AVAIL := $(shell command -v git 2> /dev/null)
|
||||||
ifneq ($(GIT_AVAIL),)
|
ifneq ($(GIT_AVAIL),)
|
||||||
GIT_DIR=$(shell git rev-parse --git-dir 2> /dev/null)
|
GIT_DIR := $(shell git rev-parse --git-dir 2> /dev/null)
|
||||||
ifneq ($(GIT_DIR),)
|
ifneq ($(GIT_DIR),)
|
||||||
OPENSBI_VERSION_GIT=$(shell if [ -d $(GIT_DIR) ]; then git describe 2> /dev/null; fi)
|
OPENSBI_VERSION_GIT := $(shell if [ -d $(GIT_DIR) ]; then git describe 2> /dev/null; fi)
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
@@ -202,16 +202,18 @@ endif
|
|||||||
BUILD_INFO ?= n
|
BUILD_INFO ?= n
|
||||||
ifeq ($(BUILD_INFO),y)
|
ifeq ($(BUILD_INFO),y)
|
||||||
OPENSBI_BUILD_DATE_FMT = +%Y-%m-%d %H:%M:%S %z
|
OPENSBI_BUILD_DATE_FMT = +%Y-%m-%d %H:%M:%S %z
|
||||||
|
ifndef OPENSBI_BUILD_TIME_STAMP
|
||||||
ifdef SOURCE_DATE_EPOCH
|
ifdef SOURCE_DATE_EPOCH
|
||||||
OPENSBI_BUILD_TIME_STAMP ?= $(shell date -u -d "@$(SOURCE_DATE_EPOCH)" \
|
OPENSBI_BUILD_TIME_STAMP := $(shell date -u -d "@$(SOURCE_DATE_EPOCH)" \
|
||||||
"$(OPENSBI_BUILD_DATE_FMT)" 2>/dev/null || \
|
"$(OPENSBI_BUILD_DATE_FMT)" 2>/dev/null || \
|
||||||
date -u -r "$(SOURCE_DATE_EPOCH)" \
|
date -u -r "$(SOURCE_DATE_EPOCH)" \
|
||||||
"$(OPENSBI_BUILD_DATE_FMT)" 2>/dev/null || \
|
"$(OPENSBI_BUILD_DATE_FMT)" 2>/dev/null || \
|
||||||
date -u "$(OPENSBI_BUILD_DATE_FMT)")
|
date -u "$(OPENSBI_BUILD_DATE_FMT)")
|
||||||
else
|
else
|
||||||
OPENSBI_BUILD_TIME_STAMP ?= $(shell date "$(OPENSBI_BUILD_DATE_FMT)")
|
OPENSBI_BUILD_TIME_STAMP := $(shell date "$(OPENSBI_BUILD_DATE_FMT)")
|
||||||
endif
|
endif
|
||||||
OPENSBI_BUILD_COMPILER_VERSION=$(shell $(CC) -v 2>&1 | grep ' version ' | \
|
endif
|
||||||
|
OPENSBI_BUILD_COMPILER_VERSION := $(shell $(CC) -v 2>&1 | grep ' version ' | \
|
||||||
sed 's/[[:space:]]*$$//')
|
sed 's/[[:space:]]*$$//')
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user