3 # SPDX-License-Identifier: GPL-3.0-only
5 version_file='version.c'
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
16 elif [ "${PWD%%-*}" = 'tfortune-' ]; then
17 ver=${PWD##*/tfortune-}
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