[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.3 and 1.14

version 1.3, 2005/12/21 18:22:32 version 1.14, 2011/08/09 01:13:54
Line 1 
Line 1 
 #!/usr/bin/perl  #!/bin/sh
 # $RedRiver: find_depends,v 1.2 2005/12/21 18:16:03 andrew Exp $  # $AFresh1$
 use strict;  
 use warnings;  
   
 # find /home/andrew/www/ -name *.so* | xargs find_depends \  find_depends() {
 #      | sort -u | xargs -I {} cp {} /home/andrew/www{}      local _file="$1"
       local _line
   
 my @Files;      test -z "$_file" && continue
 my %opts;  
   
 foreach (@ARGV) {      /usr/bin/ldd "$_file" | awk '$7 ~ /^\// { print $7 }' | {
   if (/^-(\w+)$/) {          while read _line; do
     $opts{$1} = 1;              test -z "$_line"            && continue
   } else {              echo $_line
     push @Files, $_;  
   }  
 }  
   
 die unless @Files;              test X"$_file" == X"$_line" && continue
               find_depends "$_line"
 my %libs;          done
   
 foreach my $file (@Files) {  
   my $l = find_libs($file);  
   
   foreach (keys %{ $l }) {  
     $libs{$_} = $l->{$_};  
   }  
 }  
   
 foreach (keys %libs) {  
   print $libs{$_}, "\n";  
 }  
   
 exit;  
   
 sub find_libs  
 {  
   my $file = shift;  
   my $ld   = shift || get_ldconfig();  
   my $locs = shift || {};  
   
   print STDERR "Finding libs for '$file'\n" unless $opts{q};  
   
   my @libs = search_file($file);  
   foreach (@libs) {  
     my ($name, $maj, $min) = $_ =~ /^([^\.]+)\.so\.(\d+)\.(\d+)$/;  
     my $spec = 'l' . $name . '.' . $maj . '.' . $min;  
   
     if (exists $ld->{$spec}) {  
       next if exists $locs->{$spec};  
   
       $locs->{$spec} = $ld->{$spec};  
   
       $locs = find_libs($locs->{$spec}, $ld, $locs);  
   
     } else {  
       warn "Couldn't find location for lib '$_'";  
     }      }
   }  
   
   return $locs;  
 }  }
   
 sub search_file  
 {  {
   my $file = shift;      for f in  "$@"; do
   my @libs;          find_depends "$f"
       done
   } | sort -u
   
   open my $libs, '<', $file or die;  
   local $/ = chr(0);  
   while (<$libs>) {  
     if (m|^(/[^\w\/]+/)?lib(\S+)\.(\d+)\.(\d+)|) {  
       my ($path, $name, $major, $minor) = ($1, $2, $3, $4);  
       my $spec="$name.$major.$minor";  
       if (defined $path && $path ne '/usr/local/lib') {  
         $spec="$path/$spec";  
       }  
       push @libs, $spec;  
     }  
   }  
   close $libs;  
   
   return @libs;  
 }  
   
 sub get_ldconfig  
 {  
   my $ldconfig = '/sbin/ldconfig';  
   my (%paths, %libs);  
   
   open my $ld, '-|', $ldconfig, '-r' or die;  
   while (<$ld>) {  
     chomp;  
     if (/search directories:\s+(.*)/) {  
         #search directories: /usr/lib:/usr/local/lib  
       my @p = split /:/, $1;  
       @paths{@p} = 1;  
     } elsif (/\d+:-(\S+)\s+=>\s+(\S+)/) {  
              #0:-ldes.9.0 => /usr/lib/libdes.so.9.0  
       my $lib = $1;  
       my $loc = $2;  
       #my ($name, $maj, $min) = $lib =~ /l([^\.]+)\.(\d+)\.(\d+)/;  
       #my $spec = 'lib' . $name . '.so.' . $maj . '.' . $min;  
       $libs{$lib} = $loc;  
     } else {  
       #print $_, "\n";  
     }  
   }  
   close $ld;  
   
   $libs{_paths} = [ keys %paths ];  
   return \%libs;  
 }  

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.14

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