Fix configure script for compatibility with old versions of bash.

m4/mercury.m4:
    Replace $( ) with backticks in commands that confuse the parser in
    old versions of bash.

    Use 'read -r' instead of plain 'read' so that backslash is not
    treated as an escape character, not that we expect gcc or clang
    to print backslashes in the version output.
This commit is contained in:
Peter Wang
2024-01-08 15:09:01 +11:00
parent 8a9be89a68
commit 5c081faa0f

View File

@@ -634,8 +634,12 @@ raw_gcc_version=$($CC -dumpfullversion 2>/dev/null || $CC -dumpversion)
# The major version number should always be present.
# The minor version number and patchlevel are not always present.
# MinGW-w64 may add a suffix "-win32" or "-posix" that should be ignored.
mercury_cv_gcc_version=$(echo "${raw_gcc_version%-*}" | tr . ' ' | {
read major minor patchlevel ignore;
#
# We use backticks for this command substitution because old versions of
# bash fail to parse this command with $() syntax.
# In particular, MacOS 14 and earlier use bash 3.2 as /bin/sh.
mercury_cv_gcc_version=`echo "${raw_gcc_version%-*}" | tr . ' ' | {
read -r major minor patchlevel ignore;
case $major in
[[0-9]]*) ;;
*) major=u ;;
@@ -649,7 +653,7 @@ mercury_cv_gcc_version=$(echo "${raw_gcc_version%-*}" | tr . ' ' | {
*) patchlevel=u ;;
esac;
echo "${major}_${minor}_${patchlevel}";
})
}`
AC_MSG_RESULT([$mercury_cv_gcc_version])
])
@@ -736,8 +740,8 @@ raw_clang_version=$($CC -dumpversion)
# The major version number should always be present.
# For GCC we allow for a suffix after the second or third number that should
# be ignored; it seems prudent to do the same for clang here as well.
mercury_cv_clang_version=$(echo "${raw_clang_version%-*}" | tr . ' ' | {
read major minor patchlevel ignore;
mercury_cv_clang_version=`echo "${raw_clang_version%-*}" | tr . ' ' | {
read -r major minor patchlevel ignore;
case $major in
[[0-9]]*) ;;
*) major=u ;;
@@ -751,7 +755,7 @@ mercury_cv_clang_version=$(echo "${raw_clang_version%-*}" | tr . ' ' | {
*) patchlevel=u ;;
esac;
echo "${major}_${minor}_${patchlevel}";
})
}`
AC_MSG_RESULT([$mercury_cv_clang_version])
])