Fix --basedir completion.
[tfortune.git] / version-gen.sh
1 #!/bin/sh
2
3 # SPDX-License-Identifier: GPL-3.0-only
4
5 version_file='version.c'
6 ver='unnamed_version'
7 # First try git, then gitweb, then default.
8 if [ -e '.git' -o -e '../.git' ]; then
9 git_ver=$(git describe --abbrev=4 HEAD 2>/dev/null)
10 [ -z "$git_ver" ] && git_ver="$ver"
11 # update stat information in index to match working tree
12 git update-index -q --refresh > /dev/null
13 # if there are differences (exit code 1), the working tree is dirty
14 git diff-index --quiet HEAD || git_ver=$git_ver-dirty
15 ver=$git_ver
16 elif [ "${PWD%%-*}" = 'tfortune-' ]; then
17 ver=${PWD##*/tfortune-}
18 fi
19 ver=${ver#v}
20
21 echo "$ver"
22
23 # update version file if necessary
24 content="const char *tf_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