blob: d176f3549cfea37b3e371d5e321b84e41aadb1a2 (
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
#!/bin/sh
package="$1"
version_file="$2"
ver='unnamed_version'
# Try git, version file and gitweb, in this order
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
branch=$(git describe --all --contains HEAD 2>/dev/null)
[ -n "$branch" ] && git_ver="$git_ver-$branch"
ver=$git_ver
elif [ -f VERSION ]; then
ver=$(cat VERSION)
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\";}"
info="
\"Copyright (C) $COPYRIGHT_YEAR - present $AUTHOR\\n\"
\"License: $LICENSE <$LICENSE_URL\\n\"
\"This is free software: you are free to change and redistribute it.\\n\"
\"There is NO WARRANTY, to the extent permitted by law.\\n\"
\"\\n\"
\"Project Website: $PROJECT_WEBSITE\\n\"
\"Clone URL: $CLONE_URL\\n\"
\"Gitweb: $GITWEB_URL\\n\"
\"Author Home Page: $HOME_URL\\n\"
\"Send feedback to: $AUTHOR <$EMAIL>\\n\"
"
content="$content
const char *${package}_info(void) {return $info;};"
[ -r "$version_file" ] && printf '%s\n' "$content" | cmp -s - $version_file && exit 0
[ "$version_file" = "${version_file%/*}" ] || mkdir -p ${version_file%/*}
printf '%s\n' "$content" > $version_file
|