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 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339
|
use 5.006;
use strict;
use warnings;
use Config;
use ExtUtils::CBuilder;
use ExtUtils::MakeMaker;
use File::Spec::Functions qw( catfile rel2abs );
use Getopt::Long qw( GetOptionsFromArray );
unless( require( catfile qw(inc IO Interactive Tiny.pm) ) ) {
die 'Your distribution is incomplete: Failed to load bundled IO::Interactive::Tiny';
}
run(\@ARGV, [qw{ssl crypto ssl32 ssleay32 eay32 libeay32 z}]);
sub run {
my $argv = shift;
my $libs = shift;
eval "use ExtUtils::MakeMaker::Coverage";
$@ or print "Adding testcover target\n";
my @authors = reverse ( # reverse chronological order
'Gisle Aas',
'Joshua Chamas',
'David Landgren',
'A. Sinan Unur <nanis@cpan.org>',
);
my $mm_version = $ExtUtils::MakeMaker::VERSION;
$mm_version =~ tr/_//d;
my %opt;
GetOptionsFromArray(
$argv,
\%opt,
'incpath=s',
'libpath=s',
'openssl-prefix=s',
'live-tests!',
'static',
'verbose!',
) or die "Error parsing command line options\n";
if ($ENV{AUTOMATED_TESTING}) {
$opt{verbose} = 1;
}
$opt{incpath} = select_first_realpath(
$opt{incpath},
$ENV{OPENSSL_INCLUDE},
catfile($ENV{OPENSSL_PREFIX}, 'include'),
);
$opt{libpath} = select_first_realpath(
$opt{libpath},
$ENV{OPENSSL_LIB},
catfile($ENV{OPENSSL_PREFIX}, 'lib'),
);
unless ($ENV{AUTOMATED_TESTING}) {
show_do_you_need_crypt_ssleay();
}
$libs = filter_libs(\%opt, $libs);
my $my_openssl_version_cmd = eval {
build_openssl_version(\%opt, 'openssl-version.c');
};
unless (defined $my_openssl_version_cmd) {
print "Failed to build and link a simple executable using OpenSSL\n";
exit 0;
};
show_cmd_output($my_openssl_version_cmd);
if ($ENV{PERL_MM_USE_DEFAULT}) {
$opt{'live-tests'} = 0;
}
elsif (not exists $opt{'live-tests'}) {
if (exists $ENV{CRYPT_SSLEAY_LIVE_TEST_WANTED}) {
$opt{'live-tests'} = $ENV{CRYPT_SSLEAY_LIVE_TEST_WANTED};
}
elsif (IO::Interactive::Tiny::is_interactive()) {
$opt{'live-tests'} = is_live_test_wanted();
}
}
my %params = (
META_MERGE => {
keywords => [ qw(lwp lwp-useragent openssl https) ],
no_index => {
directory => [ 'inc' ],
},
build => {
recommends => {
'Devel::CheckLib' => '0.99',
},
},
resources => {
repository => 'https://github.com/nanis/Crypt-SSLeay',
},
},
NAME => 'Crypt::SSLeay',
AUTHOR => \@authors,
ABSTRACT_FROM => 'SSLeay.pm',
VERSION_FROM => 'SSLeay.pm',
INC => $opt{incpath} ? qq{-I$opt{incpath}} : q{},
LIBS => $opt{libpath}
? [ join ' ', "-L$opt{libpath}", map "-l$_", @$libs ]
: [ join ' ', map "-l$_", @$libs ]
,
($opt{static} ? (LINK_TYPE => 'static') : ()),
TEST_REQUIRES => {
'Test::More' => '0.19',
'Try::Tiny' => '0.19',
},
CONFIGURE_REQUIRES => {
'Devel::CheckLib' => '1.09',
'ExtUtils::CBuilder' => '0.280205',
'Getopt::Long' => 0,
},
PREREQ_PM => {
'Bytes::Random::Secure' => '0.28',
'LWP::Protocol::https' => '6.02',
'MIME::Base64' => 0, # for Net::SSL
},
clean => {
FILES => join(' ',
'test.config',
'openssl-version.o',
$my_openssl_version_cmd,
'assertlib*',
),
},
LICENSE => 'artistic_2',
MIN_PERL_VERSION => 5.006,
);
$mm_version = eval $mm_version;
die "EXTRA_META is deprecated" if exists $params{EXTRA_META};
die "License not specified" if not exists $params{LICENSE};
if (
$params{AUTHOR} and
ref($params{AUTHOR}) eq ref([]) and
$mm_version < 6.5705
) {
$params{META_ADD}->{author} = $params{AUTHOR};
$params{AUTHOR}=join(', ', @{$params{AUTHOR}});
}
if ($params{TEST_REQUIRES} and $mm_version < 6.64) {
$params{BUILD_REQUIRES} = {
%{ $params{BUILD_REQUIRES} || {} },
%{ $params{TEST_REQUIRES} },
};
delete $params{TEST_REQUIRES};
}
if ($params{BUILD_REQUIRES} and $mm_version < 6.5503) {
#EUMM 6.5502 has problems with BUILD_REQUIRES
$params{PREREQ_PM} = {
%{ $params{PREREQ_PM} || {} },
%{ $params{BUILD_REQUIRES}},
};
delete $params{BUILD_REQUIRES};
}
delete $params{CONFIGURE_REQUIRES} if $mm_version < 6.52;
delete $params{MIN_PERL_VERSION} if $mm_version < 6.48;
delete $params{META_MERGE} if $mm_version < 6.46;
delete $params{META_ADD} if $mm_version < 6.46;
delete $params{LICENSE} if $mm_version < 6.31;
delete $params{AUTHOR} if $] < 5.005;
delete $params{ABSTRACT_FROM} if $] < 5.005;
delete $params{BINARY_LOCATION} if $] < 5.005;
WriteMakefile(%params);
write_test_config('test.config' =>
{
network_tests => ($opt{'live-tests'} ? 1 : 0),
}
);
}
sub is_live_test_wanted {
print <<EO_CHUNK;
The test suite can attempt to connect to public servers to ensure that the
code is working properly. If you are behind a strict firewall or have no
network connectivity, these tests may fail (through no fault of the code).
EO_CHUNK
my $wanted = prompt "Do you want to run the live tests (y/N)?", 'N';
$wanted =~ s/\A\s+//;
$wanted =~ s/\s+\z//;
return $wanted =~ /\Ay(?:es)?\z/i ? 1 : 0;
}
sub write_test_config {
my $file = shift;
my $config = shift;
open my $fh, '>', $file
or die "Failed to open '$file' to write config: $!";
for my $k ( sort keys %$config) {
print join("\t", $k, $config->{$k}), "\n";
}
close $fh
or die "Failed to close '$file' after writing config: $!";
return;
}
sub show_cmd_output {
my ($cmd) = @_;
my $sep = '=' x 80 . "\n";
my $output = `$cmd`;
print $sep,
defined($output) ? "Output from '$cmd':\n$output"
: "No output from '$cmd'",
$sep
;
return;
}
sub build_openssl_version {
my $opt = shift;
my $source = shift;
my $builder = ExtUtils::CBuilder->new(quiet => !($opt->{verbose} ? 1 : 0));
my $object = $builder->compile(
source => $source,
$opt->{incpath} ? (include_dirs => "$opt->{incpath}") : (),
);
my $executable = $builder->link_executable(
objects => $object,
);
-e $executable
and return rel2abs($executable);
return;
}
sub select_first_realpath {
my ($ret) = map rel2abs($_), grep defined && -d, @_;
$ret;
}
sub filter_libs {
my $opt = shift;
my $libs = shift;
return $libs unless eval {
require Devel::CheckLib;
1;
};
my @found;
for my $lib (@$libs) {
eval {
Devel::CheckLib::assert_lib(
debug => ($opt->{verbose} ? 1 : 0),
lib => $lib,
header => 'openssl/ssl.h',
$opt->{libpath} ? (libpath => "$opt->{libpath}") : (),
$opt->{incpath} ? (incpath => "$opt->{incpath}") : (),
);
push @found, $lib;
};
}
unless (grep /crypt|ssl|eay/, @found) {
printf(
"Cannot link with any of the requested SSL libraries '%s'\n",
join(', ' => @$libs),
);
exit 0;
}
printf "Found libraries '%s'\n", join(', ' => @found);
return \@found;
}
sub show_do_you_need_crypt_ssleay {
print <<EO_DO_YOU_NEED_CRYPT_SSLEAY;
*** THIS IS NOT AN ERROR, JUST A MESSAGE FOR YOUR INFORMATION ***
Do you really need Crypt::SSLeay?
Starting with version 6.02 of LWP, https support was unbundled into
LWP::Protocol::https. This module specifies as one of its prerequisites
IO::Socket::SSL which is automatically used by LWP::UserAgent unless
this preference is overridden separately. IO::Socket::SSL is a more
complete implementation, and, crucially, it allows hostname
verification. Crypt::SSLeay does not support this. At this point,
Crypt::SSLeay is maintained to support existing software that already
depends on it.
However, it is possible that your software does not really depend on
Crypt::SSLeay, only on the ability of LWP::UserAgent class to
communicate with sites over SSL/TLS.
If are using version LWP 6.02 or later, and therefore have installed
LWP::Protocol::https and its dependencies, and do not explicitly use
Net::SSL before loading LWP::UserAgent, or override the default socket
class, you are probably using IO::Socket::SSL and do not really need
Crypt::SSLeay.
Before installing Crypt::SSLeay, you may want to try specifying a
dependency on LWP::Protocol::https.
EO_DO_YOU_NEED_CRYPT_SSLEAY
}
|