builds: fix version .sh for standard sh

This commit is contained in:
bnnm 2021-08-15 21:22:43 +02:00
parent df7ad9f58c
commit fc56d08567
2 changed files with 25 additions and 19 deletions

View File

@ -14,29 +14,32 @@ 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
# ignore git stderr "fatal:*" or blank
if [[ $VERSION != fatal* ]] && [ ! -z "$VERSION" ] ; then
if [ ! -z "$VERSION" ]; then
LINE="$VERSION"
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
if [ "$VERSION_EMPTY" = "true" ]; then
LINE="/* ignored */"
else
LINE="$VERSION_DEFAULT"
while IFS= read -r -u3 item; do
COMP="#define $VERSION_NAME*"
if [[ $item == $COMP ]] ; then
while IFS= read -r <&3 ITEM; do
COMP="#define $VERSION_NAME"
if case "$ITEM" in *"$COMP"*) true;; *) false;; esac; then
# clean "#define ..." leaving rXXXX only
STR_REMOVE1="*$VERSION_NAME \""
STR_REMOVE2="\"*"
LINE=$item
LINE=${LINE/$STR_REMOVE1/}
LINE=${LINE/$STR_REMOVE2/}
REGEX_REMOVE1="#define $VERSION_NAME \""
REGEX_REMOVE2="\".*"
LINE="$ITEM"
LINE=$(echo $LINE | sed "s/$REGEX_REMOVE1//")
LINE=$(echo $LINE | sed "s/$REGEX_REMOVE2//")
fi
done 3< "version.h"
fi

View File

@ -14,24 +14,27 @@ 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
# ignore git stderr "fatal:*" or blank
if [[ $VERSION != fatal* ]] && [ ! -z "$VERSION" ] ; then
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
if [ "$VERSION_EMPTY" = "true" ]; then
LINE="/* ignored */"
else
LINE="#define $VERSION_NAME \"$VERSION_DEFAULT\" /* autogenerated */"
while IFS= read -r -u3 item; do
COMP="#define $VERSION_NAME*"
if [[ $item == $COMP ]] ; then
LINE="$item /* default */"
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
@ -43,6 +46,6 @@ LINE_ORIGINAL="none"
if test -f "version_auto.h"; then
LINE_ORIGINAL=$(<version_auto.h)
fi
if [[ $LINE != $LINE_ORIGINAL ]] ; then
if [ ! "$LINE" = "$LINE_ORIGINAL" ]; then
echo "$LINE" > "$VERSION_FILE"
fi