diff --git a/Makefile b/Makefile index 06d15384..80eb1c68 100644 --- a/Makefile +++ b/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 diff --git a/kernel/sys/version.c b/kernel/sys/version.c index 9d1baf38..aa032a27 100644 --- a/kernel/sys/version.c +++ b/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. * diff --git a/util/make-version b/util/make-version new file mode 100755 index 00000000..be956665 --- /dev/null +++ b/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