From af1f1db9304b29b3e408c33de7d77b3305e65a20 Mon Sep 17 00:00:00 2001
From: Gabor Szalai <gabor.szalai@ericsson.com>
Date: Wed, 18 Mar 2020 13:47:12 +0100
Subject: [PATCH] Update GCC version check

At the beginning the GCC (and clang) used the versioning scheme:
<major>.<minor>.<patch>

The <patch> part is ignored by the version check as the patch releases are
compatible.

Both the GCC and the Clang dropped the minor releases at the release of GCC5 & Clang5
They garantee the API & ABI compatibility within a major version, so only the
major version should be taken account.

Change-Id: I73447b7f994b0b9eb5c536a49d4fe537bbd30969
---
 common/version.h  | 12 ++++++++++--
 core/gccversion.c |  5 +++--
 2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/common/version.h b/common/version.h
index c04a20ea1..c2e3472a3 100644
--- a/common/version.h
+++ b/common/version.h
@@ -91,10 +91,18 @@
   #endif
 
 #ifdef __clang__
-  #define CLANG_VERSION (__clang_major__ * 10000 + __clang_minor__ * 100)
+  #if __clang_major__ > 4
+    #define CLANG_VERSION (__clang_major__ * 10000 )
+  #else
+    #define CLANG_VERSION (__clang_major__ * 10000 + __clang_minor__ * 100)
+  #endif
   #define COMPILER_VERSION_STRING " Clang: (GNU) " STR(__clang_major__) "." STR(__clang_minor__) "." STR(__clang_patchlevel__)
 #else
-  #define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100)
+  #if __GNUC__ > 4
+    #define GCC_VERSION (__GNUC__ * 10000 )
+  #else
+    #define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100)
+  #endif
   #define COMPILER_VERSION_STRING " GCC: (GNU) " STR(__GNUC__) "." STR(__GNUC_MINOR__) GCC_PATCHLEVEL_STRING
 #endif
 
diff --git a/core/gccversion.c b/core/gccversion.c
index 6ab738386..3d2f7ac54 100644
--- a/core/gccversion.c
+++ b/core/gccversion.c
@@ -72,9 +72,10 @@ int main(void)
     "#if GCC_VERSION != %d\n"
 #endif
     "#error The version of " COMPILER_NAME_STRING " does not match the expected version (" COMPILER_NAME_STRING " %d.%d.%d)\n"
-    "#endif\n", compiler_major * 10000 + compiler_minor * 100,
+    "#endif\n", compiler_major>4?compiler_major * 10000:compiler_major * 10000 + compiler_minor * 100,
     /* Note that we don't use compiler_patchlevel when checking.
-     * This assumes that code is portable between GCC a.b.x and a.b.y */
+     * This assumes that code is portable between GCC a.b.x and a.b.y
+     * The GCC & Clang changed the versioning scheme and both dropped the minor versions */
     compiler_major, compiler_minor, compiler_patchlevel);
 #elif defined(__SUNPRO_C)
   printf("\n"
-- 
GitLab