]> git.vpit.fr Git - perl/modules/Scalar-Vec-Util.git/blob - Makefile.PL
Update VPIT::TestHelpers to 15e8aee3
[perl/modules/Scalar-Vec-Util.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 sub filter_argv {
81  my ($var, $code) = @_;
82
83  my $ret;
84
85  for my $i (0 .. $#ARGV) {
86   my $arg = $ARGV[$i];
87   if ($arg =~ /^\Q$var\E=(.*)/) {
88    my $val = $1;
89    $ret = $code->($val);
90    $ARGV[$i] = undef;
91    last if $ret;
92   }
93  }
94
95  @ARGV = grep defined, @ARGV;
96
97  return $ret;
98 }
99
100 my ($cc, $ld);
101 my $pp = filter_argv PP => sub {
102  my ($val) = @_;
103  return (do { no warnings 'numeric'; int $val } or $val =~ /^(?:y|yes)$/i)
104         ? 1 : 0;
105 };
106 if ($pp) {
107  print "Forcing the pure-Perl implementation from the arguments passed to Makefile.PL.\n";
108 } else {
109  $cc = check_exe(
110   desc    => 'C compiler',
111   arg_var => 'CC',
112   try     => [ $Config{cc}, $ENV{CC}, 'cc' ],
113  );
114  if (defined $cc) {
115   my ($vol, $dir, $file) = File::Spec->splitpath($cc);
116   my $preferred_path = File::Spec->catpath($vol, $dir, '');
117   $ld = check_exe(
118    desc           => 'linker',
119    arg_var        => 'LD',
120    try            => [ $Config{ld}, $ENV{LD}, 'ld' ],
121    preferred_path => $preferred_path,
122   );
123  }
124 }
125
126 sub is_little_endian {
127  my $order = $Config{byteorder};
128  return 0 unless $order;
129  my $len = length $order;
130  if ($len > 8) {
131   $order = substr $order, 0, 8;
132   $len   = 8;
133  }
134  return $order eq (join '', 1 .. $len);
135 }
136
137 my %PARAMS;
138 my @DEFINES;
139
140 if (defined $cc and defined $ld) {
141  $PARAMS{C}  = [ 'Util.c' ];
142  $PARAMS{XS} = { 'Util.xs' => 'Util.c' };
143  $PARAMS{CC} = $cc;
144  $PARAMS{LD} = $ld;
145
146  my $type = filter_argv UNIT => sub { return $_[0] };
147  if (defined $type) {
148   print "Forcing '$type' as the unit.\n";
149   push @DEFINES, '-DBV_UNIT="' . $type . '"';
150  } else {
151   my $bits = 8;
152   if (not is_little_endian()) {
153    print "Forcing unit size of 8 on non-little-endian systems.\n";
154   } else {
155    print "Checking unit size in bits... ";
156    my $size  = 1;
157    my $align = $Config{alignbytes} || 1;
158    my @units = (8, 16, 32, 64);
159    for my $unit (@units) {
160     my $unit_size = $Config{"u${unit}size"};
161     if ($unit_size and $unit_size <= $align) {
162      $bits = $unit;
163      $size = $unit_size;
164     }
165    }
166    print "$bits (actually $size bytes for $align bytes alignment).\n";
167   }
168   push @DEFINES, '-DBV_UNIT="' . ($Config{"u${bits}type"} || "U$bits") . '"';
169   push @DEFINES, "-DSVU_SIZE=$bits";
170  }
171 } else {
172  $PARAMS{C}      = [ ];
173  $PARAMS{XS}     = { };
174  $PARAMS{OBJECT} = '';
175  print "Falling back to the pure-Perl implementation.\n";
176 }
177
178 $PARAMS{DEFINE} = join ' ', @DEFINES if @DEFINES;
179
180 my $dist = 'Scalar-Vec-Util';
181
182 (my $name = $dist) =~ s{-}{::}g;
183
184 (my $file = $dist) =~ s{-}{/}g;
185 $file = "lib/$file.pm";
186
187 my %PREREQ_PM = (
188  'Exporter' => 0,
189  'Carp'     => 0,
190  'XSLoader' => 0,
191  'base'     => 0,
192 );
193
194 my %BUILD_REQUIRES = (
195  'Config'              => 0,
196  'ExtUtils::MakeMaker' => 0,
197  'File::Spec'          => 0,
198  'Test::More'          => 0,
199  %PREREQ_PM,
200 );
201
202 my %META = (
203  configure_requires => {
204   'Config'              => 0,
205   'ExtUtils::MakeMaker' => 0,
206   'File::Spec'          => 0,
207  },
208  build_requires => {
209   %BUILD_REQUIRES,
210  },
211  dynamic_config => 1,
212  resources => {
213   bugtracker => "http://rt.cpan.org/Dist/Display.html?Name=$dist",
214   homepage   => "http://search.cpan.org/dist/$dist/",
215   license    => 'http://dev.perl.org/licenses/',
216   repository => "http://git.profvince.com/?p=perl%2Fmodules%2F$dist.git",
217  },
218 );
219
220 WriteMakefile(
221  NAME             => $name,
222  AUTHOR           => 'Vincent Pit <perl@profvince.com>',
223  LICENSE          => 'perl',
224  VERSION_FROM     => $file,
225  ABSTRACT_FROM    => $file,
226  PL_FILES         => {},
227  BUILD_REQUIRES   => \%BUILD_REQUIRES,
228  PREREQ_PM        => \%PREREQ_PM,
229  MIN_PERL_VERSION => '5.006',
230  META_MERGE       => \%META,
231  dist             => {
232   PREOP    => "pod2text -u $file > \$(DISTVNAME)/README",
233   COMPRESS => 'gzip -9f', SUFFIX => 'gz'
234  },
235  clean            => {
236   FILES => "$dist-* *.gcov *.gcda *.gcno cover_db Debian_CPANTS.txt*"
237  },
238  %PARAMS,
239 );
240
241 1;
242
243 package MY;
244
245 sub postamble {
246  my $cv = join ' -coverage ', 'cover',
247                             qw<statement branch condition path subroutine time>;
248  <<POSTAMBLE;
249 cover test_cover:
250         $cv -test
251 POSTAMBLE
252 }