From a6c292cc1e648fa80a8d9a1d8b39d0f852f66489 Mon Sep 17 00:00:00 2001
From: Axel Naumann <Axel.Naumann@cern.ch>
Date: Tue, 23 Jun 2015 15:46:03 +0200
Subject: [PATCH] Also filter --gcc-toolchain; unify filtering of args. Typo.

---
 core/utils/src/rootcling.cxx | 32 ++++++++++++++++++++++++++------
 1 file changed, 26 insertions(+), 6 deletions(-)

diff --git a/core/utils/src/rootcling.cxx b/core/utils/src/rootcling.cxx
index 1e093726d52..d8d923bcb2a 100644
--- a/core/utils/src/rootcling.cxx
+++ b/core/utils/src/rootcling.cxx
@@ -3614,6 +3614,21 @@ bool IsImplementationName(const std::string &filename)
    return !IsHeaderName(filename);
 }
 
+//______________________________________________________________________________
+int ShouldIgnoreClingArgument(const std::string& argument)
+{
+   // Returns >0 if argument is to be ignored.
+   // If 1, just skip that argument. If 2, that argument takes a parameter
+   // "-arg param" thus skip both.
+   if (argument == "-pipe") return 1;
+   if (argument == "-fPIC") return 1;
+   if (argument == "-fpic") return 1;
+   if (ROOT::TMetaUtils::BeginsWith(argument, "--gcc-toolchain="))
+      return 1;
+
+   return 0;
+}
+
 //______________________________________________________________________________
 bool IsCorrectClingArgument(const std::string& argument)
 {
@@ -3976,10 +3991,12 @@ int RootCling(int argc,
             continue;
          }
 
-         if (strcmp("-pipe", argv[ic]) != 0 && strcmp("-pthread", argv[ic]) != 0) {
-            // filter out undesirable options
-            if (strcmp("-fPIC", argv[ic]) && strcmp("-fpic", argv[ic])
-                  && strcmp("-p", argv[ic])) {
+         if (int skip = ShouldIgnoreClingArgument(argv[ic])) {
+            ic += skip;
+            continue;
+         } else {
+            // filter out even more undesirable options
+            if (strcmp("-p", argv[ic])) {
                CheckForMinusW(argv[ic], diagnosticPragmas);
                clingArgs.push_back(argv[ic]);
             }
@@ -4135,7 +4152,10 @@ int RootCling(int argc,
          // ROOT::TMetaUtils::Error(0, "%s: option -c must come directly after the output file\n", argv[0]);
          // return 1;
       }
-      if (strcmp("-pipe", argv[ic]) != 0) {
+      if (int skip = ShouldIgnoreClingArgument(argv[ic])) {
+         i += (skip - 1); // for-loop takes care of the extra 1.
+         continue;
+      } else {
          // filter out undesirable options
 
          if (*argv[i] != '-' && *argv[i] != '+') {
@@ -4731,7 +4751,7 @@ namespace genreflex {
             numberOfHeaders++;
          } else {
             ROOT::TMetaUtils::Warning(0,
-                                      "*** genreflex: %s is not a vaild header name (.h and .hpp extensions expected)!\n",
+                                      "*** genreflex: %s is not a valid header name (.h and .hpp extensions expected)!\n",
                                       headername.c_str());
          }
       }
-- 
GitLab