3 # usage: genversion.sh PKGVERSION top_srcdir
9 if which git
>/dev
/null
&& test -d $GITDIR ; then
10 # Get either -dirty or an empty string, depending on whether there are local changes.
11 dirtystr
=`(cd $SRCDIR && git diff-index --quiet HEAD) || echo "-dirty"`
12 # Get date of the head commit as YYYYMMDD (commit date).
13 date=`git --git-dir=$GITDIR rev-list -n1 --pretty=format:%ci HEAD | sed -ne '/commit/!{s/-\| .*$//g;p}'`
14 # Get a 7-character hash for the HEAD commit.
15 shorthash
=`git --git-dir=$GITDIR rev-parse --short=7 HEAD 2>/dev/null`
16 # Get the full hash for the HEAD commit.
17 fullhash
=`git --git-dir=$GITDIR rev-parse HEAD 2>/dev/null`
18 # Generate a version string like 4.0.99-dev-YYYYMMDD-1234abc-dirty.
19 # If PKGVERSION ends in a date, replace it with the head commit.
20 version
=`echo $PKGVERSION | sed -e 's/-dev-[0-9]*$/-dev/'`-$date-$shorthash$dirtystr
21 #version=$PKGVERSION-$date-$shorthash$dirtystr
22 # Find the name of the remote which has the git.gromacs.org:gromacs in its url.
23 # If not found, just set baserev to "unknown".
24 gmxremote
=`git --git-dir=$GITDIR config --get-regexp 'remote\..*\.url' 'git\.gromacs\.org[:|/]gromacs' | sed -e 's/remote\.\(.*\)\.url.*/\1/'`
25 if test "x$gmxremote" = "x" ; then
28 # Find the most recent ancestral commit that appears in $gmxremote.
29 # Gets the hash and the number of local commits that are newer than
31 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}'`
32 # Extract the base hash
33 basehash
=`expr "$baserev" : '\([0123456789abcdef]*\) '`
34 # Do not report the base revision if it is the same as the most recent commit
35 if test "$basehash" = "$fullhash" ; then
46 # Write out to a temporary file, to compare with current version.c.
47 cat > version.c.tmp
<< END
49 const char _gmx_ver_string[] = "VERSION $version";
50 const char _gmx_full_git_hash[] = "$fullhash$dirtystr";
51 const char _gmx_central_base_hash[] = "$baserev";
54 # Replace version.c with version.c.tmp if they differ.
55 [ -f version.c
] ||
touch version.c
56 cmp -s version.c.tmp version.c ||
mv -f version.c.tmp version.c