X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=Makefile.PL;h=b3d28f209747b82fba79e85732220e8f98ce3ba9;hb=4bfa5ddbc8d54123eb64b0873f71a28b03064f9a;hp=7cfceca0f69f1ab15a78b37ae15a57febffefeab;hpb=8c975dc73eafd822cdc655dc62f48e28fa187778;p=gitmo%2FClass-MOP.git diff --git a/Makefile.PL b/Makefile.PL index 7cfceca..b3d28f2 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -9,21 +9,6 @@ use File::Spec; use 5.008; -# 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; -} - -our $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.04', @@ -38,132 +23,14 @@ my %prereqs = ( 'B' => '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 t/pp*' }, - 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 $ccflags = -d '.svn' || -d '.git' || $ENV{MAINTAINER_MODE} ? '-Wall' : ''; - 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 sucks, but it's the best guess we can make. Since we just use -# it to run two sets of tests, it's not big deal if it ends up true -# for a non-maintainer. -sub is_maintainer { - return 0 if $ENV{PERL5_CPAN_IS_RUNNING} || $ENV{PERL5_CPANPLUS_IS_RUNNING}; - - return 1; -} - -sub get_pp_tests { - opendir my $dh, 't' or die "Cannot read t: $!"; - - return grep { $_ !~ /^99/ } grep {/^\d.+\.t$/} readdir $dh; -} - -# This is EUMM voodoo -sub init { - my $hash = $_[1]; - - unless ($has_compiler) { - @{$hash}{ 'XS', 'C' } = ( {}, [] ); - } - - $hash; -} - -package MY; - -sub postamble { - my @test_files = ::get_pp_tests(); - my $pp_tests = join q{ }, map { File::Spec->catfile('t', "pp_${_}") } @test_files; - my @pp_test_targets = join qq{\n}, map { - my $source = File::Spec->catfile('t', ${_}); - File::Spec->catfile('t', "pp_${_}") . q{: } - . qq{$source t/header_pp.inc\n\t} - . q{$(NOECHO) $(ABSPERLRUN) "-MExtUtils::Command" -e cat t/header_pp.inc } - . $source . q{ > $@} . qq{\n} - } @test_files; - my $test_dep = $::has_compiler && (::is_maintainer() || $ENV{AUTOMATED_TESTING}) - ? qq{pure_all :: pp_tests\n} . join qq{\n}, @pp_test_targets - : ''; - - return <<"EOM" -pp_tests: ${pp_tests} - -${test_dep} - -EOM -} +WriteMakefile( + VERSION_FROM => 'lib/Class/MOP.pm', + NAME => 'Class::MOP', + PREREQ_PM => \%prereqs, + CCFLAGS => $ccflags, + ABSTRACT_FROM => 'lib/Class/MOP.pm', + AUTHOR => 'Stevan Little ', + LICENSE => 'perl', +);