-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathMakefile.PL
198 lines (151 loc) · 5.15 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
package PerlPowerTools;
use strict;
use warnings;
=encoding utf8
=head1 The build file for PerlPowerTools
This build file is a modulino; it works as both a build script and
a module.
To build the distribution, run this file normally:
% perl Makefile.PL
If you didn't specify C<INSTALL_BASE>, the modules go into your home
directory under F<perlpowertools>. You'll need to add this to PATH to
be able to use them.
If you want to install them somewhere else, run the F<Makefile.PL>
with your installation location:
% perl Makefile.PL INSTALL_BASE=/where/you/want/them/to/go
But, this F<Makefile.PL> is more interesting than that. You can load
it with C<require> and call C<arguments> to get the data structure it
passes to C<WriteMakefile>:
my $package = require '/path/to/Makefile.PL';
my $arguments = $package->arguments;
Note that C<require>-ing a file makes an entry in C<%INC> for exactly
that name. If you try to C<require> another file with the same name,
even from a different path, C<require> thinks it has already loaded
the file. As such, I recommend you always require the full path to the
file.
The return value of the C<require> is a package name (in this case,
the name of the main module). Use that to call the C<arguments> method.
Even if this distribution needs a higher version of Perl, this bit
only needs v5.8. You can play with the data structure with a primitive
Perl.
=cut
# You can specify INSTALL_BASE on the command line or in an environment
# variable a tool sets. We should respect either of them.
my $install_base_in_argv = grep { /\AINSTALL_BASE\b/ } @ARGV;
my $install_base_in_perl_mm_opt = (defined $ENV{PERL_MM_OPT} ? $ENV{PERL_MM_OPT} : "") =~ /\bINSTALL_BASE\b/;
my $has_install_base =
$install_base_in_argv || $install_base_in_perl_mm_opt || 0;
use File::Spec::Functions qw(catfile);
my $home = home();
unless( $has_install_base ) {
my $path = catfile($home, 'perlpowertools');
print <<"HERE" unless caller();
----------------------------------------------------------------------
Welcome to Perl Power Tools (http://www.perlpowertools.com).
You didn't specify INSTALL_BASE, so I chose $path.
You'll need to add this to PATH to be able to use the Perl Power Tools.
If you want to install them somewhere else, run Makefile.PL again
with your installation location:
perl Makefile.PL INSTALL_BASE=/where/you/want/them/to/go
Most Perl distributions don't do this for you, but I'm doing this
because some of these tools installed in the wrong places can hide
the real tools, which might cause problems. I'm being careful for
you!
----------------------------------------------------------------------
HERE
push @ARGV, "INSTALL_BASE=$path";
}
open my $manifest_fh, '<:utf8', 'MANIFEST'
or die "Could not open MANIFEST: $!";
my @exe_files;
while( <$manifest_fh> ) {
chomp;
next if /\A\s*#/;
s/\s*#.*$//;
next unless m|\Abin/|;
push @exe_files, $_;
}
close $manifest_fh;
my $module = __PACKAGE__;
( my $dist = $module ) =~ s/::/-/g;
my $github = 'https://github.com/briandfoy/PerlPowerTools';
my $main_file = catfile( 'lib', split /::/, "$module.pm" );
my %WriteMakefile = (
'MIN_PERL_VERSION' => '5.008',
'NAME' => $module,
'ABSTRACT_FROM' => $main_file,
'VERSION_FROM' => $main_file,
'LICENSE' => 'perl',
'AUTHOR' => 'brian d foy <[email protected]>',
'EXE_FILES' => \@exe_files,
'CONFIGURE_REQUIRES' => {
'ExtUtils::MakeMaker' => '6.64',
'File::Spec::Functions' => '0',
},
'BUILD_REQUIRES' => {
},
'TEST_REQUIRES' => {
'IPC::Run3' => '0',
'Test::More' => '1',
'Test::Pod' => '0',
'Test::Warnings' => '0',
},
'PREREQ_PM' => {
'App::a2p' => '0',
'App::find2perl' => '0',
},
'META_MERGE' => {
'meta-spec' => { version => 2 },
resources => {
repository => {
type => 'git',
url => $github,
web => $github,
},
bugtracker => {
web => "$github/issues",
},
homepage => "https://www.perlpowertools.com/",
},
},
clean => { FILES => "$dist-*" },
test => {TESTS => 't/*.t t/*/*.t'}
);
# This module uses Test::Deep, which has a dependency that requires
# v5.12.
$WriteMakefile{PREREQ_PM}{'MIME::Parser'} = 0 if $] >= 5.012;
sub arguments { \%WriteMakefile }
do_it() unless caller;
sub do_it {
require File::Spec;
my $MM ='ExtUtils::MakeMaker';
my $MM_version =
eval{ "$MM " . $WriteMakefile{'CONFIGURE_REQUIRES'}{'ExtUtils::MakeMaker'} }
||
"$MM 6.64";
eval "use $MM_version; 1" or die "Could not load $MM_version: $@";
eval "use Test::Manifest 1.21"
if -e File::Spec->catfile( qw(t test_manifest) );
my $arguments = arguments();
my $minimum_perl = $arguments->{MIN_PERL_VERSION} || '5.008';
eval "require $minimum_perl;" or die $@;
WriteMakefile( %$arguments );
}
sub home {
if ($^O eq 'MSWin32') {
#stolen from File::HomeDir::Windows
if ( exists $ENV{HOME} and $ENV{HOME} ) {
return $ENV{HOME};
}
if ( exists $ENV{USERPROFILE} and $ENV{USERPROFILE} ) {
return $ENV{USERPROFILE};
}
if ( exists $ENV{HOMEDRIVE} and exists $ENV{HOMEPATH} and $ENV{HOMEDRIVE} and $ENV{HOMEPATH} ) {
return catpath( $ENV{HOMEDRIVE}, $ENV{HOMEPATH}, '' )
}
} else {
return '~';
}
}
no warnings;
__PACKAGE__;