diff --git a/Makefile.include b/Makefile.include index 1072231bd6..d3b2eb8d7c 100644 --- a/Makefile.include +++ b/Makefile.include @@ -350,20 +350,8 @@ include $(RIOTMAKE)/cflags.inc.mk # Include VERSION for releases -include $(RIOTBASE)/VERSION -# make the RIOT version available to the program -ifeq ($(origin RIOT_VERSION), undefined) - GIT_STRING := $(shell git --git-dir="$(RIOTBASE)/.git" describe --always --abbrev=4 2> /dev/null) - ifneq (,$(GIT_STRING)) - GIT_BRANCH := $(shell git --git-dir="$(RIOTBASE)/.git" rev-parse --abbrev-ref HEAD) - ifeq ($(strip $(GIT_BRANCH)),master) - RIOT_VERSION := $(GIT_STRING) - else - RIOT_VERSION := $(GIT_STRING)-$(GIT_BRANCH) - endif - else - RIOT_VERSION := 'UNKNOWN (builddir: $(RIOTBASE))' - endif -endif +include $(RIOTMAKE)/git_version.inc.mk +RIOT_VERSION ?= $(or $(GIT_VERSION),'UNKNOWN (builddir: $(RIOTBASE))') # Set module by prepending APPLICATION name with 'application_'. # It prevents conflict with application and modules with the same name. @@ -733,12 +721,14 @@ $(RIOTBUILD_CONFIG_HEADER_C): FORCE $(Q)'$(RIOTTOOLS)/genconfigheader/genconfigheader.sh' $(CFLAGS_WITH_MACROS) \ | '$(LAZYSPONGE)' $(LAZYSPONGE_FLAGS) '$@' -CFLAGS_WITH_MACROS := $(CFLAGS) +# Immediate evaluation but keep CLAGS_WITH_MACROS deferred +_CFLAGS := $(CFLAGS) +CFLAGS_WITH_MACROS = $(_CFLAGS) ifneq (,$(RIOT_VERSION_OVERRIDE)) -export CFLAGS_WITH_MACROS += -DRIOT_VERSION=\"$(RIOT_VERSION_OVERRIDE)\" + CFLAGS_WITH_MACROS += -DRIOT_VERSION=\"$(RIOT_VERSION_OVERRIDE)\" else -export CFLAGS_WITH_MACROS += -DRIOT_VERSION=\"$(RIOT_VERSION)\" + CFLAGS_WITH_MACROS += -DRIOT_VERSION=\"$(RIOT_VERSION)\" endif CFLAGS := $(patsubst -D%,,$(CFLAGS)) diff --git a/makefiles/git_version.inc.mk b/makefiles/git_version.inc.mk new file mode 100644 index 0000000000..03a2194564 --- /dev/null +++ b/makefiles/git_version.inc.mk @@ -0,0 +1,11 @@ +# GIT_VERSION is git description + branch name if it not master +# Empty when not in a git repository +# +# 2019.10-devel-97-g3bcc72 +# 2019.10-devel-97-g3bcc72-pr/git_version + +GIT_DESCRIBE = $(call memoized,GIT_DESCRIBE,$(shell git --git-dir="$(RIOTBASE)/.git" describe --always --abbrev=4 2> /dev/null)) +GIT_BRANCH = $(call memoized,GIT_BRANCH,$(shell git --git-dir="$(RIOTBASE)/.git" rev-parse --abbrev-ref HEAD)) +_GIT_VERSION = $(GIT_DESCRIBE)$(addprefix -,$(GIT_BRANCH:master=)) + +GIT_VERSION ?= $(if $(GIT_DESCRIBE),$(_GIT_VERSION))