2 package Module
::Install
::Can
;
6 use ExtUtils
::MakeMaker
();
7 use Module
::Install
::Base
();
9 use vars
qw{$VERSION @ISA $ISCORE};
12 @ISA = 'Module::Install::Base';
16 # check if we can load some module
17 ### Upgrade this to not have to load the module if possible
19 my ($self, $mod, $ver) = @_;
21 $mod .= '.pm' unless $mod =~ /\.pm$/i;
28 eval { require $mod; $pkg->VERSION($ver || 0); 1 };
31 # Check if we can run some command
33 my ($self, $cmd) = @_;
36 return $_cmd if (-x
$_cmd or $_cmd = MM
->maybe_command($_cmd));
38 for my $dir ((split /$Config::Config{path_sep}/, $ENV{PATH
}), '.') {
41 my $abs = File
::Spec
->catfile($dir, $cmd);
42 return $abs if (-x
$abs or $abs = MM
->maybe_command($abs));
48 # Can our C compiler environment build XS files
52 # Ensure we have the CBuilder module
53 $self->configure_requires( 'ExtUtils::CBuilder' => 0.27 );
55 # Do we have the configure_requires checker?
57 eval "require ExtUtils::CBuilder;";
59 # They don't obey configure_requires, so it is
60 # someone old and delicate. Try to avoid hurting
61 # them by falling back to an older simpler test.
62 return $self->can_cc();
65 # Do we have a working C compiler
66 my $builder = ExtUtils
::CBuilder
->new(
69 unless ( $builder->have_compiler ) {
70 # No working C compiler
74 # Write a C file representative of what XS becomes
76 my ( $FH, $tmpfile ) = File
::Temp
::tempfile
(
86 int main(int argc, char **argv) {
97 # Can the C compiler access the same headers XS does
102 $object = $builder->compile(
105 @libs = $builder->link(
107 module_name => 'sanexs',
110 my $result = $@ ? 0 : 1;
112 # Clean up all the build files
113 foreach ( $tmpfile, $object, @libs ) {
114 next unless defined $_;
121 # Can we locate a (the) C compiler
124 my @chunks = split(/ /, $Config::Config{cc}) or return;
126 # $Config{cc} may contain args; try to find out the program part
128 return $self->can_run("@chunks") || (pop(@chunks), next);
134 # Fix Cygwin bug on maybe_command();
135 if ( $^O eq 'cygwin' ) {
136 require ExtUtils::MM_Cygwin;
137 require ExtUtils::MM_Win32;
138 if ( ! defined(&ExtUtils::MM_Cygwin::maybe_command) ) {
139 *ExtUtils::MM_Cygwin::maybe_command = sub {
140 my ($self, $file) = @_;
141 if ($file =~ m{^/cygdrive/}i and ExtUtils::MM_Win32->can('maybe_command')) {
142 ExtUtils::MM_Win32->maybe_command($file);
144 ExtUtils::MM_Unix->maybe_command($file);