blob: 5149aa87f92f3b92d86ea9d74af96b5f278aeb0b (
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
|
#!/bin/sh
package="$1"
version_file="$2"
ver='unnamed_version'
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#v}
fi
printf '%s\n' "$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\"
\"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
|