]> git.vpit.fr Git - perl/modules/Scalar-Vec-Util.git/blob - Makefile.PL
Revamp compiler/linker discovery 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 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 $cc = check_exe('C compiler', 'CC', 'cc', 'CC');
65
66 my $ld;
67 if (defined $cc) {
68  $ld = check_exe('linker', 'LD', 'ld', 'LD');
69 }
70
71 sub is_little_endian {
72  my $order = $Config{byteorder};
73  return 0 unless $order;
74  my $len = length $order;
75  if ($len > 8) {
76   $order = substr $order, 0, 8;
77   $len   = 8;
78  }
79  return $order eq (join '', 1 .. $len);
80 }
81
82 my %PARAMS;
83 my @DEFINES;
84
85 if (defined $cc and defined $ld) {
86  $PARAMS{C}  = [ 'Util.c' ];
87  $PARAMS{XS} = { 'Util.xs' => 'Util.c' };
88  $PARAMS{CC} = $cc;
89  $PARAMS{LD} = $ld;
90
91  my $unit = { bits => 8, size => 1 };
92  if (not is_little_endian()) {
93   print "Forcing unit size of 8 on non-little-endian systems.\n";
94  } else {
95   print "Checking unit size in bits... ";
96   my $align = $Config{alignbytes} || 1;
97   my @bits = (8, 16, 32, 64);
98   for my $bits (@bits) {
99    my $size = $Config{"u${bits}size"};
100    next unless $size;
101    $unit = { bits => $bits, size => $size } if $size && $size <= $align;
102   }
103   print $unit->{bits},
104                 " (actually $unit->{size} bytes for $align bytes alignment).\n";
105  }
106
107  my $bits = $unit->{bits};
108  push @DEFINES, '-DBV_UNIT="' . ($Config{"u${bits}type"} || "U$bits") . '"';
109  push @DEFINES, "-DSVU_SIZE=$bits";
110 } else {
111  $PARAMS{C}      = [ ];
112  $PARAMS{XS}     = { };
113  $PARAMS{OBJECT} = '';
114 }
115
116 $PARAMS{DEFINE} = join ' ', @DEFINES if @DEFINES;
117
118 my $dist = 'Scalar-Vec-Util';
119
120 (my $name = $dist) =~ s{-}{::}g;
121
122 (my $file = $dist) =~ s{-}{/}g;
123 $file = "lib/$file.pm";
124
125 my %PREREQ_PM = (
126  'Exporter' => 0,
127  'Carp'     => 0,
128  'XSLoader' => 0,
129  'base'     => 0,
130 );
131
132 my %BUILD_REQUIRES = (
133  'Config'              => 0,
134  'ExtUtils::MakeMaker' => 0,
135  'File::Spec'          => 0,
136  'Test::More'          => 0,
137  %PREREQ_PM,
138 );
139
140 my %META = (
141  configure_requires => {
142   'Config'              => 0,
143   'ExtUtils::MakeMaker' => 0,
144   'File::Spec'          => 0,
145  },
146  build_requires => {
147   %BUILD_REQUIRES,
148  },
149  dynamic_config => 1,
150  resources => {
151   bugtracker => "http://rt.cpan.org/Dist/Display.html?Name=$dist",
152   homepage   => "http://search.cpan.org/dist/$dist/",
153   license    => 'http://dev.perl.org/licenses/',
154   repository => "http://git.profvince.com/?p=perl%2Fmodules%2F$dist.git",
155  },
156 );
157
158 WriteMakefile(
159  NAME             => $name,
160  AUTHOR           => 'Vincent Pit <perl@profvince.com>',
161  LICENSE          => 'perl',
162  VERSION_FROM     => $file,
163  ABSTRACT_FROM    => $file,
164  PL_FILES         => {},
165  BUILD_REQUIRES   => \%BUILD_REQUIRES,
166  PREREQ_PM        => \%PREREQ_PM,
167  MIN_PERL_VERSION => '5.006',
168  META_MERGE       => \%META,
169  dist             => {
170   PREOP    => "pod2text -u $file > \$(DISTVNAME)/README",
171   COMPRESS => 'gzip -9f', SUFFIX => 'gz'
172  },
173  clean            => {
174   FILES => "$dist-* *.gcov *.gcda *.gcno cover_db Debian_CPANTS.txt*"
175  },
176  %PARAMS,
177 );
178
179 1;
180
181 package MY;
182
183 sub postamble {
184  my $cv = join ' -coverage ', 'cover',
185                             qw<statement branch condition path subroutine time>;
186  <<POSTAMBLE;
187 cover test_cover:
188         $cv -test
189 POSTAMBLE
190 }