need to load EUMM early for arg parsing
[p5sagit/Devel-GlobalDestruction.git] / Makefile.PL
1 use strict;
2 use warnings FATAL => 'all';
3 use 5.006;
4 use lib 'inc';
5 use ExtUtils::HasCompiler qw(can_compile_loadable_object);
6 use ExtUtils::MakeMaker;
7
8 my %META = (
9   name => 'Devel-GlobalDestruction',
10   license => 'perl_5',
11   prereqs => {
12     configure => { requires => {
13       'ExtUtils::MakeMaker'   => 0,
14       'ExtUtils::CBuilder'    => 0.27,
15     } },
16     runtime => {
17       requires => {
18         'Sub::Exporter::Progressive' => '0.001011',
19         'perl'                      => 5.006,
20       },
21     },
22   },
23   resources => {
24     homepage => 'https://metacpan.org/release/Devel-GlobalDestruction',
25     repository => {
26       url => 'git://git.shadowcat.co.uk/p5sagit/Devel-GlobalDestruction.git',
27       web => 'http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=p5sagit/Devel-GlobalDestruction.git',
28       type => 'git',
29     },
30     bugtracker => {
31       web => 'https://rt.cpan.org/Public/Dist/Display.html?Name=Devel-GlobalDestruction',
32       mailto => 'bug-Devel-GlobalDestruction@rt.cpan.org',
33     },
34     license => [ 'http://dev.perl.org/licenses/' ],
35   },
36   no_index => {
37     directory => [ 't', 'xt' ]
38   },
39 );
40
41 my %MM_ARGS = (
42   PREREQ_PM => {
43     ( (defined ${^GLOBAL_PHASE} or parse_args()->{PUREPERL_ONLY}
44         or !can_compile_loadable_object(quiet => 1) )
45       ? ()
46       : ('Devel::GlobalDestruction::XS' => 0)
47     ),
48   },
49 );
50
51 use Text::ParseWords;
52
53 sub parse_args {
54   # copied from EUMM
55   ExtUtils::MakeMaker::parse_args(
56     my $tmp = {},
57     Text::ParseWords::shellwords($ENV{PERL_MM_OPT} || ''),
58     @ARGV,
59   );
60   return $tmp->{ARGS} || {};
61 }
62
63 if (eval { require Devel::GlobalDestruction }
64     && Devel::GlobalDestruction->VERSION < 0.10) {
65   package MY;
66   no warnings 'once';
67
68   *install = sub {
69     my $self = shift;
70     return '
71 pure_site_install ::
72         $(NOECHO) $(RM_F) ' . $self->quote_literal(
73       $self->catfile('$(DESTINSTALLSITEARCH)', 'Devel', 'GlobalDestruction.pm')
74     ) . "\n" . $self->SUPER::install;
75   };
76 }
77
78 ## BOILERPLATE ###############################################################
79 require ExtUtils::MakeMaker;
80 (do './maint/Makefile.PL.include' or die $@) unless -f 'META.yml';
81
82 # have to do this since old EUMM dev releases miss the eval $VERSION line
83 my $eumm_version  = eval $ExtUtils::MakeMaker::VERSION;
84 my $mymeta        = $eumm_version >= 6.57_02;
85 my $mymeta_broken = $mymeta && $eumm_version < 6.57_07;
86
87 ($MM_ARGS{NAME} = $META{name}) =~ s/-/::/g;
88 ($MM_ARGS{VERSION_FROM} = "lib/$MM_ARGS{NAME}.pm") =~ s{::}{/}g;
89 $META{license} = [ $META{license} ]
90   if $META{license} && !ref $META{license};
91 $MM_ARGS{LICENSE} = $META{license}[0]
92   if $META{license} && $eumm_version >= 6.30;
93 $MM_ARGS{NO_MYMETA} = 1
94   if $mymeta_broken;
95 $MM_ARGS{META_ADD} = { 'meta-spec' => { version => 2 }, %META }
96   unless -f 'META.yml';
97
98 for (qw(configure build test runtime)) {
99   my $key = $_ eq 'runtime' ? 'PREREQ_PM' : uc $_.'_REQUIRES';
100   my $r = $MM_ARGS{$key} = {
101     %{$META{prereqs}{$_}{requires} || {}},
102     %{delete $MM_ARGS{$key} || {}},
103   };
104   defined $r->{$_} or delete $r->{$_} for keys %$r;
105 }
106
107 $MM_ARGS{MIN_PERL_VERSION} = delete $MM_ARGS{PREREQ_PM}{perl} || 0;
108
109 delete $MM_ARGS{MIN_PERL_VERSION}
110   if $eumm_version < 6.47_01;
111 $MM_ARGS{BUILD_REQUIRES} = {%{$MM_ARGS{BUILD_REQUIRES}}, %{delete $MM_ARGS{TEST_REQUIRES}}}
112   if $eumm_version < 6.63_03;
113 $MM_ARGS{PREREQ_PM} = {%{$MM_ARGS{PREREQ_PM}}, %{delete $MM_ARGS{BUILD_REQUIRES}}}
114   if $eumm_version < 6.55_01;
115 delete $MM_ARGS{CONFIGURE_REQUIRES}
116   if $eumm_version < 6.51_03;
117
118 ExtUtils::MakeMaker::WriteMakefile(%MM_ARGS);
119 ## END BOILERPLATE ###########################################################