Skip to content

Commit

Permalink
version.h: dynamically create version number based on git
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Jason Cooper authored and yrutschle committed Sep 16, 2013
1 parent c6adb6a commit f36eb7b
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ sslh-fork
sslh-select
sslh.8.gz
tags
version.h
14 changes: 8 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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?
Expand Down Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) { \
Expand Down
33 changes: 33 additions & 0 deletions genver.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit f36eb7b

Please sign in to comment.