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