| 1 | #!/bin/sh |
| 2 | |
| 3 | srcdir=`dirname $0` |
| 4 | |
| 5 | if [ ! -f git-version.h ]; then |
| 6 | touch git-version.h |
| 7 | fi |
| 8 | |
| 9 | if test -d "$srcdir/.git" || test -f "$srcdir/.git"; then |
| 10 | # Identify a git build by the development version from version.h plus the |
| 11 | # exact commit (e.g. "3.5.0dev-g1234abcd"), rather than the nearest release |
| 12 | # tag that `git describe` would pick: that tag can sit far behind a rebased |
| 13 | # development branch and then misnames the line you are actually on (showing, |
| 14 | # say, 3.4.3 for a 3.5.0dev tree). This also works in a shallow/tag-less |
| 15 | # clone. A release tarball has no .git, so git-version.h stays empty and |
| 16 | # rsync prints the plain RSYNC_VERSION. |
| 17 | # cd into the subshell rather than "git -C" (avoids needing a newer git). |
| 18 | gitsha=`(cd "$srcdir" && git rev-parse --short=8 HEAD) 2>/dev/null` |
| 19 | # Tolerate any preprocessor spacing and a trailing comment; capture only the |
| 20 | # quoted value. Empty (define missing/unmatched) -> leave RSYNC_GITVER unset. |
| 21 | rsyncver=`sed -n 's/^[[:space:]]*#[[:space:]]*define[[:space:]][[:space:]]*RSYNC_VERSION[[:space:]][[:space:]]*"\([^"]*\)".*/\1/p' "$srcdir/version.h"` |
| 22 | if [ -n "$gitsha" ] && [ -n "$rsyncver" ]; then |
| 23 | gitver="$rsyncver-g$gitsha" |
| 24 | echo "#define RSYNC_GITVER \"$gitver\"" >git-version.h.new |
| 25 | if ! diff git-version.h.new git-version.h >/dev/null; then |
| 26 | echo "Updating git-version.h" |
| 27 | mv git-version.h.new git-version.h |
| 28 | else |
| 29 | rm git-version.h.new |
| 30 | fi |
| 31 | fi |
| 32 | fi |