1 # The perl/C checking voodoo is mostly stolen from Graham Barr's
2 # Scalar-List-Utils distribution.
6 use ExtUtils::MakeMaker;
7 use Config qw(%Config);
12 # If undefined, try our best, if true, require XS, if false, never do
17 /^--pm/ and $force_xs = 0;
18 /^--xs/ and $force_xs = 1;
21 my $has_compiler = $force_xs;
22 unless ( defined $force_xs ) {
23 $has_compiler = check_for_compiler()
28 'Scalar::Util' => '1.18',
29 'Sub::Name' => '0.04',
30 'Sub::Identify' => '0.03',
31 'MRO::Compat' => '0.05',
33 'Test::Exception' => '0',
36 'Devel::GlobalDestruction' => '0',
39 delete @prereqs{qw(Sub::Name Devel::GlobalDestruction)}
42 if ($has_compiler && is_maintainer()) {
49 my $ccflags = -d '.svn' || $ENV{MAINTAINER_MODE} ? '-Wall' : '';
52 VERSION_FROM => 'lib/Class/MOP.pm',
54 PREREQ_PM => \%prereqs,
57 clean => { FILES => 'test.c test.o t/pp*' },
58 ABSTRACT_FROM => 'lib/Class/MOP.pm',
59 AUTHOR => 'Stevan Little <stevan@iinteractive.com>',
67 I cannot determine if you have a C compiler
68 so I will install a perl-only implementation
70 You can force installation of the XS version with
77 sub check_for_compiler {
78 print "Testing if you have a C compiler\n";
80 eval { require ExtUtils::CBuilder };
82 return _check_for_compiler_manually();
85 return _check_for_compiler_with_cbuilder();
89 sub _check_for_compiler_with_cbuilder {
90 my $cb = ExtUtils::CBuilder->new( quiet => 1 );
92 return $cb->have_compiler();
95 sub _check_for_compiler_manually {
96 unless ( open F, '>', 'test.c' ) {
98 "Cannot write test.c, skipping test compilation and installing pure Perl version.\n";
103 int main() { return 0; }
108 my $cc = $Config{cc};
109 if ( $cc =~ /cl(\.exe)?$/ ) {
111 # stupid stupid MSVC compiler hack tacken from version.pm's
113 $cc .= ' -c'; # prevent it from calling the linker
116 system("$cc -o test$Config{obj_ext} test.c") and return 0;
118 unlink $_ for grep {-f} 'test.c', "test$Config{obj_ext}";
123 # This sucks, but it's the best guess we can make. Since we just use
124 # it to run two sets of tests, it's not big deal if it ends up true
125 # for a non-maintainer.
127 return 0 if $ENV{PERL5_CPAN_IS_RUNNING} || $ENV{PERL5_CPANPLUS_IS_RUNNING};
132 sub create_pp_tests {
133 opendir my $dh, 't' or die "Cannot read t: $!";
135 foreach my $file ( grep {/^\d.+\.t$/} readdir $dh ) {
136 next if $file =~ /^99/;
138 my $real_file = File::Spec->catfile( 't', $file );
140 open my $fh, '<', $real_file
141 or die "Cannot read $real_file: $!";
144 my $test = do { local $/; <$fh> };
148 $test = "$shbang\nBEGIN { \$ENV{CLASS_MOP_NO_XS} = 1 }\n\n$test";
150 my $new_file = File::Spec->catfile( 't', "pp_$file" );
151 open my $new_fh, '>', $new_file
152 or die "Cannot write to $new_file: $!";
160 # This is EUMM voodoo
164 unless ($has_compiler) {
165 @{$hash}{ 'XS', 'C' } = ( {}, [] );