]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Automatically detect the compiler which the user has installed.
authorPeter Powell <petpow@saberuk.com>
Thu, 4 Jul 2013 07:41:33 +0000 (08:41 +0100)
committerPeter Powell <petpow@saberuk.com>
Fri, 5 Jul 2013 06:12:02 +0000 (07:12 +0100)
configure
make/configure.pm

index 0b3f293c01f6f33e70880d9f1020791a87033cff..777c6c32394ab9744ec249ef558fb465ee59ac33 100755 (executable)
--- a/configure
+++ b/configure
@@ -232,16 +232,15 @@ $config{DESTINATION}        = "BASE";                             # Is target path.
 if ($config{OSNAME} =~ /darwin/i)
 {
        $config{STARTSCRIPT}      = "org.inspircd.plist";               # start script for OSX.
-       $config{CC}                 = "xcrun clang++";                                  # C++ compiler for OSX.
 }
-else
-{
-       $config{CC}                 = "g++";                                            # C++ compiler
-}
-if (defined $ENV{CXX})
-{
-       $config{CC} = $ENV{CXX};
+
+$config{CC} = defined $ENV{CXX} && !system("$ENV{CXX} -v > /dev/null 2>&1") ? $ENV{CXX} : find_compiler();
+if ($config{CC} eq "") {
+       print "A C++ compiler could not be detected on your system!\n";
+       print "Set the CXX environment variable to the full path if this is incorrect.\n";
+       exit 1; 
 }
+
 our $exec = $config{CC} . " -dumpversion | cut -c 1";
 chomp($config{GCCVER}          = `$exec`);                             # Major GCC Version
 $exec = $config{CC} . " -dumpversion | cut -c 3";
@@ -253,15 +252,6 @@ if ($config{HAS_OPENSSL} =~ /^([-[:digit:].]+)(?:[a-z])?(?:\-[a-z][0-9])?/) {
        $config{HAS_OPENSSL} = "";
 }
 
-if (($config{GCCVER} eq "") || ($config{GCCMINOR} eq "")) {
-       if ($config{OSNAME} eq 'darwin') {
-               print $config{CC} . " was not found! You require clang++ (the LLVM C++ compiler, part of the OSX developer tools) to build InspIRCd!\n";
-       } else {
-               print $config{CC} . " was not found! You require g++ (the GNU C++ compiler, part of GCC) to build InspIRCd!\n";         
-       }
-       exit;
-}
-
 # Get and Set some important vars..
 getmodules();
 
index 194d439e327d587caa3b8a3b5c2c424c96dc4039..c022a7493bb5c687ade613dce41edb957ed3f230 100644 (file)
@@ -31,10 +31,20 @@ use warnings FATAL => qw(all);
 use Exporter 'import';
 use POSIX;
 use make::utilities;
-our @EXPORT = qw(test_file test_header promptnumeric dumphash is_dir getmodules getrevision getcompilerflags getlinkerflags getdependencies nopedantic resolve_directory yesno showhelp promptstring_s module_installed);
+our @EXPORT = qw(find_compiler test_file test_header promptnumeric dumphash is_dir getmodules getrevision getcompilerflags getlinkerflags getdependencies nopedantic resolve_directory yesno showhelp promptstring_s module_installed);
 
 my $no_git = 0;
 
+sub find_compiler {
+       foreach my $compiler ('c++', 'g++', 'clang++', 'icpc') {
+               return $compiler unless system "$compiler -v > /dev/null 2>&1";
+               if ($^O eq 'Darwin') {
+                       return $compiler unless system "xcrun $compiler -v > /dev/null 2>&1";
+               }
+       }
+       return "";
+}
+
 sub test_file($$;$) {
        my ($cc, $file, $args) = @_;
        my $status = 0;