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 our $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)}
47 my $ccflags = -d '.svn' || $ENV{MAINTAINER_MODE} ? '-Wall' : '';
50 VERSION_FROM => 'lib/Class/MOP.pm',
52 PREREQ_PM => \%prereqs,
55 clean => { FILES => 'test.c test.o t/pp*' },
56 ABSTRACT_FROM => 'lib/Class/MOP.pm',
57 AUTHOR => 'Stevan Little <stevan@iinteractive.com>',
65 I cannot determine if you have a C compiler
66 so I will install a perl-only implementation
68 You can force installation of the XS version with
75 sub check_for_compiler {
76 print "Testing if you have a C compiler\n";
78 eval { require ExtUtils::CBuilder };
80 return _check_for_compiler_manually();
83 return _check_for_compiler_with_cbuilder();
87 sub _check_for_compiler_with_cbuilder {
88 my $cb = ExtUtils::CBuilder->new( quiet => 1 );
90 return $cb->have_compiler();
93 sub _check_for_compiler_manually {
94 unless ( open F, '>', 'test.c' ) {
96 "Cannot write test.c, skipping test compilation and installing pure Perl version.\n";
101 int main() { return 0; }
106 my $cc = $Config{cc};
107 if ( $cc =~ /cl(\.exe)?$/ ) {
109 # stupid stupid MSVC compiler hack tacken from version.pm's
111 $cc .= ' -c'; # prevent it from calling the linker
114 system("$cc -o test$Config{obj_ext} test.c") and return 0;
116 unlink $_ for grep {-f} 'test.c', "test$Config{obj_ext}";
121 # This sucks, but it's the best guess we can make. Since we just use
122 # it to run two sets of tests, it's not big deal if it ends up true
123 # for a non-maintainer.
125 return 0 if $ENV{PERL5_CPAN_IS_RUNNING} || $ENV{PERL5_CPANPLUS_IS_RUNNING};
131 opendir my $dh, 't' or die "Cannot read t: $!";
133 return grep { $_ !~ /^99/ } grep {/^\d.+\.t$/} readdir $dh;
136 # This is EUMM voodoo
140 unless ($has_compiler) {
141 @{$hash}{ 'XS', 'C' } = ( {}, [] );
150 my @test_files = ::get_pp_tests();
151 my $pp_tests = join q{ }, map { File::Spec->catfile('t', "pp_${_}") } @test_files;
152 my @pp_test_targets = join qq{\n}, map {
153 my $source = File::Spec->catfile('t', ${_});
154 File::Spec->catfile('t', "pp_${_}") . q{: }
155 . qq{$source t/header_pp.inc\n\t}
156 . q{$(NOECHO) $(ABSPERLRUN) "-MExtUtils::Command" -e cat t/header_pp.inc }
157 . $source . q{ > $@} . qq{\n}
159 my $test_dep = $::has_compiler && (::is_maintainer() || $ENV{AUTOMATED_TESTING})
160 ? qq{pure_all :: pp_tests\n} . join qq{\n}, @pp_test_targets
164 pp_tests: ${pp_tests}