[m-rev.] for review: Fix detection of MinGW-w64 gcc version.

Peter Wang novalazy at gmail.com
Thu May 3 17:14:55 AEST 2018


The MinGW-w64 port of gcc may report a version like "7.3-win32" or
"7.3-posix". Our gcc version detection code did not expect the
suffixes so would extract "3-win32" or "3-posix" as the minor version.

m4/mercury.m4:
    Ignore a "-suffix" in the output of gcc -dumpversion.
---
 m4/mercury.m4 | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/m4/mercury.m4 b/m4/mercury.m4
index a06baecda..17c47aa83 100644
--- a/m4/mercury.m4
+++ b/m4/mercury.m4
@@ -663,8 +663,19 @@ AC_SUBST([ERL])
 AC_DEFUN([MERCURY_GCC_VERSION], [
 AC_REQUIRE([AC_PROG_CC])
 
-mercury_cv_gcc_version=`$CC -dumpversion | tr . ' ' | {
-    read major minor patchlevel ignore
+# We expect that the major and minor version numbers will always be present.
+# MinGW-w64 may add a suffix "-win32" or "-posix" after the second or third
+# number that should be ignored.
+mercury_cv_gcc_version=`$CC -dumpversion | tr .- '  ' | {
+    read major minor third ignore
+    case $third in
+        [0-9]*)
+            patchlevel=$third
+            ;;
+        *)
+            patchlevel=
+            ;;
+    esac
     echo ${major:-u}_${minor:-u}_${patchlevel:-u}
     }`
 ])
-- 
2.17.0



More information about the reviews mailing list