root/nicotine-app/trunk/nicotine/reparent

Revision 33, 2.0 KB (checked in by vasi, 4 years ago)

new module

  • Property svn:executable set to *
Line 
1#!/usr/bin/perl
2use warnings;
3use strict;
4
5use Cwd                         qw(cwd);
6use File::Basename      qw(dirname basename);
7use File::Spec;
8
9my $DEBUG = 0;
10my $prefix = '/sw';
11my $parent = "Resources";
12
13sub do_cmd {
14        my $cmd = shift;
15        print "$cmd\n" if $DEBUG;
16        system($cmd) == 0 or die "Command failed: $cmd\nError: $!\n";
17}
18
19sub resolve_link {
20        my $source = shift;
21        if (-l $source) {
22                my $target = readlink($source);
23                if ($target =~ m,^/,) {
24                        return resolve_link($target);
25                } else {
26                        return resolve_link(File::Spec->catfile(dirname($source), $target));
27                }
28        } else {
29                return File::Spec->rel2abs($source);
30        }
31}
32
33my @pkgs = @ARGV;
34my $pwd = cwd;
35for my $pkg (@pkgs) {
36        print "  reparenting $pkg\n";
37#       open FILE, "dpkg -L \Q$pkg\E | xargs file |"
38#               or die "Can't read package files: $!\n";
39        open FILE, "dpkg -L $pkg |"
40                or die "Can't read package files: $!\n";
41        for my $file (<FILE>) {
42                next unless $file =~ m,^$prefix/,;
43               
44#               my ($fname, $ftype) = ($file =~ /^([^:]+):(.*)/)
45#                       or die "Can't understand 'file' output: $file\n";
46                my $fname = $file; chomp $fname;
47                next unless -f $fname;
48               
49                (my $dir = dirname($fname)) =~ s,^,$parent,;
50                do_cmd("mkdir -p \Q$dir\E");
51                do_cmd("/bin/cp -RP \Q$fname\E \Q$dir\E");
52               
53#               if ($ftype =~ /Mach-O/) {
54#                       my $newfile = File::Spec->catfile($dir, basename($fname));
55#                       open OTOOL, "otool -L \Q$newfile\E |"
56#                               or die "Can't run otool: $!\n";
57#                       my @libs = <OTOOL>;
58#                       close OTOOL;
59#                       
60#                       for my $libline (@libs) {
61#                               $libline =~ m,^\s+$prefix/(.*)\s\(comp, or next;
62#                               my $lib = $1;
63#                               (my $libdir = $lib) =~ s,^/,$parent,;
64#                               my $plib = File::Spec->catfile($prefix, $lib);
65#                               my $ilib = File::Spec->catfile($libdir, $lib);
66#                               my $inst = File::Spec->catfile('@executable_path',
67#                                       File::Spec->abs2rel($ilib, "$pwd/$parent$prefix/bin"));
68#                               if (resolve_link($plib) eq $fname) {
69#                                       do_cmd("install_name_tool -id \Q$inst\E \Q$newfile\E");
70#                               } else {
71#                                       do_cmd("install_name_tool -change \Q$plib\E \Q$inst\E " .
72#                                               "\Q$newfile\E");
73#                               }
74#                       }
75#               }
76        }
77        close FILE;
78}
Note: See TracBrowser for help on using the browser.