From: Vincent Pit Date: Fri, 30 Oct 2015 14:27:36 +0000 (-0200) Subject: Freshen Makefile.PL X-Git-Tag: v1.15~11 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=f1aad8ec2ce1d9605f720789dbb48fb3afbec3e8;p=perl%2Fmodules%2FTest-Valgrind.git Freshen Makefile.PL This should also fix handshake-related test failures with recent perls. --- diff --git a/Makefile.PL b/Makefile.PL index bb4a768..f6fb3be 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -4,41 +4,113 @@ use strict; use warnings; use ExtUtils::MakeMaker; -BEGIN { - eval { require Config }; - die 'OS unsupported' if $@; - Config->import(qw<%Config>); - eval { require File::Spec }; - die 'OS unsupported' if $@; +use Config; +use File::Spec; + +sub validate_exe { + my ($name, $preferred_path) = @_; + + my (@candidates, @args); + if (File::Spec->file_name_is_absolute($name)) { + # No need to look for args if the name is absolute. + @candidates = $name; + } else { + my @path; + if (defined $preferred_path) { + @path = ($preferred_path, grep { $_ ne $preferred_path } File::Spec->path); + } else { + @path = File::Spec->path; + } + + (my $base, @args) = split ' ', $name; + for my $path_entry (@path) { + my ($vol, $dir, $file) = File::Spec->splitpath($path_entry, 1); + next if defined $file and length $file; + push @candidates, File::Spec->catpath($vol, $dir, $base); + } + } + + for my $path (@candidates) { + my $command = MM->maybe_command($path); + if (defined $command) { + $command .= " @args" if @args; + return $command; + } + } + + return; } -# Inspired from Module::Install::Can -print "Checking for a valid C compiler in the PATH... "; -my @ccs = ($Config{cc}); -unshift @ccs, $ENV{CC} if $ENV{CC}; -my @path = File::Spec->path; -@ccs = map { - my $cc = $_; - File::Spec->file_name_is_absolute($cc) - ? $cc - : map File::Spec->catfile($_, $cc), @path -} @ccs; -my $has_cc; -CC: -for my $cc (@ccs) { - if (-x $cc or MM->maybe_command($cc)) { - $has_cc = $cc; - last CC; +sub check_exe { + my (%args) = @_; + + my $desc = delete $args{desc}; + my $arg_var = delete $args{arg_var}; + my $tries = delete $args{try}; + my $preferred_path = delete $args{preferred_path}; + + my $exe; + + for (@ARGV) { + if (/^\Q$arg_var\E=(.*)/) { + $exe = validate_exe($1, $preferred_path); + last if defined $exe; + } + } + + if (defined $exe) { + print "Forcing the use of $exe as the $desc.\n"; + } else { + print "Checking for a valid $desc in the PATH... "; + for my $try (@$tries) { + next unless defined $try; + $exe = validate_exe($try, $preferred_path); + last if defined $exe; + } + if (defined $exe) { + print "$exe\n"; + } else { + print "none\n"; + } } + + return $exe; } -my (@C); -if ($has_cc) { - my $xs = 'Valgrind.xs'; - (my $c = $xs) =~ s/\.xs$/.c/; - push @C, $c; - print $has_cc, "\n"; -} else { - print "none\n"; + +my %PARAMS; + +my $cc = check_exe( + desc => 'C compiler', + arg_var => 'CC', + try => [ $Config{cc}, $ENV{CC}, 'cc' ], +); +if (defined $cc) { + my ($vol, $dir, $file) = File::Spec->splitpath($cc); + my $preferred_path = File::Spec->catpath($vol, $dir, ''); + my $ld = check_exe( + desc => 'linker', + arg_var => 'LD', + try => [ $Config{ld}, $ENV{LD}, 'ld' ], + preferred_path => $preferred_path, + ); + if (defined $ld) { + my $xs = 'Valgrind.xs'; + (my $c = $xs) =~ s/\.xs$/.c/; + my $opt = $Config{optimize}; + $opt =~ s/-O\S*//g; + $opt .= ' -O0 -g'; + $PARAMS{C} = [ $c ]; + $PARAMS{XS} = { $xs => $c }; + $PARAMS{CC} = $cc; + $PARAMS{LD} = $ld; + $PARAMS{OPTIMIZE} = $opt; + } +} + +unless ($PARAMS{C}) { + $PARAMS{C} = [ ]; + $PARAMS{XS} = { }; + $PARAMS{OBJECT} = ''; } my $dist = 'Test-Valgrind'; @@ -69,15 +141,27 @@ my %PREREQ_PM = ( 'version' => 0, ); +my %CONFIGURE_REQUIRES = ( + 'Config' => 0, + 'ExtUtils::MakeMaker' => 0, + 'File::Spec' => 0, +); + +my %BUILD_REQUIRES = ( + %CONFIGURE_REQUIRES, + 'File::Temp' => 0, + 'Test::More' => 0, + 'base' => 0, + 'lib' => 0, + %PREREQ_PM, +); + my %META = ( configure_requires => { - 'File::Spec' => 0, - 'ExtUtils::MakeMaker' => 0, + %CONFIGURE_REQUIRES, }, build_requires => { - 'ExtUtils::MakeMaker' => 0, - 'Test::More' => 0, - %PREREQ_PM, + %BUILD_REQUIRES, }, recommends => { 'DynaLoader' => 0, @@ -98,8 +182,7 @@ WriteMakefile( LICENSE => 'perl', VERSION_FROM => $file, ABSTRACT_FROM => $file, - OPTIMIZE => '-g', - C => \@C, + BUILD_REQUIRES => \%BUILD_REQUIRES, PREREQ_PM => \%PREREQ_PM, MIN_PERL_VERSION => '5.006', META_MERGE => \%META, @@ -108,6 +191,7 @@ WriteMakefile( COMPRESS => 'gzip -9f', SUFFIX => 'gz', }, clean => { - FILES => "$dist-* *.gcov *.gcda *.gcno cover_db Debian_CPANTS.txt" + FILES => "$dist-* *.gcov *.gcda *.gcno cover_db Debian_CPANTS.txt*" }, + %PARAMS, );