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