2 # Execute in the root of the project to get the version
4 [ $# -gt 0 ] && PACKAGE_NAME
=$1
5 PACKAGE_NAME
=${PACKAGE_NAME:-cdimgtools}
6 DEF_VER
="unknown_version"
11 # First try git-describe, then see if there is a VERSION file (included in
12 # release tarballs), then see if the project directory matches the project
13 # name, then use the default.
14 if test -d .git
-o -f .git
&&
15 VN
=$
(git describe
--abbrev=7 --match "version/*" --tags HEAD
--always 2>/dev
/null
) &&
19 git update-index
-q --refresh
20 test -z "$(git diff-index --name-only HEAD --)" ||
24 VN
=$
(echo "$VN" |
sed -e 's#^\(ver\|VER\)[a-zA-Z]*/##' -e 's/-/+/' -e 's/-/_/')
25 # <tag>+<num-of-commits>_g<hash>.dirty
26 elif test -f VERSION
&& test -s VERSION
28 VN
=$
(cat VERSION
) || VN
="$DEF_VER"
29 elif VN
=$
(pwd -P |
sed -e 's#^.*/##') &&
30 test x
"$VN" != x
"${VN#"$PACKAGE_NAME-"}"
32 VN
=${VN#"$PACKAGE_NAME-"}