mirror of
https://github.com/g4klx/DMRGateway
synced 2025-12-20 13:15:37 +08:00
Add compilation time stamp and GitID to binaries
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
#include "Thread.h"
|
||||
#include "Voice.h"
|
||||
#include "Log.h"
|
||||
#include "GitVersion.h"
|
||||
|
||||
#include <cstdio>
|
||||
#include <vector>
|
||||
@@ -77,7 +78,7 @@ int main(int argc, char** argv)
|
||||
for (int currentArg = 1; currentArg < argc; ++currentArg) {
|
||||
std::string arg = argv[currentArg];
|
||||
if ((arg == "-v") || (arg == "--version")) {
|
||||
::fprintf(stdout, "DMRGateway version %s\n", VERSION);
|
||||
::fprintf(stdout, "DMRGateway version %s git #%.7s\n", VERSION, gitversion);
|
||||
return 0;
|
||||
} else if (arg.substr(0,1) == "-") {
|
||||
::fprintf(stderr, "Usage: DMRGateway [-v|--version] [filename]\n");
|
||||
@@ -231,6 +232,7 @@ int CDMRGateway::run()
|
||||
LogInfo(HEADER4);
|
||||
|
||||
LogMessage("DMRGateway-%s is starting", VERSION);
|
||||
LogMessage("Built %s %s (GitID #%.7s)", __TIME__, __DATE__, gitversion);
|
||||
|
||||
ret = createMMDVM();
|
||||
if (!ret)
|
||||
|
||||
@@ -108,6 +108,12 @@
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalDependencies>wsock32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
<PreBuildEvent>
|
||||
<Command>"$(ProjectDir)prebuild.cmd" $(ProjectDir)</Command>
|
||||
</PreBuildEvent>
|
||||
<PreBuildEvent>
|
||||
<Message>prebuild.cmd generates GitVersion.h from git refs heads master</Message>
|
||||
</PreBuildEvent>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
@@ -217,4 +223,4 @@
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
|
||||
13
Makefile
13
Makefile
@@ -10,11 +10,20 @@ OBJECTS = BPTC19696.o Conf.o CRC.o DMRData.o DMREmbeddedData.o DMREMB.o DMRFullL
|
||||
|
||||
all: DMRGateway
|
||||
|
||||
DMRGateway: $(OBJECTS)
|
||||
DMRGateway: GitVersion.h $(OBJECTS)
|
||||
$(CXX) $(OBJECTS) $(CFLAGS) $(LIBS) -o DMRGateway
|
||||
|
||||
%.o: %.cpp
|
||||
$(CXX) $(CFLAGS) -c -o $@ $<
|
||||
|
||||
clean:
|
||||
$(RM) DMRGateway *.o *.d *.bak *~
|
||||
$(RM) DMRGateway *.o *.d *.bak *~ GitVersion.h
|
||||
|
||||
# Export the current git version if the index file exists, else 000...
|
||||
GitVersion.h:
|
||||
ifneq ("$(wildcard .git/index)","")
|
||||
echo "const char *gitversion = \"$(shell git rev-parse HEAD)\";" > $@
|
||||
else
|
||||
echo "const char *gitversion = \"0000000000000000000000000000000000000000\";" > $@
|
||||
endif
|
||||
|
||||
|
||||
38
prebuild.cmd
Normal file
38
prebuild.cmd
Normal file
@@ -0,0 +1,38 @@
|
||||
@echo off
|
||||
REM This pre-build file is for MSVS VC++. It parses the git master hash and
|
||||
REM converts it into GitVersion.h for compiling into builds. [George M1GEO]
|
||||
|
||||
cd %1
|
||||
setlocal enabledelayedexpansion
|
||||
set HEADFILE=.git\HEAD
|
||||
set HASHFILE=0
|
||||
if exist %HEADFILE% (
|
||||
for /F "tokens=4 delims=/:" %%a in ('type %HEADFILE%') do set HEADBRANCH=%%a
|
||||
set HASHFILE=.git\refs\heads\!HEADBRANCH!
|
||||
echo Found Git HEAD file: %HEADFILE%
|
||||
echo Git HEAD branch: !HEADBRANCH!
|
||||
echo Git HASH file: !HASHFILE!
|
||||
call :USEHASH
|
||||
) else (
|
||||
echo No head file :(
|
||||
call :USENULL
|
||||
)
|
||||
|
||||
goto :EOF
|
||||
|
||||
:USENULL
|
||||
set GITHASH=0000000000000000000000000000000000000000
|
||||
goto :WRITEGITVERSIONHEADER
|
||||
|
||||
:USEHASH
|
||||
for /f %%i in ('type !HASHFILE!') do set GITHASH=%%i
|
||||
goto :WRITEGITVERSIONHEADER
|
||||
|
||||
:WRITEGITVERSIONHEADER
|
||||
echo // File contains Git commit ID SHA1 present at buildtime (prebuild.cmd) > GitVersion.h
|
||||
echo const char *gitversion = "%GITHASH%"; >> GitVersion.h
|
||||
echo Current Git HASH: %GITHASH%
|
||||
goto :FINISHED
|
||||
|
||||
:FINISHED
|
||||
echo GitVersion.h written...
|
||||
Reference in New Issue
Block a user