Add short git version if building non-release build, also if git command is not available or if .git is not there (so building out of other sources) (nw)

This commit is contained in:
Miodrag Milanovic 2016-04-16 10:19:59 +02:00
parent 942472ea22
commit 6bb33aa52c
3 changed files with 38 additions and 1 deletions

View File

@ -823,10 +823,12 @@ ifeq (posix,$(SHELLTYPE))
GCC_VERSION := $(shell $(TOOLCHAIN)$(subst @,,$(CC)) -dumpversion 2> /dev/null)
CLANG_VERSION := $(shell $(TOOLCHAIN)$(subst @,,$(CC)) --version 2> /dev/null| head -n 1 | grep clang | sed "s/^.*[^0-9]\([0-9]*\.[0-9]*\.[0-9]*\).*$$/\1/" | head -n 1)
PYTHON_AVAILABLE := $(shell $(PYTHON) --version > /dev/null 2>&1 && echo python)
GIT_AVAILABLE := $(shell git --version > /dev/null 2>&1 && echo git)
else
GCC_VERSION := $(shell $(TOOLCHAIN)$(subst @,,$(CC)) -dumpversion 2> NUL)
CLANG_VERSION := $(shell $(TOOLCHAIN)$(subst @,,$(CC)) --version 2> NUL| head -n 1 | grep clang | sed "s/^.*[^0-9]\([0-9]*\.[0-9]*\.[0-9]*\).*$$/\1/" | head -n 1)
PYTHON_AVAILABLE := $(shell $(PYTHON) --version > NUL 2>&1 && echo python)
GIT_AVAILABLE := $(shell git --version > NUL 2>&1 && echo git)
endif
ifdef MSBUILD
MSBUILD_PARAMS := /v:minimal /m:$(NUMBER_OF_PROCESSORS)
@ -847,6 +849,7 @@ ifneq ($(OS),solaris)
CLANG_VERSION := $(shell $(TOOLCHAIN)$(subst @,,$(CC)) --version 2> /dev/null | head -n 1 | grep -e 'version [0-9]\.[0-9]\(\.[0-9]\)\?' -o | grep -e '[0-9]\.[0-9]\(\.[0-9]\)\?' -o | tail -n 1)
endif
PYTHON_AVAILABLE := $(shell $(PYTHON) --version > /dev/null 2>&1 && echo python)
GIT_AVAILABLE := $(shell git --version > /dev/null 2>&1 && echo git)
endif
ifeq ($(CLANG_VERSION),)
@ -866,6 +869,13 @@ ifneq ($(PYTHON_AVAILABLE),python)
$(error Python is not available in path)
endif
ifneq ($(GIT_AVAILABLE),git)
PARAMS += --IGNORE_GIT='1'
endif
ifeq ($(wildcard .git/*),)
PARAMS += --IGNORE_GIT='1'
endif
GENIE := 3rdparty/genie/bin/$(GENIEOS)/genie$(EXE)
ifeq ($(TARGET),$(SUBTARGET))

View File

@ -348,6 +348,15 @@ newoption {
}
}
newoption {
trigger = "IGNORE_GIT",
description = "Ignore usage of git command in build process",
allowed = {
{ "0", "Do not ignore" },
{ "1", "Ingore" },
},
}
newoption {
trigger = "SOURCES",
description = "List of sources to compile.",
@ -520,6 +529,18 @@ if (_OPTIONS["SOURCES"] == nil) then
dofile (path.join("target", _OPTIONS["target"],_OPTIONS["subtarget"] .. ".lua"))
end
if _OPTIONS["IGNORE_GIT"]~="1" then
GIT_VERSION = backtick( "git rev-parse --short HEAD" )
GIT_VERSION_RELEASE = backtick( "git rev-list --tags --max-count=1" )
GIT_VERSION_LASTONE = backtick( "git rev-list --max-count=1 HEAD" )
if (GIT_VERSION_RELEASE ~= GIT_VERSION_LASTONE) then
defines {
"GIT_VERSION=" .. GIT_VERSION,
}
end
end
configuration { "gmake" }
flags {
"SingleOutputDir",

View File

@ -13,4 +13,10 @@
extern const char bare_build_version[];
extern const char build_version[];
const char bare_build_version[] = BARE_BUILD_VERSION;
const char build_version[] = BARE_BUILD_VERSION " (" __DATE__")";
#if defined(GIT_VERSION)
#define VERSION_TO_STRING(s) XVERSION_TO_STRING(s)
#define XVERSION_TO_STRING(ver) #ver
const char build_version[] = BARE_BUILD_VERSION " (" VERSION_TO_STRING(GIT_VERSION) ")";
#else
const char build_version[] = BARE_BUILD_VERSION;
#endif