Merge branches 't/debian', 't/dynamic-lib', 't/lls_check_arg_count' and 't/news'
[lopsub.git] / version-gen.sh
1 #!/bin/sh
2
3 version_file='version.c'
4 ver='unnamed_version'
5 # First try git, then gitweb, then default.
6 if [ -e '.git' -o -e '../.git' ]; then
7 git_ver=$(git describe --abbrev=4 HEAD 2>/dev/null)
8 [ -z "$git_ver" ] && git_ver="$ver"
9 # update stat information in index to match working tree
10 git update-index -q --refresh > /dev/null
11 # if there are differences (exit code 1), the working tree is dirty
12 git diff-index --quiet HEAD || git_ver=$git_ver-dirty
13 ver=$git_ver
14 elif [ -f debian/changelog ]; then
15 ver="$(sed -ne '1s/.*(\(.*\)-.*/\1/1; tx; d; :x; p' debian/changelog)"
16 elif [ "${PWD%%-*}" = 'lopsub-' ]; then
17 ver=${PWD##*/lopsub-}
18 fi
19 ver=${ver#v}
20
21 echo "$ver"
22
23 # update version file if necessary
24 content="const char *lls_version(void) {return \"$ver\";};"
25 [ -r "$version_file" ] && echo "$content" | cmp -s - $version_file && exit 0
26 echo >&2 "new git version: $ver"
27 echo "$content" > $version_file