Use Devel::Dwarn instead of Data::Dump
[p5sagit/Devel-Size.git] / Makefile.PL
1 #!/usr/bin/perl -w
2 use 5.005;
3 use ExtUtils::MakeMaker;
4 use File::Spec::Functions 'catfile';
5 use strict;
6
7 use Config;
8 (unpack "B*", pack "N", $Config{ptrsize}) =~ /^0+1(0+)$/
9     or die "Your pointer size of $Config{ptrsize} is very confusing";
10 my $ptr_bits = length $1;
11
12 write_header(
13     'refcounted_he.h' =>
14     extract_refcounted_he(catfile($Config{archlib}, 'CORE', 'hv.h'))
15 );
16
17 WriteMakefile(
18     OPTIMIZE => "-g",
19     NAME => 'Devel::SizeMe',
20     VERSION_FROM => 'lib/Devel/SizeMe.pm',
21     DEFINE => "-DALIGN_BITS=$ptr_bits",
22     PREREQ_PM => {
23         'Test::More' => 0,
24         'JSON::XS' => 0,
25         'HTML::Entities' => 0,
26         # Removed for now as it stops people using SizeMe with 5.8
27         # sizeme_graph.pl will eventually become a separate module
28         #'Mojolicious::Lite' => 0,
29         'Devel::Dwarn' => 0,
30         'XSLoader' => 0,
31         'ORLite' => 0,
32     },
33     EXE_FILES => [ 'bin/sizeme_store.pl', 'bin/sizeme_graph.pl' ],
34     clean => {
35         FILES => 'refcounted_he.h',
36     },
37     (eval $ExtUtils::MakeMaker::VERSION >= 6.47 ? (MIN_PERL_VERSION => '5.005') : ()),
38     (eval $ExtUtils::MakeMaker::VERSION >= 6.31 ? (LICENSE => 'perl') : ()),
39 );
40
41 sub extract_refcounted_he {
42     my ($header) = @_;
43     open my $fh, '<', $header or die $!;
44
45     my $def;
46     while (<$fh>) {
47         next unless /struct refcounted_he \{/ .. /\};/;
48         $def .= $_;
49     }
50     close $fh or die $!;
51
52     return $def;
53 }
54
55 sub write_header {
56     my ($filename, $contents) = @_;
57     my $guard_name = uc $filename;
58     $guard_name =~ tr/./_/;
59
60     open my $fh, '>', $filename or die $!;
61     print { $fh } "#ifndef ${guard_name}\n";
62     print { $fh } "#define ${guard_name}\n";
63     print { $fh } $contents if defined $contents;
64     print { $fh } "#endif /* ${guard_name} */\n";
65     close $fh or die $!;
66 }