]> git.vpit.fr Git - perl/modules/Test-Valgrind.git/blob - Makefile.PL
Prevent double ... at the end of a suppression
[perl/modules/Test-Valgrind.git] / Makefile.PL
1 use 5.006;
2
3 use strict;
4 use warnings;
5 use ExtUtils::MakeMaker;
6
7 use Config;
8 use File::Spec;
9
10 sub validate_exe {
11  my ($name, $preferred_path) = @_;
12
13  my (@candidates, @args);
14  if (File::Spec->file_name_is_absolute($name)) {
15   # No need to look for args if the name is absolute.
16   @candidates = $name;
17  } else {
18   my @path;
19   if (defined $preferred_path) {
20    @path = ($preferred_path, grep { $_ ne $preferred_path } File::Spec->path);
21   } else {
22    @path = File::Spec->path;
23   }
24
25   (my $base, @args) = split ' ', $name;
26   for my $path_entry (@path) {
27    my ($vol, $dir, $file) = File::Spec->splitpath($path_entry, 1);
28    next if defined $file and length $file;
29    push @candidates, File::Spec->catpath($vol, $dir, $base);
30   }
31  }
32
33  for my $path (@candidates) {
34   my $command = MM->maybe_command($path);
35   if (defined $command) {
36    $command .= " @args" if @args;
37    return $command;
38   }
39  }
40
41  return;
42 }
43
44 sub check_exe {
45  my (%args) = @_;
46
47  my $desc           = delete $args{desc};
48  my $arg_var        = delete $args{arg_var};
49  my $tries          = delete $args{try};
50  my $preferred_path = delete $args{preferred_path};
51
52  my $exe;
53
54  for (@ARGV) {
55   if (/^\Q$arg_var\E=(.*)/) {
56    $exe = validate_exe($1, $preferred_path);
57    last if defined $exe;
58   }
59  }
60
61  if (defined $exe) {
62   print "Forcing the use of $exe as the $desc.\n";
63  } else {
64   print "Checking for a valid $desc in the PATH... ";
65   for my $try (@$tries) {
66    next unless defined $try;
67    $exe = validate_exe($try, $preferred_path);
68    last if defined $exe;
69   }
70   if (defined $exe) {
71    print "$exe\n";
72   } else {
73    print "none\n";
74   }
75  }
76
77  return $exe;
78 }
79
80 my %PARAMS;
81
82 my $cc = check_exe(
83  desc    => 'C compiler',
84  arg_var => 'CC',
85  try     => [ $Config{cc}, $ENV{CC}, 'cc' ],
86 );
87 if (defined $cc) {
88  my ($vol, $dir, $file) = File::Spec->splitpath($cc);
89  my $preferred_path = File::Spec->catpath($vol, $dir, '');
90  my $ld = check_exe(
91   desc           => 'linker',
92   arg_var        => 'LD',
93   try            => [ $Config{ld}, $ENV{LD}, 'ld' ],
94   preferred_path => $preferred_path,
95  );
96  if (defined $ld) {
97   my $xs  = 'Valgrind.xs';
98   (my $c  = $xs) =~ s/\.xs$/.c/;
99   my $opt = $Config{optimize};
100   $opt    =~ s/-O\S*//g;
101   $opt   .= ' -O0 -g';
102   $PARAMS{C}        = [ $c ];
103   $PARAMS{XS}       = { $xs => $c };
104   $PARAMS{CC}       = $cc;
105   $PARAMS{LD}       = $ld;
106   $PARAMS{OPTIMIZE} = $opt;
107  }
108 }
109
110 unless ($PARAMS{C}) {
111  $PARAMS{C}      = [ ];
112  $PARAMS{XS}     = { };
113  $PARAMS{OBJECT} = '';
114 }
115
116 my $dist = 'Test-Valgrind';
117
118 (my $name = $dist) =~ s{-}{::}g;
119
120 (my $file = $dist) =~ s{-}{/}g;
121 $file = "lib/$file.pm";
122
123 my %PREREQ_PM = (
124  'Carp'                  => 0,
125  'Digest::MD5'           => 0,
126  'Env::Sanctify'         => 0,
127  'ExtUtils::MM'          => 0,
128  'File::HomeDir'         => '0.86',
129  'File::Path'            => 0,
130  'File::Spec'            => 0,
131  'File::Temp'            => '0.19', # ->newdir in tests
132  'Filter::Util::Call'    => 0,
133  'Fcntl'                 => 0,
134  'IO::Select'            => 0,
135  'List::Util'            => 0,
136  'POSIX'                 => 0,
137  'Perl::Destruct::Level' => 0,
138  'Scalar::Util'          => 0,
139  'Test::Builder'         => 0,
140  'Test::More'            => 0,
141  'XML::Twig'             => 0,
142  'base'                  => 0,
143  'overload'              => 0,
144 );
145
146 my %CONFIGURE_REQUIRES = (
147  'Config'              => 0,
148  'ExtUtils::MakeMaker' => 0,
149  'File::Spec'          => 0,
150 );
151
152 my %BUILD_REQUIRES = (
153  %CONFIGURE_REQUIRES,
154  'File::Temp'          => '0.19', # ->newdir in tests
155  'IO::Handle'          => 0,
156  'IO::Select'          => 0,
157  'IPC::Open3'          => 0,
158  'Socket'              => 0,
159  'Test::More'          => 0,
160  'base'                => 0,
161  'lib'                 => 0,
162  %PREREQ_PM,
163 );
164
165 my %META = (
166  configure_requires => {
167   %CONFIGURE_REQUIRES,
168  },
169  build_requires => {
170   %BUILD_REQUIRES,
171  },
172  recommends => {
173   'DynaLoader' => 0,
174   'XSLoader'   => 0,
175  },
176  dynamic_config => 1,
177  resources => {
178   bugtracker => "http://rt.cpan.org/Dist/Display.html?Name=$dist",
179   homepage   => "http://search.cpan.org/dist/$dist/",
180   license    => 'http://dev.perl.org/licenses/',
181   repository => "http://git.profvince.com/?p=perl%2Fmodules%2F$dist.git",
182  },
183 );
184
185 WriteMakefile(
186  NAME             => $name,
187  AUTHOR           => 'Vincent Pit <perl@profvince.com>',
188  LICENSE          => 'perl',
189  VERSION_FROM     => $file,
190  ABSTRACT_FROM    => $file,
191  BUILD_REQUIRES   => \%BUILD_REQUIRES,
192  PREREQ_PM        => \%PREREQ_PM,
193  MIN_PERL_VERSION => '5.006',
194  META_MERGE       => \%META,
195  dist             => {
196   PREOP    => "pod2text -u $file > \$(DISTVNAME)/README",
197   COMPRESS => 'gzip -9f', SUFFIX => 'gz',
198  },
199  clean            => {
200   FILES => "$dist-* *.gcov *.gcda *.gcno cover_db Debian_CPANTS.txt*"
201  },
202  %PARAMS,
203 );