=================================================================== RCS file: /cvs/openbsd/fill_chroot/find_depends,v retrieving revision 1.4 retrieving revision 1.12 diff -u -r1.4 -r1.12 --- openbsd/fill_chroot/find_depends 2005/12/21 18:37:38 1.4 +++ openbsd/fill_chroot/find_depends 2008/09/16 23:38:04 1.12 @@ -1,10 +1,8 @@ #!/usr/bin/perl -# $RedRiver: find_depends,v 1.3 2005/12/21 18:22:32 andrew Exp $ +# $RedRiver: find_depends,v 1.11 2008/09/16 22:28:53 andrew Exp $ use strict; use warnings; -use Data::Dumper; - my %opts; my @Files; @@ -68,19 +66,35 @@ my @libs = search_file($file); foreach (@libs) { - my ($name, $maj, $min) = $_ =~ /^([^\.]+)\.so\.(\d+)\.(\d+)$/; - my $spec = 'l' . $name . '.' . $maj . '.' . $min; + my $spec; + + 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}) { - next if exists $locs->{$spec}; + if (! $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; @@ -90,18 +104,14 @@ { my $file = shift; my @libs; - - open my $libs, '<', $file or die "Couldn't open lib '$file': $!"; - local $/ = chr(0); + + open my $libs, '-|', '/usr/bin/ldd', $file or die "Couldn't open ldd '$file': $!"; 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; - } + chomp; + my ($spec) = (split(/\s+/, $_))[7]; + next if ! $spec; + next if $spec !~ m{^/}xms; + push @libs, $spec; } close $libs;