]> git.vpit.fr Git - perl/modules/Test-Valgrind.git/blob - Makefile.PL
XSLoader and DynaLoader aren't really required, just recommended
[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 $dist = 'Test-Valgrind';
62
63 my %META = (
64  configure_requires => {
65   'Config'              => 0,
66   'ExtUtils::MakeMaker' => 0,
67   'File::Spec'          => 0,
68  },
69  build_requires => {
70   'ExtUtils::MakeMaker' => 0,
71   'File::Copy'          => 0,
72   'Test::More'          => 0,
73  },
74  recommends => {
75   'DynaLoader' => 0,
76   'XSLoader'   => 0,
77  },
78  resources => {
79   bugtracker => "http://rt.cpan.org/NoAuth/ReportBug.html?Queue=$dist",
80   homepage   => "http://search.cpan.org/dist/$dist/",
81   license    => 'http://dev.perl.org/licenses/',
82   repository => "http://git.profvince.com/perl/modules/$dist.git",
83  },
84 );
85
86 my $supp = 'lib/Test/Valgrind/Suppressions';
87 open my $tpl, '<', $supp . '.tpl' or die "open($supp.tpl): $!";
88 open my $out, '>', $supp . '.pm'  or die "open($supp.pm): $!";
89 while (<$tpl>) {
90  s/(VG_PATH\s*=>\s*)undef/$1'$vg'/g;
91  print $out $_;
92 }
93 close $out;
94 close $tpl;
95
96 $supp = 'Test/Valgrind/perlTestValgrind.supp';
97
98 WriteMakefile(
99     NAME             => 'Test::Valgrind',
100     AUTHOR           => 'Vincent Pit <perl@profvince.com>',
101     LICENSE          => 'perl',
102     VERSION_FROM     => 'lib/Test/Valgrind.pm',
103     ABSTRACT_FROM    => 'lib/Test/Valgrind.pm',
104     PL_FILES         => {
105         './Gensupp.PL'    => 'blib/archpub/' . $supp,
106         './FixInstall.PL' => 'Makefile.bak',
107     },
108     OPTIMIZE         => '-g',
109     PM               => {
110         'lib/Test/Valgrind.pm'
111         => '$(INST_LIB)/Test/Valgrind.pm',
112         'lib/Test/Valgrind/Suppressions.pm'
113         => 'blib/archpub/Test/Valgrind/Suppressions.pm',
114     },
115     C                => \@C,
116     PREREQ_PM        => {
117         'Carp'                  => 0,
118         'Exporter'              => 0,
119         'Fcntl'                 => 0,
120         'POSIX'                 => 0,
121         'Perl::Destruct::Level' => 0,
122         'Test::Builder'         => 0,
123     },
124     MIN_PERL_VERSION => 5.006,
125     META_MERGE       => \%META,
126     dist             => {
127         PREOP    => "touch lib/$supp; "
128                     . 'pod2text lib/Test/Valgrind.pm > $(DISTVNAME)/README',
129         COMPRESS => 'gzip -9f', SUFFIX => 'gz',
130     },
131     clean            => {
132         FILES => "$dist-* lib/$supp Makefile.bak *.gcov *.gcda *.gcno cover_db Debian_CPANTS.txt"
133     },
134 );
135 1 while unlink 'lib/' . $supp;
136
137 package MY;
138
139 sub dist_core {
140  my $dist = shift->SUPER::dist_core(@_);
141  $dist =~ s/^(\s*dist\s*:+\s*)/$1testvg_dist /m;
142  return <<DISTCORE . $dist;
143 testvg_dist :
144         \$(CP) lib/Test/Valgrind/Suppressions.{tpl,pm}
145         \$(RM) lib/$supp
146         \$(TOUCH) lib/$supp
147 DISTCORE
148 }
149
150 sub test {
151  my $test = shift->SUPER::test(@_);
152  my ($target) = $test =~ /^\s*(test\s*:+)/m;
153  return "$target Makefile.bak blib/archpub/$supp\n$test";
154 }
155
156 sub postamble {
157  return <<POSTAMBLE;
158 clean ::
159         \$(CP) lib/Test/Valgrind/Suppressions.{tpl,pm}
160         \$(TOUCH) lib/$supp
161 POSTAMBLE
162 }