X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=Makefile.PL;h=4fdf33563cdcb7efb39165f3175714c004194148;hb=b16217dda005ba1dc4a1f96366e992d867d702d4;hp=daeed088a19469ab7355ec41ab8408a32142441b;hpb=a2e85e6c752e6dd43555a7eb5623696a86afa858;p=gitmo%2FClass-MOP.git diff --git a/Makefile.PL b/Makefile.PL index daeed08..4fdf335 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -1,13 +1,123 @@ +# The perl/C checking voodoo is mostly stolen from Graham Barr's +# Scalar-List-Utils distribution. +use strict; +use warnings; + use ExtUtils::MakeMaker; -WriteMakefile( - NAME => 'Class::MOP', - VERSION_FROM => 'lib/Class/MOP.pm', - PREREQ_PM => { - 'Test::More' => '0.47', - 'Test::Exception' => '0.21', - 'Scalar::Util' => '1.17', - 'Sub::Name' => '0.02', - 'Carp' => '0.01', - 'B' => '0', - } +use Config qw(%Config); +use File::Spec; + +# If undefined, try our best, if true, require XS, if false, never do +# XS +my $force_xs; + +for (@ARGV) { + /^--pm/ and $force_xs = 0; + /^--xs/ and $force_xs = 1; +} + +my $has_compiler = $force_xs; +unless ( defined $force_xs ) { + $has_compiler = check_for_compiler() + or no_cc(); +} + +my %prereqs = ( + 'Scalar::Util' => '1.18', + 'Sub::Name' => '0.02', + 'Sub::Identify' => '0.03', + 'MRO::Compat' => '0.05', + 'Carp' => 0, + 'Devel::GlobalDestruction' => 0, ); + +delete @prereqs{qw(Sub::Name Devel::GlobalDestruction)} + unless $has_compiler; + +write_makefile(); + +sub write_makefile { + my $ccflags = -d '.svn' || $ENV{MAINTAINER_MODE} ? '-Wall' : ''; + + WriteMakefile( + VERSION_FROM => 'lib/Class/MOP.pm', + NAME => 'Class::MOP', + PREREQ_PM => \%prereqs, + CONFIGURE => \&init, + CCFLAGS => $ccflags, + clean => { FILES => 'test.c test.o' }, + ABSTRACT_FROM => 'lib/Class/MOP.pm', + AUTHOR => 'Stevan Little ', + LICENSE => 'perl', + ); +} + +sub no_cc { + print <<'EOF'; + + I cannot determine if you have a C compiler + so I will install a perl-only implementation + + You can force installation of the XS version with + + perl Makefile.PL --xs + +EOF +} + +sub check_for_compiler { + print "Testing if you have a C compiler\n"; + + eval { require ExtUtils::CBuilder }; + if ($@) { + return _check_for_compiler_manually(); + } + else { + return _check_for_compiler_with_cbuilder(); + } +} + +sub _check_for_compiler_with_cbuilder { + my $cb = ExtUtils::CBuilder->new( quiet => 1 ); + + return $cb->have_compiler(); +} + +sub _check_for_compiler_manually { + unless ( open F, '>', 'test.c' ) { + warn + "Cannot write test.c, skipping test compilation and installing pure Perl version.\n"; + return 0; + } + + print F <<'EOF'; +int main() { return 0; } +EOF + + close F or return 0; + + my $cc = $Config{cc}; + if ( $cc =~ /cl(\.exe)?$/ ) { + + # stupid stupid MSVC compiler hack tacken from version.pm's + # Makefile.PL + $cc .= ' -c'; # prevent it from calling the linker + } + + system("$cc -o test$Config{obj_ext} test.c") and return 0; + + unlink $_ for grep {-f} 'test.c', "test$Config{obj_ext}"; + + return 1; +} + +# This is EUMM voodoo +sub init { + my $hash = $_[1]; + + unless ($has_compiler) { + @{$hash}{ 'XS', 'C' } = ( {}, [] ); + } + + $hash; +}