Alien-IUP
view release on metacpan or search on metacpan
inc/My/Builder.pm view on Meta::CPAN
my $unpack;
$unpack = (-d "$build_src/iup") && !$ENV{TRAVIS} ? $self->prompt("\nDir '$build_src/iup' exists, wanna replace with clean sources?", "n") : 'y';
if (lc($unpack) eq 'y') {
File::Path::rmtree("$build_src/iup") if -d "$build_src/iup";
$self->prepare_sources($self->notes('iup_url'), $self->notes('iup_sha1'), $download, $build_src);
if ($self->notes('iup_patches')) {
$self->apply_patch("$build_src/iup", $_) foreach (@{$self->notes('iup_patches')});
}
}
$unpack = (-d "$build_src/im") && !$ENV{TRAVIS} ? $self->prompt("\nDir '$build_src/im' exists, wanna replace with clean sources?", "n") : 'y';
if (lc($unpack) eq 'y') {
File::Path::rmtree("$build_src/im") if -d "$build_src/im";
$self->prepare_sources($self->notes('im_url'), $self->notes('im_sha1'), $download, $build_src);
if ($self->notes('im_patches')) {
$self->apply_patch("$build_src/im", $_) foreach (@{$self->notes('im_patches')});
}
}
$unpack = (-d "$build_src/cd") && !$ENV{TRAVIS} ? $self->prompt("\nDir '$build_src/cd' exists, wanna replace with clean sources?", "n") : 'y';
if (lc($unpack) eq 'y') {
File::Path::rmtree("$build_src/cd") if -d "$build_src/cd";
$self->prepare_sources($self->notes('cd_url'), $self->notes('cd_sha1'), $download, $build_src);
if ($self->notes('cd_patches')) {
$self->apply_patch("$build_src/cd", $_) foreach (@{$self->notes('cd_patches')});
}
}
$unpack = (-d "$build_src/zlib") && !$ENV{TRAVIS} ? $self->prompt("\nDir '$build_src/zlib' exists, wanna replace with clean sources?", "n") : 'y';
if ($self->notes('zlib_url') && !$self->config_data('syszlib_lflags') && lc($unpack) eq 'y') {
File::Path::rmtree("$build_src/zlib") if -d "$build_src/zlib";
$self->prepare_sources($self->notes('zlib_url'), $self->notes('zlib_sha1'), $download, $build_src);
if ($self->notes('zlib_patches')) {
$self->apply_patch("$build_src/zlib", $_) foreach (@{$self->notes('zlib_patches')});
}
}
$unpack = (-d "$build_src/freetype") && !$ENV{TRAVIS} ? $self->prompt("\nDir '$build_src/freetype' exists, wanna replace with clean sources?", "n") : 'y';
if ($self->notes('freetype_url') && !$self->config_data('sysfreetype_lflags') && lc($unpack) eq 'y') {
File::Path::rmtree("$build_src/freetype") if -d "$build_src/freetype";
$self->prepare_sources($self->notes('freetype_url'), $self->notes('freetype_sha1'), $download, $build_src);
if ($self->notes('freetype_patches')) {
$self->apply_patch("$build_src/freetype", $_) foreach (@{$self->notes('freetype_patches')});
}
}
$unpack = (-d "$build_src/ftgl") && !$ENV{TRAVIS} ? $self->prompt("\nDir '$build_src/ftgl' exists, wanna replace with clean sources?", "n") : 'y';
if ($self->notes('ftgl_url') && lc($unpack) eq 'y') {
File::Path::rmtree("$build_src/ftgl") if -d "$build_src/ftgl";
$self->prepare_sources($self->notes('ftgl_url'), $self->notes('ftgl_sha1'), $download, $build_src);
if ($self->notes('ftgl_patches')) {
$self->apply_patch("$build_src/ftgl", $_) foreach (@{$self->notes('ftgl_patches')});
}
}
### XXX hack for handling github tarballs
unless (-d "$build_src/cd" && -d "$build_src/im" && -d "$build_src/iup") {
for my $f (bsd_glob("$build_src/*")) {
if ($f =~ m!^\Q$build_src\E/.*?(im|cd|iup).*$!) {
print "renaming: $f $build_src/$1\n";
rename ($f, "$build_src/$1");
}
}
}
# go for build
my $success = $self->build_binaries($build_out, $build_src);
my $done = $self->config_data('info_done');
my $iuplibs = $self->config_data('iup_libs');
if ($self->notes('build_debug_info')) {
print STDERR "Build result: $done->{$_} - $_\n" foreach (sort keys %$done);
print STDERR "Output libs : $iuplibs->{$_} - $_\n" foreach (sort keys %$iuplibs);
}
die "###BUILD FAILED### essential libs (iup/im/cd) not built!" unless $done->{"iup:iup"} && $done->{"iup:iupim"} && $done->{"iup:iupcd"};
die "###BUILD FAILED###" unless $success;
#DEBUG: die intentionally at this point if you want to see build details from cpan testers
print STDERR "RESULT: OK!\n";
# store info about build to ConfigData
$self->config_data('share_subdir', $share_subdir);
$self->config_data('config', { PREFIX => '@PrEfIx@',
LIBS => '-L' . $self->quote_literal('@PrEfIx@/lib') .
' -l' . join(' -l', @{$self->config_data('linker_libs')}) .
' ' . $self->config_data('extra_lflags'),
INC => '-I' . $self->quote_literal('@PrEfIx@/include') .
' ' . $self->config_data('extra_cflags'),
});
}
# mark sucessfully finished build
$self->touchfile('build_done');
}
$self->SUPER::ACTION_code;
}
sub prepare_sources {
my ($self, $url, $sha1, $download, $build_src) = @_;
my $archive = $self->fetch_file( url=>$url, sha1=>$sha1, localdir=>$download );
#XXX hack
if ($archive !~ /\.(tar.gz|tgz|tar|zip|tbz|tar.bz2)$/) {
rename($archive, "$archive.$$.tgz");
$archive = "$archive.$$.tgz";
}
my $ae = Archive::Extract->new( archive => $archive );
die "###ERROR### Cannot extract tarball ", $ae->error unless $ae->extract(to => $build_src);
}
sub fetch_file {
my ($self, %args) = @_;
my $url = $args{url};
my $sha1 = $args{sha1};
my $localdir = $args{localdir};
my $localfile = $args{localfile};
die "###ERROR### fetch_file: undefined url\n" unless $url;
# create $localdir if necessary
File::Path::mkpath($localdir) unless $localdir && -d $localdir;
# handle redirects
my $head = head($url);
$url = $head->request->uri if defined $head;
# download destination
unless ($localfile) {
$localfile = $url;
$localfile =~ s/^.*?([^\\\/]+)$/$1/; #skip all but file part of URL
$localfile =~ s/\?.*$//; #skip URL params
}
$localfile = File::Spec->catfile($localdir, $localfile) if $localdir;
# check existing file
if (-f $localfile) {
if ($sha1) {
if ($self->check_sha1sum($localfile, $sha1)) {
return rel2abs($localfile);
}
else {
warn "Checksum FAILURE";
}
}
unlink $localfile; # if sha1 not given we force re-download
}
# download
warn "Fetching '$url'...\n";
my $rv = getstore($url, $localfile);
die "###ERROR### fetch_file: download error - return code '$rv'\n" unless $rv == 200;
die "###ERROR### fetch_file: download error - '$localfile' not saved\n" unless -f $localfile;
# checksum
if ($sha1) {
die "###ERROR### fetch_file: checksum failed" unless $self->check_sha1sum($localfile, $sha1);
}
return rel2abs($localfile);
}
sub check_sha1sum {
my ($self, $file, $sha1sum) = @_;
return 1 if $sha1sum eq 'DO_NOT_CHECK_SHA1';
( run in 0.894 second using v1.01-cache-2.11-cpan-2398b32b56e )