From: Dave Rolsky Date: Fri, 8 Aug 2008 21:11:12 +0000 (+0000) Subject: Switched to EUMM with compiler detection (from Params::Validate, which X-Git-Tag: 0_64_01~81 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f125b31ebf5eead9cb712aad3ea4a29f7ce3d611;p=gitmo%2FClass-MOP.git Switched to EUMM with compiler detection (from Params::Validate, which got it from Scalar-List-Utils). --- diff --git a/Changes b/Changes index e1b863c..ba3fc1e 100644 --- a/Changes +++ b/Changes @@ -1,6 +1,11 @@ Revision history for Perl extension Class-MOP. 0.65 + * Makefile.PL + - We now check to see if you have a compiler. If you don't, the + module installs without some XS bits, but will work the same + as with XS. This should make it easier to install on platforms + without a compiler (like Windows). (Dave Rolsky) 0.64 Sun August 3, 2008 * Class::MOP::Immutable diff --git a/MANIFEST b/MANIFEST index 6cd322a..39862d0 100644 --- a/MANIFEST +++ b/MANIFEST @@ -7,14 +7,6 @@ examples/InsideOutClass.pod examples/InstanceCountingClass.pod examples/LazyClass.pod examples/Perl6Attribute.pod -inc/Module/Install.pm -inc/Module/Install/Base.pm -inc/Module/Install/Can.pm -inc/Module/Install/Fetch.pm -inc/Module/Install/Makefile.pm -inc/Module/Install/Metadata.pm -inc/Module/Install/Win32.pm -inc/Module/Install/WriteAll.pm lib/Class/MOP.pm lib/Class/MOP/Attribute.pm lib/Class/MOP/Class.pm @@ -30,9 +22,8 @@ lib/Class/MOP/Object.pm lib/Class/MOP/Package.pm lib/metaclass.pm Makefile.PL -MANIFEST +MANIFEST This list of files MANIFEST.SKIP -META.yml MOP.xs ppport.h README diff --git a/Makefile.PL b/Makefile.PL index 3ae0fb4..cd4a289 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -1,20 +1,117 @@ +# The perl/C checking voodoo is mostly stolen from Graham Barr's +# Scalar-List-Utils distribution. use strict; use warnings; -use inc::Module::Install; -name 'Class-MOP'; -all_from 'lib/Class/MOP.pm'; -license 'perl'; +use ExtUtils::MakeMaker; +use Config qw(%Config); +use File::Spec; -requires 'Scalar::Util' => '1.18'; -requires 'Sub::Name' => '0.02'; -requires 'Sub::Identify' => '0.03'; -requires 'MRO::Compat' => '0.05'; -requires 'Carp' => '0'; +# If undefined, try our best, if true, require XS, if false, never do +# XS +my $force_xs; -build_requires 'Test::More' => '0.62'; -build_requires 'Test::Exception' => '0.21'; -build_requires 'File::Spec' => '0'; +for (@ARGV) { + /^--pm/ and $force_xs = 0; + /^--xs/ and $force_xs = 1; +} -auto_provides; -WriteAll(); +my $has_compiler = $force_xs; +unless ( defined $force_xs ) { + $has_compiler = check_for_compiler() + or no_cc(); +} + +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 => { + 'Scalar::Util' => '1.18', + 'Sub::Name' => '0.02', + 'Sub::Identify' => '0.03', + 'MRO::Compat' => '0.05', + 'Carp' => 0, + }, + 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; +}