1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
|
package TestGuess;
use strict;
use warnings;
# This is the logic we used to keep in Makefile.PL that was used to make an
# educated guess as to what compiler, compiler flags, standard libraries, and
# linker flags to configure into Inline::CPP.
# Inline::CPP shifted to using ExtUtils::CppGuess instead, but retains this
# logic for testing purposes, as well as for working toward improving
# ExtUtils::CppGuess.
# my( $cc_guess, $libs_guess ) = guess_compiler();
#============================================================================
# Make an intelligent guess about what compiler to use
#============================================================================
sub new {
my( $class, $config ) = @_;
return bless { config => $config }, $class;
}
sub guess_compiler {
my $self = shift;
my( $cc_guess, $libs_guess );
if ( $self->{config}{osname} eq 'darwin' ) {
my $stdlib_query
= 'find /usr/lib/gcc -name "libstdc++*" | grep $( uname -p )';
my $stdcpp = `$stdlib_query`;
+$stdcpp =~ s/^(.*)\/[^\/]+$/$1/;
$cc_guess = 'g++';
$libs_guess = "-L$stdcpp -lstdc++";
}
elsif ( $self->{config}{osname} ne 'darwin'
and $self->{config}{gccversion}
and $self->{config}{cc} =~ m#\bgcc\b[^/]*$#
) {
( $cc_guess = $self->{config}{cc} ) =~ s[\bgcc\b([^/]*)$(?:)][g\+\+$1];
$libs_guess = '-lstdc++';
}
elsif ( $self->{config}{osname} =~ m/^MSWin/ ) {
$cc_guess = 'cl -TP -EHsc';
$libs_guess = 'MSVCIRT.LIB';
}
elsif ( $self->{config}{osname} eq 'linux' ) {
$cc_guess = 'g++';
$libs_guess = '-lstdc++';
}
# Dragonfly patch is just a hunch... (still doesn't work)
elsif ( $self->{config}{osname} eq 'netbsd' || $self->{config}{osname} eq 'dragonfly' ) {
$cc_guess = 'g++';
$libs_guess = '-lstdc++ -lgcc_s';
}
elsif ( $self->{config}{osname} eq 'cygwin' ) {
$cc_guess = 'g++';
$libs_guess = '-lstdc++';
}
elsif ( $self->{config}{osname} eq 'solaris'
|| $self->{config}{osname} eq 'SunOS' ) {
if ( $self->{config}{cc} eq 'gcc'
|| ( exists( $self->{config}{gccversion} ) && $self->{config}{gccversion} > 0 ) )
{
$cc_guess = 'g++';
$libs_guess = '-lstdc++';
}
else {
$cc_guess = 'CC';
$libs_guess = '-lCrun';
}
}
# MirBSD: Still problematic.
elsif ( $self->{config}{osname} eq 'mirbsd' ) {
my $stdlib_query
= 'find /usr/lib/gcc -name "libstdc++*" | grep $( uname -p ) | head -1';
my $stdcpp = `$stdlib_query`;
+$stdcpp =~ s/^(.*)\/[^\/]+$/$1/;
$cc_guess = 'g++';
$libs_guess = "-L$stdcpp -lstdc++ -lc -lgcc_s";
}
elsif( $self->{config}{osname} eq 'freebsd'
and $self->{config}{osvers} =~ /^(\d+)/
and $1 >= 10
){
$cc_guess = 'clang++';
$libs_guess = '-lc++';
}
# Sane defaults for other (probably unix-like) operating systems
else {
$cc_guess = 'g++';
$libs_guess = '-lstdc++';
}
return( $cc_guess, $libs_guess );
}
1;
|