summaryrefslogtreecommitdiffstats
path: root/version.sh
blob: 3eac7ef050c417340535bac291981e4a2ad0d24e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/sh

export LC_ALL=C

for ac_option do
  case "$ac_option" in
  --extra=*)
    extra="-$option"
    ;;
  --print)
    print=yes
    ;;
  *)
    echo "Unknown parameter: $option" >&2
    exit 1
    ;;

  esac
done

# Extract revision number from file used by daily tarball snapshots
# or from "git describe" output
git_revision=$(cat snapshot_version 2> /dev/null)
test "$git_revision" || test ! -e .git || git_revision="$(git rev-parse --short HEAD)"
test "$git_revision" && git_revision="git-$git_revision"
version="$git_revision"

# releases extract the version number from the VERSION file
releaseversion="$(cat VERSION 2> /dev/null)"
if test "$releaseversion" ; then
    test "$version" && version="-$version"
    version="$releaseversion$version"
fi

test "$version" || version=UNKNOWN

VERSION="${version}${extra}"

if test "$print" = yes ; then
    echo "$VERSION"
    exit 0
fi

NEW_REVISION="#define VERSION \"${VERSION}\""
OLD_REVISION=$(head -n 1 version.h 2> /dev/null)
BUILDDATE="#define BUILDDATE \"$(date)\""

# Update version.h only on revision changes to avoid spurious rebuilds
if test "$NEW_REVISION" != "$OLD_REVISION"; then
    cat <<EOF > version.h
$NEW_REVISION
$BUILDDATE
EOF
fi