Alien-SDL3_image

 view release on metacpan or  search on metacpan

builder/Alien/SDL3_image/Builder.pm  view on Meta::CPAN

            unshift @PATH, Alien::cmake3->bin_dir;
            say 'Looking for SDL3_image library...' if $verbose;
            my ($path) = DynaLoader::dl_findfile('-lSDL3_image');
            if ($path) {
                $config{type} = 'system';
                $config{path} = path($path)->realpath->stringify;
                say 'Library found at ' . $config{path} if $verbose;
            }
            else {
                say 'Building SDL3_image from source...' if $verbose;
                my $store = tempdir()->child( path($archive)->basename );
                my $build = tempdir()->child('build');
                my $okay  = $self->fetch( $archive, $store );
                die 'Failed to download SDL3_image source' unless $okay;

                #~ $self->add_to_cleanup( $okay->canonpath );
                $config{path} = 'share';
                $config{okay} = 0;
                my $cflags = '';
                require Alien::SDL3;
                {
                    $self->_do_in_dir(
                        $okay,
                        sub {
                            system( Alien::cmake3->exe, grep {length} '-S ' . $okay,
                                '-B ' . $build->canonpath,      '--install-prefix=' . $p->canonpath,
                                '-Wdeprecated -Wdev -Werror',   '-DSDL_SHARED=ON',
                                '-DSDL_TESTS=OFF',              '-DSDL_INSTALL_TESTS=OFF',
                                '-DSDL_DISABLE_INSTALL_MAN=ON', '-DSDL_VENDOR_INFO=SDL3.pm',
                                '-DCMAKE_BUILD_TYPE=Release',   '-DSDL3_DIR=' . Alien::SDL3->sdldir->child(qw[lib cmake SDL3])->absolute,
                                $cflags
                            );
                            system( Alien::cmake3->exe, '--build', $build->canonpath

                                #, '--config Release', '--parallel'
                            );
                            die "Failed to build SDL3_image! %s\n", $archive // '' if system( Alien::cmake3->exe, '--install', $build->canonpath );
                            $config{okay}    = 1;
                            $config{version} = $version;
                        }
                    );
                }
            }
        }
        {
            my @out;
            push @out, sprintf '%s = %s', $_, $config{$_} for sort keys %config;
            $p->child('.config')->spew( join "\n", @out );
        }
    }

    method get_arguments (@sources) {
        $_ = detildefy($_) for grep {defined} $install_base, $destdir, $prefix, values %{$install_paths};
        $install_paths = ExtUtils::InstallPaths->new( dist_name => $meta->name );
        return;
    }

    method fetch ( $liburl, $outfile ) {
        $http //= HTTP::Tiny->new();
        printf 'Downloading %s... ', $liburl if $verbose;
        $outfile->parent->mkpath;
        my $response = $http->mirror( $liburl, $outfile, {} );
        say $response->{reason} if $verbose;
        if ( $response->{success} ) {    #ddx $response;

            #~ $self->add_to_cleanup($outfile);
            my $outdir = $outfile->parent->child( $outfile->basename( '.tar.gz', '.zip' ) );
            printf 'Extracting %s to %s... ', $outfile, $outdir if $verbose;
            require Archive::Extract;
            my $ae = Archive::Extract->new( archive => $outfile );
            if ( $ae->extract( to => $outdir ) ) {
                say 'done' if $verbose;

                #~ $self->add_to_cleanup( $ae->extract_path );
                return path( $ae->extract_path );
            }
            else {
                croak 'Failed to extract ' . $outfile;
            }
        }
        else {
            croak 'Failed to download ' . $liburl;
        }
        return 0;
    }

    method Build(@args) {
        my $method = $self->can( 'step_' . $action );
        $method // die "No such action '$action'\n";
        exit $method->($self);
    }

    method Build_PL() {
        say sprintf 'Creating new Build script for %s %s', $meta->name, $meta->version;
        $self->write_file( 'Build', sprintf <<'', $^X, __PACKAGE__, __PACKAGE__ );
#!%s
use lib 'builder';
use %s;
use Getopt::Long qw[GetOptionsFromArray];
my %%opts = ( @ARGV && $ARGV[0] =~ /\A\w+\z/ ? ( action => shift @ARGV ) : () );
GetOptionsFromArray \@ARGV, \%%opts, qw[install_base=s install_path=s%% installdirs=s destdir=s prefix=s config=s%% uninst:1 verbose:1 dry_run:1 jobs=i prebuilt:1];
%s->new(%%opts)->Build();

        make_executable('Build');
        my @env = defined $ENV{PERL_MB_OPT} ? split_like_shell( $ENV{PERL_MB_OPT} ) : ();
        $self->write_file( '_build_params', encode_json( [ \@env, \@ARGV ] ) );
        if ( my $dynamic = $meta->custom('x_dynamic_prereqs') ) {
            my %meta = ( %{ $meta->as_struct }, dynamic_config => 0 );
            $self->get_arguments( \@env, \@ARGV );
            require CPAN::Requirements::Dynamic;
            my $dynamic_parser = CPAN::Requirements::Dynamic->new();
            my $prereq         = $dynamic_parser->evaluate($dynamic);
            $meta{prereqs} = $meta->effective_prereqs->with_merged_prereqs($prereq)->as_string_hash;
            $meta = CPAN::Meta->new( \%meta );
        }
        $meta->save(@$_) for ['MYMETA.json'];
    }

    sub find ( $pattern, $base ) {
        $base = path($base) unless builtin::blessed $base;
        my $blah = $base->visit(
            sub ( $path, $state ) {
                $state->{$path} = $path if -f $path && $path =~ $pattern;

                #~ return \0 if keys %$state == 10;
            },
            { recurse => 1 }



( run in 1.238 second using v1.01-cache-2.11-cpan-e1769b4cff6 )