]> git.vpit.fr Git - perl/modules/Scalar-Vec-Util.git/blob - Makefile.PL
Improve size discovery
[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 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 # Inspired from Module::Install::Can
16 print "Checking for a valid C compiler in the PATH... ";
17 my @ccs = ($Config{cc});
18 unshift @ccs, $ENV{CC} if $ENV{CC};
19 my $cc;
20 CC:
21 for my $c (@ccs) {
22  for my $dir (split /$Config{path_sep}/, $ENV{PATH}) {
23   my $abs = File::Spec->catfile($dir, $c);
24   if (-x $abs or MM->maybe_command($abs)) {
25    $cc = $c;
26    last CC;
27   }
28  }
29 }
30 my @C;
31 if ($cc) {
32  push @C, 'Util.c';
33  print $cc, "\n";
34 } else {
35  print "none\n";
36 }
37
38 my @DEFINES;
39
40 my $unit = { bits => 8, size => 1 };
41 if (unpack("h*", pack("s", 0x1234)) != 4321) {
42  print "Forcing unit size of 8 on non-little-endian systems.\n";
43 } else {
44  print "Checking unit size in bits... ";
45  my $align = $Config{alignbytes} || 1;
46  my @bits = (8, 16, 32);
47  push @bits, 64 unless $^O eq 'MSWin32';
48  for my $bits (@bits) {
49   my $size = $Config{"u${bits}size"};
50   next unless $size;
51   $unit = { bits => $bits, size => $size } if $size && $size <= $align;
52  }
53  print $unit->{bits},
54                 " (actually $unit->{size} bytes for $align bytes alignment).\n";
55 }
56
57 {
58  my $bits = $unit->{bits};
59  push @DEFINES, '-DBV_UNIT="' . ($Config{"u${bits}type"} || "U$bits") . '"';
60  push @DEFINES, "-DSVU_SIZE=$bits";
61 }
62
63 @DEFINES = (DEFINE => join ' ', @DEFINES) if @DEFINES;
64
65 my $dist = 'Scalar-Vec-Util';
66
67 my %META = (
68  configure_requires => {
69   'Config'              => 0,
70   'ExtUtils::MakeMaker' => 0,
71   'File::Spec'          => 0,
72  },
73  build_requires => {
74   'Config'              => 0,
75   'ExtUtils::MakeMaker' => 0,
76   'Test::More'          => 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/?p=perl%2Fmodules%2F$dist.git",
83  },
84 );
85
86 WriteMakefile(
87     NAME             => 'Scalar::Vec::Util',
88     AUTHOR           => 'Vincent Pit <perl@profvince.com>',
89     LICENSE          => 'perl',
90     VERSION_FROM     => 'lib/Scalar/Vec/Util.pm',
91     ABSTRACT_FROM    => 'lib/Scalar/Vec/Util.pm',
92     PL_FILES         => {},
93     C                => \@C,
94     @DEFINES,
95     PREREQ_PM        => {
96         'Exporter' => 0,
97         'Carp'     => 0,
98         'XSLoader' => 0
99     },
100     MIN_PERL_VERSION => 5.006,
101     META_MERGE       => \%META,
102     dist             => {
103         PREOP    => 'pod2text lib/Scalar/Vec/Util.pm > $(DISTVNAME)/README',
104         COMPRESS => 'gzip -9f', SUFFIX => 'gz'
105     },
106     clean            => {
107         FILES => "$dist-* *.gcov *.gcda *.gcno cover_db Debian_CPANTS.txt"
108     },
109 );
110
111 1;
112
113 package MY;
114
115 sub postamble {
116  my $cv = join ' -coverage ', 'cover',
117                             qw/statement branch condition path subroutine time/;
118  <<POSTAMBLE;
119 cover test_cover:
120         $cv -test
121 POSTAMBLE
122 }