]> git.vpit.fr Git - perl/modules/Test-Valgrind.git/blob - Makefile.PL
Test real-life leaks with some XS
[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 /:/, $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         'POSIX'                 => 0,
112         'Perl::Destruct::Level' => 0,
113         'Test::More'            => 0,
114     },
115     dist          => {
116         PREOP      => "touch lib/$supp; "
117                       . 'pod2text lib/Test/Valgrind.pm > $(DISTVNAME)/README; '
118                       . build_req,
119         COMPRESS   => 'gzip -9f', SUFFIX => 'gz',
120     },
121     clean         => { FILES => "Test-Valgrind-* lib/$supp Makefile.bak *.gcov *.gcda *.gcno cover_db Debian_CPANTS.txt" },
122 );
123 1 while unlink 'lib/' . $supp;
124
125 package MY;
126
127 sub postamble {
128  <<'POSTAMBLE';
129 clean ::
130         $(CP) lib/Test/Valgrind/Suppressions.{tpl,pm}
131         $(TOUCH) lib/Test/Valgrind/perlTestValgrind.supp
132 POSTAMBLE
133 }