]> git.vpit.fr Git - perl/modules/Scalar-Vec-Util.git/blob - Makefile.PL
Simplify Config and File::Spec loading in 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
9 BEGIN {
10  local $@;
11  eval { require File::Spec; 1 } or die 'OS unsupported';
12 }
13
14 my $cc;
15 for (@ARGV) {
16  if (/^CC=(.*)/) {
17   $cc = $1;
18   last;
19  }
20 }
21 if (defined $cc) {
22  print "Forcing the use of $cc as the C compiler.\n";
23 } else {
24  # Inspired from Module::Install::Can
25  print "Checking for a valid C compiler in the PATH... ";
26  my @ccs = ($Config{cc});
27  unshift @ccs, $ENV{CC} if $ENV{CC};
28 CC:
29  for my $c (@ccs) {
30   for my $dir (split /$Config{path_sep}/, $ENV{PATH}) {
31    my $abs = File::Spec->catfile($dir, $c);
32    if (-x $abs or MM->maybe_command($abs)) {
33     $cc = $c;
34     print $cc, "\n";
35     last CC;
36    }
37   }
38  }
39  print "none\n" unless defined $cc;
40 }
41
42 my @C;
43 push @C, 'Util.c' if defined $cc;
44
45 my @DEFINES;
46
47 sub is_little_endian {
48  my $order = $Config{byteorder};
49  return 0 unless $order;
50  my $len = length $order;
51  if ($len > 8) {
52   $order = substr $order, 0, 8;
53   $len   = 8;
54  }
55  return $order eq (join '', 1 .. $len);
56 }
57
58 my $unit = { bits => 8, size => 1 };
59 if (not is_little_endian()) {
60  print "Forcing unit size of 8 on non-little-endian systems.\n";
61 } else {
62  print "Checking unit size in bits... ";
63  my $align = $Config{alignbytes} || 1;
64  my @bits = (8, 16, 32, 64);
65  for my $bits (@bits) {
66   my $size = $Config{"u${bits}size"};
67   next unless $size;
68   $unit = { bits => $bits, size => $size } if $size && $size <= $align;
69  }
70  print $unit->{bits},
71                 " (actually $unit->{size} bytes for $align bytes alignment).\n";
72 }
73
74 {
75  my $bits = $unit->{bits};
76  push @DEFINES, '-DBV_UNIT="' . ($Config{"u${bits}type"} || "U$bits") . '"';
77  push @DEFINES, "-DSVU_SIZE=$bits";
78 }
79
80 @DEFINES = (DEFINE => join ' ', @DEFINES) if @DEFINES;
81
82 my $dist = 'Scalar-Vec-Util';
83
84 (my $name = $dist) =~ s{-}{::}g;
85
86 (my $file = $dist) =~ s{-}{/}g;
87 $file = "lib/$file.pm";
88
89 my %PREREQ_PM = (
90  'Exporter' => 0,
91  'Carp'     => 0,
92  'XSLoader' => 0,
93  'base'     => 0,
94 );
95
96 my %META = (
97  configure_requires => {
98   'Config'              => 0,
99   'ExtUtils::MakeMaker' => 0,
100   'File::Spec'          => 0,
101  },
102  build_requires => {
103   'Config'              => 0,
104   'ExtUtils::MakeMaker' => 0,
105   'Test::More'          => 0,
106   %PREREQ_PM,
107  },
108  dynamic_config => 1,
109  resources => {
110   bugtracker => "http://rt.cpan.org/NoAuth/ReportBug.html?Queue=$dist",
111   homepage   => "http://search.cpan.org/dist/$dist/",
112   license    => 'http://dev.perl.org/licenses/',
113   repository => "http://git.profvince.com/?p=perl%2Fmodules%2F$dist.git",
114  },
115 );
116
117 WriteMakefile(
118  NAME             => $name,
119  AUTHOR           => 'Vincent Pit <perl@profvince.com>',
120  LICENSE          => 'perl',
121  VERSION_FROM     => $file,
122  ABSTRACT_FROM    => $file,
123  PL_FILES         => {},
124  C                => \@C,
125  @DEFINES,
126  PREREQ_PM        => \%PREREQ_PM,
127  MIN_PERL_VERSION => '5.006',
128  META_MERGE       => \%META,
129  dist             => {
130   PREOP    => "pod2text -u $file > \$(DISTVNAME)/README",
131   COMPRESS => 'gzip -9f', SUFFIX => 'gz'
132  },
133  clean            => {
134   FILES => "$dist-* *.gcov *.gcda *.gcno cover_db Debian_CPANTS.txt*"
135  },
136 );
137
138 1;
139
140 package MY;
141
142 sub postamble {
143  my $cv = join ' -coverage ', 'cover',
144                             qw<statement branch condition path subroutine time>;
145  <<POSTAMBLE;
146 cover test_cover:
147         $cv -test
148 POSTAMBLE
149 }