diff --git a/version-get.sh b/version-get.sh index 3a908fc3..fc8696d7 100755 --- a/version-get.sh +++ b/version-get.sh @@ -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 diff --git a/version-make.sh b/version-make.sh index b848f421..f4b26824 100755 --- a/version-make.sh +++ b/version-make.sh @@ -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_FILE" fi