-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathversion-magic.sh
59 lines (55 loc) · 1.97 KB
/
version-magic.sh
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/bin/sh
getgit_ () {
base_="$(git describe --abbrev=12)"
[ -z "$base_" ] && base_="noversion-$(git show -s --pretty='%h')"
dirty_=""
git update-index -q --refresh
[ -z "$(git diff-index --name-only HEAD --)" ] || dirty_="-dirty"
printf '%s%s' "${base_#v}" "${dirty_}"
}
getdesc_ () {
git show -s --pretty="tformat:%h (%s, %ai" | \
sed -e "s~ [012][0-9]:[0-5][0-9]:[0-5][0-9] [-+][0-9][0-9][0-9][0-9]$~)~"
}
if ! git rev-parse --is-inside-work-tree > /dev/null 2>&1 ; then
make_macro='PLAIN_SOURCE'
make_deps='info.cpp'
else
make_macro='GIT_SOURCE'
make_deps='info.cpp git-version.h'
gitdesc="$(getdesc_)"
if [ -e git-version.h ] ; then
while IFS= read -r line; do
case "${line}" in
'#define GIT_VERSION'*)
gitversion_old="${line#\#define*VERSION}"
gitversion_old="${gitversion_old##* \"}"
gitversion_old="${gitversion_old%\"}"
break
;;
*) ;;
esac
done < ./git-version.h
gitversion_new="$(getgit_)"
if [ "${gitversion_old}" != "${gitversion_new}" ] ; then
printf 'version-magic.sh: Updating git version: %s\n' \
"${gitversion_new}"
sed -e 's~@@GIT-VERSION@@~'"${gitversion_new}"'~g' \
-e 's~@@GIT-DESCRIPTION@@~'"${gitdesc}"'~g' \
< ./git-version.h.in > git-version.h
fi
else
gitversion="$(getgit_)"
printf 'version-magic.sh: Setting up git version: %s\n' \
"${gitversion}"
sed -e 's~@@GIT-VERSION@@~'"${gitversion}"'~g' \
-e 's~@@GIT-DESCRIPTION@@~'"${gitdesc}"'~g' \
< ./git-version.h.in > git-version.h
fi
fi
if [ ! -e version-magic.make ]; then
sed -e 's~@@MAKE-MACRO@@~'"${make_macro}"'~g' \
-e 's~@@MAKE-DEPS@@~'"${make_deps}"'~g' \
< ./version-magic.make.in > version-magic.make
fi
exit 0