=================================================================== RCS file: /cvs/openbsd/fill_chroot/find_depends,v retrieving revision 1.3 retrieving revision 1.13 diff -u -r1.3 -r1.13 --- openbsd/fill_chroot/find_depends 2005/12/21 18:22:32 1.3 +++ openbsd/fill_chroot/find_depends 2008/09/30 21:54:01 1.13 @@ -1,115 +1,26 @@ -#!/usr/bin/perl -# $RedRiver: find_depends,v 1.2 2005/12/21 18:16:03 andrew Exp $ -use strict; -use warnings; +#!/bin/sh +# $RedRiver$ -# find /home/andrew/www/ -name *.so* | xargs find_depends \ -# | sort -u | xargs -I {} cp {} /home/andrew/www{} +find_depends() { + local _file="$1" + local _line -my @Files; -my %opts; + test -z "$_file" && continue -foreach (@ARGV) { - if (/^-(\w+)$/) { - $opts{$1} = 1; - } else { - push @Files, $_; - } -} + /usr/bin/ldd "$_file" | awk '$7 ~ /^\// { print $7 }' | { + while read _line; do + test -z "$_line" && continue + echo $_line -die unless @Files; - -my %libs; - -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 '$_'"; + test X"$_file" == X"$_line" && continue + find_depends "$_line" + done } - } - - return $locs; } -sub search_file { - my $file = shift; - my @libs; + for f in "$@"; do + 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; -}