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