Add a few more global pointers
[p5sagit/Devel-Size.git] / Makefile.PL
CommitLineData
d9b022a1 1#!/usr/bin/perl -w
177ebd37 2use 5.005;
6cc998b7 3use ExtUtils::MakeMaker;
f21502d1 4use File::Spec::Functions 'catfile';
d9b022a1 5use strict;
6cc998b7 6
5f03b77e 7use Config;
8(unpack "B*", pack "N", $Config{ptrsize}) =~ /^0+1(0+)$/
390777e7 9 or die "Your pointer size of $Config{ptrsize} is very confusing";
5f03b77e 10my $ptr_bits = length $1;
11
f21502d1 12write_header(
13 'refcounted_he.h' =>
14 extract_refcounted_he(catfile($Config{archlib}, 'CORE', 'hv.h'))
15);
16
1a36ac09 17WriteMakefile(
c07e8ef8 18 OPTIMIZE => "-g",
d3b8a135 19 NAME => 'Devel::Memory',
20 VERSION_FROM => 'lib/Devel/Memory.pm',
21 DEFINE => "-DALIGN_BITS=$ptr_bits",
986013ef 22 PREREQ_PM => {
23 'Test::More' => 0,
24 'JSON::XS' => 0,
25 'HTML::Entities' => 0,
63cf269b 26 'Mojolicious::Lite' => 0,
27 'Devel::Dwarn' => 0,
986013ef 28 XSLoader => 0,
7cc24077 29 ORLite => 0,
986013ef 30 },
d3b8a135 31 EXE_FILES => [ 'bin/dmemtree.pl' ],
f21502d1 32 clean => {
33 FILES => 'refcounted_he.h',
34 },
d3b8a135 35 (eval $ExtUtils::MakeMaker::VERSION >= 6.47 ? (MIN_PERL_VERSION => '5.005') : ()),
36 (eval $ExtUtils::MakeMaker::VERSION >= 6.31 ? (LICENSE => 'perl') : ()),
6cc998b7 37);
f21502d1 38
39sub extract_refcounted_he {
40 my ($header) = @_;
41 open my $fh, '<', $header or die $!;
42
43 my $def;
44 while (<$fh>) {
45 next unless /struct refcounted_he \{/ .. /\};/;
46 $def .= $_;
47 }
48 close $fh or die $!;
49
50 return $def;
51}
52
53sub write_header {
54 my ($filename, $contents) = @_;
55 my $guard_name = uc $filename;
56 $guard_name =~ tr/./_/;
57
58 open my $fh, '>', $filename or die $!;
59 print { $fh } "#ifndef ${guard_name}\n";
60 print { $fh } "#define ${guard_name}\n";
61 print { $fh } $contents or die $!;
62 print { $fh } "#endif /* ${guard_name} */\n";
63 close $fh or die $!;
64}