blob: ba4af3eb7105a9ca52e5d2af84331a3c79380666 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
#!/bin/sh
# SPDX-License-Identifier: GPL-3.0-only
package="$1"
version_file="$2"
ver='unnamed_version'
# First try git, then gitweb, then default.
if [ -e '.git' -o -e '../.git' ]; then
git_ver=$(git describe --abbrev=4 --always HEAD 2>/dev/null)
[ -z "$git_ver" ] && git_ver="$ver"
# update stat information in index to match working tree
git update-index -q --refresh > /dev/null
# if there are differences (exit code 1), the working tree is dirty
git diff-index --quiet HEAD || git_ver=$git_ver-dirty
ver=$git_ver
elif [ "${PWD%%-*}" = $package- ]; then
ver=${PWD##*/$package-}
fi
ver=${ver#v}
echo "$ver"
[ -z "${version_file}" ] && exit 0
# update version file if necessary
content="const char *${package}_version(void) {return \"$ver\";};"
[ -r "$version_file" ] && echo "$content" | cmp -s - $version_file && exit 0
[ "$version_file" = "${version_file%/*}" ] || mkdir -p ${version_file%/*}
printf '%s\n' "$content" > $version_file
|