diff --git a/ESP32/main.ino b/ESP32/main.ino
index 9a2c45e..6ba4f7b 100644
--- a/ESP32/main.ino
+++ b/ESP32/main.ino
@@ -43,6 +43,7 @@
#include "memory.h"
#include "tty.h"
#include "utils.h"
+#include "version.h"
constexpr const char NET_DISK_CFG_FILE[] = "/net-disk.json";
@@ -547,7 +548,8 @@ void setup() {
delay(100);
Serial.println(F("This PDP-11 emulator is called \"kek\" (reason for that is forgotten) and was written by Folkert van Heusden."));
-
+ Serial.print(F("GIT hash: "));
+ Serial.println(version_str);
Serial.println(F("Build on: " __DATE__ " " __TIME__));
Serial.print(F("Size of int: "));
diff --git a/ESP32/platformio.ini b/ESP32/platformio.ini
index b36016a..8a9be1f 100644
--- a/ESP32/platformio.ini
+++ b/ESP32/platformio.ini
@@ -19,6 +19,7 @@ lib_deps = greiman/SdFat@^2.1.2
bblanchon/ArduinoJson@^6.19.4
build_flags = -std=gnu++17 -Ofast -DESP32=1 -ggdb3 -D_GLIBCXX_USE_C99
build_unflags = -std=gnu++11 -Os
+extra_scripts = pre:prepare.py
[env:SHA2017-badge]
build_src_filter = +<*> -<.git/> -<.svn/> - - - - - - - - -
diff --git a/ESP32/prepare.py b/ESP32/prepare.py
new file mode 100755
index 0000000..6713332
--- /dev/null
+++ b/ESP32/prepare.py
@@ -0,0 +1,17 @@
+#! /usr/bin/python3
+
+import json
+import subprocess
+import sys
+
+
+def get_git_hash():
+ ret = subprocess.run(["git", "diff", "--quiet"], stdout=subprocess.PIPE, text=True)
+ add = '*' if ret.returncode != 0 else ''
+
+ ret = subprocess.run(["git", "rev-parse", "--short", "HEAD"], stdout=subprocess.PIPE, text=True)
+ return ret.stdout.strip() + add
+
+fh = open('version.cpp', 'w')
+fh.write('const char *version_str = "' + get_git_hash() + '";\n')
+fh.close()
diff --git a/ESP32/version.h b/ESP32/version.h
new file mode 100644
index 0000000..a6983b8
--- /dev/null
+++ b/ESP32/version.h
@@ -0,0 +1 @@
+extern const char *version_str;