forked from vgmstream/vgmstream
-
Notifications
You must be signed in to change notification settings - Fork 0
/
version-make.sh
executable file
·51 lines (44 loc) · 1.56 KB
/
version-make.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
#!/bin/sh
# make current git version (overwrites version_auto.h)
VERSION_EMPTY=$1
VERSION_FILE=$2
VERSION_NAME=$3
if [ -z "$VERSION_EMPTY" ]; then VERSION_EMPTY=false; fi
if [ -z "$VERSION_FILE" ]; then VERSION_FILE=version_auto.h; fi
if [ -z "$VERSION_NAME" ]; then VERSION_NAME=VGMSTREAM_VERSION; fi
VERSION_DEFAULT=unknown
# try get version from Git (dynamic), including lightweight tags
if ! command -v git > /dev/null ; then
VERSION=""
else
VERSION=$(git describe --tags --always 2>&1 | tr : _ )
if case "$VERSION" in fatal*) true;; *) false;; esac; then
VERSION=""
fi
fi
if [ ! -z "$VERSION" ]; then
LINE="#define $VERSION_NAME \"$VERSION\" /* autogenerated */"
else
# try to get version from version.h (static)
echo "Git version not found, can't autogenerate version (using default)"
# option to output empty line instead of default version, so plugins can detect git-less builds
if [ "$VERSION_EMPTY" = "true" ]; then
LINE="/* ignored */"
else
LINE="#define $VERSION_NAME \"$VERSION_DEFAULT\" /* autogenerated */"
while IFS= read -r <&3 ITEM; do
COMP="#define $VERSION_NAME"
if case "$ITEM" in *"$COMP"*) true;; *) false;; esac; then
LINE="$ITEM /* default */"
fi
done 3< "version.h"
fi
fi
# avoid overwritting if contents are the same, as some systems rebuild on timestamp
LINE_ORIGINAL="none"
if test -f "version_auto.h"; then
LINE_ORIGINAL=$(<version_auto.h)
fi
if [ ! "$LINE" = "$LINE_ORIGINAL" ]; then
echo "$LINE" > "$VERSION_FILE"
fi