Browse Source

Include git short sha in version string instead of -dev

Kevin Lange 6 years ago
parent
commit
1c65d3d663
3 changed files with 21 additions and 1 deletions
  1. 3 0
      Makefile
  2. 8 1
      kernel/sys/version.c
  3. 10 0
      util/make-version

+ 3 - 0
Makefile

@@ -11,6 +11,9 @@ CFLAGS += -Wall -Wextra -Wno-unused-function -Wno-unused-parameter
 CFLAGS += -Wstrict-prototypes -pedantic -fno-omit-frame-pointer
 CFLAGS += -D_KERNEL_
 
+# Kernel autoversioning with git sha
+CFLAGS += -DKERNEL_GIT_TAG=`util/make-version`
+
 # We have some pieces of assembly sitting around as well...
 YASM = yasm
 

+ 8 - 1
kernel/sys/version.c

@@ -21,7 +21,14 @@ int    __kernel_version_lower = 1;
  * mean anything, but can be used to distinguish
  * between different features included while
  * building multiple kernels. */
-char * __kernel_version_suffix   = "dev";
+#ifdef KERNEL_GIT_TAG
+# define STR(x) #x
+# define STRSTR(x) STR(x)
+# define KERNEL_VERSION_SUFFIX STRSTR(KERNEL_GIT_TAG)
+#else
+# define KERNEL_VERSION_SUFFIX "r"
+#endif
+char * __kernel_version_suffix   = KERNEL_VERSION_SUFFIX;
 
 /* The release codename.
  *

+ 10 - 0
util/make-version

@@ -0,0 +1,10 @@
+#!/bin/bash
+
+VERSION=`git rev-parse --short HEAD`
+
+X=$(git status -s | grep -q '^.M')
+if [ $? -eq 0 ]; then
+    VERSION="$VERSION-dirty"
+fi
+
+echo -n $VERSION