version.sh: Don't use dashes in version numbers
[petitboot] / version.sh
1 #! /bin/bash
2 #
3 # version.sh: create a version string for use by configure.ac
4
5 version=
6 datefmt='%Y%m%d'
7
8 export GIT_DIR=$(basename $0)/.git/
9
10 if head=$(git rev-parse --short=8 --verify HEAD 2>/dev/null); then
11
12         suffix=''
13         # Add a '-dirty' suffix for uncommitted changes.
14         if git diff-index HEAD | read dummy; then
15                 suffix=-dirty
16         fi
17
18         if tag=$(git describe --tags --exact-match 2>/dev/null); then
19                 # use a tag; remove any 'v' prefix from v<VERSION> tags
20                 tag=${tag#v}
21                 version=$(printf "%s%s" ${tag} ${suffix})
22         else
23                 # Use the git commit revision for the package version, and add
24                 # a date prefix for easy comparisons.
25                 date=$(git log --pretty=format:"%ct" -1 HEAD)
26                 version=$(printf "%($datefmt)T.g%s%s" ${date} ${head} ${suffix})
27         fi
28 else
29         # Default to current date and time.
30         version="$(date +dev.$datefmt)"
31 fi
32
33 echo $version