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

Annotation of openbsd/fill_chroot/find_depends, Revision 1.2

1.1       andrew      1: #!/usr/bin/perl
1.2     ! andrew      2: # $RedRiver: find_depends,v 1.1 2005/12/21 18:04:06 andrew Exp $
1.1       andrew      3: use strict;
                      4: use warnings;
                      5:
1.2     ! andrew      6: # find /home/andrew/www/ -name *.so* | xargs find_depends | sort -u | xargs -I {} cp {} /home/andrew/www{}
1.1       andrew      7:
                      8: die unless @ARGV;
                      9:
                     10: my %libs;
1.2     ! andrew     11:
1.1       andrew     12: foreach my $file (@ARGV) {
1.2     ! andrew     13:   my $l = find_libs($file);
        !            14:
        !            15:   foreach (keys %{ $l }) {
        !            16:     $libs{$_} = $l->{$_};
1.1       andrew     17:   }
                     18: }
                     19:
                     20: foreach (keys %libs) {
                     21:   print $libs{$_}, "\n";
                     22: }
                     23:
                     24: exit;
                     25:
                     26: sub find_libs
                     27: {
                     28:   my $file = shift;
                     29:   my $ld   = shift || get_ldconfig();
                     30:   my $locs = shift || {};
                     31:
                     32:   print STDERR "Finding libs for '$file'\n";
                     33:
                     34:   my @libs = search_file($file);
                     35:   foreach (@libs) {
                     36:     my ($name, $maj, $min) = $_ =~ /^([^\.]+)\.so\.(\d+)\.(\d+)$/;
                     37:     my $spec = 'l' . $name . '.' . $maj . '.' . $min;
                     38:
                     39:     if (exists $ld->{$spec}) {
                     40:       next if exists $locs->{$spec};
                     41:
                     42:       $locs->{$spec} = $ld->{$spec};
                     43:
                     44:       $locs = find_libs($locs->{$spec}, $ld, $locs);
                     45:
                     46:     } else {
                     47:       warn "Couldn't find location for lib '$_'";
                     48:     }
                     49:   }
                     50:
                     51:   return $locs;
                     52: }
                     53:
                     54: sub search_file
                     55: {
                     56:   my $file = shift;
                     57:   my @libs;
                     58:
                     59:   open my $libs, '<', $file or die;
                     60:   local $/ = chr(0);
                     61:   while (<$libs>) {
                     62:     if (m|^(/[^\w\/]+/)?lib(\S+)\.(\d+)\.(\d+)|) {
                     63:       my ($path, $name, $major, $minor) = ($1, $2, $3, $4);
                     64:       my $spec="$name.$major.$minor";
                     65:       if (defined $path && $path ne '/usr/local/lib') {
                     66:         $spec="$path/$spec";
                     67:       }
                     68:       push @libs, $spec;
                     69:     }
                     70:   }
                     71:   close $libs;
                     72:
                     73:   return @libs;
                     74: }
                     75:
                     76: sub get_ldconfig
                     77: {
                     78:   my $ldconfig = '/sbin/ldconfig';
                     79:   my (%paths, %libs);
                     80:
                     81:   open my $ld, '-|', $ldconfig, '-r' or die;
                     82:   while (<$ld>) {
                     83:     chomp;
                     84:     if (/search directories:\s+(.*)/) {
                     85:         #search directories: /usr/lib:/usr/local/lib
                     86:       my @p = split /:/, $1;
                     87:       @paths{@p} = 1;
                     88:     } elsif (/\d+:-(\S+)\s+=>\s+(\S+)/) {
                     89:              #0:-ldes.9.0 => /usr/lib/libdes.so.9.0
                     90:       my $lib = $1;
                     91:       my $loc = $2;
                     92:       #my ($name, $maj, $min) = $lib =~ /l([^\.]+)\.(\d+)\.(\d+)/;
                     93:       #my $spec = 'lib' . $name . '.so.' . $maj . '.' . $min;
                     94:       $libs{$lib} = $loc;
                     95:     } else {
                     96:       #print $_, "\n";
                     97:     }
                     98:   }
                     99:   close $ld;
                    100:
                    101:   $libs{_paths} = [ keys %paths ];
                    102:   return \%libs;
                    103: }

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