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',
37 'Task::Weaken' => '0',
41 delete @prereqs{qw(Sub::Name Devel::GlobalDestruction)}
44 if ($has_compiler && is_maintainer()) {
51 my $ccflags = -d '.svn' || $ENV{MAINTAINER_MODE} ? '-Wall' : '';
54 VERSION_FROM => 'lib/Class/MOP.pm',
56 PREREQ_PM => \%prereqs,
59 clean => { FILES => 'test.c test.o t/pp*' },
60 ABSTRACT_FROM => 'lib/Class/MOP.pm',
61 AUTHOR => 'Stevan Little <stevan@iinteractive.com>',
69 I cannot determine if you have a C compiler
70 so I will install a perl-only implementation
72 You can force installation of the XS version with
79 sub check_for_compiler {
80 print "Testing if you have a C compiler\n";
82 eval { require ExtUtils::CBuilder };
84 return _check_for_compiler_manually();
87 return _check_for_compiler_with_cbuilder();
91 sub _check_for_compiler_with_cbuilder {
92 my $cb = ExtUtils::CBuilder->new( quiet => 1 );
94 return $cb->have_compiler();
97 sub _check_for_compiler_manually {
98 unless ( open F, '>', 'test.c' ) {
100 "Cannot write test.c, skipping test compilation and installing pure Perl version.\n";
105 int main() { return 0; }
110 my $cc = $Config{cc};
111 if ( $cc =~ /cl(\.exe)?$/ ) {
113 # stupid stupid MSVC compiler hack tacken from version.pm's
115 $cc .= ' -c'; # prevent it from calling the linker
118 system("$cc -o test$Config{obj_ext} test.c") and return 0;
120 unlink $_ for grep {-f} 'test.c', "test$Config{obj_ext}";
125 # This sucks, but it's the best guess we can make. Since we just use
126 # it to run two sets of tests, it's not big deal if it ends up true
127 # for a non-maintainer.
129 return 0 if $ENV{PERL5_CPAN_IS_RUNNING} || $ENV{PERL5_CPANPLUS_IS_RUNNING};
134 sub create_pp_tests {
135 opendir my $dh, 't' or die "Cannot read t: $!";
137 foreach my $file ( grep {/^\d.+\.t$/} readdir $dh ) {
138 next if $file =~ /^99/;
140 my $real_file = File::Spec->catfile( 't', $file );
142 open my $fh, '<', $real_file
143 or die "Cannot read $real_file: $!";
146 my $test = do { local $/; <$fh> };
150 $test = "$shbang\nBEGIN { \$ENV{CLASS_MOP_NO_XS} = 1 }\n\n$test";
152 my $new_file = File::Spec->catfile( 't', "pp_$file" );
153 open my $new_fh, '>', $new_file
154 or die "Cannot write to $new_file: $!";
162 # This is EUMM voodoo
166 unless ($has_compiler) {
167 @{$hash}{ 'XS', 'C' } = ( {}, [] );