--- SOURCE_TOOLS/arb_compiler_version.pl.orig	2014-07-22 09:59:34.000000000 -0500
+++ SOURCE_TOOLS/arb_compiler_version.pl	2014-08-05 04:34:02.000000000 -0500
@@ -26,17 +26,22 @@
     if (not defined $dumpedVersion)   { $dumpedVersion   = $undetectable; }
     if (not defined $detailedVersion) { $detailedVersion = $undetectable; }
 
-    if ($detailedVersion =~ /\s/) {
-      my $firstWord = $`;
-      if ($firstWord eq 'gcc' or $firstWord eq 'clang') {
-        $detectedCompiler = $firstWord;
+    my $cmd = "$compiler -dM -E -x c /dev/null";
+    if (open(CMD,$cmd.'|')) {
+    LINE: foreach (<CMD>) {
+        if (/__GNUC__/) {
+          $detectedCompiler = 'gcc';
+          # clang also defines __GNUC__ so don't "last" here
+        }
+        elsif (/__clang__/) {
+          $detectedCompiler = 'clang';
+          last LINE;
+        }
       }
-      elsif ($firstWord eq 'g++') { $detectedCompiler = 'gcc'; }
-      elsif ($firstWord eq 'clang++') { $detectedCompiler = 'clang'; }
+      close(CMD);
     }
-
-    if ($detectedCompiler eq 'unknown') {
-      if ($detailedVersion =~ /apple.*llvm.*clang/oi) { $detectedCompiler = 'clang'; }
+    else {
+      print STDERR "failed to execute '$cmd'";
     }
 
     if ($detectedCompiler eq 'unknown') {
@@ -45,13 +50,11 @@
       print STDERR "detailedVersion='$detailedVersion'\n";
     }
 
-    if ($dumpedVersion =~ /\..*\./) {
-      $detectedVersion = $dumpedVersion;
+    if ($detailedVersion =~ /\s([0-9]+(?:\.[0-9]+)+)\s/) {
+      $detectedVersion = $1;
     }
-    else {                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     # if version info does not contain patchlevel -> use detailedVersion
-      if ($detailedVersion =~ /\s([0-9]+\.[0-9]+\.[0-9]+)\s/) {
-        $detectedVersion = $1;
-      }
+    elsif ($dumpedVersion =~ /^([0-9]+(?:\.[0-9]+)+)$/) {
+      $detectedVersion = $dumpedVersion;
     }
   }
 
