[sslh] [PATCH 5/5 V2] version.h: dynamically create version number based on git
Jason Cooper
jason at lakedaemon.net
Tue Aug 6 14:29:56 CEST 2013
When building the source from a checked out tag, eg v1.15, VERSION will
equal v1.15. However, when building from anything other than a tagged
version, you get 'v1.15-4-g50432d5-dirty' meaning I was 4 patches in
front of v1.15, particularly '50432d5' was my current HEAD, and I had
uncommited changes, '-dirty'.
Very useful for folks submitting bug reports on versions they compiled
themselves.
Signed-off-by: Jason Cooper <jason at lakedaemon.net>
---
Changes since v1:
- include'd version.h in common.h only (at the request of Yves).
.gitignore | 1 +
Makefile | 14 ++++++++------
common.h | 5 +----
genver.sh | 33 +++++++++++++++++++++++++++++++++
4 files changed, 43 insertions(+), 10 deletions(-)
create mode 100755 genver.sh
diff --git a/.gitignore b/.gitignore
index f0a8563..d9ab5e4 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,3 +7,4 @@ sslh-fork
sslh-select
sslh.8.gz
tags
+version.h
diff --git a/Makefile b/Makefile
index f3a8bea..01eb4ab 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
# Configuration
-VERSION="1.15"
+VERSION=$(shell ./genver.sh -r)
USELIBCONFIG=1 # Use libconfig? (necessary to use configuration files)
USELIBWRAP= # Use libwrap?
COV_TEST= # Perform test coverage?
@@ -34,17 +34,19 @@ endif
all: sslh $(MAN) echosrv
.c.o: *.h
- $(CC) $(CFLAGS) -D'VERSION=$(VERSION)' -c $<
+ $(CC) $(CFLAGS) -c $<
+version.h:
+ ./genver.sh >version.h
sslh: $(OBJS) sslh-fork sslh-select
-sslh-fork: $(OBJS) sslh-fork.o Makefile common.h
- $(CC) $(CFLAGS) -D'VERSION=$(VERSION)' -o sslh-fork sslh-fork.o $(OBJS) $(LIBS)
+sslh-fork: $(OBJS) sslh-fork.o Makefile common.h version.h
+ $(CC) $(CFLAGS) -o sslh-fork sslh-fork.o $(OBJS) $(LIBS)
#strip sslh-fork
-sslh-select: $(OBJS) sslh-select.o Makefile common.h
- $(CC) $(CFLAGS) -D'VERSION=$(VERSION)' -o sslh-select sslh-select.o $(OBJS) $(LIBS)
+sslh-select: $(OBJS) sslh-select.o Makefile common.h version.h
+ $(CC) $(CFLAGS) -o sslh-select sslh-select.o $(OBJS) $(LIBS)
#strip sslh-select
echosrv: $(OBJS) echosrv.o
diff --git a/common.h b/common.h
index 81fc3e6..7d49b0f 100644
--- a/common.h
+++ b/common.h
@@ -27,10 +27,7 @@
#include <libgen.h>
#include <time.h>
#include <getopt.h>
-
-#ifndef VERSION
-#define VERSION "v?"
-#endif
+#include "version.h"
#define CHECK_RES_DIE(res, str) \
if (res == -1) { \
diff --git a/genver.sh b/genver.sh
new file mode 100755
index 0000000..bd06d86
--- /dev/null
+++ b/genver.sh
@@ -0,0 +1,33 @@
+#!/bin/sh
+
+if [ ${#} -eq 1 ] && [ "x$1" == "x-r" ]; then
+ # release text only
+ QUIET=1
+else
+ QUIET=0
+fi
+
+if head=`git rev-parse --verify HEAD 2>/dev/null`; then
+
+ if [ $QUIET -ne 1 ]; then
+ printf "#ifndef _VERSION_H_ \n"
+ printf "#define _VERSION_H_ \n\n"
+ printf "#define VERSION \""
+ fi
+
+ # generate the version info based on the tag
+ (git describe --tags || git --describe || git describe --all --long) \
+ 2>/dev/null | tr -d '\n'
+
+ # Are there uncommitted changes?
+ git update-index --refresh --unmerged > /dev/null
+ if git diff-index --name-only HEAD | grep -v "^scripts/package" \
+ | read dummy; then
+ printf '%s' -dirty
+ fi
+
+ if [ $QUIET -ne 1 ]; then
+ printf "\"\n"
+ printf "\n#endif\n"
+ fi
+fi
--
1.8.3.2
More information about the sslh
mailing list