Alien-SDL

 view release on metacpan or  search on metacpan

inc/My/Builder.pm  view on Meta::CPAN

  if (-e $fn) {
    print "Checking checksum for already existing '$fn'...\n";
    return 1 if $self->check_sha1sum($fn, $sha1sum);
    unlink $fn; #exists but wrong checksum
  }

  my $fullpath;
  foreach my $current_url (@{$url})
  {
    die "###ERROR### _fetch_file undefined url\n" unless $current_url;
    print "Fetching '$current_url'...\n";
    $ff = File::Fetch->new(uri => $current_url);
    $fullpath = $ff->fetch(to => $download);
    last if $fullpath;
  }
  die "###ERROR### Unable to fetch '$ff->file'" unless $fullpath;
  if (-e $fn) {
    print "Checking checksum for '$fn'...\n";
    return 1 if $self->check_sha1sum($fn, $sha1sum);
    die "###ERROR### Checksum failed '$fn'";
  }
  die "###ERROR### _fetch_file failed '$fn'";
}

sub fetch_binaries {
  my ($self, $download) = @_;
  my $bp = $self->notes('build_params');
  $self->fetch_file($bp->{url}, $bp->{sha1sum}, $download);
}

sub fetch_sources {
  my ($self, $download) = @_;
  my $bp = $self->notes('build_params');
  $self->fetch_file($_->{url}, $_->{sha1sum}, $download) foreach (@{$bp->{members}});
}

sub extract_binaries {
  my ($self, $download, $build_out) = @_;

  # do extract binaries
  my $bp = $self->notes('build_params');
  my $archive = catfile($download, File::Fetch->new(uri => @{$bp->{url}}[0])->file);
  print "Extracting $archive...\n";
  my $ae = Archive::Extract->new( archive => $archive );
  die "###ERROR###: Cannot extract $archive ", $ae->error unless $ae->extract(to => $build_out);

  # fix hardcoded prefix path in bin/sdl-config
  my ($version, $prefix, $incdir, $libdir) = find_SDL_dir(rel2abs($build_out));
  sed_inplace("$prefix/bin/sdl-config", 's/^prefix=.*/prefix=\''.quotemeta($prefix).'\'/');
  if( $^O eq 'MSWin32' && $My::Utility::cc eq 'cl' ) {
    cp( catfile('patches', 'SDL_config_win32.h'), catfile($incdir, 'SDL', 'SDL_config.h') );
  }
}

sub extract_sources {
  my ($self, $download, $patches, $build_src) = @_;
  my $bp = $self->notes('build_params');
  foreach my $pack (@{$bp->{members}}) {
    my $srcdir = catfile($build_src, $pack->{dirname});
    my $unpack = 'y';
    $unpack = $self->prompt("Dir '$srcdir' exists, wanna replace with clean sources?", "y") if (-d $srcdir);
    if (lc($unpack) eq 'y') {
      my $archive = catfile($download, File::Fetch->new(uri => @{$pack->{url}}[0])->file);
      print "Extracting $pack->{pack}...\n";
      my $ae = Archive::Extract->new( archive => $archive );
      die "###ERROR###: cannot extract $pack ", $ae->error unless $ae->extract(to => $build_src);
      foreach my $i (@{$pack->{patches}}) {
        chdir $srcdir;
        my $patch_file = File::Spec->abs2rel( catfile($patches, $i), $srcdir );
        print "Applying patch '$i'\n";
        foreach my $k ($self->patch_get_affected_files($patch_file)) {
          # doing the same like -p1 for 'patch'
          $k =~ s/^[^\/]*\/(.*)$/$1/;
          open(SRC, $k) or die "###ERROR### Cannot open file: '$k'\n";
          my @src = <SRC>;
          close(SRC);
          open(DIFF, $patch_file) or die "###ERROR### Cannot open file: '$patch_file'\n";
          my @diff = <DIFF>;
          close(DIFF);
          foreach(@src)  { $_=~ s/[\r\n]+$//; }
          foreach(@diff) { $_=~ s/[\r\n]+$//; }
          my $out = Text::Patch::patch( join("\n", @src) . "\n", join("\n", @diff) . "\n", { STYLE => "Unified" } );
          open(OUT, ">$k") or die "###ERROR### Cannot open file for writing: '$k'\n";
          print(OUT $out);
          close(OUT);
        }
        chdir $self->base_dir();
      }
    }
  }
  return 1;
}

sub set_config_data {
  my( $self, $build_out ) = @_;

  # try to find SDL root dir
  my ($version, $prefix, $incdir, $libdir) = find_SDL_dir(rel2abs($build_out));
  die "###ERROR### Cannot find SDL directory in 'sharedir'" unless $version;
  $self->config_data('share_subdir', abs2rel($prefix, rel2abs('sharedir')));

  # set defaults
  my $L   = $My::Utility::cc eq 'cl'
          ? '/LIBPATH:'
          : '-L';
  my $cfg = $self->config_data('config') || {};

  # defaults
  $cfg->{version}        = $version;
  $cfg->{prefix}         = '@PrEfIx@';
  $cfg->{libs}           = $L . $self->get_path('@PrEfIx@/lib') . ' -lSDLmain -lSDL';
  $cfg->{cflags}         = '-I' . $self->get_path('@PrEfIx@/include/SDL') . ' -D_GNU_SOURCE=1 -Dmain=SDL_main';
  $cfg->{ld_shared_libs} = [ ];

  # overwrite values available via sdl-config
  my $bp      = $self->config_data('build_prefix') || $prefix;
  my $devnull = File::Spec->devnull();
  my $script  = $self->escape_path( rel2abs("$prefix/bin/sdl-config") );
  foreach my $p (qw(version prefix libs cflags)) {
    my $o=`$script --$p 2>$devnull`;
    if ($o) {



( run in 2.237 seconds using v1.01-cache-2.11-cpan-6aa56a78535 )