]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Switch compiler detection to use a more reliable method.
authorPeter Powell <petpow@saberuk.com>
Wed, 22 Mar 2017 17:44:33 +0000 (17:44 +0000)
committerPeter Powell <petpow@saberuk.com>
Fri, 14 Apr 2017 13:59:03 +0000 (14:59 +0100)
Its clear that parsing version output is not reliable enough so
switch to using a method which is less likely to break.

make/configure.pm
make/test/clock_gettime.cpp
make/test/compiler.cpp
make/test/compiler_info.cpp [new file with mode: 0644]

index a104933188f4afcf27a7c0807b0923a7df154457..48bd8db3842a445d352f79a7236f240261a11c74 100644 (file)
@@ -227,19 +227,15 @@ sub write_configure_cache(%) {
 
 sub get_compiler_info($) {
        my $binary = shift;
-       my $version = `$binary -v 2>&1`;
-       if ($version =~ /Apple\sLLVM\sversion\s(\d+\.\d+)/i) {
-               # Apple version their LLVM releases slightly differently to the mainline LLVM.
-               # See https://trac.macports.org/wiki/XcodeVersionInfo for more information.
-               return (NAME => 'AppleClang', VERSION => $1);
-       } elsif ($version =~ /clang\sversion\s(\d+\.\d+)/i) {
-               return (NAME => 'Clang', VERSION => $1);
-       } elsif ($version =~ /gcc\sversion\s(\d+\.\d+)/i) {
-               return (NAME => 'GCC', VERSION => $1);
-       } elsif ($version =~ /(?:icc|icpc)\sversion\s(\d+\.\d+).\d+\s\(gcc\sversion\s(\d+\.\d+).\d+/i) {
-               return (NAME => 'ICC', VERSION => $1);
+       my %info = (NAME => 'Unknown', VERSION => '0.0');
+       return %info if system "$binary -o __compiler_info make/test/compiler_info.cpp ${\CONFIGURE_ERROR_PIPE}";
+       open(my $fh, '-|', './__compiler_info 2>/dev/null');
+       while (my $line = <$fh>) {
+               $info{$1} = $2 if $line =~ /^([A-Z]+)\s(.+)$/;
        }
-       return (NAME => $binary, VERSION => '0.0');
+       close $fh;
+       unlink './__compiler_info';
+       return %info;
 }
 
 sub find_compiler {
index 91d8cd412a5e014c5bfb24f8abf4468757c6a0e5..d111d591ff827317cff8e42004a1e4e8c3f2fe42 100644 (file)
@@ -1,6 +1,7 @@
 /*
  * InspIRCd -- Internet Relay Chat Daemon
  *
+ *   Copyright (C) 2013 Peter Powell <petpow@saberuk.com>
  *
  * This file is part of InspIRCd.  InspIRCd is free software: you can
  * redistribute it and/or modify it under the terms of the GNU General Public
index e2cbd9f64f0cd2ea586bcffe169166d49c61e8c9..f01423325abbc7ac855f678146d845c61a4552f8 100644 (file)
@@ -1,6 +1,8 @@
 /*
  * InspIRCd -- Internet Relay Chat Daemon
  *
+ *   Copyright (C) 2016 Attila Molnar <attilamolnar@hush.com>
+ *   Copyright (C) 2014-2015 Peter Powell <petpow@saberuk.com>
  *
  * This file is part of InspIRCd.  InspIRCd is free software: you can
  * redistribute it and/or modify it under the terms of the GNU General Public
diff --git a/make/test/compiler_info.cpp b/make/test/compiler_info.cpp
new file mode 100644 (file)
index 0000000..10b156f
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * InspIRCd -- Internet Relay Chat Daemon
+ *
+ *   Copyright (C) 2017 Peter Powell <petpow@saberuk.com>
+ *
+ * This file is part of InspIRCd.  InspIRCd is free software: you can
+ * redistribute it and/or modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation, version 2.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include <iostream>
+
+#if defined __INTEL_COMPILER // Also defines __clang__ and __GNUC__
+# define INSPIRCD_COMPILER_NAME "Intel"
+# define INSPIRCD_COMPILER_VERSION (__INTEL_COMPILER / 100) << '.' << (__INTEL_COMPILER % 100)
+#elif defined __clang__ // Also defines __GNUC__
+# if defined __apple_build_version__
+#  define INSPIRCD_COMPILER_NAME "AppleClang"
+# else
+#  define INSPIRCD_COMPILER_NAME "Clang"
+# endif
+# define INSPIRCD_COMPILER_VERSION __clang_major__ << '.' << __clang_minor__
+#elif defined __GNUC__
+# define INSPIRCD_COMPILER_NAME "GCC"
+# define INSPIRCD_COMPILER_VERSION __GNUC__ << '.' << __GNUC_MINOR__
+#endif
+
+int main() {
+       std::cout << "NAME " << INSPIRCD_COMPILER_NAME << std::endl
+               << "VERSION " << INSPIRCD_COMPILER_VERSION << std::endl;
+       return 0;
+}