=================================================================== RCS file: /cvs/openbsd/fill_chroot/find_depends,v retrieving revision 1.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- openbsd/fill_chroot/find_depends 2008/09/16 23:38:04 1.12 +++ openbsd/fill_chroot/find_depends 2008/09/30 21:54:01 1.13 @@ -1,149 +1,26 @@ -#!/usr/bin/perl -# $RedRiver: find_depends,v 1.11 2008/09/16 22:28:53 andrew Exp $ -use strict; -use warnings; +#!/bin/sh +# $RedRiver$ -my %opts; -my @Files; +find_depends() { + local _file="$1" + local _line -foreach (@ARGV) { - if (/^-+(\w+)$/) { - $opts{$1} = 1; - } else { - push @Files, $_; - } -} + test -z "$_file" && continue -Help() if $opts{h} || $opts{help}; -Usage() unless @Files; + /usr/bin/ldd "$_file" | awk '$7 ~ /^\// { print $7 }' | { + while read _line; do + test -z "$_line" && continue + echo $_line -my %libs; - -foreach my $file (@Files) { - my $l = find_libs($file); - - foreach (keys %{ $l }) { - $libs{$_} = $l->{$_}; - } -} - -foreach (keys %libs) { - print $libs{$_}, "\n"; -} - -exit; - -sub Usage -{ - print "Usage: $0 [-v] file [file2 [file3 [...]]]\n"; - exit; -} - -sub Help -{ - print <{$spec}) { - $locs->{$spec} = $ld->{$spec}; - } - } - elsif (-e $_) { - $spec = $_; - $locs->{$spec} = $spec; - } - else { - next; - } - - if (! $locs->{$spec}) { - print STDERR "Couldn't find location for '$_' (file '$file')\n"; - next; - } - - print " Found '$spec' => '$locs->{$spec}'\n" if $opts{v}; - - $locs = find_libs($locs->{$spec}, $ld, $locs); - - } - - return $locs; } -sub search_file { - my $file = shift; - my @libs; - - open my $libs, '-|', '/usr/bin/ldd', $file or die "Couldn't open ldd '$file': $!"; - while (<$libs>) { - chomp; - my ($spec) = (split(/\s+/, $_))[7]; - next if ! $spec; - next if $spec !~ m{^/}xms; - push @libs, $spec; - } - close $libs; + for f in "$@"; do + find_depends "$f" + done +} | sort -u - return @libs; -} - -sub get_ldconfig -{ - my $ldconfig = '/sbin/ldconfig'; - my (%paths, %libs); - - open my $ld, '-|', $ldconfig, '-r' - or die "Couldn't open pipe to ldconfig: $!"; - 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; -}