Revised wording in pdb2gmx.c, hopefully clearer now.
[gromacs/rigid-bodies.git] / src / gmxlib / genversion.sh
blobec412b686d2cf437b8b60f2a6369a8c736a8be61
1 #!/bin/sh
3 # usage: genversion.sh PKGVERSION top_srcdir
4 # Requires git 1.5.1 or later
6 PKGVERSION=$1
7 SRCDIR=$2
8 GITDIR=$SRCDIR/.git
10 if which git >/dev/null && test -d $GITDIR ; then
11 # Get either -dirty or an empty string, depending on whether there are local changes.
12 dirtystr=`(cd $SRCDIR && git diff-index --quiet HEAD) || echo "-dirty"`
13 # Get date of the head commit as YYYYMMDD (commit date).
14 # Git before 1.5.3 does not support any sensible date format,
15 # so we need to massage the output.
16 if git --git-dir=$GITDIR rev-list -n1 --pretty=format:%ci HEAD | grep '[0-9]\{4\}' >/dev/null 2>&1; then
17 date=`git --git-dir=$GITDIR rev-list -n1 --pretty=format:%ci HEAD | sed -ne '/commit/!{s/ .*$//;s/-//g;p;}'`
18 else
19 date=`git --git-dir=$GITDIR rev-list -n1 --pretty=format:%cD HEAD | \
20 sed -ne '/commit/!{s/^.*, *\([ 0-9][0-9]\) \([a-zA-Z]*\) \([0-9]*\) .*$/\3\2\1/;y/ /0/;\
21 s/Jan/01/;s/Feb/02/;s/Mar/03/;s/Apr/04/;s/May/05/;s/Jun/06/;
22 s/Jul/07/;s/Aug/08/;s/Sep/09/;s/Oct/10/;s/Nov/11/;s/Dec/12/;
23 p;}'`
25 # Get a 7-character hash for the HEAD commit.
26 shorthash=`git --git-dir=$GITDIR rev-parse --short=7 HEAD 2>/dev/null`
27 # Get the full hash for the HEAD commit.
28 fullhash=`git --git-dir=$GITDIR rev-parse HEAD 2>/dev/null`
29 # Generate a version string like 4.0.99-dev-YYYYMMDD-1234abc-dirty.
30 # If PKGVERSION ends in a date, replace it with the head commit.
31 version=`echo $PKGVERSION | sed -e 's/-dev-[0-9]*$/-dev/'`-$date-$shorthash$dirtystr
32 #version=$PKGVERSION-$date-$shorthash$dirtystr
33 # Find the name of the remote which has the git.gromacs.org:gromacs in its url.
34 # If not found, just set baserev to "unknown".
35 gmxremote=`git --git-dir=$GITDIR config --get-regexp 'remote\..*\.url' 'git\.gromacs\.org[:|/]gromacs' | sed -e 's/remote\.\(.*\)\.url.*/\1/'`
36 if test "x$gmxremote" = "x" ; then
37 baserev="unknown"
38 else
39 # Find the most recent ancestral commit that appears in $gmxremote.
40 # Gets the hash and the number of local commits that are newer than
41 # the found commit.
42 baserev=`git --git-dir=$GITDIR rev-list HEAD | git --git-dir=$GITDIR name-rev --stdin --refs=refs/remotes/$gmxremote/* | awk 'NF > 1 {print $1 " (" NR-1 " newer local commits)"; exit 0}'`
43 # Extract the base hash
44 basehash=`expr "$baserev" : '\([0123456789abcdef]*\) '`
45 # Do not report the base revision if it is the same as the most recent commit
46 if test "$basehash" = "$fullhash" ; then
47 baserev=
50 else
51 version=$PKGVERSION
52 fullhash="unknown"
53 dirtystr=
54 baserev=
57 # Write out to a temporary file, to compare with current version.c.
58 cat > version.c.tmp << END
59 #include "version.h"
60 const char _gmx_ver_string[] = "VERSION $version";
61 const char _gmx_full_git_hash[] = "$fullhash$dirtystr";
62 const char _gmx_central_base_hash[] = "$baserev";
63 END
65 # Replace version.c with version.c.tmp if they differ.
66 [ -f version.c ] || touch version.c
67 cmp -s version.c.tmp version.c || mv -f version.c.tmp version.c
68 rm -f version.c.tmp