fix bin/sizeme_graph.pl for older Mojolicious versions RT80195
[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",
eda23e24 19 NAME => 'Devel::SizeMe',
20 VERSION_FROM => 'lib/Devel/SizeMe.pm',
d3b8a135 21 DEFINE => "-DALIGN_BITS=$ptr_bits",
986013ef 22 PREREQ_PM => {
23 'Test::More' => 0,
24 'JSON::XS' => 0,
25 'HTML::Entities' => 0,
3d2b08ed 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,
63cf269b 29 'Devel::Dwarn' => 0,
d9d259d1 30 'XSLoader' => 0,
31 'ORLite' => 0,
986013ef 32 },
e610a166 33 EXE_FILES => [ 'bin/sizeme_store.pl', 'bin/sizeme_graph.pl' ],
f21502d1 34 clean => {
35 FILES => 'refcounted_he.h',
36 },
d3b8a135 37 (eval $ExtUtils::MakeMaker::VERSION >= 6.47 ? (MIN_PERL_VERSION => '5.005') : ()),
38 (eval $ExtUtils::MakeMaker::VERSION >= 6.31 ? (LICENSE => 'perl') : ()),
6cc998b7 39);
f21502d1 40
41sub 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
55sub 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";
3d2b08ed 63 print { $fh } $contents if defined $contents;
f21502d1 64 print { $fh } "#endif /* ${guard_name} */\n";
65 close $fh or die $!;
66}