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