File: fix_old_strawberry.pl

package info (click to toggle)
libpkgconfig-perl 0.26026-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,912 kB
  • sloc: ansic: 6,120; perl: 1,922; makefile: 4; sh: 3
file content (76 lines) | stat: -rw-r--r-- 1,631 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
use strict;
use warnings;
use Config;
use File::Spec;
use File::Copy qw( copy );

if($^O eq 'cygwin')
{
  print "this script is for native build version of Perl (Strawberry)\n";
  exit 2;
}

unless($^O eq 'MSWin32')
{
  print "this does not appear to be Windows Perl\n";
  exit 2;
}

my $uname = $Config{myuname};

print "myuname = $uname\n";

unless(defined $uname && $uname =~ /strawberry-perl/)
{
  print "this does not appear to be Strawberry Perl\n";
  exit 2;
}

if($uname =~ /strawberry-perl 5\.(\d+)\.(\d+)\.(\d+)/)
{
  my($major,$minor,$patch) = ($1,$2,$3);

  if( ($major == 20 && !($minor == 0 && $patch == 1))
  ||  ($major > 20))
  {
    print "this version of Perl doesn't need to be patched\n";
    exit 2;
  }

  my($vol, $dir, $file) = File::Spec->splitpath($^X);
  my @dirs = File::Spec->splitdir($dir);
  splice @dirs, -3;
  my $path = (File::Spec->catdir($vol, @dirs, qw( c lib pkgconfig )));

  my $dh;
  opendir $dh, $path;
  my @pcfiles = grep !/^\./, grep /\.pc$/, readdir $dh;
  closedir $dh;

  foreach my $pcfile (@pcfiles)
  {
    my $bak = File::Spec->catfile($path, "$pcfile.bak");
    my $pc  = File::Spec->catfile($path, $pcfile);

    if(-e $bak)
    {
      print "already exists: $bak\n";
      print "patch has probably already been applied\n";
      next;
    }

    print "copy $pc => $bak\n";
    copy($pc, $bak) || die "Copy failed: $!";

    print "read $bak\n";
    open my $fh, '<', $bak;
    my @content = map { s{/mingw}{"\${pcfiledir}/../.."}eg; $_ } <$fh>;
    close $fh;

    print "write $pc\n";
    open $fh, '>', $pc;
    binmode $fh;
    print $fh @content;
    close $fh;
  }
}