]> git.vpit.fr Git - perl/modules/Test-Valgrind.git/blob - Makefile.PL
Make sure File::Temp is recent enough for ->newdir
[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  'File::HomeDir'         => '0.86',
128  'File::Path'            => 0,
129  'File::Spec'            => 0,
130  'File::Temp'            => '0.19', # ->newdir in tests
131  'Filter::Util::Call'    => 0,
132  'Fcntl'                 => 0,
133  'IO::Select'            => 0,
134  'List::Util'            => 0,
135  'POSIX'                 => 0,
136  'Perl::Destruct::Level' => 0,
137  'Scalar::Util'          => 0,
138  'Test::Builder'         => 0,
139  'Test::More'            => 0,
140  'XML::Twig'             => 0,
141  'base'                  => 0,
142  'version'               => 0,
143 );
144
145 my %CONFIGURE_REQUIRES = (
146  'Config'              => 0,
147  'ExtUtils::MakeMaker' => 0,
148  'File::Spec'          => 0,
149 );
150
151 my %BUILD_REQUIRES = (
152  %CONFIGURE_REQUIRES,
153  'File::Temp'          => '0.19', # ->newdir in tests
154  'IO::Handle'          => 0,
155  'IO::Select'          => 0,
156  'IPC::Open3'          => 0,
157  'Socket'              => 0,
158  'Test::More'          => 0,
159  'base'                => 0,
160  'lib'                 => 0,
161  %PREREQ_PM,
162 );
163
164 my %META = (
165  configure_requires => {
166   %CONFIGURE_REQUIRES,
167  },
168  build_requires => {
169   %BUILD_REQUIRES,
170  },
171  recommends => {
172   'DynaLoader' => 0,
173   'XSLoader'   => 0,
174  },
175  dynamic_config => 1,
176  resources => {
177   bugtracker => "http://rt.cpan.org/Dist/Display.html?Name=$dist",
178   homepage   => "http://search.cpan.org/dist/$dist/",
179   license    => 'http://dev.perl.org/licenses/',
180   repository => "http://git.profvince.com/?p=perl%2Fmodules%2F$dist.git",
181  },
182 );
183
184 WriteMakefile(
185  NAME             => $name,
186  AUTHOR           => 'Vincent Pit <perl@profvince.com>',
187  LICENSE          => 'perl',
188  VERSION_FROM     => $file,
189  ABSTRACT_FROM    => $file,
190  BUILD_REQUIRES   => \%BUILD_REQUIRES,
191  PREREQ_PM        => \%PREREQ_PM,
192  MIN_PERL_VERSION => '5.006',
193  META_MERGE       => \%META,
194  dist             => {
195   PREOP    => "pod2text -u $file > \$(DISTVNAME)/README",
196   COMPRESS => 'gzip -9f', SUFFIX => 'gz',
197  },
198  clean            => {
199   FILES => "$dist-* *.gcov *.gcda *.gcno cover_db Debian_CPANTS.txt*"
200  },
201  %PARAMS,
202 );