diff options
author | Attila Molnar <attilamolnar@hush.com> | 2013-07-06 08:35:04 -0700 |
---|---|---|
committer | Attila Molnar <attilamolnar@hush.com> | 2013-07-06 08:35:04 -0700 |
commit | b64221d8ba35b461af9267537b3853728e4e02df (patch) | |
tree | 50b48a1cd9720b0fa939a293d737dccb5d08b497 | |
parent | 752cb8b179cc1cbec3f36d7a3084fa98a81f92d8 (diff) | |
parent | 1b475afbe5e033a55795271cdf98108dac3e97a7 (diff) |
Merge pull request #578 from SaberUK/master+configure-compiler-detection
Improve compiler logic in configure.
-rwxr-xr-x | configure | 108 | ||||
-rw-r--r-- | make/configure.pm | 40 | ||||
-rw-r--r-- | make/template/main.mk | 7 |
3 files changed, 63 insertions, 92 deletions
@@ -56,7 +56,7 @@ use make::configure; our ($opt_use_gnutls, $opt_use_openssl, $opt_nointeractive, $opt_ports, $opt_epoll, $opt_kqueue, $opt_noports, $opt_noepoll, $opt_nokqueue, $opt_freebsd_port, $opt_system, $opt_uid); -our ($opt_cc, $opt_base_dir, $opt_config_dir, $opt_module_dir, $opt_binary_dir, $opt_data_dir, $opt_log_dir); +our ($opt_base_dir, $opt_config_dir, $opt_module_dir, $opt_binary_dir, $opt_data_dir, $opt_log_dir); sub list_extras (); @@ -79,7 +79,6 @@ GetOptions ( 'disable-ports' => \$opt_noports, 'disable-epoll' => \$opt_noepoll, 'disable-kqueue' => \$opt_nokqueue, - 'with-cc=s' => \$opt_cc, 'enable-freebsd-ports-openssl' => \$opt_freebsd_port, 'prefix=s' => \$opt_base_dir, 'config-dir=s' => \$opt_config_dir, @@ -114,7 +113,6 @@ our $interactive = !( (defined $opt_data_dir) || (defined $opt_log_dir) || (defined $opt_nointeractive) || - (defined $opt_cc) || (defined $opt_kqueue) || (defined $opt_epoll) || (defined $opt_ports) || @@ -234,20 +232,21 @@ $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 + +$config{CXX} = defined $ENV{CXX} && !system("$ENV{CXX} -v > /dev/null 2>&1") ? $ENV{CXX} : find_compiler(); +if ($config{CXX} 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; } -if (defined $opt_cc) -{ - $config{CC} = $opt_cc; + +our %cxx = get_compiler_info($config{CXX}); +if ($cxx{UNSUPPORTED}) { + print "Your C++ compiler is too old to build InspIRCd!\n"; + print "Reason: $cxx{REASON}\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"; -chomp($config{GCCMINOR} = `$exec`); if ($config{HAS_OPENSSL} =~ /^([-[:digit:].]+)(?:[a-z])?(?:\-[a-z][0-9])?/) { $config{HAS_OPENSSL} = $1; @@ -255,15 +254,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(); @@ -310,14 +300,8 @@ print ($cache_loaded ? "found\n" : "not found\n"); $config{SYSTEM} = lc $^O; print "Checking operating system version... $config{SYSTEM}\n"; -$exec = $config{CC} . " -dumpversion | cut -c 1"; -chomp($config{GCCVER} = `$exec`); # Major GCC Version -$exec = $config{CC} . " -dumpversion | cut -c 3"; -chomp($config{GCCMINOR} = `$exec`); - - print "Checking whether <stdint.h> exists... "; -if (test_header($config{CC}, "stdint.h")) { +if (test_header($config{CXX}, "stdint.h")) { $config{HAS_STDINT} = "true"; print "yes\n"; } else { @@ -326,7 +310,7 @@ if (test_header($config{CC}, "stdint.h")) { } printf "Checking whether clock_gettime() exists... "; -if (test_file($config{CC}, "clock_gettime.cpp", "-lrt")) { +if (test_file($config{CXX}, "clock_gettime.cpp", "-lrt")) { $config{HAS_CLOCK_GETTIME} = "true"; print "yes\n"; } else { @@ -335,7 +319,7 @@ if (test_file($config{CC}, "clock_gettime.cpp", "-lrt")) { } printf "Checking whether eventfd() exists... "; -if (test_file($config{CC}, "eventfd.cpp")) { +if (test_file($config{CXX}, "eventfd.cpp")) { $config{HAS_EVENTFD} = "true"; print "yes\n"; } else { @@ -344,10 +328,10 @@ if (test_file($config{CC}, "eventfd.cpp")) { } printf "Checking if a TCP deferring mechanism is available... "; -if (test_file($config{CC}, "tcp_defer_accept.cpp")) { +if (test_file($config{CXX}, "tcp_defer_accept.cpp")) { $config{HAS_DEFER} = "TCP_DEFER_ACCEPT"; print "yes (TCP_DEFER_ACCEPT)\n"; -} elsif (test_file($config{CC}, "so_acceptfilter.cpp")) { +} elsif (test_file($config{CXX}, "so_acceptfilter.cpp")) { $config{HAS_DEFER} = "SO_ACCEPTFILTER"; print "yes (SO_ACCEPTFILTER)\n"; } else { @@ -356,15 +340,15 @@ if (test_file($config{CC}, "tcp_defer_accept.cpp")) { } print "Checking whether epoll is available... "; -$has_epoll = test_header($config{CC}, "sys/epoll.h"); +$has_epoll = test_header($config{CXX}, "sys/epoll.h"); print $has_epoll ? "yes\n" : "no\n"; print "Checking whether Kqueue is available... "; -$has_kqueue = test_file($config{CC}, "kqueue.cpp"); +$has_kqueue = test_file($config{CXX}, "kqueue.cpp"); print $has_kqueue ? "yes\n" : "no\n"; print 'Checking whether Solaris IOCP is available... '; -$has_ports = test_header($config{CC}, 'port.h'); +$has_ports = test_header($config{CXX}, 'port.h'); print $has_ports ? "yes\n" : "no\n"; $config{HAS_EPOLL} = $has_epoll; @@ -451,36 +435,7 @@ STOP } print ".\n\n"; - $config{CHANGE_COMPILER} = "n"; - print "I have detected the following compiler: \e[1;32m$config{CC}\e[0m (version \e[1;32m$config{GCCVER}.$config{GCCMINOR}\e[0m)\n"; - - while (($config{GCCVER} < 3) || ($config{GCCVER} eq "")) { - print "\e[1;32mIMPORTANT!\e[0m A GCC 2.x compiler has been detected, and -should NOT be used. You should probably specify a newer compiler.\n\n"; - yesno('CHANGE_COMPILER',"Do you want to change the compiler?"); - if ($config{CHANGE_COMPILER} =~ /y/i) { - print "What command do you want to use to invoke your compiler?\n"; - print "[\e[1;32m$config{CC}\e[0m] -> "; - chomp($config{CC} = <STDIN>); - if ($config{CC} eq "") { - $config{CC} = "g++"; - } - chomp(my $foo = `$config{CC} -dumpversion | cut -c 1`); - if ($foo ne "") { - chomp($config{GCCVER} = `$config{CC} -dumpversion | cut -c 1`); # we must redo these if we change compilers - chomp($config{GCCMINOR} = `$config{CC} -dumpversion | cut -c 3`); - print "Queried compiler: \e[1;32m$config{CC}\e[0m (version \e[1;32m$config{GCCVER}.$config{GCCMINOR}\e[0m)\n"; - if ($config{GCCVER} < 4 || $config{GCCVER} == 4 && $config{GCCMINOR} < 1) { - print "\e[1;32mGCC 4.1 and earlier WILL NOT WORK!\e[0m. Let's try that again, shall we?\n"; - } - } - else { - print "\e[1;32mWARNING!\e[0m Could not execute the compiler you specified. You may want to try again.\n"; - } - } - } - - print "\n"; + print "I have detected the following compiler: \e[1;32m$cxx{NAME}\e[0m (version \e[1;32m$cxx{VERSION}\e[0m)\n\n"; # Directory Settings.. my $tmpbase = $config{BASE_DIR}; @@ -700,19 +655,6 @@ if (($config{USE_GNUTLS} eq "y") || ($config{USE_OPENSSL} eq "y")) { print "\e[1;32mhttp://wiki.inspircd.org/Installation_From_Tarball\e[0m\n"; } print "*** \e[1;32mRemember to edit your configuration files!!!\e[0m ***\n\n\n"; -if (($config{OSNAME} eq "OpenBSD") && ($config{CC} ne "eg++")) { - print "\e[1;32mWARNING!\e[0m You are running OpenBSD but you are using the base gcc package\nrather than eg++. This compile will most likely fail, but i'm letting you\ngo ahead with it anyway, just in case i'm wrong :-)\n"; -} - -if ($config{GCCVER} < "3") { - print <<FOO2; -\e[1;32mWARNING!\e[0m You are attempting to compile InspIRCd on GCC 2.x! -GCC 2.x series compilers only had partial (read as broken) C++ support, and -your compile will most likely fail horribly! If you have any problems, do NOT -report them to the bugtracker or forums without first upgrading your compiler -to a newer 3.x or 4.x (or whatever is available currently) version. -FOO2 -} ################################################################################ # HELPER FUNCTIONS # @@ -840,9 +782,6 @@ EOF if ($config{OSNAME} =~ /MINGW32/i) { print FILEHANDLE "#define IS_MINGW\n"; } - if ($config{GCCVER} >= 3) { - print FILEHANDLE "#define GCC3\n"; - } if ($config{HAS_STDINT} eq "true") { print FILEHANDLE "#define HAS_STDINT\n"; } @@ -943,9 +882,10 @@ EOF close(FILEHANDLE); $config{BUILD_DIR} ||= resolve_directory($config{ME}."/build"); + $config{COMPILER} = lc $cxx{NAME}; for my $var (qw( - CC SYSTEM BASE_DIR CONFIG_DIR MODULE_DIR BINARY_DIR BUILD_DIR DATA_DIR UID + CXX COMPILER SYSTEM BASE_DIR CONFIG_DIR MODULE_DIR BINARY_DIR BUILD_DIR DATA_DIR UID STARTSCRIPT DESTINATION SOCKETENGINE )) { s/\@$var\@/$config{$var}/g; diff --git a/make/configure.pm b/make/configure.pm index 2ae9c7fa0..95499720f 100644 --- a/make/configure.pm +++ b/make/configure.pm @@ -31,10 +31,43 @@ 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(get_compiler_info 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 get_compiler_info($) { + my %info = (NAME => shift, VERSION => '0.0'); + my $version = `$info{NAME} -v 2>&1`; + return (ERROR => 1) if $?; + if ($version =~ /(?:clang|llvm)\sversion\s(\d+\.\d+)/i) { + $info{NAME} = 'Clang'; + $info{VERSION} = $1; + $info{UNSUPPORTED} = $1 lt '3.0'; + $info{REASON} = 'Clang 2.9 and older do not have adequate C++ support.'; + } elsif ($version =~ /gcc\sversion\s(\d+\.\d+)/i) { + $info{NAME} = 'GCC'; + $info{VERSION} = $1; + $info{UNSUPPORTED} = $1 lt '4.1'; + $info{REASON} = 'GCC 4.0 and older do not have adequate C++ support.'; + } elsif ($version =~ /(?:icc|icpc)\sversion\s(\d+\.\d+).\d+\s\(gcc\sversion\s(\d+\.\d+).\d+/i) { + $info{NAME} = 'ICC'; + $info{VERSION} = $1; + $info{UNSUPPORTED} = $2 lt '4.1'; + $info{REASON} = "ICC $1 (GCC $2 compatibility mode) does not have adequate C++ support." + } + return %info; +} + +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; @@ -237,8 +270,7 @@ sub dumphash() print "\e[0mBase install path:\e[1;32m\t\t$main::config{BASE_DIR}\e[0m\n"; print "\e[0mConfig path:\e[1;32m\t\t\t$main::config{CONFIG_DIR}\e[0m\n"; print "\e[0mModule path:\e[1;32m\t\t\t$main::config{MODULE_DIR}\e[0m\n"; - print "\e[0mGCC Version Found:\e[1;32m\t\t$main::config{GCCVER}.$main::config{GCCMINOR}\e[0m\n"; - print "\e[0mCompiler program:\e[1;32m\t\t$main::config{CC}\e[0m\n"; + print "\e[0mCompiler:\e[1;32m\t\t\t$main::cxx{NAME} $main::cxx{VERSION}\e[0m\n"; print "\e[0mGnuTLS Support:\e[1;32m\t\t\t$main::config{USE_GNUTLS}\e[0m\n"; print "\e[0mOpenSSL Support:\e[1;32m\t\t$main::config{USE_OPENSSL}\e[0m\n\n"; print "\e[1;32mImportant note: The maximum length values are now configured in the\e[0m\n"; @@ -295,8 +327,6 @@ InspIRCd 1.0.x, are also allowed. to select() [not set] --disable-kqueue Do not enable kqueue(), fall back to select() [not set] - --with-cc=[filename] Use an alternative compiler to - build InspIRCd [g++] --prefix=[directory] Base directory to install into (if defined, can automatically define config, module, bin and library dirs as subdirectories of prefix) diff --git a/make/template/main.mk b/make/template/main.mk index fd094b578..b93c15094 100644 --- a/make/template/main.mk +++ b/make/template/main.mk @@ -30,12 +30,13 @@ # -CXX = @CC@ +CXX = @CXX@ +COMPILER = @COMPILER@ SYSTEM = @SYSTEM@ BUILDPATH = @BUILD_DIR@ SOCKETENGINE = @SOCKETENGINE@ CORECXXFLAGS = -fPIC -pipe -Iinclude -Wall -Wextra -Wfatal-errors -Wno-unused-parameter -Wshadow -LDLIBS = -pthread -lstdc++ +LDLIBS = -lstdc++ CORELDFLAGS = -rdynamic -L. $(LDFLAGS) PICLDFLAGS = -fPIC -shared -rdynamic $(LDFLAGS) BASE = "$(DESTDIR)@BASE_DIR@" @@ -49,7 +50,7 @@ INSTMODE_DIR = 0755 INSTMODE_BIN = 0755 INSTMODE_LIB = 0644 -@IFNEQ $(CXX) icc +@IFNEQ $(COMPILER) icc CORECXXFLAGS += -pedantic -Woverloaded-virtual -Wshadow -Wformat=2 -Wmissing-format-attribute @ENDIF |