]> git.vpit.fr Git - perl/modules/Scalar-Vec-Util.git/blob - Makefile.PL
Test for little endianess more reliably
[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 sub is_little_endian {
41  my $order = $Config{byteorder};
42  return 0 unless $order;
43  my $len = length $order;
44  if ($len > 8) {
45   $order = substr $order, 0, 8;
46   $len   = 8;
47  }
48  return $order eq (join '', 1 .. $len);
49 }
50
51 my $unit = { bits => 8, size => 1 };
52 if (not is_little_endian()) {
53  print "Forcing unit size of 8 on non-little-endian systems.\n";
54 } else {
55  print "Checking unit size in bits... ";
56  my $align = $Config{alignbytes} || 1;
57  my @bits = (8, 16, 32);
58  push @bits, 64 unless $^O eq 'MSWin32';
59  for my $bits (@bits) {
60   my $size = $Config{"u${bits}size"};
61   next unless $size;
62   $unit = { bits => $bits, size => $size } if $size && $size <= $align;
63  }
64  print $unit->{bits},
65                 " (actually $unit->{size} bytes for $align bytes alignment).\n";
66 }
67
68 {
69  my $bits = $unit->{bits};
70  push @DEFINES, '-DBV_UNIT="' . ($Config{"u${bits}type"} || "U$bits") . '"';
71  push @DEFINES, "-DSVU_SIZE=$bits";
72 }
73
74 @DEFINES = (DEFINE => join ' ', @DEFINES) if @DEFINES;
75
76 my $dist = 'Scalar-Vec-Util';
77
78 my %META = (
79  configure_requires => {
80   'Config'              => 0,
81   'ExtUtils::MakeMaker' => 0,
82   'File::Spec'          => 0,
83  },
84  build_requires => {
85   'Config'              => 0,
86   'ExtUtils::MakeMaker' => 0,
87   'Test::More'          => 0,
88  },
89  resources => {
90   bugtracker => "http://rt.cpan.org/NoAuth/ReportBug.html?Queue=$dist",
91   homepage   => "http://search.cpan.org/dist/$dist/",
92   license    => 'http://dev.perl.org/licenses/',
93   repository => "http://git.profvince.com/?p=perl%2Fmodules%2F$dist.git",
94  },
95 );
96
97 WriteMakefile(
98     NAME             => 'Scalar::Vec::Util',
99     AUTHOR           => 'Vincent Pit <perl@profvince.com>',
100     LICENSE          => 'perl',
101     VERSION_FROM     => 'lib/Scalar/Vec/Util.pm',
102     ABSTRACT_FROM    => 'lib/Scalar/Vec/Util.pm',
103     PL_FILES         => {},
104     C                => \@C,
105     @DEFINES,
106     PREREQ_PM        => {
107         'Exporter' => 0,
108         'Carp'     => 0,
109         'XSLoader' => 0
110     },
111     MIN_PERL_VERSION => 5.006,
112     META_MERGE       => \%META,
113     dist             => {
114         PREOP    => 'pod2text lib/Scalar/Vec/Util.pm > $(DISTVNAME)/README',
115         COMPRESS => 'gzip -9f', SUFFIX => 'gz'
116     },
117     clean            => {
118         FILES => "$dist-* *.gcov *.gcda *.gcno cover_db Debian_CPANTS.txt"
119     },
120 );
121
122 1;
123
124 package MY;
125
126 sub postamble {
127  my $cv = join ' -coverage ', 'cover',
128                             qw/statement branch condition path subroutine time/;
129  <<POSTAMBLE;
130 cover test_cover:
131         $cv -test
132 POSTAMBLE
133 }