]> git.vpit.fr Git - perl/modules/Test-Valgrind.git/blob - Makefile.PL
Use $Config{path_sep} whenever possible
[perl/modules/Test-Valgrind.git] / Makefile.PL
1 use 5.006;
2
3 use strict;
4 use warnings;
5 use ExtUtils::MakeMaker;
6
7 BEGIN {
8  eval { require Config };
9  die 'OS unsupported' if $@;
10  Config->import(qw/%Config/);
11  eval { require File::Spec };
12  die 'OS unsupported' if $@;
13 }
14
15 my $vg;
16 print 'Checking for valgrind >= 3.1.0 in PATH... ';
17 for (split /$Config{path_sep}/, $ENV{PATH}) {
18  $_ .= '/valgrind';
19  if (-x) {
20   my $ver = qx/$_ --version/;
21   if ($ver =~ s/^valgrind-//) {
22    $ver = join '', map chr, split /\./, $ver;
23    if ($ver ge v3.1.0) {
24     print "$_\n";
25     $vg = $_;
26     last;
27    }
28   }
29  }
30 }
31 if (!$vg) {
32  print "no\n";
33  die 'OS unsupported';
34 }
35
36 # Inspired from Module::Install::Can
37 print "Checking for a valid C compiler in the PATH... ";
38 my @ccs = ($Config{cc});
39 unshift @ccs, $ENV{CC} if $ENV{CC};
40 my $cc;
41 CC:
42 for my $c (@ccs) {
43  for my $dir (split /$Config{path_sep}/, $ENV{PATH}) {
44   my $abs = File::Spec->catfile($dir, $c);
45   if (-x $abs or MM->maybe_command($abs)) {
46    $cc = $c;
47    last CC;
48   }
49  }
50 }
51 my (@C);
52 if ($cc) {
53  my $xs = 'Valgrind.xs';
54  (my $c = $xs) =~ s/\.xs$/.c/;
55  push @C, $c;
56  print $cc, "\n";
57 } else {
58  print "none\n";
59 }
60
61 my $BUILD_REQUIRES = {
62  'ExtUtils::MakeMaker' => 0,
63  'File::Copy'          => 0,
64  'Test::More'          => 0,
65  'XSLoader'            => 0
66 };
67
68 sub build_req {
69  my $tometa = ' >> $(DISTVNAME)/META.yml;';
70  my $build_req = 'echo "build_requires:" ' . $tometa;
71  foreach my $mod ( sort { lc $a cmp lc $b } keys %$BUILD_REQUIRES ) {
72   my $ver = $BUILD_REQUIRES->{$mod};
73   $build_req .= sprintf 'echo "    %-30s %s" %s', "$mod:", $ver, $tometa;
74  }
75  return $build_req;
76 }
77
78 my $supp = 'lib/Test/Valgrind/Suppressions';
79 open my $tpl, '<', $supp . '.tpl' or die "open($supp.tpl): $!";
80 open my $out, '>', $supp . '.pm'  or die "open($supp.pm): $!";
81 while (<$tpl>) {
82  s/(VG_PATH\s*=>\s*)undef/$1'$vg'/g;
83  print $out $_;
84 }
85 close $out;
86 close $tpl;
87
88 $supp = 'Test/Valgrind/perlTestValgrind.supp';
89
90 WriteMakefile(
91     NAME          => 'Test::Valgrind',
92     AUTHOR        => 'Vincent Pit <perl@profvince.com>',
93     LICENSE       => 'perl',
94     VERSION_FROM  => 'lib/Test/Valgrind.pm',
95     ABSTRACT_FROM => 'lib/Test/Valgrind.pm',
96     PL_FILES      => {
97         './Gensupp.PL'    => 'blib/archpub/' . $supp,
98         './FixInstall.PL' => 'Makefile.bak',
99     },
100     OPTIMIZE      => '-g',
101     PM            => {
102         'lib/Test/Valgrind.pm'
103         => '$(INST_LIB)/Test/Valgrind.pm',
104         'lib/Test/Valgrind/Suppressions.pm'
105         => 'blib/archpub/Test/Valgrind/Suppressions.pm',
106     },
107     C             => \@C,
108     PREREQ_PM     => {
109         'Carp'                  => 0,
110         'Exporter'              => 0,
111         'Fcntl'                 => 0,
112         'POSIX'                 => 0,
113         'Perl::Destruct::Level' => 0,
114         'Test::Builder'         => 0,
115     },
116     dist          => {
117         PREOP      => "touch lib/$supp; "
118                       . 'pod2text lib/Test/Valgrind.pm > $(DISTVNAME)/README; '
119                       . build_req,
120         COMPRESS   => 'gzip -9f', SUFFIX => 'gz',
121     },
122     clean         => { FILES => "Test-Valgrind-* lib/$supp Makefile.bak *.gcov *.gcda *.gcno cover_db Debian_CPANTS.txt" },
123 );
124 1 while unlink 'lib/' . $supp;
125
126 package MY;
127
128 sub dist_core {
129  my $dist = shift->SUPER::dist_core(@_);
130  $dist =~ s/^(\s*dist\s*:+\s*)/$1testvg_dist /m;
131  return <<DISTCORE . $dist;
132 testvg_dist :
133         \$(CP) lib/Test/Valgrind/Suppressions.{tpl,pm}
134         \$(RM) lib/$supp
135         \$(TOUCH) lib/$supp
136 DISTCORE
137 }
138
139 sub test {
140  my $test = shift->SUPER::test(@_);
141  my ($target) = $test =~ /^\s*(test\s*:+)/m;
142  return "$target Makefile.bak blib/archpub/$supp\n$test";
143 }
144
145 sub postamble {
146  return <<POSTAMBLE;
147 clean ::
148         \$(CP) lib/Test/Valgrind/Suppressions.{tpl,pm}
149         \$(TOUCH) lib/$supp
150 POSTAMBLE
151 }