76cffdd5739760e7608ca51bfec53729bc1de671
[dh-make-perl] / dev / i386 / libnet-ssleay-perl / libnet-ssleay-perl-1.35 / inc / Module / Install / PRIVATE / Net / SSLeay.pm
1 #line 1
2 package Module::Install::PRIVATE::Net::SSLeay;
3
4 use strict;
5 use Module::Install::Base;
6 use File::Basename ();
7 use File::Spec;
8 use Config;
9 use Symbol qw(gensym);
10
11 use vars qw{$VERSION @ISA};
12 BEGIN {
13     $VERSION = 0.01;
14     @ISA     = qw{Module::Install::Base};
15 }
16
17 # Define this to one if you want to link the openssl libraries statically into 
18 # the Net-SSLeay loadable object on Windows
19 my $win_link_statically = 0;
20
21 sub ssleay {
22     my ($self) = @_;
23
24     $self->requires_external_cc;
25
26     my $prefix = $self->find_openssl_prefix;
27     my $exec   = $self->find_openssl_exec($prefix);
28
29     unless (-x $exec) {
30         die <<EOM;
31 *** Could not find OpenSSL
32     If it's already installed, please set the OPENSSL_PREFIX environment
33     variable accordingly. If it isn't installed yet, get the latest version
34     from http://www.openssl.org/.
35 EOM
36     }
37
38     $self->check_openssl_version($prefix, $exec);
39     my $opts = $self->ssleay_get_build_opts($prefix, $exec);
40
41     $self->cc_inc_paths(      @{ $opts->{inc_paths} } );
42     $self->cc_lib_paths(      @{ $opts->{lib_paths} } );
43     $self->cc_lib_links(      @{ $opts->{lib_links} } );
44     $self->cc_optimize_flags(    $opts->{optimize}    );
45
46     $self->makemaker_args( CCCDLFLAGS => $opts->{cccdlflags} );
47
48     if ( $self->prompt(
49             "Do you want to run external tests?\n".
50             "These tests *will* *fail* if you do not have network connectivity.",
51             'n',
52     ) =~ /^y/i ) {
53         $self->tests('t/*/*.t t/*/*/*.t');
54     } else {
55         $self->tests('t/local/*.t t/handle/local/*.t');
56     }
57 }
58
59 sub ssleay_get_build_opts {
60     my ($self, $prefix, $exec) = @_;
61
62     my $opts = {
63         inc_paths  => ["$prefix/include", "$prefix/inc32", '/usr/kerberos/include'],
64         lib_paths  => [$prefix, "$prefix/lib", "$prefix/out32dll"],
65         lib_links  => [],
66         cccdlflags => '',
67     };
68
69     my $rsaref  = $self->ssleay_is_rsaref;
70
71     print <<EOM;
72 *** Be sure to use the same compiler and options to compile your OpenSSL, perl,
73     and Net::SSLeay. Mixing and matching compilers is not supported.
74 EOM
75
76     if ($^O eq 'MSWin32') {
77         print "*** RSAREF build on Windows not supported out of box" if $rsaref;
78         if ($win_link_statically)
79         {
80             # Link to static libs
81             push @{ $opts->{lib_paths} }, "$prefix/lib/VC/static";
82         }
83         else
84         {
85             push @{ $opts->{lib_paths} }, "$prefix/lib/VC";
86         }
87         # Library names depend on the compiler. We expect either 
88         # libeay32MD and ssleay32MD or
89         # libeay32 and ssleay32.
90         # This construction will not complain as long as it find at least one
91         # libssl32.a is made by openssl onWin21 with the ms/minw32.bat builder
92         push @{ $opts->{lib_links} }, qw( libeay32MD ssleay32MD libeay32 ssleay32 libssl32);
93     } else {
94         $opts->{optimize} = '-O2 -g';
95         push @{ $opts->{lib_links} },
96              ($rsaref
97               ? qw( ssl crypto RSAglue rsaref z )
98               : qw( ssl crypto z )
99              );
100
101         if (($Config{cc} =~ /aCC/i) && $^O eq 'hpux') {
102             print "*** Enabling HPUX aCC options (+e)\n";
103             $opts->{optimize} = '+e '. $opts->{optimize};
104         }
105
106         if ( (($Config{ccname} || $Config{cc}) eq 'gcc') && ($Config{cccdlflags} =~ /-fpic/) ) {
107             print "*** Enabling gcc -fPIC optimization\n";
108             $opts->{cccdlflags} .= '-fPIC';
109         }
110     }
111
112     return $opts;
113 }
114
115 sub ssleay_is_rsaref {
116     my ($self) = @_;
117
118     return $ENV{OPENSSL_RSAREF};
119 }
120
121 sub find_openssl_prefix {
122     my ($self, $dir) = @_;
123
124     if (defined $ENV{OPENSSL_PREFIX}) {
125         return $ENV{OPENSSL_PREFIX};
126     }
127
128     my %guesses = (
129             '/usr/bin/openssl'               => '/usr',
130             '/usr/sbin/openssl'              => '/usr',
131             '/opt/ssl/bin/openssl'           => '/opt/ssl',
132             '/opt/ssl/sbin/openssl'          => '/opt/ssl',
133             '/usr/local/ssl/bin/openssl'     => '/usr/local/ssl',
134             '/usr/local/openssl/bin/openssl' => '/usr/local/openssl',
135             '/apps/openssl/std/bin/openssl'  => '/apps/openssl/std',
136             '/usr/sfw/bin/openssl'           => '/usr/sfw', # Open Solaris
137             'C:\OpenSSL\bin\openssl.exe'     => 'C:\OpenSSL',
138     );
139
140     while (my ($k, $v) = each %guesses) {
141         if ( -x $k ) {
142             return $v;
143         }
144     }
145
146     return;
147 }
148
149 sub find_openssl_exec {
150     my ($self, $prefix) = @_;
151
152     my $exe_path;
153     for my $subdir (qw( bin sbin out32dll )) {
154         my $path = File::Spec->catfile($prefix, $subdir, "openssl$Config{_exe}");
155         if ( -x $path ) {
156             return $path;
157         }
158     }
159 }
160
161 sub check_openssl_version {
162     my ($self, $prefix, $exec) = @_;
163     my ($major, $minor, $letter);
164
165     {
166         my $pipe = gensym();
167         open($pipe, "$exec version |")
168             or die "Could not execute $exec";
169         my $output = <$pipe>;
170         chomp $output;
171         close $pipe;
172
173         unless ( ($major, $minor, $letter) = $output =~ /^OpenSSL\s+(\d+\.\d+)\.(\d+)([a-z]?)/ ) {
174             die <<EOM
175 *** OpenSSL version test failed
176     (`$output' has been returned)
177     Either you have bogus OpenSSL or a new version has changed the version
178     number format. Please inform the authors!
179 EOM
180         }
181     }
182
183     print "*** Found OpenSSL-${major}.${minor}${letter} installed in $prefix\n";
184
185     if ($major < 0.9 || ($major == 0.9 && $minor < 3)) {
186         die <<EOM;
187 *** That's too old!
188     Please upgrade OpenSSL to the latest version (http://www.openssl.org/)
189 EOM
190     }
191
192     if ($major > 0.9 || ($major == 0.9 && $minor > 8)) {
193         print <<EOM;
194 *** That's newer than what this module was tested with
195     You should consider checking if there is a newer release of this module
196     available. Everything will probably work OK, though.
197 EOM
198     }
199 }
200
201 sub fixpath {
202     my ($self, $text) = @_;
203
204     my $sep = File::Spec->catdir('');
205     $text =~ s{\b/}{$sep}g;
206
207     return $text;
208 }
209
210 1;