com_ff(): Depreciate "n-" syntax.
[paraslash.git] / GIT-VERSION-GEN
1 #!/usr/bin/env bash
2
3 (($# > 1)) && { echo >&2 "usage: $0 [<version file>]"; exit 1; }
4 GVF="$1"
5
6 DEF_VER="unnamed_version"
7 LF='
8 '
9
10 # First see if there is a version file (included in release tarballs),
11 # then try git-describe, then gitweb, then default.
12 if [[ -f VERSION ]]; then
13 VN=$(cat VERSION) || VN="$DEF_VER"
14 elif [[ -d .git || -f .git ]] &&
15 VN=$(git describe --abbrev=4 HEAD 2>/dev/null) &&
16 case "$VN" in
17 *$LF*) (exit 1) ;;
18 v[0-9]*)
19 git update-index -q --refresh &>/dev/null
20 test -z "$(git diff-index --name-only HEAD --)" ||
21 VN="$VN-dirty" ;;
22 esac
23 then
24 VN=$(echo "$VN" | sed -e 's/-/./g');
25 elif [[ "$PWD" =~ paraslash-[a-f0-9]{1,} ]]; then
26 VN="${PWD#*-}"
27 else
28 VN="$DEF_VER"
29 fi
30
31 VN=$(expr "$VN" : v*'\(.*\)')
32 echo "$VN"
33
34 [[ -z "$GVF" ]] && exit 0
35 if [[ -r "$GVF" ]]; then
36 pattern='^#define GIT_VERSION "'
37 VC=$(grep "$pattern" < "$GVF" | sed -e "s/$pattern//; s/\"$//")
38 [[ "$VN" == "$VC" ]] && exit 0
39 fi
40 echo >&2 "new git version: $VN"
41 echo "/** \\file ${GVF##*/} Auto-generated version file. Do not edit. */" >$GVF
42 echo "#define GIT_VERSION \"$VN\"" >> $GVF