1
0
mirror of https://github.com/moparisthebest/sslh synced 2024-11-22 00:52:18 -05:00

version.h: dynamically create version number based on git

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@lakedaemon.net>
This commit is contained in:
Jason Cooper 2013-08-06 12:29:56 +00:00 committed by Yves Rutschle
parent c6adb6a1e1
commit f36eb7be39
4 changed files with 43 additions and 10 deletions

1
.gitignore vendored
View File

@ -6,3 +6,4 @@ sslh-fork
sslh-select sslh-select
sslh.8.gz sslh.8.gz
tags tags
version.h

View File

@ -1,6 +1,6 @@
# Configuration # Configuration
VERSION="1.15" VERSION=$(shell ./genver.sh -r)
USELIBCONFIG=1 # Use libconfig? (necessary to use configuration files) USELIBCONFIG=1 # Use libconfig? (necessary to use configuration files)
USELIBWRAP= # Use libwrap? USELIBWRAP= # Use libwrap?
COV_TEST= # Perform test coverage? COV_TEST= # Perform test coverage?
@ -34,17 +34,19 @@ endif
all: sslh $(MAN) echosrv all: sslh $(MAN) echosrv
.c.o: *.h .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: $(OBJS) sslh-fork sslh-select
sslh-fork: $(OBJS) sslh-fork.o Makefile common.h sslh-fork: $(OBJS) sslh-fork.o Makefile common.h version.h
$(CC) $(CFLAGS) -D'VERSION=$(VERSION)' -o sslh-fork sslh-fork.o $(OBJS) $(LIBS) $(CC) $(CFLAGS) -o sslh-fork sslh-fork.o $(OBJS) $(LIBS)
#strip sslh-fork #strip sslh-fork
sslh-select: $(OBJS) sslh-select.o Makefile common.h sslh-select: $(OBJS) sslh-select.o Makefile common.h version.h
$(CC) $(CFLAGS) -D'VERSION=$(VERSION)' -o sslh-select sslh-select.o $(OBJS) $(LIBS) $(CC) $(CFLAGS) -o sslh-select sslh-select.o $(OBJS) $(LIBS)
#strip sslh-select #strip sslh-select
echosrv: $(OBJS) echosrv.o echosrv: $(OBJS) echosrv.o

View File

@ -27,10 +27,7 @@
#include <libgen.h> #include <libgen.h>
#include <time.h> #include <time.h>
#include <getopt.h> #include <getopt.h>
#include "version.h"
#ifndef VERSION
#define VERSION "v?"
#endif
#define CHECK_RES_DIE(res, str) \ #define CHECK_RES_DIE(res, str) \
if (res == -1) { \ if (res == -1) { \

33
genver.sh Executable file
View File

@ -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