5eb43c6e88a1da038a7cc122435a5023e09928ab
[p5sagit/Devel-Size.git] / Makefile.PL
1 #!/usr/bin/perl -w
2 use 5.008;
3 use ExtUtils::MakeMaker;
4 use strict;
5
6 use Config;
7 (unpack "B*", pack "N", $Config{ptrsize}) =~ /^0+1(0+)$/
8     or die "Your pointer size of $Config{ptrsize} is very confusing";
9 my $ptr_bits = length $1;
10
11 my $svh = "$Config{archlibexp}/CORE/perl.h";
12 my $vtable_file = 'vtables.inc';
13
14 my %vtables;
15 open FH, "<$svh"
16     or die "Can't open $svh ($!) - is your perl install missing its headers?";
17 while (<FH>) {
18     next unless /^\s+(PL_vtbl_[a-z]+),\s*$/ or /^EXT MGVTBL (PL_vtbl_[a-z]+) =/;
19     ++$vtables{$1};
20 }
21 warn "Didn't find any vtable names in $svh" unless %vtables;
22 close FH;
23
24
25 my %special = (
26                PL_vtbl_collxfrm => 'USE_LOCALE_COLLATE',
27                PL_vtbl_mutex => 'USE_5005THREADS',
28 );
29
30 open FH, ">$vtable_file" or die "Can't open $vtable_file: $!";
31 foreach (sort keys %vtables) {
32     if ($special{$_}) {
33         print FH <<"EOT";
34 #ifdef $special{$_}
35     &$_,
36 #endif
37 EOT
38     } else {
39         print FH "    &$_,\n";
40     }
41 }
42
43 close FH or die "Error closing $vtable_file: $!";
44
45 WriteMakefile(
46               NAME => 'Devel::Size',
47               VERSION_FROM => 'lib/Devel/Size.pm',
48               DEFINE => "-DALIGN_BITS=$ptr_bits",
49               (eval $ExtUtils::MakeMaker::VERSION >= 6.47 ? (MIN_PERL_VERSION => '5.008') : ()),
50               (eval $ExtUtils::MakeMaker::VERSION >= 6.31 ? (LICENSE => 'perl') : ()),
51               realclean => {FILES=> $vtable_file},
52 );