Alien-Box2D

 view release on metacpan or  search on metacpan

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


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

sub extract_sources {
  my ($self, $download, $build_src) = @_;
  my $bp = $self->notes('build_params');

  my $srcdir = catfile($build_src, $bp->{dirname});
  my $unpack = 'y';
  $unpack = $self->prompt("Dir '$srcdir' exists, wanna replace with clean sources?", "n") if (-d $srcdir);
  if (lc($unpack) eq 'y') {
    $self->clean_dir($srcdir);
    my $archive = catfile($download, File::Fetch->new(uri => $bp->{url})->file);
    print "Extracting sources...\n";
    my $ae = Archive::Extract->new( archive => $archive );
    die "###ERROR###: cannot extract $bp ", $ae->error unless $ae->extract(to => $build_src);
    $self->apply_patch($build_src, $_) foreach (@{$bp->{patches}});
  }
  return 1;
}

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

  # try to find Box2D root dir
  my $prefix = rel2abs($build_out);
  $self->config_data('share_subdir', $self->{properties}->{dist_version});

  # set defaults
  my $cfg = {
    # defaults (used on MS Windows build)
    version     => $self->notes('build_box2d_version'),
    prefix      => '@PrEfIx@',
    libs        => '-L' . $self->quote_literal('@PrEfIx@/lib') . ' -lBox2D',
    cflags      => '-I' . $self->quote_literal('@PrEfIx@/include'),
    shared_libs => [ ],
  };

  if($^O =~ /(bsd|linux)/) {
    $cfg->{libs} = '-L' . $self->quote_literal('@PrEfIx@/lib') . ' -Wl,-rpath,' . $self->quote_literal('@PrEfIx@/lib') . ' -lBox2D -lm',
  }

  # write config
  $self->config_data('config', $cfg);
}

sub build_binaries {
  my( $self, $build_out, $build_src ) = @_;
  my $bp = $self->notes('build_params');

  print "BUILDING '" . $bp->{dirname} . "'...\n";
  my $srcdir = catfile($build_src, $bp->{dirname});
  my $prefixdir = rel2abs($build_out);
  $self->config_data('build_prefix', $prefixdir); # save it for future Alien::Box2D::ConfigData

  # some platform specific stuff
  my $makefile = rel2abs('patches/Makefile.unix');
  $makefile = rel2abs('patches/Makefile.mingw') if $^O eq 'MSWin32' && $Config{cc} =~ /gcc/;
  $makefile = rel2abs('patches/Makefile.nmake') if $^O eq 'MSWin32' && $Config{cc} =~ /cl/;
  my $cxxflags = '-O3';
  $cxxflags   .= " $1" if $Config{cccdlflags} =~ /((-[df]PIC\s+)?-[df]PIC)/i;
  # MacOSX related flags
  # 'as' for 'arch' can be in /usr/libexec/gcc/darwin/<arch_type>/as or in /usr/local/libexec/gcc/darwin/<arch_type>/as
  foreach my $arch (qw(x86_64 i386 ppc)) {
    if($Config{ccflags} =~ /-arch \Q$arch\E/
    && (-e "/usr/libexec/gcc/darwin/$arch/as"
     || -e "/usr/local/libexec/gcc/darwin/$arch/as")) {
      $cxxflags .= " -arch $arch";
    }
  }

  my $cxx = $self->search_env_path(qw/c++ g++ gpp aCC CC cxx cc++ cl FCC KCC RCC xlC_r xlC/); #search PATH for c++ compiler
  my $ar = $self->search_env_path('ar');
  my $ranlib = $self->search_env_path('ranlib');
  ### workaround for http://www.cpantesters.org/cpan/report/16e1fb62-8bc3-11e0-a7f7-6524785ebe45
  #On solaris, some tools like 'ar' are not in the default PATH, but in /usr/???/bin
  if ($^O eq 'solaris') {
    for (qw[/usr/ccs/bin /usr/xpg4/bin /usr/sfw/bin /usr/xpg6/bin /usr/gnu/bin /opt/gnu/bin /usr/bin]) {
      last if $ar && $ranlib;
      $ar = "$_/ar" if (!$ar && -x "$_/ar");
      $ranlib = "$_/ranlib" if (!$ranlib && -x "$_/ranlib");
    }
  }

  print "Gonna read version info from $srcdir/Common/b2Settings.cpp\n";
  open(DAT, "$srcdir/Common/b2Settings.cpp") || die;
  my @raw=<DAT>;
  close(DAT);
  my ($version) = grep(/version\s?=\s?\{[\d\s,]+\}/, @raw);
  if ($version =~ /version\s?=\s?\{(\d+)[^\d]+(\d+)[^\d]+(\d+)\}/) {
    print STDERR "Got version=$1.$2.$3\n";
    $self->notes('build_box2d_version', "$1.$2.$3");
  }

  chdir $srcdir;
  my @cmd = ($self->_get_make, '-f', $makefile, "PREFIX=$prefixdir", 'install');
  push @cmd, "CXXFLAGS=$cxxflags" if $cxxflags;
  push @cmd, "AR=$ar" if $ar;
  push @cmd, "RANLIB=$ranlib" if $ranlib;
  push @cmd, "CXX=$cxx" if $cxx;
  printf("(cmd: %s)\n", join(' ', @cmd));
  $self->config_data('make_command', \@cmd);
  $self->do_system(@cmd) or die "###ERROR### [$?] during make ... ";
  chdir $self->base_dir();

  return 1;
}

sub clean_dir {
  my( $self, $dir ) = @_;
  if (-d $dir) {
    File::Path::rmtree($dir);
    File::Path::mkpath($dir);
  }
}

sub check_build_done_marker {



( run in 0.914 second using v1.01-cache-2.11-cpan-df04353d9ac )