diff options
author | Jesse Luehrs <doy@tozt.net> | 2010-11-16 02:54:10 -0600 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2010-11-16 02:54:10 -0600 |
commit | 079d40f534bbc0751bd6e2c621edfd367d3943f8 (patch) | |
tree | 09907d61198376cb43501d37ae894791601d8d5c /inc | |
parent | a5129e538980a4e414dffc8ded23c921642e2dea (diff) | |
download | package-stash-079d40f534bbc0751bd6e2c621edfd367d3943f8.tar.gz package-stash-079d40f534bbc0751bd6e2c621edfd367d3943f8.zip |
depend on ::XS if a compiler is available
Diffstat (limited to 'inc')
-rw-r--r-- | inc/MMPackageStash.pm | 45 |
1 files changed, 41 insertions, 4 deletions
diff --git a/inc/MMPackageStash.pm b/inc/MMPackageStash.pm index e69c8a6..b29aa5e 100644 --- a/inc/MMPackageStash.pm +++ b/inc/MMPackageStash.pm @@ -7,11 +7,43 @@ extends 'Dist::Zilla::Plugin::MakeMaker::Awesome'; around _build_MakeFile_PL_template => sub { my $orig = shift; my $self = shift; - my $template = $self->$orig(@_); - $template =~ s/(use ExtUtils::MakeMaker.*)/$1\n\ncheck_conflicts();/; + # copied from M::I + my $can_cc = <<'CAN_CC'; +use Config (); +use File::Spec (); + +# check if we can run some command +sub can_run { + my ($cmd) = @_; + + my $_cmd = $cmd; + return $_cmd if (-x $_cmd or $_cmd = MM->maybe_command($_cmd)); + + for my $dir ((split /$Config::Config{path_sep}/, $ENV{PATH}), '.') { + next if $dir eq ''; + my $abs = File::Spec->catfile($dir, $_[1]); + return $abs if (-x $abs or $abs = MM->maybe_command($abs)); + } + + return; +} + +# can we locate a (the) C compiler +sub can_cc { + my @chunks = split(/ /, $Config::Config{cc}) or return; - $template .= <<'CHECK_CONFLICTS'; + # $Config{cc} may contain args; try to find out the program part + while (@chunks) { + return can_run("@chunks") || (pop(@chunks), next); + } + + return; +} +CAN_CC + + # copied out of moose + my $check_conflicts = <<'CHECK_CONFLICTS'; sub check_conflicts { my %conflicts = ( 'Class::MOP' => '1.08', @@ -52,7 +84,12 @@ EOF } CHECK_CONFLICTS - return $template; + my $template = $self->$orig(@_); + + $template =~ s/(use ExtUtils::MakeMaker.*)/$1\n\ncheck_conflicts();/; + $template =~ s/(WriteMakefile\()/delete \$WriteMakefileArgs{PREREQ_PM}{'Package::Stash::XS'}\n unless can_cc();\n\n$1/; + + return $template . $can_cc . $check_conflicts; }; __PACKAGE__->meta->make_immutable; |