diff --git a/.gitignore b/.gitignore
index f1260a1..690a1f9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -15,3 +15,4 @@ MMDVMHost
*.VC.db
.vs
*.ambe
+GitVersion.h
diff --git a/MMDVMHost.cpp b/MMDVMHost.cpp
index cea5c9b..4d9ed6a 100644
--- a/MMDVMHost.cpp
+++ b/MMDVMHost.cpp
@@ -33,6 +33,7 @@
#include "LCDproc.h"
#include "Thread.h"
#include "Log.h"
+#include "GitVersion.h"
#if defined(HD44780)
#include "HD44780.h"
@@ -235,6 +236,7 @@ int CMMDVMHost::run()
LogInfo(HEADER4);
LogMessage("MMDVMHost-%s is starting", VERSION);
+ LogMessage("Built %s %s (GitID #%.7s)", __TIME__, __DATE__, gitversion);
readParams();
diff --git a/MMDVMHost.vcxproj b/MMDVMHost.vcxproj
index 1c9a25e..ea4eb81 100644
--- a/MMDVMHost.vcxproj
+++ b/MMDVMHost.vcxproj
@@ -108,6 +108,12 @@
true
kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;ws2_32.lib;%(AdditionalDependencies)
+
+ "$(ProjectDir)prebuild.cmd" $(ProjectDir)
+
+
+ prebuild.cmd generates GitVersion.h from git refs heads master
+
diff --git a/Makefile b/Makefile
index f180e2d..b1f1050 100644
--- a/Makefile
+++ b/Makefile
@@ -15,12 +15,19 @@ OBJECTS = \
all: MMDVMHost
-MMDVMHost: $(OBJECTS)
+MMDVMHost: gitversion.h $(OBJECTS)
$(CXX) $(OBJECTS) $(CFLAGS) $(LIBS) -o MMDVMHost
%.o: %.cpp
$(CXX) $(CFLAGS) -c -o $@ $<
clean:
- $(RM) MMDVMHost *.o *.d *.bak *~
-
+ $(RM) MMDVMHost *.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
diff --git a/Makefile.Pi b/Makefile.Pi
index 0734d47..f683ec6 100644
--- a/Makefile.Pi
+++ b/Makefile.Pi
@@ -15,12 +15,19 @@ OBJECTS = \
all: MMDVMHost
-MMDVMHost: $(OBJECTS)
+MMDVMHost: gitversion.h $(OBJECTS)
$(CXX) $(OBJECTS) $(CFLAGS) $(LIBS) -o MMDVMHost
%.o: %.cpp
$(CXX) $(CFLAGS) -c -o $@ $<
clean:
- $(RM) MMDVMHost *.o *.d *.bak *~
-
+ $(RM) MMDVMHost *.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
diff --git a/Makefile.Pi.Adafruit b/Makefile.Pi.Adafruit
index bbe5dfe..16ecc2f 100644
--- a/Makefile.Pi.Adafruit
+++ b/Makefile.Pi.Adafruit
@@ -15,12 +15,19 @@ OBJECTS = \
all: MMDVMHost
-MMDVMHost: $(OBJECTS)
+MMDVMHost: gitversion.h $(OBJECTS)
$(CXX) $(OBJECTS) $(CFLAGS) $(LIBS) -o MMDVMHost
%.o: %.cpp
$(CXX) $(CFLAGS) -c -o $@ $<
clean:
- $(RM) MMDVMHost *.o *.d *.bak *~
-
+ $(RM) MMDVMHost *.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
diff --git a/Makefile.Pi.HD44780 b/Makefile.Pi.HD44780
index a4b9c97..981af5e 100644
--- a/Makefile.Pi.HD44780
+++ b/Makefile.Pi.HD44780
@@ -15,12 +15,19 @@ OBJECTS = \
all: MMDVMHost
-MMDVMHost: $(OBJECTS)
+MMDVMHost: gitversion.h $(OBJECTS)
$(CXX) $(OBJECTS) $(CFLAGS) $(LIBS) -o MMDVMHost
%.o: %.cpp
$(CXX) $(CFLAGS) -c -o $@ $<
clean:
- $(RM) MMDVMHost *.o *.d *.bak *~
-
+ $(RM) MMDVMHost *.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
diff --git a/Makefile.Pi.OLED b/Makefile.Pi.OLED
index 167c739..660fc88 100644
--- a/Makefile.Pi.OLED
+++ b/Makefile.Pi.OLED
@@ -15,12 +15,19 @@ OBJECTS = \
all: MMDVMHost
-MMDVMHost: $(OBJECTS)
+MMDVMHost: gitversion.h $(OBJECTS)
$(CXX) $(OBJECTS) $(CFLAGS) $(LIBS) -o MMDVMHost
%.o: %.cpp
$(CXX) $(CFLAGS) -c -o $@ $<
clean:
- $(RM) MMDVMHost *.o *.d *.bak *~
-
+ $(RM) MMDVMHost *.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
diff --git a/Makefile.Pi.PCF8574 b/Makefile.Pi.PCF8574
index e5df3a5..2ea81dd 100644
--- a/Makefile.Pi.PCF8574
+++ b/Makefile.Pi.PCF8574
@@ -15,11 +15,19 @@ OBJECTS = \
all: MMDVMHost
-MMDVMHost: $(OBJECTS)
+MMDVMHost: gitversion.h $(OBJECTS)
$(CXX) $(OBJECTS) $(CFLAGS) $(LIBS) -o MMDVMHost
%.o: %.cpp
$(CXX) $(CFLAGS) -c -o $@ $<
clean:
- $(RM) MMDVMHost *.o *.d *.bak *~
+ $(RM) MMDVMHost *.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
diff --git a/Makefile.Solaris b/Makefile.Solaris
index a2c74ac..6113fa6 100644
--- a/Makefile.Solaris
+++ b/Makefile.Solaris
@@ -15,12 +15,19 @@ OBJECTS = \
all: MMDVMHost
-MMDVMHost: $(OBJECTS)
+MMDVMHost: gitversion.h $(OBJECTS)
$(CXX) $(OBJECTS) $(CFLAGS) $(LIBS) -o MMDVMHost
%.o: %.cpp
$(CXX) $(CFLAGS) -c -o $@ $<
clean:
- $(RM) MMDVMHost *.o *.d *.bak *~
-
+ $(RM) MMDVMHost *.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
diff --git a/prebuild.cmd b/prebuild.cmd
new file mode 100644
index 0000000..2dc5f9d
--- /dev/null
+++ b/prebuild.cmd
@@ -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...