Alien-spatialite

 view release on metacpan or  search on metacpan

alienfile  view on Meta::CPAN

  #  see if this helps with cirrus bsd builds
  #$ENV{SQLITE3_CFLAGS} = Alien::sqlite->cflags;
  #$ENV{SQLITE3_LIBS} = Alien::sqlite->libs;
  #say "sqlite cflags: " . Alien::sqlite->cflags;
  #say "sqlite libs: " . Alien::sqlite->libs;
  
  if ($^O =~ /bsd/) {
    plugin 'Build::Make' => 'gmake';
    if (-d '/usr/local') {
        $with_local = ' --with-local=/usr/local ';
    }
    if (!-e '/usr/local/include/sqlite3.h' && Alien::sqlite->install_type eq 'system') {
      warn '/usr/local/include/sqlite3.h does not exist, '
         . 'you might need to install the sqlite package for your system, '
         . 'or install a share version of Alien::sqlite';
    }
  }
  elsif ($^O =~ /dragonfly/) {
    #  might need to be combined with bsd check above
    #  but not sure if /usr/local is needed yet
    plugin 'Build::Make' => 'gmake';
  }

  my $make_cmd = '%{make}';
  my $make_inst_cmd = '%{make} install';
  my @make_clean;
  #  try not to exceed the cpan-testers log limits
  if ($on_automated_rig) {
    say "Running under CI or automated testing";
    $make_cmd      .= q/ | perl -ne "BEGIN {$|=1; open our $log, q|>|, q|build.log|};   print qq|\n| if 0 == ($. %% 100); print q|.|; print {$log} $_;" || type build.log/;
    $make_inst_cmd .= q/ | perl -ne "BEGIN {$|=1; open our $log, q|>|, q|install.log|}; print qq|\n| if 0 == ($. %% 100); print q|.|; print {$log} $_;" || type install.log/;
    if (!$on_windows) {
        $make_cmd =~ s/%%/%/;
        $make_cmd =~ s/type/cat/;
        $make_cmd =~ s/"/'/g;
        $make_inst_cmd =~ s/%%/%/;
        $make_inst_cmd =~ s/type/cat/;
        $make_inst_cmd =~ s/"/'/g;
    }
    #  clean up the build dir on cpan testers etc
    plugin 'Cleanse::BuildDir';
  }

  meta->around_hook( build => \&set_compiler_flags );
  meta->around_hook(
    build => sub {
      my ($orig, $build, @args) = @_;
      $build->log("Setting CCACHE_BASEDIR to " . getcwd());
      local $ENV{CCACHE_BASEDIR} = getcwd();
      $orig->($build, @args);
    }
  );

  meta->before_hook( build => \&update_configure_freebsd );

  build [
    "%{configure} $with_local $with_cpp11 $build_static $extra_build_args",
    \&pause,
    $make_cmd,
    \&patch_rpaths,
    \&rename_la_files,
    $make_inst_cmd,
    #@make_clean
  ];

};


sub update_configure_freebsd {
  my ($build) = @_;

  return if not $^O =~ /bsd/;

  $build->log ('Updating configure for FreeBSD');

  use File::Find::Rule;
  my @configures
    = File::Find::Rule->file()
                        ->name( 'configure' )
                        ->in( '.' );
  
  foreach my $fname (@configures) {
    $build->log ($fname);
    my $permissions = (stat ($fname))[2];
    open my $fh, $fname or die $!;
    my $text = do {local $/ = undef; <$fh>};
    $fh->close;
    $text =~ s/(freebsd[12])\*/$1.*/gms;
    $text =~ s/(freebsd\[123?\])\*/$1.*/gms;
    rename $fname, "$fname.bak";
    open my $ofh, '>', $fname or die $!;
    print {$ofh} $text;
    $ofh->close;
    chmod $permissions, $fname;
  }
  
  return;
}

sub rename_la_files {
    #  need to return if not share
    return if !$on_windows;
    
    use File::Find::Rule;
    my @la_files
      = File::Find::Rule->file()
                        ->name( '*.la' )
                        ->in( '.' );
    foreach my $file (@la_files) {
        Alien::Build->log("Renaming $file so it will not interfere with gdal compilation");
        rename $file, $file . '.bak';
    }

}

#  should be a gather hook working on the stage dir
sub patch_rpaths {
  my ($build) = @_;
  
  #  only run on unices - incomplete check but
  #  I don't think aliens work on VMS or zOS
  return if ($on_windows or $^O =~ /darwin/i);

  my $h = get_alien_state_hash();
  my $install_path = $h->{install}{prefix};
  return if !defined $install_path;

  my @alien_rpaths;
  for my $alien (@alien_deps) {
    next if not $alien->install_type('share');
    push @alien_rpaths, $alien->dist_dir . '/lib';
  }
  if (!@alien_rpaths) {
    $build->log('No shared alien deps found, not updating rpaths');
    return;
  }

  my $origin_string = $^O =~ /darwin/ ? '@loader_path' : '${ORIGIN}';
  my $alien_rpath_text
    = join ':', (
       (map {$origin_string . '/../' . path ($_)->relative($install_path)->stringify} @alien_rpaths),
       @alien_rpaths
      );

  $build->log ("Prepending rpaths with $alien_rpath_text");
  
  use File::Find::Rule;
  my (@so_files)
    = grep {not -l $_}
      File::Find::Rule
              ->file()
              ->name( qr/^(lib|mod_)spatialite.so.?/ )
              ->in( getcwd() );
  
  eval 'require Alien::patchelf'
    or do {
      warn 'Unable to load Alien::patchelf ($@), cannot update rpaths';
      return;
    };
  my $pe = Alien::patchelf->new;
  foreach my $so_file (@so_files) {
    my ($old_rpath, $result, $stderr, @errors);
    ($old_rpath, $stderr, @errors)
      = $pe->patchelf ('--print-rpath', $so_file);
    $old_rpath //= '';
    #  prepend our paths
    my $rpath = $alien_rpath_text . ($old_rpath ? (':' . $old_rpath) : '');
    $build->log("Updating rpath for $so_file to $rpath, was $old_rpath");
    ($result, $stderr, @errors)
      = $pe->patchelf ('--set-rpath', $rpath, $so_file);
    warn $stderr if $stderr;



( run in 0.365 second using v1.01-cache-2.11-cpan-7fcb06a456a )