Alien-geos-af

 view release on metacpan or  search on metacpan

alienfile  view on Meta::CPAN

    
    use File::Find::Rule;
    use Path::Tiny qw /path/;
    my (@files)
      = File::Find::Rule
                ->file()
                ->name( 'Geometry.cpp' )
                ->in( $base_dir );
    #  loop is brute force
    foreach my $file (@files) {
        say "Modifying file $file";
        path($file)->edit (
            sub {
              s{^//(#define USE_RECTANGLE_INTERSECTION 1)}{$1}ms;
            }
        );
    }
}

sub update_geos_config {
    my ($build) = @_;

    $build->log ('updating geos-config to use dynamic base dir');
    use File::Find::Rule;
    my ($geos_config)
      = $build->install_type eq 'share'
          ? File::Find::Rule
                ->file()
                ->name( 'geos-config' )
                ->in( getcwd() )
          : 'geos-config';

    $build->log("Updating $geos_config");

    open my $fh , '<', $geos_config
      or die "Could not open $geos_config for reading, $!";
    my $file_contents;

    while (defined (my $line = <$fh>)) {
        if ($line =~ /^\s*prefix=/) {
            #  MSYS1 does not have realpath
            my $part1
              = q{BASEPATH=`perl -MCwd -MFile::Basename -e"print File::Basename::dirname(Cwd::abs_path (qq{$0}))"`};
            #  some variants use an escape function
            my $part2 = $line =~ /`escape/
              ? 'prefix=`escape "${BASEPATH}"`'
              : 'prefix="${BASEPATH}"';
            my $part3 = 'prefix=$(dirname ${prefix})';
            $line = "$part1\n$part2\n$part3\n";
        }
        $file_contents .= $line;
    }
    $fh->close;
    my $permissions = (stat ($geos_config))[2];
    rename $geos_config, "$geos_config.bak";
    open my $ofh, '>', $geos_config
      or die "Could not open $geos_config for writing, $!";
    print {$ofh} $file_contents;
    $ofh->close or die $!;
    #  make sure we get the same permissions
    chmod $permissions, $geos_config or die $!;
    return;
}

sub set_runtime_props_from_config {
    my ($build) = @_;

    $build->log ('set_runtime_props_from_config: Currently in ' . getcwd());

    $build->log("UPDATING PKG_CONFIG_PATH");
    
    use Env qw /@PKG_CONFIG_PATH @PATH/;
    use Capture::Tiny;
    use Path::Tiny;

    # should use proper Alien::Build methods to get location of file     
    use File::Find::Rule;
    my ($pk_config)
      = $build->install_type eq 'share'
          ? File::Find::Rule
                ->file()
                ->name( 'geos.pc' )
                ->in( getcwd() )
          : 'geos.pc';
    
    my $pk_path = path($pk_config)->parent->stringify;
    unshift @PKG_CONFIG_PATH, $pk_path;
    $build->log("PKG_CONFIG_PATH is $ENV{PKG_CONFIG_PATH}");

    #  should use perl package api?
    my $pkgconf = File::Which::which ('pkg-config') || File::Which::which ('ppkg-config');
    foreach my $flag (qw /cflags libs static/) {
        my @cmd = ($pkgconf, "--$flag", 'geos');
        $build->log("Calling: " . join ' ', @cmd);
        my ($stdout, $stderr, @result) = Capture::Tiny::capture {system @cmd};
        $build->log("ERROR: $stderr") if $stderr;
        $build->runtime_prop->{$flag} = $stdout;
        $build->runtime_prop->{$flag} =~ s/[\r\n]+$//;  #  generic chomp
        if ($on_windows) {
            #  windowsify the paths
            $build->runtime_prop->{$flag} =~ s|(?<=-[IL])/C/|C:/|i;
        }
        if ($^O =~ /bsd/i) {
            #  maybe will help?
            $build->runtime_prop->{$flag} =~ s/-\d+$//;
        }
        $build->log ("Runtime prop $flag is " . $build->runtime_prop->{$flag});
    }
}

sub rename_la_files {
    #  need to return if not share
    return if !$on_windows;
    
    use File::Find::Rule;
    my @la_files
      = File::Find::Rule->file()
                        ->name( '*.la' )
                        ->in( '.' );
    foreach my $file (@la_files) {
        say "Renaming $file so it will not interfere with gdal compilation";



( run in 1.473 second using v1.01-cache-2.11-cpan-39bf76dae61 )