Added ptest target for parallel testing
[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
f1a287f3 17
18WriteMakefile1(
c07e8ef8 19 OPTIMIZE => "-g",
eda23e24 20 NAME => 'Devel::SizeMe',
21 VERSION_FROM => 'lib/Devel/SizeMe.pm',
d3b8a135 22 DEFINE => "-DALIGN_BITS=$ptr_bits",
986013ef 23 PREREQ_PM => {
24 'Test::More' => 0,
25 'JSON::XS' => 0,
26 'HTML::Entities' => 0,
3d2b08ed 27 # Removed for now as it stops people using SizeMe with 5.8
28 # sizeme_graph.pl will eventually become a separate module
29 #'Mojolicious::Lite' => 0,
63cf269b 30 'Devel::Dwarn' => 0,
d9d259d1 31 'XSLoader' => 0,
32 'ORLite' => 0,
986013ef 33 },
e610a166 34 EXE_FILES => [ 'bin/sizeme_store.pl', 'bin/sizeme_graph.pl' ],
f21502d1 35 clean => {
36 FILES => 'refcounted_he.h',
37 },
f1a287f3 38 META_MERGE => {
39 resources => {
40 repository => {
41 type => 'git',
42 url => 'git://github.com/timbunce/devel-sizeme.git',
43 web => 'https://github.com/timbunce/devel-sizeme',
44 },
45 bugtracker => {
46 web => 'https://github.com/timbunce/devel-sizeme/issues',
47 },
48 homepage => 'https://github.com/timbunce/devel-sizeme',
49 },
50 },
51 MIN_PERL_VERSION => '5.008',
52 LICENSE => 'perl',
6cc998b7 53);
f21502d1 54
f1a287f3 55
56sub WriteMakefile1 {
57 #Written by Alexandr Ciornii, version 0.21. Added by eumm-upgrade.
58 my %params = @_;
59 my $eumm_version = $ExtUtils::MakeMaker::VERSION;
60 $eumm_version = eval $eumm_version;
61 die "EXTRA_META is deprecated" if ( exists( $params{EXTRA_META} ) );
62 die "License not specified" if ( !exists( $params{LICENSE} ) );
63 if ( $params{BUILD_REQUIRES} and ( $eumm_version < 6.5503 ) ) {
64 #EUMM 6.5502 has problems with BUILD_REQUIRES
65 $params{PREREQ_PM} = { %{ $params{PREREQ_PM} || {} }, %{ $params{BUILD_REQUIRES} } };
66 delete $params{BUILD_REQUIRES};
67 }
68
69 # more or less taken from Moose' Makefile.PL
70 if ( $params{CONFLICTS} ) {
71 my $ok = CheckConflicts(%params);
72 exit(0) if ( $params{PREREQ_FATAL} and not $ok );
73 my $cpan_smoker = grep { $_ =~ m/(?:CR_SMOKER|CPAN_REPORTER|AUTOMATED_TESTING)/ } keys %ENV;
74 unless ( $cpan_smoker || $ENV{PERL_MM_USE_DEFAULT} ) {
75 sleep 4 unless ($ok);
76 }
77 %{$params{META_MERGE}{conflicts}} = %{$params{CONFLICTS}};
78 delete $params{CONFLICTS};
79 }
80
81 delete $params{CONFIGURE_REQUIRES} if ( $eumm_version < 6.52 );
82 delete $params{MIN_PERL_VERSION} if ( $eumm_version < 6.48 );
83 delete $params{META_MERGE} if ( $eumm_version < 6.46 );
84 delete $params{META_ADD} if ( $eumm_version < 6.46 );
85 delete $params{LICENSE} if ( $eumm_version < 6.31 );
86
87 WriteMakefile(%params);
88}
89
90
91my $conflictMsg = <<EOCM;
92***
93 This version of Devel::SizeMe conflicts with the version of
94 module %s (%s) you have installed.
95
96 It's strongly recommended that you update it after
97 installing this version of Devel::SizeMe.
98***
99EOCM
100
101sub CheckConflicts {
102 my %params = @_;
103 my %conflicts = %{ $params{CONFLICTS} };
104 my $found = 0;
105
106 while ( my ( $module, $version ) = each(%conflicts) ) {
107 undef $@;
108 eval "require $module";
109 next if $@;
110 my $installed = eval "\$" . $module . "::VERSION";
111 if ( $installed le $version ) {
112 ++$found;
113 my $msg = $conflictMsg;
114 my $warning = sprintf( $msg, $module, $installed );
115 warn $warning;
116 }
117 }
118
119 return !$found;
120}
121
122
f21502d1 123sub extract_refcounted_he {
124 my ($header) = @_;
125 open my $fh, '<', $header or die $!;
126
127 my $def;
128 while (<$fh>) {
129 next unless /struct refcounted_he \{/ .. /\};/;
130 $def .= $_;
131 }
132 close $fh or die $!;
133
134 return $def;
135}
136
137sub write_header {
138 my ($filename, $contents) = @_;
139 my $guard_name = uc $filename;
140 $guard_name =~ tr/./_/;
141
142 open my $fh, '>', $filename or die $!;
143 print { $fh } "#ifndef ${guard_name}\n";
144 print { $fh } "#define ${guard_name}\n";
3d2b08ed 145 print { $fh } $contents if defined $contents;
f21502d1 146 print { $fh } "#endif /* ${guard_name} */\n";
147 close $fh or die $!;
148}
06ccead3 149
150
151# =====================================================================
152
153package MY;
154
155sub postamble {
156 return qq{
157
158ptest: all
159\t prove --blib --jobs 4 --shuffle
160
161 \n};
162}