Be explicit about our minimum required Perl.
[gitmo/Class-MOP.git] / Makefile.PL
CommitLineData
f125b31e 1# The perl/C checking voodoo is mostly stolen from Graham Barr's
2# Scalar-List-Utils distribution.
591a9381 3use strict;
4use warnings;
591a9381 5
f125b31e 6use ExtUtils::MakeMaker;
7use Config qw(%Config);
8use File::Spec;
591a9381 9
f125b31e 10# If undefined, try our best, if true, require XS, if false, never do
11# XS
12my $force_xs;
591a9381 13
f125b31e 14for (@ARGV) {
15 /^--pm/ and $force_xs = 0;
16 /^--xs/ and $force_xs = 1;
17}
591a9381 18
f125b31e 19my $has_compiler = $force_xs;
20unless ( defined $force_xs ) {
21 $has_compiler = check_for_compiler()
22 or no_cc();
23}
24
e896822d 25my %prereqs = (
dfe3e4d0 26 'perl' => '5.008',
e896822d 27 'Scalar::Util' => '1.18',
7b3af905 28 'Sub::Name' => '0.04',
e896822d 29 'Sub::Identify' => '0.03',
30 'MRO::Compat' => '0.05',
31 'Carp' => 0,
9ad4163c 32 'Devel::GlobalDestruction' => 0,
e896822d 33);
34
9ad4163c 35delete @prereqs{qw(Sub::Name Devel::GlobalDestruction)}
e896822d 36 unless $has_compiler;
37
f125b31e 38write_makefile();
39
40sub write_makefile {
41 my $ccflags = -d '.svn' || $ENV{MAINTAINER_MODE} ? '-Wall' : '';
42
43 WriteMakefile(
e896822d 44 VERSION_FROM => 'lib/Class/MOP.pm',
45 NAME => 'Class::MOP',
46 PREREQ_PM => \%prereqs,
f125b31e 47 CONFIGURE => \&init,
48 CCFLAGS => $ccflags,
49 clean => { FILES => 'test.c test.o' },
50 ABSTRACT_FROM => 'lib/Class/MOP.pm',
51 AUTHOR => 'Stevan Little <stevan@iinteractive.com>',
52 LICENSE => 'perl',
53 );
54}
55
56sub no_cc {
57 print <<'EOF';
58
59 I cannot determine if you have a C compiler
60 so I will install a perl-only implementation
61
62 You can force installation of the XS version with
63
64 perl Makefile.PL --xs
65
66EOF
67}
68
69sub check_for_compiler {
70 print "Testing if you have a C compiler\n";
71
72 eval { require ExtUtils::CBuilder };
73 if ($@) {
74 return _check_for_compiler_manually();
75 }
76 else {
77 return _check_for_compiler_with_cbuilder();
78 }
79}
80
81sub _check_for_compiler_with_cbuilder {
82 my $cb = ExtUtils::CBuilder->new( quiet => 1 );
83
84 return $cb->have_compiler();
85}
86
87sub _check_for_compiler_manually {
88 unless ( open F, '>', 'test.c' ) {
89 warn
90 "Cannot write test.c, skipping test compilation and installing pure Perl version.\n";
91 return 0;
92 }
93
94 print F <<'EOF';
95int main() { return 0; }
96EOF
97
98 close F or return 0;
99
100 my $cc = $Config{cc};
101 if ( $cc =~ /cl(\.exe)?$/ ) {
102
103 # stupid stupid MSVC compiler hack tacken from version.pm's
104 # Makefile.PL
105 $cc .= ' -c'; # prevent it from calling the linker
106 }
107
108 system("$cc -o test$Config{obj_ext} test.c") and return 0;
109
110 unlink $_ for grep {-f} 'test.c', "test$Config{obj_ext}";
111
112 return 1;
113}
114
115# This is EUMM voodoo
116sub init {
117 my $hash = $_[1];
118
119 unless ($has_compiler) {
120 @{$hash}{ 'XS', 'C' } = ( {}, [] );
121 }
122
123 $hash;
124}