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="" VERSION=""
else else
VERSION=$(git describe --tags --always 2>&1 | tr : _ ) VERSION=$(git describe --tags --always 2>&1 | tr : _ )
if case "$VERSION" in fatal*) true;; *) false;; esac; then
VERSION=""
fi
fi fi
# ignore git stderr "fatal:*" or blank
if [[ $VERSION != fatal* ]] && [ ! -z "$VERSION" ] ; then if [ ! -z "$VERSION" ]; then
LINE="$VERSION" LINE="$VERSION"
else else
# try to get version from version.h (static) # try to get version from version.h (static)
#echo "Git version not found, can't autogenerate version (using default)" #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 # 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 */" LINE="/* ignored */"
else else
LINE="$VERSION_DEFAULT" LINE="$VERSION_DEFAULT"
while IFS= read -r -u3 item; do while IFS= read -r <&3 ITEM; do
COMP="#define $VERSION_NAME*" COMP="#define $VERSION_NAME"
if [[ $item == $COMP ]] ; then if case "$ITEM" in *"$COMP"*) true;; *) false;; esac; then
# clean "#define ..." leaving rXXXX only # clean "#define ..." leaving rXXXX only
STR_REMOVE1="*$VERSION_NAME \"" REGEX_REMOVE1="#define $VERSION_NAME \""
STR_REMOVE2="\"*" REGEX_REMOVE2="\".*"
LINE=$item LINE="$ITEM"
LINE=${LINE/$STR_REMOVE1/} LINE=$(echo $LINE | sed "s/$REGEX_REMOVE1//")
LINE=${LINE/$STR_REMOVE2/} LINE=$(echo $LINE | sed "s/$REGEX_REMOVE2//")
fi fi
done 3< "version.h" done 3< "version.h"
fi fi

View File

@ -14,24 +14,27 @@ if ! command -v git > /dev/null ; then
VERSION="" VERSION=""
else else
VERSION=$(git describe --tags --always 2>&1 | tr : _ ) VERSION=$(git describe --tags --always 2>&1 | tr : _ )
if case "$VERSION" in fatal*) true;; *) false;; esac; then
VERSION=""
fi
fi fi
# ignore git stderr "fatal:*" or blank
if [[ $VERSION != fatal* ]] && [ ! -z "$VERSION" ] ; then if [ ! -z "$VERSION" ]; then
LINE="#define $VERSION_NAME \"$VERSION\" /* autogenerated */" LINE="#define $VERSION_NAME \"$VERSION\" /* autogenerated */"
else else
# try to get version from version.h (static) # try to get version from version.h (static)
echo "Git version not found, can't autogenerate version (using default)" 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 # 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 */" LINE="/* ignored */"
else else
LINE="#define $VERSION_NAME \"$VERSION_DEFAULT\" /* autogenerated */" LINE="#define $VERSION_NAME \"$VERSION_DEFAULT\" /* autogenerated */"
while IFS= read -r -u3 item; do while IFS= read -r <&3 ITEM; do
COMP="#define $VERSION_NAME*" COMP="#define $VERSION_NAME"
if [[ $item == $COMP ]] ; then if case "$ITEM" in *"$COMP"*) true;; *) false;; esac; then
LINE="$item /* default */" LINE="$ITEM /* default */"
fi fi
done 3< "version.h" done 3< "version.h"
fi fi
@ -43,6 +46,6 @@ LINE_ORIGINAL="none"
if test -f "version_auto.h"; then if test -f "version_auto.h"; then
LINE_ORIGINAL=$(<version_auto.h) LINE_ORIGINAL=$(<version_auto.h)
fi fi
if [[ $LINE != $LINE_ORIGINAL ]] ; then if [ ! "$LINE" = "$LINE_ORIGINAL" ]; then
echo "$LINE" > "$VERSION_FILE" echo "$LINE" > "$VERSION_FILE"
fi fi