use strict; use warnings; use Config; use ExtUtils::MakeMaker; use File::Basename qw(dirname); use Getopt::Long; eval "use ExtUtils::MakeMaker::Coverage"; $@ or print "Adding testcover target\n"; use vars qw($opt_default $opt_libpath); GetOptions( "default", \$opt_default, "lib=s", \$opt_libpath, ); $opt_default ||= $ENV{CRYPT_SSLEAY_DEFAULT}; # FIND POSSIBLE SSL INSTALLATIONS my @POSSIBLE_SSL_DIRS; if ($opt_libpath) { # explicit from command-line @POSSIBLE_SSL_DIRS = ($opt_libpath); $opt_default = 1; } elsif ($^O eq 'MSWin32') { @POSSIBLE_SSL_DIRS = 'c:\\openssl'; } elsif ($^O eq 'VMS') { @POSSIBLE_SSL_DIRS = '/ssl$root'; } else { # Unix and the rest @POSSIBLE_SSL_DIRS = qw( /usr/local/openssl /usr/local/ssl /local/ssl /opt/ssl /usr/local /local /usr ); } my @CANDIDATE = map {Candidate($_)} @POSSIBLE_SSL_DIRS; if (@CANDIDATE == 0) { $opt_default = 0; my $bar = '=' x 72; print <{dir}; } else { print <{type} installation found at $pkg_config->{dir} Consider running 'perl Makefile.PL --default' the next time Crypt::SSLeay is upgraded to select this directory automatically thereby avoiding the following prompt. ======================================================= INFO } } elsif (@CANDIDATE > 1) { print "Found multiple possibilities for OpenSSL\n"; for my $c (@CANDIDATE) { print " $c->{dir} ($c->{type} $c->{ver})\n"; } } if (not $SSL_DIR) { my %cand; for my $c (@CANDIDATE) { $cand{$c->{dir}} = {%$c}; } $SSL_DIR = prompt "Which SSL install path do you want to use?", $CANDIDATE[0]->{dir}; if (exists $cand{$SSL_DIR}) { # we've already determined that this directory is usable $pkg_config = $cand{$SSL_DIR}; } else { # unknown directory, better check it out $pkg_config = Candidate($SSL_DIR); if (not $pkg_config) { die <{inc}"; push @LIB_FLAGS, qw(-L/SYS$SHARE -lSSL$LIBSSL_SHR32 -lSSL$LIBCRYPTO_SHR32); } elsif ($^O eq 'MSWin32') { # external tools probably expect \ and not / for path separators $SSL_DIR =~ tr{/}{\\}; # default to drive C: $SSL_DIR = "c:$SSL_DIR" if $SSL_DIR !~ /\A[a-z]:/i; my $inc = $pkg_config->{inc}; $inc =~ tr{/}{\\}; $inc !~ /^[a-z]:/i and $inc = "c:$inc"; push @INC_FLAGS, "-I$inc"; push @INC_FLAGS, "-I$SSL_DIR\\inc32" if -d "$SSL_DIR/inc32"; my $vanilla = $Config{cc} eq 'gcc' ? 1 : 0; $vanilla and print "Assuming Vanilla/Strawberry Perl installation\n"; if ($vanilla and -d "$SSL_DIR\\lib\\MinGW") { push @LIB_FLAGS, "-L$SSL_DIR\\lib\\MinGW"; } elsif(-d "$SSL_DIR/lib") { push @LIB_FLAGS, "-L$SSL_DIR\\lib"; } elsif(-d "$SSL_DIR/out32dll") { # patch from Ben Laurie push @LIB_FLAGS, "-L$SSL_DIR\\out32dll"; } else { # Allow developers to point at OpenSSL source... push @LIB_FLAGS, "-L$SSL_DIR"; } push @LIB_FLAGS, qw(-lssleay32 -llibeay32); push @LIB_FLAGS, qw(-lRSAglue -lrsaref) if $pkg_config->{type} ne 'OpenSSL'; } else { push @INC_FLAGS, "-I$pkg_config->{inc}"; push @LIB_FLAGS, "-L$SSL_DIR/lib", qw(-lssl -lcrypto -lgcc); push @LIB_FLAGS, qw(-lRSAglue -lrsaref) if $pkg_config->{type} ne 'OpenSSL'; # ccc on alpha support if ($^O eq 'linux' and `uname -m` =~ /alpha/ and !(system("nm $SSL_DIR/lib/libssl.a|grep -q 'U _Ots'")>>8) ) { push @LIB_FLAGS, '-lots'; } # this fix was suggested for building on RedHat 9 push @INC_FLAGS, '-I/usr/kerberos/include' if -d '/usr/kerberos/include'; } # write include file that determines ssl support my $ssl_header_prefix = ($pkg_config->{inc} =~ /\bopenssl/i) ? 'openssl/' : '' ; # we need to include crypto.h for SSLeay so the version gets picked up in SSLeay.xs open(INCLUDE, ">crypt_ssleay_version.h") || die("can't open crypt_ssleay_version.h for writing: $!"); print INCLUDE <{ver}; if(($openssl_version =~ /^OpenSSL/) and ($openssl_version !~ /0\.9\.[2-5]/)) { print INCLUDE "#define CRYPT_SSLEAY_free OPENSSL_free\n"; } else { print INCLUDE "#define CRYPT_SSLEAY_free free\n"; } close INCLUDE or die "Cannot close crypt_ssleay_version.h for output: $!\n"; print <{type} $pkg_config->{ver} in $SSL_DIR ssl header: ${ssl_header_prefix}ssl.h libraries: @LIB_FLAGS include dir: @INC_FLAGS ================================================ INFO my @license = $ExtUtils::MakeMaker::VERSION > 6.30 ? qw(LICENSE perl) : (); WriteMakefile( NAME => 'Crypt::SSLeay', AUTHOR => 'David Landgren', ABSTRACT_FROM => 'SSLeay.pm', VERSION_FROM => 'SSLeay.pm', LIBS => ["@LIB_FLAGS"], INC => "@INC_FLAGS", NEEDS_LINKING => 1, clean => { FILES => 'crypt_ssleay_version.h test.config', }, @license, ); if (open OUT, '> test.config') { print OUT <{type} $pkg_config->{ver} in $SSL_DIR lib @LIB_FLAGS inc @INC_FLAGS cc $Config{cc} INFO print <) { if (/^#define\s+$version_match\s+0x0+(\d\d\d)/) { $version = $1; $version =~ s/(\d)0(\d)/$1$2/; $type = ($version > 92) ? "OpenSSL" : "SSLeay"; $version = join('.', split(//, "0$version")); last; } } close(VERSION_FILE); # Silly test to look for the library files my $foundlib = 0; my $libd; if (-d "$dir/out32dll") { $libd = 'out32dll'; } elsif ($^O eq 'MSWin32' and $Config{cc} eq 'gcc') { $libd = 'lib/MinGW'; } else { $libd = 'lib'; } if (opendir(LIBDIR, "$dir/$libd")) { while (defined($_ = readdir(LIBDIR))) { if (/\A(?:lib(?:crypto|eay32|ssl)|ssleay32)/) { $foundlib++; last; } } closedir(LIBDIR); } print "$dir/$libd does not seem to contain the SSLeay library files\n" unless $foundlib; return { dir => $dir, inc => $inc_dir, ver => $version, type => $type, }; }