37a8e07c5bb46137b73529116a39fd64263b9bd6
[p5sagit/JSON-MaybeXS.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 => 'JSON-MaybeXS',
10   license => 'perl_5',
11   dynamic_config => 1,
12   prereqs => {
13     configure => {
14       requires => {
15         'ExtUtils::MakeMaker' => '0',
16       },
17     },
18     runtime => {
19       requires => {
20         'Scalar::Util' => '0',
21         'Carp' => '0',
22         'JSON::PP' => '2.27300',
23         # we may also add a runtime prereq for Cpanel::JSON::XS, on the
24         # installer's machine
25         perl => '5.006',
26       },
27       recommends => { 'Cpanel::JSON::XS' => '2.3310' },
28     },
29     test => {
30       requires => {
31         'Test::More' => '0.88',
32       },
33     },
34   },
35   resources => {
36     # GitHub mirrors from Shadowcat. We list it so we can get pull requests.
37     # The canonical repo is:
38     # r/o: git://git.shadowcat.co.uk/p5sagit/JSON-MaybeXS.git
39     # r/w: p5sagit@git.shadowcat.co.uk:JSON-MaybeXS.git
40     # web: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=p5sagit/JSON-MaybeXS.git
41     repository => {
42       url => 'https://github.com/p5sagit/JSON-MaybeXS.git',
43       web => 'https://github.com/p5sagit/JSON-MaybeXS',
44       type => 'git',
45     },
46     bugtracker => {
47       mailto => 'bug-JSON-MaybeXS@rt.cpan.org',
48       web => 'https://rt.cpan.org/Public/Dist/Display.html?Name=JSON-MaybeXS',
49     },
50     license => [ 'http://dev.perl.org/licenses/' ],
51   },
52   x_contributors => [ # manually added, from git shortlog -e -s -n
53     'Clinton Gormley <develop@traveljury.com>',
54     'Graham Knop <haarg@haarg.org>',
55     'John SJ Anderson <genehack@genehack.org>',
56     'Karen Etheridge <ether@cpan.org>',
57     'Kieren Diment <diment@gmail.com>',
58     'Matt S Trout <mst@shadowcat.co.uk>',
59   ],
60   keywords => [ qw(json serializer serialiser data) ],
61   no_index => {
62     directory => [ 't', 'xt' ]
63   },
64 );
65
66 my %MM_ARGS = ();
67
68 if (! parse_args()->{PUREPERL_ONLY}) {
69   # we require Cpanel::JSON::XS whenever a compiler is available.
70   # (we also always recommend Cpanel::JSON::XS, just to make sure.)
71   $MM_ARGS{PREREQ_PM}{'Cpanel::JSON::XS'} = '2.3310'
72     if eval { require Cpanel::JSON::XS; 1 }
73       or can_compile_loadable_object(quiet => 1);
74
75   # JSON::XS 3 changed its boolean handling - update it
76   # if JSON::XS is installed and < 3.0
77   $MM_ARGS{PREREQ_PM}{'JSON::XS'} = '3.00'
78     if eval { require JSON::XS; 1 }
79       and not eval { JSON::XS->VERSION('3.0'); 1 };
80 }
81
82 use Text::ParseWords;
83
84 sub parse_args {
85   # copied from EUMM
86   ExtUtils::MakeMaker::parse_args(
87     my $tmp = {},
88     Text::ParseWords::shellwords($ENV{PERL_MM_OPT} || ''),
89     @ARGV,
90   );
91   return $tmp->{ARGS} || {};
92 }
93
94 ## BOILERPLATE ###############################################################
95 require ExtUtils::MakeMaker;
96 (do './maint/Makefile.PL.include' or die $@) unless -f 'META.yml';
97
98 # have to do this since old EUMM dev releases miss the eval $VERSION line
99 my $eumm_version  = eval $ExtUtils::MakeMaker::VERSION;
100 my $mymeta        = $eumm_version >= 6.57_02;
101 my $mymeta_broken = $mymeta && $eumm_version < 6.57_07;
102
103 ($MM_ARGS{NAME} = $META{name}) =~ s/-/::/g;
104 ($MM_ARGS{VERSION_FROM} = "lib/$MM_ARGS{NAME}.pm") =~ s{::}{/}g;
105 $META{license} = [ $META{license} ]
106   if $META{license} && !ref $META{license};
107 $MM_ARGS{LICENSE} = $META{license}[0]
108   if $META{license} && $eumm_version >= 6.30;
109 $MM_ARGS{NO_MYMETA} = 1
110   if $mymeta_broken;
111 $MM_ARGS{META_ADD} = { 'meta-spec' => { version => 2 }, %META }
112   unless -f 'META.yml';
113
114 for (qw(configure build test runtime)) {
115   my $key = $_ eq 'runtime' ? 'PREREQ_PM' : uc $_.'_REQUIRES';
116   my $r = $MM_ARGS{$key} = {
117     %{$META{prereqs}{$_}{requires} || {}},
118     %{delete $MM_ARGS{$key} || {}},
119   };
120   defined $r->{$_} or delete $r->{$_} for keys %$r;
121 }
122
123 $MM_ARGS{MIN_PERL_VERSION} = delete $MM_ARGS{PREREQ_PM}{perl} || 0;
124
125 delete $MM_ARGS{MIN_PERL_VERSION}
126   if $eumm_version < 6.47_01;
127 $MM_ARGS{BUILD_REQUIRES} = {%{$MM_ARGS{BUILD_REQUIRES}}, %{delete $MM_ARGS{TEST_REQUIRES}}}
128   if $eumm_version < 6.63_03;
129 $MM_ARGS{PREREQ_PM} = {%{$MM_ARGS{PREREQ_PM}}, %{delete $MM_ARGS{BUILD_REQUIRES}}}
130   if $eumm_version < 6.55_01;
131 delete $MM_ARGS{CONFIGURE_REQUIRES}
132   if $eumm_version < 6.51_03;
133
134 ExtUtils::MakeMaker::WriteMakefile(%MM_ARGS);
135 ## END BOILERPLATE ###########################################################