Perl-Repository-APC

 view release on metacpan or  search on metacpan

scripts/buildaperl  view on Meta::CPAN

# concurrency disallowed intentionally: it makes no sense that two
# processes build the exact same perl (yes, there may be exceptions
# and then we will have to revisit this)
rename $bdir, $target_dir or die "Could not rename to $target_dir";
rmdir $ptempdir or die "Could not remove temporary directory '$ptempdir': $!";
system "chmod -R u+w $target_dir";
chdir $target_dir or die "Could not chdir to $target_dir";
if ($Opt{branch} eq "perl" &&
    -e "patchlevel.h" &&
    $patchlevel >= 18749
   ) {
  0==system($^X,
            "-x",
            "patchlevel.h",
            "patchaperlup:$branch_arg$upto_arg$start_arg",
           ) or die;
}

unless ($Opt{noconfigure}) {
  my $absprefix = File::Spec->file_name_is_absolute($Opt{prefix}) ? 
      $Opt{prefix} : File::Spec->catfile($pwd,$Opt{prefix});
  mkpath "$absprefix/$Opt{branch}";
  my $tempdir = tempdir( "pXXXXXX", DIR => "$absprefix/$Opt{branch}");
  chmod 0755, $tempdir or die "Could not chmod to mode 0755 on directory '$tempdir': $!";

  # too many versions come without a wince/perl.ico:
  if (open my $fh, "MANIFEST") {
    my @manifest =  <$fh>;
    if (grep { /^wince\/perl\.ico\s/ } @manifest
        and not -f "wince/perl.ico") {
      close $fh;
      chmod 0644, "MANIFEST" or die "Could not chmod 0644 MANIFEST: $!";
      open $fh, ">", "MANIFEST" or die "Could not open >MANIFEST: $!";
      print $fh grep { ! /^wince\/perl\.ico\s/ } @manifest;
      close $fh;
    }
  }

  # here we do not need $target_dir, because branch is visible in directory
  mysystem "sh Configure -Dprefix=$tempdir/perl-$baseperl\@$patchlevel $Opt{config}";
  my $target = "";
  if ($Opt{target}) {
    $target = " $Opt{target}";
  }
  my $makeout = "";
  open my($make), "make$target 2>&1 |" or die;
  while (<$make>) {
    print;
    $makeout .= $_;
  }
  unless (close $make) {
    my $ret = $?;
    # if ($makeout =~ /No rule to make target.*built-in/) {
    if ($makeout =~ /(?:no rule to make target|don't know how to make).*built-in/i) {
      print "\aWARNING: Running 'make' failed. It produced the infamous
  <built-in> error that old perls have with new gccs. I'll work around this
  in the makefiles now and retry. If you do not like that, hit ^C and FIXME.
  Sleeping 5 seconds...\n";
      sleep 5;
      {
        local @ARGV = qw( makefile x2p/makefile);
        local $^I = "~";
        while (<>) {
          print unless /<(built-in|command line)>/;
        }
      }
      mysystem "make$target";
    } else {
      die "make failed with ret[$ret]";
    }
  }
  mysystem "make test" unless $Opt{notest};
  mysystem "LD_LIBRARY_PATH=. ./perl installperl" unless $Opt{noinstall};
}

if ($Opt{remo}){
  chdir $pwd;
  my $rmtree = $target_dir;
  warn "Removing $rmtree\n";
  rmtree $rmtree;
}

sub mysystem ($) {
  my $system = shift;
  warn "Running $system\n";
  my $start = time;
  $ENV{LANG} = "C"; # we rely on system messages!
  my $ret = system($system);
  unless ($ret==0) {
    my $cwd = cwd;
    Carp::confess("system[$system] failed with ret[$ret] in cwd[$cwd]");
  }
  push @SYSTEMTIMES, $system, time-$start;
  for (my $i = 0; $i < @SYSTEMTIMES; $i+=2){
    printf "%3d secs for[%s]\n", @SYSTEMTIMES[$i+1, $i];
  }
}

__END__

=head1 NAME

buildaperl - Build an arbitrary perl version from APC

=head1 SYNOPSIS

 buildaperl 5.7.0@7100
 buildaperl 5.8.0@
 buildaperl @
 buildaperl --h

=head1 DESCRIPTION

This script builds the sources for any perl version between 5.004 and
bleadperl.

The --h option displays all available options.

The argument consists of C<PERL_VERSION@PATCHNUMBER>. The C<@> is
mandatory, both C<PERL_VERSION> and C<PATCHNUMER> are optional.



( run in 0.505 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )