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',
40 delete @prereqs{qw(Sub::Name Devel::GlobalDestruction)}
43 if ($has_compiler && is_maintainer()) {
50 my $ccflags = -d '.svn' || $ENV{MAINTAINER_MODE} ? '-Wall' : '';
53 VERSION_FROM => 'lib/Class/MOP.pm',
55 PREREQ_PM => \%prereqs,
58 clean => { FILES => 'test.c test.o t/pp*' },
59 ABSTRACT_FROM => 'lib/Class/MOP.pm',
60 AUTHOR => 'Stevan Little <stevan@iinteractive.com>',
68 I cannot determine if you have a C compiler
69 so I will install a perl-only implementation
71 You can force installation of the XS version with
78 sub check_for_compiler {
79 print "Testing if you have a C compiler\n";
81 eval { require ExtUtils::CBuilder };
83 return _check_for_compiler_manually();
86 return _check_for_compiler_with_cbuilder();
90 sub _check_for_compiler_with_cbuilder {
91 my $cb = ExtUtils::CBuilder->new( quiet => 1 );
93 return $cb->have_compiler();
96 sub _check_for_compiler_manually {
97 unless ( open F, '>', 'test.c' ) {
99 "Cannot write test.c, skipping test compilation and installing pure Perl version.\n";
104 int main() { return 0; }
109 my $cc = $Config{cc};
110 if ( $cc =~ /cl(\.exe)?$/ ) {
112 # stupid stupid MSVC compiler hack tacken from version.pm's
114 $cc .= ' -c'; # prevent it from calling the linker
117 system("$cc -o test$Config{obj_ext} test.c") and return 0;
119 unlink $_ for grep {-f} 'test.c', "test$Config{obj_ext}";
124 # This sucks, but it's the best guess we can make. Since we just use
125 # it to run two sets of tests, it's not big deal if it ends up true
126 # for a non-maintainer.
128 return 0 if $ENV{PERL5_CPAN_IS_RUNNING} || $ENV{PERL5_CPANPLUS_IS_RUNNING};
133 sub create_pp_tests {
134 opendir my $dh, 't' or die "Cannot read t: $!";
136 foreach my $file ( grep {/^\d.+\.t$/} readdir $dh ) {
137 next if $file =~ /^99/;
139 my $real_file = File::Spec->catfile( 't', $file );
141 open my $fh, '<', $real_file
142 or die "Cannot read $real_file: $!";
145 my $test = do { local $/; <$fh> };
149 $test = "$shbang\nBEGIN { \$ENV{CLASS_MOP_NO_XS} = 1 }\n\n$test";
151 my $new_file = File::Spec->catfile( 't', "pp_$file" );
152 open my $new_fh, '>', $new_file
153 or die "Cannot write to $new_file: $!";
161 # This is EUMM voodoo
165 unless ($has_compiler) {
166 @{$hash}{ 'XS', 'C' } = ( {}, [] );