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