Alien-OpenSSL

 view release on metacpan or  search on metacpan

alienfile  view on Meta::CPAN

use alienfile;
use Config;
use Env qw( @PKG_CONFIG_PATH @PKG_CONFIG_LIBDIR );

configure {
  requires 'Path::Tiny';
};

if(defined $ENV{OPENSSL_PREFIX} && -d "$ENV{OPENSSL_PREFIX}/lib/pkgconfig") {
  unshift @PKG_CONFIG_PATH, "$ENV{OPENSSL_PREFIX}/lib/pkgconfig";
}

if($^O eq 'darwin' && ! -d '/usr/include/openssl') {
  # The OpenSSL that ships with recent OS X is completely broken
  # from a developer perspective.  They provide an openssl binary,
  # libraries and a .pc file, but no headers.  I guess the reason
  # is OpenSSL is considered deprecated on the platform, but then
  # why ship the .pc file?  We set PKG_CONFIG_LIBDIR to just the
  # to skip /usr/lib/pkgconfig, unless the user has specified it.
  # (presumably if they have set it, they have done so for a reason).
  unless(defined $ENV{PKG_CONFIG_LIBDIR}) {
    @PKG_CONFIG_LIBDIR = qw(
      /usr/local/lib/pkgconfig
      /usr/local/share/pkgconfig
    )
  }

  if( -d '/usr/local/Cellar/openssl' ) {
    require File::Glob;
    my($dir) = File::Glob::bsd_glob('/usr/local/Cellar/openssl/*/lib/pkgconfig');
    push @PKG_CONFIG_LIBDIR, $dir;
  }

  if( -d '/usr/local/Cellar/libressl' ) {
    require File::Glob;
    my($dir) = File::Glob::bsd_glob('/usr/local/Cellar/libressl/*/lib/pkgconfig');
    push @PKG_CONFIG_LIBDIR, $dir;
  }

  if( -l '/opt/local/bin/openssl' ) {
    require Path::Tiny;
    my $dir = Path::Tiny->new(readlink '/opt/local/bin/openssl');
    $dir = $dir->relative('/opt/local/bin') if $dir->is_relative;
    $dir = $dir
      ->parent
      ->parent
      ->child('lib')
      ->child('pkgconfig');
    push @PKG_CONFIG_LIBDIR, "$dir";
  }

  log "overridding PKG_CONFIG_LIBDIR on macOS: $ENV{PKG_CONFIG_LIBDIR}";
}

plugin 'PkgConfig' => (
  pkg_name => 'openssl',
);

share {

  requires 'Test::More' => '0.96';
  requires 'Text::Template';

  meta->prop->{env}->{CC}   = $Config{cc};
  meta->prop->{env}->{PERL} = $^X;
  meta->prop->{destdir} = 1;

  # when building OpenSSL from source we have a few challenges.
  # - AB uses Net::SSLeay (via HTTP::Tiny) by default when downloading https URLs
  # - Net::SSLeay requires OpenSSL
  # - We can download OpenSSL from FTP, but that is susceptible to man-in-the-middle attacks
  #   (and that is a bad look for a security product)

  # Solution:
  # - try downloading with curl or wget via the 'bootstrap_ssl' option.
  # - if that doesn't work, fallback on FTP



( run in 0.791 second using v1.01-cache-2.11-cpan-e1769b4cff6 )