-
Notifications
You must be signed in to change notification settings - Fork 10
/
Makefile.PL
220 lines (192 loc) · 7.01 KB
/
Makefile.PL
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
use strict;
use warnings;
use ExtUtils::MakeMaker 6.17;
my $EUMM = eval( $ExtUtils::MakeMaker::VERSION );
# 1. Start with one big hash is consistent with CPAN::Meta::Spec, version 2
# and holds all the settings we'll need.
my $meta = {
# "abstract" : See x_abstract_from
"author" => ["Goru Fuji (gfuji\@cpan.org)"],
"dynamic_config" => 1,
"generated_by" => "ExtUtils::MakeMaker version 7.70, CPAN::Meta::Converter version 2.150010",
"license" => ["perl_5"],
"meta-spec" => {
url => "https://metacpan.org/pod/CPAN::Meta::Spec",
version => 2,
},
"name" => "Test-Vars",
"no_index" => { directory => ["example", "t", "xt"] },
"prereqs" => {
"develop" => {
"requires" => {
"Pod::Spelling" => "0",
"Test::Pod" => "1.41",
"Test::Pod::Coverage" => "1.04",
"Test::Spelling" => "0.12",
"Test::Synopsis" => "0"
}
},
"configure" => {
"requires" => {
"ExtUtils::MakeMaker" => "6.17",
}
},
"build" => {
"requires" => {
"ExtUtils::MakeMaker" => "6.17",
}
},
"runtime" => {
"requires" => {
"B" => "0",
"ExtUtils::Manifest" => "0",
"IO::Pipe" => "0",
"List::Util" => "1.33",
"parent" => "0",
"perl" => "5.010000",
"Storable" => "0",
"Symbol" => "0",
}
},
"test" => {
"requires" => {
"File::Spec::Functions" => "0",
"Test::More" => "0.88",
"Test::Tester" => "0",
},
"recommends" => {
"Moose::Role" => "0",
"Test::Output" => "0",
},
},
}, # END "prereqs"
"provides" => {
"Test::Vars" => {
"file" => "lib/Test/Vars.pm",
"version" => "0.017",
}
},
"release_status" => "stable",
"resources" => {
"bugtracker" => {
"web" => "https://github.com/houseabsolute/p5-Test-Vars/issues"
},
"homepage" => "https://github.com/houseabsolute/p5-Test-Vars",
"repository" => {
"url" => "git://github.com/houseabsolute/p5-Test-Vars.git",
"web" => "https://github.com/houseabsolute/p5-Test-Vars"
}
},
# "version" # See x_version_from
"x_contributors" => [
'Dave Rolsky <[email protected]>',
'Dmitry Matrosov <[email protected]>',
'FUJI Goro <[email protected]>',
'FUJI Goro <[email protected]>',
'FUJI Goro <[email protected]>',
'Fuji, Goro <[email protected]>',
'Gregory Oschwald <[email protected]>',
'James E Keenan <[email protected]>',
'Michael G. Schwern <[email protected]>',
'Nicholas Clark <[email protected]>',
'Olivier Mengué <[email protected]>',
'Ran Eilam <[email protected]>',
'Richard Leach <[email protected]>',
'cpansprout <[email protected]>'
],
"x_abstract_from" => "lib/Test/Vars.pm",
"x_serialization_backend" => "JSON::PP version 4.16",
"x_version_from" => "lib/Test/Vars.pm",
};
my %dynamic_config;
# 2. In style of Type::Tiny Makefile.PL, handle some special cases defined by
# environmental variables like PERL_AUTHOR_TESTING, PERL_EXTENDED_TESTING,
# PERL_MINIMAL_INSTALL. For example, in Type::Tiny MINIMAL_INSTALL omits
# 'recommends' and 'suggests' elements underneath 'prereqs'; EXTENDED_TESTING
# adds key-value pairs to prereqs->test->requires for further testing
# (INVESTIGATE FURTHER).
# TK
# 3. Create %WriteMakefileArgs. Here we begin to create the data structure
# traditionally passed to ExtUtils::MakeMaker::WriteMakefile().
# %explicits: elements in $meta which we handle explicitly and which therefore
# do not need to be in META_MERGE
my %explicits = map {$_ => 1} qw( author license name x_abstract_from x_version_from );
my $for_meta_merge = { map { $_ => $meta->{$_} } grep { ! $explicits{$_} } keys %{$meta} };
my %WriteMakefileArgs = (
ABSTRACT_FROM => $meta->{x_abstract_from},
AUTHOR => ($EUMM >= 6.5702 ? $meta->{author}[0] : $meta->{author}),
DISTNAME => $meta->{name},
VERSION_FROM => $meta->{x_version_from},
LICENSE => ($EUMM >= 6.3001 ? $meta->{license}[0] : ''),
EXE_FILES => [],
NAME => do { my $n = $meta->{name}; $n =~ s/-/::/g; $n },
test => { TESTS => ($ENV{PERL_AUTHOR_TESTING} ? "t/*.t xt/*.t" : "t/*.t") },
($EUMM < 6.46 ? () : (META_MERGE => $for_meta_merge) ),
%dynamic_config,
);
my ($build_requires, $configure_requires, $runtime_requires, $test_requires);
# Verify EUMM versions from Changes
# Validate by running against older perls with earlier versions of EUMM
if ($EUMM >= 6.6303) {
$WriteMakefileArgs{BUILD_REQUIRES} ||= deps('build');
$WriteMakefileArgs{CONFIGURE_REQUIRES} ||= deps('configure');
$WriteMakefileArgs{TEST_REQUIRES} ||= deps('test');
$WriteMakefileArgs{PREREQ_PM} ||= deps('runtime');
}
elsif ($EUMM >= 6.5503) {
$WriteMakefileArgs{BUILD_REQUIRES} ||= deps('build', 'test');
$WriteMakefileArgs{CONFIGURE_REQUIRES} ||= deps('configure');
$WriteMakefileArgs{PREREQ_PM} ||= deps('runtime');
}
elsif ($EUMM >= 6.52) {
$WriteMakefileArgs{CONFIGURE_REQUIRES} ||= deps('configure');
$WriteMakefileArgs{PREREQ_PM} ||= deps('runtime', 'build', 'test');
}
else {
$WriteMakefileArgs{PREREQ_PM} ||= deps('configure', 'build', 'test', 'runtime');
}
my $minperl = min_perl_version($meta);
$WriteMakefileArgs{MIN_PERL_VERSION} = $EUMM >= 6.48 ? $minperl : '';
WriteMakefile(%WriteMakefileArgs);
#my $mm = WriteMakefile(%WriteMakefileArgs);
#require Data::Dump;
#Data::Dump::pp($mm);
########## SUBROUTINES ##########
sub deps { # Note: Not fully encapsulated; presumes $meta
my %r;
for my $stage (@_) {
for my $degree (qw| requires recommends |) {
for my $dep (keys %{$meta->{prereqs}{$stage}{$degree}}) {
next if $dep eq 'perl';
my $ver = $meta->{prereqs}{$stage}{$degree}{$dep};
$r{$dep} = $ver if !exists($r{$dep}) || $ver >= $r{$dep};
}
}
}
return \%r;
}
sub min_perl_version {
my $meta = shift;
my ($minperl) = reverse sort(
grep defined && /^[0-9]+(\.[0-9]+)?$/,
map $meta->{prereqs}{$_}{requires}{perl},
qw( configure build runtime )
);
if (defined($minperl)) {
die "Installing $meta->{name} requires Perl >= $minperl"
unless $] >= $minperl;
}
return $minperl;
}
# --- MakeMaker overrides ---
# inspired by Devel::NYTProf's Makefile.PL
package MY;
# add some extra utility targets to the make file
sub post_constants {
q{
AUTHOR_TEST_FILES = "t/*.t xt/*.t"
test_author ::
PERL_DL_NONLAZY=1 $(FULLPERLRUN) "-MExtUtils::Command::MM" "-MTest::Harness" "-e" "undef *Test::Harness::Switches; test_harness($(TEST_VERBOSE), '$(INST_LIB)', '$(INST_ARCHLIB)')" $(AUTHOR_TEST_FILES)
atest: test_author
}
}