]> git.vpit.fr Git - perl/modules/Scalar-Vec-Util.git/blob - Makefile.PL
1af2ae870c9cb66f18790ff2bfd16ba9dc5835b9
[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) = @_;
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 $base, @args) = split ' ', $name;
19   for my $path_entry (File::Spec->path) {
20    my ($vol, $dir, $file) = File::Spec->splitpath($path_entry, 1);
21    next if defined $file and length $file;
22    push @candidates, File::Spec->catpath($vol, $dir, $base);
23   }
24  }
25
26  for my $path (@candidates) {
27   my $command = MM->maybe_command($path);
28   if (defined $command) {
29    $command .= " @args" if @args;
30    return $command;
31   }
32  }
33
34  return;
35 }
36
37 sub check_exe {
38  my ($desc, $arg_var, $config_var, $env_var) = @_;
39
40  my $exe;
41
42  for (@ARGV) {
43   if (/^\Q$arg_var\E=(.*)/) {
44    $exe = validate_exe($1);
45    last if defined $exe;
46   }
47  }
48
49  if (defined $exe) {
50   print "Forcing the use of $exe as the $desc.\n";
51  } else {
52   print "Checking for a valid $desc in the PATH... ";
53   $exe = validate_exe($Config{$config_var});
54   # Only fall back to env if we cannot find the one used to build perl.
55   if (not defined $exe and defined $ENV{$env_var}) {
56    $exe = validate_exe($ENV{$env_var});
57   }
58   if (defined $exe) {
59    print "$exe\n";
60   } else {
61    print "none\n";
62   }
63  }
64
65  return $exe;
66 }
67
68 my ($pp, $skip_arg);
69 for my $i (0 .. $#ARGV) {
70  my $arg = $ARGV[$i];
71  if ($arg =~ /^PP=(.*)/) {
72   my $val = $1;
73   if (do { no warnings 'numeric'; int $val } or $val =~ /^(?:y|yes)$/i) {
74    print "Forcing the pure-Perl implementation from the arguments passed to Makefile.PL.\n";
75    $pp       = 1;
76    $skip_arg = $i;
77    last;
78   }
79  }
80 }
81 if (defined $skip_arg) {
82  splice @ARGV, $skip_arg, 1;
83 }
84
85 my ($cc, $ld);
86 unless ($pp) {
87  $cc = check_exe('C compiler', 'CC', 'cc', 'CC');
88  if (defined $cc) {
89   $ld = check_exe('linker', 'LD', 'ld', 'LD');
90  }
91 }
92
93 sub is_little_endian {
94  my $order = $Config{byteorder};
95  return 0 unless $order;
96  my $len = length $order;
97  if ($len > 8) {
98   $order = substr $order, 0, 8;
99   $len   = 8;
100  }
101  return $order eq (join '', 1 .. $len);
102 }
103
104 my %PARAMS;
105 my @DEFINES;
106
107 if (defined $cc and defined $ld) {
108  $PARAMS{C}  = [ 'Util.c' ];
109  $PARAMS{XS} = { 'Util.xs' => 'Util.c' };
110  $PARAMS{CC} = $cc;
111  $PARAMS{LD} = $ld;
112
113  my $unit = { bits => 8, size => 1 };
114  if (not is_little_endian()) {
115   print "Forcing unit size of 8 on non-little-endian systems.\n";
116  } else {
117   print "Checking unit size in bits... ";
118   my $align = $Config{alignbytes} || 1;
119   my @bits = (8, 16, 32, 64);
120   for my $bits (@bits) {
121    my $size = $Config{"u${bits}size"};
122    next unless $size;
123    $unit = { bits => $bits, size => $size } if $size && $size <= $align;
124   }
125   print $unit->{bits},
126                 " (actually $unit->{size} bytes for $align bytes alignment).\n";
127  }
128
129  my $bits = $unit->{bits};
130  push @DEFINES, '-DBV_UNIT="' . ($Config{"u${bits}type"} || "U$bits") . '"';
131  push @DEFINES, "-DSVU_SIZE=$bits";
132 } else {
133  $PARAMS{C}      = [ ];
134  $PARAMS{XS}     = { };
135  $PARAMS{OBJECT} = '';
136  print "Falling back to the pure-Perl implementation.\n";
137 }
138
139 $PARAMS{DEFINE} = join ' ', @DEFINES if @DEFINES;
140
141 my $dist = 'Scalar-Vec-Util';
142
143 (my $name = $dist) =~ s{-}{::}g;
144
145 (my $file = $dist) =~ s{-}{/}g;
146 $file = "lib/$file.pm";
147
148 my %PREREQ_PM = (
149  'Exporter' => 0,
150  'Carp'     => 0,
151  'XSLoader' => 0,
152  'base'     => 0,
153 );
154
155 my %BUILD_REQUIRES = (
156  'Config'              => 0,
157  'ExtUtils::MakeMaker' => 0,
158  'File::Spec'          => 0,
159  'Test::More'          => 0,
160  %PREREQ_PM,
161 );
162
163 my %META = (
164  configure_requires => {
165   'Config'              => 0,
166   'ExtUtils::MakeMaker' => 0,
167   'File::Spec'          => 0,
168  },
169  build_requires => {
170   %BUILD_REQUIRES,
171  },
172  dynamic_config => 1,
173  resources => {
174   bugtracker => "http://rt.cpan.org/Dist/Display.html?Name=$dist",
175   homepage   => "http://search.cpan.org/dist/$dist/",
176   license    => 'http://dev.perl.org/licenses/',
177   repository => "http://git.profvince.com/?p=perl%2Fmodules%2F$dist.git",
178  },
179 );
180
181 WriteMakefile(
182  NAME             => $name,
183  AUTHOR           => 'Vincent Pit <perl@profvince.com>',
184  LICENSE          => 'perl',
185  VERSION_FROM     => $file,
186  ABSTRACT_FROM    => $file,
187  PL_FILES         => {},
188  BUILD_REQUIRES   => \%BUILD_REQUIRES,
189  PREREQ_PM        => \%PREREQ_PM,
190  MIN_PERL_VERSION => '5.006',
191  META_MERGE       => \%META,
192  dist             => {
193   PREOP    => "pod2text -u $file > \$(DISTVNAME)/README",
194   COMPRESS => 'gzip -9f', SUFFIX => 'gz'
195  },
196  clean            => {
197   FILES => "$dist-* *.gcov *.gcda *.gcno cover_db Debian_CPANTS.txt*"
198  },
199  %PARAMS,
200 );
201
202 1;
203
204 package MY;
205
206 sub postamble {
207  my $cv = join ' -coverage ', 'cover',
208                             qw<statement branch condition path subroutine time>;
209  <<POSTAMBLE;
210 cover test_cover:
211         $cv -test
212 POSTAMBLE
213 }