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

Annotation of openbsd/fill_chroot/find_depends, Revision 1.3

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

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