[BACK]Return to find_depends CVS log [TXT][DIR] Up to [local] / openbsd / fill_chroot

Diff for /openbsd/fill_chroot/find_depends between version 1.1 and 1.12

version 1.1, 2005/12/21 18:04:06 version 1.12, 2008/09/16 23:38:04
Line 1 
Line 1 
 #!/usr/bin/perl  #!/usr/bin/perl
 # $RedRiver$  # $RedRiver: find_depends,v 1.11 2008/09/16 22:28:53 andrew Exp $
 use strict;  use strict;
 use warnings;  use warnings;
   
 # find www/ -name *.so* | xargs find_depends | sort -u | xargs -I {} cp {} /home/andrew/www{}  my %opts;
   my @Files;
   
   foreach (@ARGV) {
     if (/^-+(\w+)$/) {
       $opts{$1} = 1;
     } else {
       push @Files, $_;
     }
   }
   
 #use OpenBSD::PackageInfo;  Help()  if $opts{h} || $opts{help};
 #use OpenBSD::PackingList;  Usage() unless @Files;
 #use OpenBSD::SharedLibs;  
 #use Data::Dumper;  
   
 #my $dir = '/var/db/pkg';  my %libs;
 #my $pkg = 'p5-DBD-mysql-3.0002';  
 #my $pkg = 'p5-DBD-mysql';  
   
   foreach my $file (@Files) {
     my $l = find_libs($file);
   
     foreach (keys %{ $l }) {
 #my $file = shift || '/usr/local/libdata/perl5/site_perl/i386-openbsd/auto/DBD/mysql/mysql.so';      $libs{$_} = $l->{$_};
   
   
 die unless @ARGV;  
   
 my %libs;  
 foreach my $file (@ARGV) {  
   my $libs = find_libs($file);  
   #print Dumper $libs;  
   foreach (keys %{ $libs }) {  
     $libs{ $_ } = $libs->{$_};  
   }    }
 }  }
   
Line 37 
Line 33 
   
 exit;  exit;
   
 #OpenBSD::SharedLibs::add_system_libs('/');  sub Usage
   {
     print "Usage: $0 [-v] file [file2 [file3 [...]]]\n";
     exit;
   }
   
 #print installed_packages();  sub Help
 #print installed_name($pkg);  {
 #print info_names();    print <<EOL;
 #exit;  Hopefully finds all libraries that are required by an executable
   or shared library.
   
 #my $plist = OpenBSD::PackingList->from_installation($pkg) || die $!;  Usage:
     $0 [-v] file [file2 [file3 [...]]]
   
 #print Dumper $plist->{wantlib};  Example:
     find /var/www/ -name *.so* | xargs find_depends | \\
          sort -u | xargs -I {} cp {} /var/www{}
   EOL
   
 #print Dumper $OpenBSD::SharedLibs::registered_libs;    exit;
   }
   
 #foreach (@{ $plist->{wantlib} }) {  
 #  print Dumper $_->{name}, find_library($_->{name});  
 #}  
   
 #sub find_library  
 #{  
 #   my $spec = shift;  
 #   my @r;  
 #   OpenBSD::SharedLibs::add_system_libs('/');  
 #  
 #   my $lib = '/usr';  
 #   @r = OpenBSD::SharedLibs::lookup_libspec('/usr', $spec);  
 #   unless (@r) {  
 #               $lib = '/usr/X11R6';  
 #      @r = OpenBSD::SharedLibs::lookup_libspec('/usr/X11R6', $spec);  
 #   }  
 #   unless (@r) {  
 #      for my $pkg (installed_packages()) {  
 #          OpenBSD::SharedLibs::add_package_libs($pkg, 1);  
 #      }  
 #      $lib = '/usr/local';  
 #      @r = OpenBSD::SharedLibs::lookup_libspec('/usr/local', $spec);  
 #   }  
 #   return $lib, @r;  
 #}  
   
 sub find_libs  sub find_libs
 {  {
   my $file = shift;    my $file = shift;
   my $ld   = shift || get_ldconfig();    my $ld   = shift || get_ldconfig();
   my $locs = shift || {};    my $locs = shift || {};
   
   print STDERR "Finding libs for '$file'\n";    print STDERR "Finding libs for '$file'\n" if $opts{v};
   
   my @libs = search_file($file);    my @libs = search_file($file);
   foreach (@libs) {    foreach (@libs) {
     my ($name, $maj, $min) = $_ =~ /^([^\.]+)\.so\.(\d+)\.(\d+)$/;      my $spec;
     my $spec = 'l' . $name . '.' . $maj . '.' . $min;  
       if ($_ eq $file) {
           # We don't want to include the file we are looking in
           next;
       }
       elsif ( my ($name, $maj, $min) = $_ =~ /lib([^\/]+)\.so\.(\d+)\.(\d+)$/ ) {
           $spec = 'l' . $name . '.' . $maj . '.' . $min;
           if ($ld->{$spec}) {
               $locs->{$spec} = $ld->{$spec};
           }
       }
       elsif (-e $_) {
           $spec = $_;
           $locs->{$spec} = $spec;
       }
       else {
           next;
       }
   
     if (exists $ld->{$spec}) {      if (! $locs->{$spec}) {
       next if exists $locs->{$spec};        print STDERR "Couldn't find location for '$_' (file '$file')\n";
         next;
       }
   
       $locs->{$spec} = $ld->{$spec};      print "  Found '$spec' => '$locs->{$spec}'\n" if $opts{v};
   
       $locs = find_libs($locs->{$spec}, $ld, $locs);      $locs = find_libs($locs->{$spec}, $ld, $locs);
   
     } else {  
       warn "Couldn't find location for lib '$_'";  
     }  
   }    }
   
   return $locs;    return $locs;
Line 108 
Line 104 
 {  {
   my $file = shift;    my $file = shift;
   my @libs;    my @libs;
   
   open my $libs, '<', $file or die;    open my $libs, '-|', '/usr/bin/ldd', $file or die "Couldn't open ldd '$file': $!";
   local $/ = chr(0);  
   while (<$libs>) {    while (<$libs>) {
     if (m|^(/[^\w\/]+/)?lib(\S+)\.(\d+)\.(\d+)|) {      chomp;
       my ($path, $name, $major, $minor) = ($1, $2, $3, $4);      my ($spec) = (split(/\s+/, $_))[7];
       my $spec="$name.$major.$minor";      next if ! $spec;
       if (defined $path && $path ne '/usr/local/lib') {      next if $spec !~ m{^/}xms;
         $spec="$path/$spec";      push @libs, $spec;
       }  
       push @libs, $spec;  
     }  
   }    }
   close $libs;    close $libs;
   
Line 131 
Line 123 
   my $ldconfig = '/sbin/ldconfig';    my $ldconfig = '/sbin/ldconfig';
   my (%paths, %libs);    my (%paths, %libs);
   
   open my $ld, '-|', $ldconfig, '-r' or die;    open my $ld, '-|', $ldconfig, '-r'
       or die "Couldn't open pipe to ldconfig: $!";
   while (<$ld>) {    while (<$ld>) {
     chomp;      chomp;
     if (/search directories:\s+(.*)/) {      if (/search directories:\s+(.*)/) {

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.12

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>